Exemplo n.º 1
0
            public void should_do_nothing_when_unexposed_if_not_exposed()
            {
                SimCapiString simCapiString = new SimCapiString("InitialValue");

                string exposedName = "exposeName";

                simCapiString.unexpose();

                Dictionary <string, SimCapiValue> _outGoingMap =
                    TestHelpers.getReferenceField <Dictionary <string, SimCapiValue> >(_transporter, "_outGoingMap");

                Assert.AreNotEqual(null, _outGoingMap);
                Assert.AreEqual(false, _outGoingMap.ContainsKey(exposedName));
            }
Exemplo n.º 2
0
            public void should_error_when_try_to_expose_twice()
            {
                SimCapiString simCapiString = new SimCapiString("InitialValue");

                string exposedName = "exposeName";

                simCapiString.expose(exposedName, true, true);

                Assert.Catch(
                    delegate()
                {
                    simCapiString.expose(exposedName, true, true);
                });
            }
Exemplo n.º 3
0
            public void should_expose_value()
            {
                SimCapiString simCapiString = new SimCapiString("InitialValue");

                string exposedName = "exposeName";

                simCapiString.expose(exposedName, true, true);

                Dictionary <string, SimCapiValue> _outGoingMap =
                    TestHelpers.getReferenceField <Dictionary <string, SimCapiValue> >(_transporter, "_outGoingMap");

                Assert.AreNotEqual(null, _outGoingMap);
                Assert.AreEqual(true, _outGoingMap.ContainsKey(exposedName));
            }
Exemplo n.º 4
0
    void Awake()
    {
        CurrentState = new SimCapiString("");
        CurrentState.expose("State.Current", true, false);
        CurrentState.setChangeDelegate(
            delegate(string value, ChangedBy changedBy)
        {
            // Internal updates
            if (changedBy == ChangedBy.SIM)
            {
                return;
            }
            CurrentState.setValue(value);
            this.Current = value;
        }
            );

        // Intialize prior state list. Individual items are added at run-time.
        savedStates = new List <SimCapiString>();
    }
Exemplo n.º 5
0
            public void should_call_on_change_delegate()
            {
                SimCapiString simCapiString = new SimCapiString("InitialValue");

                string exposedName = "exposeName";

                simCapiString.expose(exposedName, true, true);

                bool changeDelegateCalled = false;
                bool correctValue         = false;

                string newValue = "newValue";


                simCapiString.setChangeDelegate(
                    delegate(string value, ChangedBy changedBy)
                {
                    changeDelegateCalled = true;

                    if (value == newValue)
                    {
                        correctValue = true;
                    }
                });

                // Create the VALUE_CHANGE message
                SimCapiValue simCapiValue = new SimCapiValue(exposedName, SimCapiValueType.STRING, false, false, false, new StringData(newValue));
                Dictionary <string, SimCapiValue> valueDictionary = new Dictionary <string, SimCapiValue>();

                valueDictionary.Add(exposedName, simCapiValue);

                string valueChangedJson = SimCapiJsonMaker.create_VALUE_CHANGE(_transporter.getHandshake(), valueDictionary);

                _transporter.reciveJsonMessage(valueChangedJson);

                Assert.AreEqual(true, changeDelegateCalled);
                Assert.AreEqual(true, correctValue);
            }
Exemplo n.º 6
0
    /// <summary>
    /// Saves the current state to a save slot.
    /// </summary>
    public void Save()
    {
        string state = Current;

        // Ignore save is state has not changed from last save.
        if (state == GetLastSave())
        {
            return;
        }

        SimCapiString capi = new SimCapiString("");

        capi.expose("State.History." + NextId, false, false);
        capi.setValue(state);
        savedStates.Add(capi);
        NextId++;

        // Remove oldest state (except original) if more prior states exist then the PRIOR_STATE_LIMIT.
        if (savedStates.Count > SAVE_STATE_LIMIT)
        {
            savedStates[1].unexpose();
            savedStates.RemoveAt(1);
        }
    }
Exemplo n.º 7
0
    public void Init(int id)
    {
        Id = id;

        string baseName = "Body." + id;

        capiName = new SimCapiString(name);
        capiName.expose(baseName + ".Name", false, false);
        capiName.setChangeDelegate(
            delegate(string value, SimCapi.ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Name = value;
            }
        }
            );

        capiActive = new SimCapiBoolean(active);
        capiActive.expose(baseName + ".Active", false, false);
        capiActive.setChangeDelegate(
            delegate(bool value, SimCapi.ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Active = value;
            }
        }
            );

        capiType = new SimCapiEnum <BodyType>(type);
        capiType.expose(baseName + ".Type", false, false);
        capiType.setChangeDelegate(
            delegate(BodyType value, SimCapi.ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Type = value;
            }
        }
            );

        capiMaterial = new SimCapiEnum <BodyMaterial>(material);
        capiMaterial.expose(baseName + ".Material", false, false);
        capiMaterial.setChangeDelegate(
            delegate(BodyMaterial value, SimCapi.ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Material = value;
            }
        }
            );

        capiMass = new SimCapiNumber((float)mass);
        capiMass.expose(baseName + ".Mass", false, false);
        capiMass.setChangeDelegate(
            delegate(float value, SimCapi.ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Mass = value;
            }
        }
            );

        capiDiameter = new SimCapiNumber((float)diameter);
        capiDiameter.expose(baseName + ".Diameter", false, false);
        capiDiameter.setChangeDelegate(
            delegate(float value, SimCapi.ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Diameter = value;
            }
        }
            );

        capiRotation = new SimCapiNumber((float)rotation);
        capiRotation.expose(baseName + ".Rotation", false, false);
        capiRotation.setChangeDelegate(
            delegate(float value, SimCapi.ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Rotation = value;
            }
        }
            );

        // Set Capi Vectors. Exposure and Delegation are handled interally.
        capiPosition = new SimCapiVector(baseName + ".Position", Position);
        capiVelocity = new SimCapiVector(baseName + ".Velocity", Velocity);

        //Auto velocity
        capiAutoVelocity = new SimCapiBoolean(!initialVelocity);
        capiAutoVelocity.expose(baseName + ".Velocity.Auto", false, false);
        capiAutoVelocity.setChangeDelegate(
            delegate(bool value, SimCapi.ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                InitialVelocity = !value;
            }
        }
            );
    }