示例#1
0
            public void should_do_nothing_when_unexposed_if_not_exposed()
            {
                SimCapiNumber simCapiNumber = new SimCapiNumber(2);

                string exposedName = "exposeName";

                simCapiNumber.unexpose();

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

                Assert.AreNotEqual(null, _outGoingMap);
                Assert.AreEqual(false, _outGoingMap.ContainsKey(exposedName));
            }
示例#2
0
            public void should_error_when_try_to_expose_twice()
            {
                SimCapiNumber simCapiNumber = new SimCapiNumber(2);

                string exposedName = "exposeName";

                simCapiNumber.expose(exposedName, true, true);

                Assert.Catch(
                    delegate()
                {
                    simCapiNumber.expose(exposedName, true, true);
                });
            }
示例#3
0
            public void should_expose_value()
            {
                SimCapiNumber simCapiNumber = new SimCapiNumber(2);

                string exposedName = "exposeName";

                simCapiNumber.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));
            }
    /// <summary>
    /// Sets initial values.
    /// </summary>
    public void Init()
    {
        capiPaused = new SimCapiBoolean(Sim.Settings.Paused);
        capiPaused.expose("Speed.Pause", false, false);
        capiPaused.setChangeDelegate(
            delegate(Boolean value, ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Sim.Settings.Paused = value;
            }
        }
            );

        capiSpeedTime = new SimCapiNumber((float)Sim.Settings.Speed);
        capiSpeedTime.expose("Speed.Time", false, false);
        capiSpeedTime.setChangeDelegate(
            delegate(float value, ChangedBy changedBy)
        {
            // Debug.Log("Speed.Time " + value + " " + changedBy);
            // Any changes done by the SIM go through the Body system first, which updates the Exposed Data.
            if (changedBy == ChangedBy.AELP)
            {
                Sim.Settings.Speed = value * (int)capiSpeedRatio.getValue();
            }
        }
            );

        capiSpeedRatio = new SimCapiEnum <SpeedRatio>(SpeedRatio.Second);
        capiSpeedRatio.expose("Speed.Ratio", false, false);
        capiSpeedRatio.setChangeDelegate(
            delegate(SpeedRatio value, ChangedBy changedBy)
        {
            if (changedBy == ChangedBy.AELP)
            {
                Sim.Settings.Speed = capiSpeedTime.getValue() * (int)value;
            }
        }
            );
    }
    /// <summary>
    /// Generate a Capi vector.
    /// </summary>
    /// <param name="name">Base Name. NAME_SUFFIX will be added to each axis.</param>
    /// <param name="vector">Linked Vector</param>
    /// <param name="readOnly">If exposed value is read-only.</param>
    /// <param name="writeOnly">If exposed value is write-only.</param>
    public SimCapiVector(string name, Vector3d vector, bool readOnly, bool writeOnly)
    {
        capiAxis    = new SimCapiNumber[3];
        this.vector = vector;

        // Create, Expose, and initiate
        for (int i = 0; i < 3; i++)
        {
            int axis = i;
            capiAxis[axis] = new SimCapiNumber((float)vector[axis]);
            capiAxis[axis].expose(name + NAME_SUFFIX[axis], readOnly, writeOnly);
            capiAxis[axis].setChangeDelegate(
                delegate(float value, SimCapi.ChangedBy changedBy)
            {
                if (changedBy == ChangedBy.SIM)
                {
                    return;
                }
                vector[axis] = value;
                capiAxis[axis].setValue(value);
            }
                );
        }
    }
示例#6
0
            public void should_call_on_change_delegate()
            {
                SimCapiNumber simCapiNumber = new SimCapiNumber(2);

                string exposedName = "exposeName";

                simCapiNumber.expose(exposedName, true, true);

                bool changeDelegateCalled = false;
                bool correctValue         = false;


                simCapiNumber.setChangeDelegate(
                    delegate(float value, ChangedBy changedBy)
                {
                    changeDelegateCalled = true;

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

                // Create the VALUE_CHANGE message
                SimCapiValue simCapiValue = new SimCapiValue(exposedName, SimCapiValueType.STRING, false, false, false, new StringData("10"));
                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);
            }
    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;
            }
        }
            );
    }