public SimCapiValue(string key, SimCapiValueType type, bool isReadonly, bool isWriteonly, bool exposed, SimCapiData simCapiData, string[] allowedValues = null)
 {
     _key           = key;
     _type          = type;
     _isReadonly    = isReadonly;
     _isWriteonly   = isWriteonly;
     _exposed       = exposed;
     _value         = simCapiData;
     _allowedValues = allowedValues;
 }
Exemplo n.º 2
0
            public static SimCapiValue createUnitySimCapiValue(JProperty values)
            {
                JToken p_key            = values.Value["key"];
                JToken p_type           = values.Value["type"];
                JToken p_value          = values.Value["value"];
                JToken p_is_read_only   = values.Value["readonly"];
                JToken p_is_write_only  = values.Value["writeonly"];
                JToken p_allowed_values = values.Value["allowedValues"];

                //JToken p_bind_to = values.Value["bindTo"];

                // Check all needed value exist
                if (p_key == null)
                {
                    return(null);
                }

                if (p_type == null)
                {
                    return(null);
                }

                if (p_value == null)
                {
                    return(null);
                }

                if (p_is_read_only == null)
                {
                    return(null);
                }

                if (p_is_write_only == null)
                {
                    return(null);
                }

                if (p_allowed_values == null)
                {
                    return(null);
                }


                SimCapiValueType type_value = p_type.ToObject <SimCapiValueType>();

                string key           = p_key.ToObject <string>();
                bool   is_read_only  = p_is_read_only.ToObject <bool>();
                bool   is_write_only = p_is_write_only.ToObject <bool>();


                switch (type_value)
                {
                case SimCapiValueType.NUMBER:
                {
                    float value = p_value.ToObject <float>();
                    return(new SimCapiValue(key, SimCapiValueType.NUMBER, is_read_only, is_write_only, false, new NumberData(value)));
                }

                case SimCapiValueType.STRING:
                {
                    string value = p_value.ToObject <string>();
                    return(new SimCapiValue(key, SimCapiValueType.STRING, is_read_only, is_write_only, false, new StringData(value)));
                }

                case SimCapiValueType.ARRAY:
                {
                    if (p_value.Type == JTokenType.Array)
                    {
                        string[] arrayString = getStringArray(p_value);
                        return(new SimCapiValue(key, SimCapiValueType.ARRAY, is_read_only, is_write_only, false, new ArrayData(arrayString)));
                    }
                    if (p_value.Type == JTokenType.String)
                    {
                        string arrayAsString = p_value.ToString();
                        return(new SimCapiValue(key, SimCapiValueType.ARRAY, is_read_only, is_write_only, false, new StringData(arrayAsString)));
                    }


                    throw new System.Exception("Invalid SimCapiValueType.ARRAY, must be an Array or String!");
                }

                case SimCapiValueType.BOOLEAN:
                {
                    bool value = p_value.ToObject <bool>();
                    return(new SimCapiValue(key, SimCapiValueType.BOOLEAN, is_read_only, is_write_only, false, new BoolData(value)));
                }

                case SimCapiValueType.ENUM:
                {
                    string value = p_value.ToObject <string>();

                    string[] allowedValues = getStringArray(values.Value["allowedValues"]);

                    if (allowedValues == null)
                    {
                        throw new System.Exception("Invalid SimCapiEnum allowedValues array, must be a string array!");
                    }

                    return(new SimCapiValue(key, SimCapiValueType.ENUM, is_read_only, is_write_only, false, new StringData(value), allowedValues));
                }

                case SimCapiValueType.MATH_EXPR:
                {
                    string value = p_value.ToObject <string>();
                    return(new SimCapiValue(key, SimCapiValueType.MATH_EXPR, is_read_only, is_write_only, false, new StringData(value)));
                }

                case SimCapiValueType.ARRAY_POINT:
                    return(null);
                }



                return(null);
            }