Esempio n. 1
0
        public void expose(SimCapiValue simCapiValue)
        {
            string key = simCapiValue.key;


            if (_outGoingMap.ContainsKey(key) && _outGoingMap[key].exposed == true)
            {
                return;
            }


            // Set the value to be exposed
            simCapiValue.exposed = true;

            // Override the value with the one already in the map
            if (_outGoingMap.ContainsKey(key) && _outGoingMap[key].exposed == false)
            {
                simCapiValue = _outGoingMap[key];
                List <SimCapiValue> changedList = new List <SimCapiValue>();
                changedList.Add(simCapiValue);
                callChangeListeners(changedList);
            }

            // add it to the map
            _outGoingMap[key] = simCapiValue;

            notifyValueChange();
        }
Esempio n. 2
0
            public static ValueChange create(JObject jObject)
            {
                JProperty handshake = jObject.Property("handshake");
                JProperty values    = jObject.Property("values");

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

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

                ValueChange valueChange = new ValueChange();

                valueChange.handshake = handshake.Value.ToObject <SimCapiHandshake>();

                foreach (JProperty property in values.Values())
                {
                    SimCapiValue simCapiValue = createUnitySimCapiValue(property);

                    if (simCapiValue != null)
                    {
                        valueChange.values.Add(simCapiValue.key, simCapiValue);
                    }
                }

                return(valueChange);
            }
Esempio n. 3
0
        public bool exposeValue(SimCapiExposableValue exposableValue, SimCapiValue simCapiValue)
        {
            if (_valueMap.ContainsKey(simCapiValue.key) == true)
            {
                throw new System.Exception("Value already exposed under the key/name: " + exposableValue.exposedName);
            }

            _valueMap[simCapiValue.key] = exposableValue;

            _transporter.expose(simCapiValue);

            return(true);
        }
Esempio n. 4
0
            public static ValueChange createWithJsonString(string jsonString)
            {
                JObject jObject = deserializeJson(jsonString);

                JProperty type      = jObject.Property("type");
                JProperty handshake = jObject.Property("handshake");
                JProperty values    = jObject.Property("values");

                if (type == null || type.Value == null || type.Value.Type != JTokenType.Integer)
                {
                    return(null);
                }

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

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

                SimCapiMessageType messageType = type.ToObject <SimCapiMessageType>();

                if (messageType != SimCapiMessageType.VALUE_CHANGE)
                {
                    return(null);
                }

                ValueChange valueChange = new ValueChange();

                valueChange.handshake = handshake.Value.ToObject <SimCapiHandshake>();

                foreach (JProperty property in values.Values())
                {
                    SimCapiValue simCapiValue = createUnitySimCapiValue(property);

                    if (simCapiValue != null)
                    {
                        valueChange.values.Add(simCapiValue.key, simCapiValue);
                    }
                }

                return(valueChange);
            }
Esempio n. 5
0
        public override void expose(string name, bool isReadonly, bool isWriteonly)
        {
            if (_exposedName != null)
            {
                throw new Exception("Value has alread been exposed as: " + _exposedName);
            }

            if (name == null)
            {
                throw new Exception("Exposed name cannot be null!");
            }

            SimCapiValue simCapiValue = new SimCapiValue(name, SimCapiValueType.ARRAY_POINT, isReadonly, isWriteonly, false, new StringData(arrayToString()));
            bool         exposed      = Transporter.getInstance().getModel().exposeValue(this, simCapiValue);

            if (exposed == true)
            {
                _exposedName = name;
            }
        }
Esempio n. 6
0
        void handleValueChangeMessage(Message.ValueChange valueChange)
        {
            if (valueChange.handshake.authToken != _handshake.authToken)
            {
                return;
            }

            List <SimCapiValue> changed_values = new List <SimCapiValue>();

            foreach (KeyValuePair <string, SimCapiValue> keyPair in valueChange.values)
            {
                string       key          = keyPair.Key;
                SimCapiValue simCapiValue = keyPair.Value;


                if (simCapiValue != null && !simCapiValue.isReadonly)
                {
                    bool exists_in_map = _outGoingMap.ContainsKey(key);

                    // Does the value exist in the map and are the values different?
                    if (exists_in_map == true && _outGoingMap[key].compare(simCapiValue) == false)
                    {
                        _outGoingMap[key].setValue(simCapiValue);

                        changed_values.Add(simCapiValue);
                    }
                    else if (exists_in_map == false)
                    {
                        simCapiValue.exposed = false;
                        _outGoingMap[key]    = simCapiValue;

                        changed_values.Add(simCapiValue);
                    }
                }
            }

            if (changed_values.Count > 0)
            {
                callChangeListeners(changed_values);
            }
        }
 public bool compare(SimCapiValue simCapiValue)
 {
     return(_value.compare(simCapiValue._value));
 }
 public void setValue(SimCapiValue simCapiValue)
 {
     setValueWithData(simCapiValue._value);
 }
Esempio n. 9
0
        void  updateValueInModel(SimCapiValue simCapiValue)
        {
            if (_valueMap.ContainsKey(simCapiValue.key) == false)
            {
                SimCapiConsole.log("Key not found in model");
                return;
            }

            SimCapiExposableValue exposableValue = _valueMap[simCapiValue.key];

            if (exposableValue == null)
            {
                SimCapiConsole.log("Error no linked exposed value, This should not occur");
                return;
            }

            if (exposableValue.GetType() == typeof(SimCapiNumber))
            {
                SimCapiNumber number = (SimCapiNumber)exposableValue;

                float?value = simCapiValue.value.getNumber();

                if (value == null)
                {
                    SimCapiExposableValue.invokeInvalidValueRecivedDelegate(exposableValue);
                }
                else
                {
                    SimCapiNumber.setInternalValue(number, value.Value);
                    SimCapiNumber.triggerChangeDelegate(number, ChangedBy.AELP);
                }
            }
            else if (exposableValue.GetType() == typeof(SimCapiString))
            {
                SimCapiString exposableString = (SimCapiString)exposableValue;
                SimCapiString.setInternalValue(exposableString, simCapiValue.value.ToString());
                SimCapiString.triggerChangeDelegate(exposableString, ChangedBy.AELP);
            }
            else if (exposableValue.GetType() == typeof(SimCapiStringArray))
            {
                SimCapiStringArray stringArray = (SimCapiStringArray)exposableValue;

                string[] sArray = simCapiValue.value.getStringArray();

                if (sArray == null)
                {
                    SimCapiExposableValue.invokeInvalidValueRecivedDelegate(exposableValue);
                }
                else
                {
                    stringArray.setWithStringArray(sArray);
                    SimCapiStringArray.triggerChangeDelegate(stringArray, ChangedBy.AELP);
                }
            }
            else if (exposableValue.GetType() == typeof(SimCapiBoolean))
            {
                SimCapiBoolean boolean = (SimCapiBoolean)exposableValue;

                bool?value = simCapiValue.value.getBool();

                if (value == null)
                {
                    SimCapiExposableValue.invokeInvalidValueRecivedDelegate(exposableValue);
                }
                else
                {
                    boolean.setValue(value.Value);
                    SimCapiBoolean.triggerChangeDelegate(boolean, ChangedBy.AELP);
                }
            }
            else if (typeof(SimCapiGenericEnum).IsAssignableFrom(exposableValue.GetType()))
            {
                SimCapiGenericEnum simCapiGenericEnum = (SimCapiGenericEnum)exposableValue;

                bool valid = SimCapiGenericEnum.setInternalValue(simCapiGenericEnum, simCapiValue.value.ToString());

                if (valid == false)
                {
                    UnityEngine.Debug.LogError("simCapiValue is not a valid Enum");
                    return;
                }
                else
                {
                    SimCapiGenericEnum.triggerChangeDelegate(simCapiGenericEnum, ChangedBy.AELP);
                }
            }
            else if (exposableValue.GetType() == typeof(SimCapiMathExpression))
            {
                SimCapiMathExpression mathExpression = (SimCapiMathExpression)exposableValue;
                SimCapiMathExpression.InternalUseOnly.setInternalValue(mathExpression, simCapiValue.value.ToString());
                SimCapiMathExpression.triggerChangeDelegate(mathExpression, ChangedBy.AELP);
            }
            else if (exposableValue.GetType() == typeof(SimCapiPointArray))
            {
                SimCapiPointArray pointArray = (SimCapiPointArray)exposableValue;

                UnityEngine.Vector2[] vector2Array = simCapiValue.value.getPointArray();

                if (vector2Array == null)
                {
                    SimCapiConsole.log("Invalid PointArrayData!");
                }
                else
                {
                    SimCapiPointArray.setInternalValue(pointArray, vector2Array);
                    SimCapiPointArray.triggerChangeDelegate(pointArray, ChangedBy.AELP);
                }
            }
            else
            {
                SimCapiConsole.log("Exposed value not set");
            }
        }