示例#1
0
        internal CameraValueModifier AddModifier(CameraState fromState, CameraValueModifier.ModifierTypes type, double amount, bool autoRemoveOnLeaveState = true, long autoRemoveDelay = 0)
        {
            if ((this.Flags & CameraValueFlags.NoModifiers) != CameraValueFlags.None)
            {
                return(null);
            }

            var  mod   = new CameraValueModifier(this, fromState, type, amount, autoRemoveOnLeaveState, autoRemoveDelay);
            bool added = false;

            for (int i = 0; i < this.Modifiers.Count; i++)
            {
                var m = this.Modifiers[i];
                if (m.Priority > mod.Priority)
                {
                    this.Modifiers.Insert(i, mod);
                    added = true;
                    break;
                }
            }

            if (!added)
            {
                this.Modifiers.Add(mod);
            }

            if (mod.AutoRemove && fromState != null)
            {
                fromState.RemoveModifiersOnLeave.Add(mod);
            }

            this.UpdatedCountWhenDisabled = 0;

            return(mod);
        }
        private void AddSetter(string keyword, double value, CameraValueModifier.ModifierTypes type, long removeDelay)
        {
            value = GetCameraValueAmount(keyword, value);
            var ls = GetCameraValues(keyword);

            foreach (var v in ls)
            {
                setters.Add(state => { v.AddModifier(state, type, value, true, removeDelay); });
            }
        }
示例#3
0
        internal bool LoadFrom(string keyword)
        {
            init_cv();

            var type   = typeof(Settings).GetType();
            var fields = type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            var props  = type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            var cf = new ConfigFile(keyword);

            cf.AddSetting("Priority", new Value((int)50), "Priority", "The priority of profile. Higher value means profile is loaded later and will overwrite others.");
            cf.AddSetting("Group", new Value((int)0), "Group", "The group of profile. Multiple profiles with same group ID can not be active at the same time. Only one profile (highest priority) from same group will be active (or none).");

            var cf2 = new ConfigFile(keyword);

            if (!cf2.Load())
            {
                return(false);
            }

            List <Tuple <ConfigEntry, System.Reflection.FieldInfo, System.Reflection.PropertyInfo> > valid = new List <Tuple <ConfigEntry, System.Reflection.FieldInfo, System.Reflection.PropertyInfo> >();

            foreach (var f in fields)
            {
                var attrs = f.GetCustomAttributes(typeof(ConfigValueAttribute), true);
                if (attrs == null || attrs.Length == 0)
                {
                    continue;
                }

                var a = attrs[0] as ConfigValueAttribute;
                if (a == null)
                {
                    continue;
                }

                if (cf2.GetValue(a.Keyword) == null)
                {
                    continue;
                }

                var val     = ToValue(f.FieldType, f.GetValue(Settings.Instance));
                var setting = cf.AddSetting(a.Keyword, val, a.Name, a.Description, a.Flags);
                valid.Add(new Tuple <ConfigEntry, System.Reflection.FieldInfo, System.Reflection.PropertyInfo>(setting, f, null));
            }

            foreach (var p in props)
            {
                var attrs = p.GetCustomAttributes(typeof(ConfigValueAttribute), true);
                if (attrs == null || attrs.Length == 0)
                {
                    continue;
                }

                var a = attrs[0] as ConfigValueAttribute;
                if (a == null)
                {
                    continue;
                }

                if (p.GetMethod == null || p.SetMethod == null)
                {
                    continue;
                }

                if (cf2.GetValue(a.Keyword) == null)
                {
                    continue;
                }

                var val     = ToValue(p.PropertyType, p.GetValue(Settings.Instance));
                var setting = cf.AddSetting(a.Keyword, val, a.Name, a.Description, a.Flags);
                valid.Add(new Tuple <ConfigEntry, System.Reflection.FieldInfo, System.Reflection.PropertyInfo>(setting, null, p));
            }

            if (valid.Count == 0)
            {
                return(false);
            }

            if (!cf.Load())
            {
                return(false);
            }

            foreach (var t in valid)
            {
                var val = t.Item1.CurrentValue;
                if (val == null)
                {
                    continue;
                }

                double dv = 0.0;
                if (!val.TryToDouble(out dv))
                {
                    continue;
                }

                var t2 = cf2.GetValue(t.Item1.Keyword + "_Type");
                CameraValueModifier.ModifierTypes settype = CameraValueModifier.ModifierTypes.Set;
                if (t2 != null)
                {
                    string tx = t2.ToString().ToLowerInvariant().Trim();
                    switch (tx)
                    {
                    case "set": settype = CameraValueModifier.ModifierTypes.Set; break;

                    case "add": settype = CameraValueModifier.ModifierTypes.Add; break;

                    case "multiply": settype = CameraValueModifier.ModifierTypes.Multiply; break;

                    case "force": settype = CameraValueModifier.ModifierTypes.Force; break;

                    case "setifpreviousishigherthanthis": settype = CameraValueModifier.ModifierTypes.SetIfPreviousIsHigherThanThis; break;

                    case "setifpreviousislowerthanthis": settype = CameraValueModifier.ModifierTypes.SetIfPreviousIsLowerThanThis; break;
                    }
                }

                long removeDelay = 0;
                t2 = cf2.GetValue(t.Item1.Keyword + "_RemoveDelay");
                if (t2 != null)
                {
                    long nx = 0;
                    if (t2.TryToInt64(out nx) && nx >= 0)
                    {
                        removeDelay = nx;
                    }
                }

                this.AddSetter(t.Item1.Keyword, dv, settype, removeDelay);
            }

            foreach (var pair in _cond_map)
            {
                string kw  = "Condition_" + pair.Key;
                var    val = cf2.GetValue(kw);
                if (val == null)
                {
                    continue;
                }

                double amt = 0.0;
                if (!val.TryToDouble(out amt))
                {
                    continue;
                }

                this.conditions.Add(new Tuple <double, _ConditionDelegate>(amt, pair.Value));
            }

            foreach (var pair in _cond_map2)
            {
                string kw  = "Condition_" + pair.Key;
                var    val = cf2.GetValue(kw);
                if (val == null)
                {
                    continue;
                }

                string amt = val.ToString();
                this.conditions2.Add(new Tuple <string, _ConditionDelegate2>(amt, pair.Value));
            }

            return(true);
        }