Paste #27552: Untitled Paste

Date: 2015/12/29 03:05:05 UTC-08:00
Type: Plain Text

View Raw Paste Download This Paste
Copy Link


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Frenetic.TagHandlers;
using Frenetic.TagHandlers.Objects;
using Voxalia.ServerGame.TagSystem.TagObjects;
using Voxalia.Shared;

namespace Voxalia.ServerGame.TagSystem.TagBases
{
    class ColorTagBase : TemplateTagBase
    {
        public ColorTagBase()
        {
            Name = "color";
        }

        public override string Handle(TagData data)
        {
            String[] val = data.GetModifier(0).Replace(" ", "").Split(',');
            if (val.Length != 4 && val.Length != 3)
            {
                return new TextTag("&{NULL}").Handle(data.Shrink());
            }
            double r = Utilities.StringToDouble(val[0]);
            double g = Utilities.StringToDouble(val[1]);
            double b = Utilities.StringToDouble(val[2]);
            double a = 1d;
            if (val.Length == 4)
            {
                a = Utilities.StringToDouble(val[3]);
            }
            return new ColorTag(Color.FromArgb(r, g, b, a)).Handle(data.Shrink());
        }
    }
}