Пример #1
0
        void SetEffectProperty(IFx fx, string classname, string property, JsonValue jsonv)
        {
            var pi = fx.GetType().GetRuntimeProperty(property);

            if (null == pi)
            {
                throw new JsonEffectParameterUnknownException(classname, jsonv);
            }
            // check for configurable
            var ca = pi.GetCustomAttribute <ConfigurableAttribute>(true);

            if (null == ca)
            {
                throw new JsonEffectParameterNotConfigurableException(classname, jsonv);
            }
            // a JSON object as the value is always some complex solution, probably a control
            if (JsonValueKind.Object == jsonv.ValueKind)
            {
                var vctl = jsonv.AsObject()["Control"];
                if (!Program.Controls.TryGetValue(vctl.AsString(), out IControlVariable ctl))
                {
                    throw new JsonEffectParameterControlReferenceUnknown(vctl);
                }
                // grab the current value
                ca.SetObjectProperty(fx, pi, ctl.Value, false);
                // set up for change triggers
                ctl.ValueChanged += (s, e) => ca.SetObjectProperty(fx, pi, ctl.Value, false);
            }
            else
            {
                // the property determines JSON interpretation
                switch (pi.PropertyType.Name)
                {
                //case "String": -- lolwut?
                //	break;
                case "Int32":
                case "Int64":
                case "Double":
                case "Single":
                    // test limits
                    try {
                        ca.SetObjectProperty(fx, pi, jsonv.AsNumber(), true);
                    }
                    catch (Exception ex) {
                        throw new JsonEffectParameterValueOutOfRangeException(classname, jsonv, ex.Message);
                    }
                    break;

                case "Color":
                    // @todo: colour property parsing
                    break;
                }
            }
        }