Ejemplo n.º 1
0
        private static void AssignOverrideToOverride(IEnumerable <Exposed.Entry> entries, Override ovdBase, Override ovdOverride)
        /// Analog of AssignOverrideToFields, but overrides sub-graph defaults instead of generator fields
        {
            foreach (Exposed.Entry entry in entries)
            {
                if (!ovdBase.TryGetValue(entry.name, out Type origType, out object origVal))
                {
                    continue;
                }
                //do not override values that were not exposed

                if (origType != entry.type)
                {
                    continue;
                }
                //do not override if they are of the same type


                object            val;
                Calculator.Vector vec = entry.calculator.Calculate(ovdOverride);

                if (entry.channel == -1)                 //non-channel
                {
                    val = vec.Convert(entry.type);
                }
                else
                {
                    val = vec.ConvertToChannel(origVal, entry.channel, entry.type);
                }

                ovdBase[entry.name] = val;
            }
        }
Ejemplo n.º 2
0
        private static void AssignOverrideToFields(IUnit unit, Exposed exp, Override ovd)
        /// Assigns overriden values to standard (field) generator/layer
        {
            Type type = unit.GetType();

            foreach (Exposed.Entry entry in exp.EntriesById(unit.Id))
            {
                FieldInfo fieldInfo = type.GetField(entry.name);
                if (fieldInfo == null)
                {
                    continue;                     //might happen in biome, which has not fields, but ovd exposed
                }
                if (fieldInfo.FieldType != entry.type && !fieldInfo.FieldType.IsArray)
                {
                    throw new Exception("Recorded field type doesn't match generator field type. Possibly generator has changed.");
                }


                object            val;
                Calculator.Vector vec = entry.calculator.Calculate(ovd);

                if (entry.channel == -1)                 //non-channel
                {
                    val = vec.Convert(entry.type);
                }
                else
                {
                    object origVal = fieldInfo.GetValue(unit);                     //loading original value to take other channels
                    val = vec.ConvertToChannel(origVal, entry.channel, entry.type);
                }

                if (entry.arrIndex == -1)                 //non-array
                {
                    fieldInfo.SetValue(unit, val);
                }
                else if (unit is Nodes.MatrixGenerators.Blend200 blendGen)                 //special case for blend node
                {
                    blendGen.layers[entry.arrIndex].opacity = (float)val;
                }
                else                 //array
                {
                    Array arr = (Array)fieldInfo.GetValue(unit);
                    arr.SetValue(val, entry.arrIndex);
                    fieldInfo.SetValue(unit, arr);
                }
            }
        }