Beispiel #1
0
 public void Assign(Color color, float offset, RelativeColor source)
 {
     this.source = source;
     this.value  = color;
     this.offset = offset;
     this.Assign(source);
 }
Beispiel #2
0
        public RelativeColor Copy()
        {
            var copy = new RelativeColor(this.value, this.offset, this.source);

            copy.UseVariables(this);
            return(copy);
        }
Beispiel #3
0
 public void Assign(RelativeColor source)
 {
     if (!source.IsNull())
     {
         var alpha = this.value.a;
         this.value   = source.value;
         this.value.a = alpha;
     }
     this.source = source;
 }
Beispiel #4
0
        //=================================
        // Data
        //=================================
        public void Deserialize(string data)
        {
            if (data.IsEmpty())
            {
                return;
            }
            bool skipTexture = false;
            var  group       = "Default";
            var  sourceMap   = new Dictionary <string, string>();

            this.colors.Clear();
            foreach (var line in data.GetLines())
            {
                if (line.Trim().IsEmpty())
                {
                    continue;
                }
                if (line.Contains("("))
                {
                    group = line.Parse("(", ")");
                    continue;
                }
                if (line.Contains("["))
                {
                    group       = "Default";
                    skipTexture = line.Contains("[No", true) || line.Contains("[Skip", true);
                    continue;
                }
                var color = new RelativeColor().Deserialize(line);
                color.skipTexture = skipTexture;
                this.colors.AddNew(group)[color.name] = color;
                this.colors.AddNew("*")[color.name]   = color;
                sourceMap[color.name] = color.sourceName;
            }
            RelativeColor.UpdateSystem();
            foreach (var item in sourceMap)
            {
                if (item.Value.IsEmpty())
                {
                    continue;
                }
                this.colors["*"][item.Key].Assign(this, item.Value);
                if (this.colors["*"][item.Key].source == RelativeColor.system)
                {
                    this.usesSystem = true;
                }
            }
            foreach (var color in this.colors["*"])
            {
                color.Value.ApplyOffset();
            }
        }
Beispiel #5
0
        public Color ApplyOffset(bool allowBalance = true)
        {
            var processed = RelativeColor.lookupBuffer.Contains(this.source);

            if (!this.source.IsNull() && this.source != this && !processed)
            {
                RelativeColor.lookupBuffer.Add(this.source);
                var offset = this.offset;
                var source = this.source.ApplyOffset();
                RelativeColor.lookupBuffer.Remove(this.source);
                if (this.blendMode != ColorBlend.Normal)
                {
                    this.value = this.blend.Blend(source, this.blendMode, offset);
                    return(this.value);
                }
                if (offset != 1 && allowBalance && RelativeColor.autoBalance != AutoBalance.Off)
                {
                    var sourceIntensity = RelativeColor.autoBalance.Matches("Intensity") ? source.GetIntensity() : source.GetLuminance();
                    var result          = offset * sourceIntensity;
                    var tooDark         = sourceIntensity < 0.3f && result.Distance(sourceIntensity) < 0.2f;
                    var tooBright       = result > 1.25f;
                    if (tooDark)
                    {
                        var natural = source.ToVector3().normalized.ToColor();
                        source = natural.Lerp(source, sourceIntensity.InverseLerp(0, 0.2f));
                        if (sourceIntensity == 0)
                        {
                            source = new Color(0.25f, 0.25f, 0.25f);
                        }
                    }
                    var difference = source.Multiply(offset).Difference(source);
                    if (tooBright || difference < 0.05f)
                    {
                        offset = 1 / offset;
                    }
                }
                var alpha = this.value.a;
                this.value   = source.Multiply(offset);
                this.value.a = this.source.value.a == 1 ? alpha : this.value.a;
            }
            return(this.value);
        }
Beispiel #6
0
 public RelativeColor(Color color, float offset, RelativeColor source)
 {
     this.Assign(color, offset, source);
 }