Beispiel #1
0
        public void TestStateSetting()
        {
            FlatRedBall.PositionedObject directObjectReference =
                ((FlatRedBall.PositionedObject)mElementRuntime.ContainedElements[0].DirectObjectReference);
            directObjectReference.ForceUpdateDependencies();

            float yBefore = directObjectReference.Y;

            mElementRuntime.SetState("", false);

            directObjectReference.ForceUpdateDependencies();
            float yAfter = directObjectReference.Y;


            if (yBefore != yAfter)
            {
                throw new Exception("Setting an empty state modifies the position values when it shouldn't");
            }


            mContainerElementRuntime.SetState(mContainer.States[0].Name);

            mContainerElementRuntime.ContainedElements[0].ForceUpdateDependencies();
            if (mContainerElementRuntime.ContainedElements[0].X != 10.0f)
            {
                throw new Exception("Setting a state on a container which sets the state of a contained object seems to not be actually setting the state of the contained object.");
            }

            Sprite sprite = mContainerElementRuntime.ContainedElements[0].ContainedElements[0].DirectObjectReference as Sprite;

            if (sprite.ScaleX != 4.0f)
            {
                throw new Exception("Setting a state on a container which sets the state of a contained object, and that state sets a tunneled variable on a FRB type seems to not be working properly");
            }
        }
Beispiel #2
0
        public static void InterpolateBetween(ElementRuntime elementRuntime, object firstStateSaveAsObject, object secondStateSaveAsObject, object interpolationValueAsObject,
                                              StringBuilder logStringBuilder = null)
        {
            StateSave firstStateSave     = firstStateSaveAsObject as StateSave;
            StateSave secondStateSave    = secondStateSaveAsObject as StateSave;
            float     interpolationValue = 0;

            if (interpolationValueAsObject is float)
            {
                interpolationValue = (float)interpolationValueAsObject;
            }
            if (interpolationValueAsObject is double)
            {
                interpolationValue = (float)((double)interpolationValueAsObject);
            }
            else if (interpolationValueAsObject is int)
            {
                interpolationValue = (int)interpolationValueAsObject;
            }

            if (float.IsNaN(interpolationValue))
            {
                throw new Exception("InterpolationValue is NaN");
            }

            StateSave resultingStateSave = StateSaveExtensionMethodsGlueView.CreateCombinedState(firstStateSave, secondStateSave, interpolationValue);
            string    nameOfObject       = "unnamed object";

            if (elementRuntime.AssociatedNamedObjectSave != null)
            {
                nameOfObject = elementRuntime.AssociatedNamedObjectSave.ToString();
            }
            else if (elementRuntime.AssociatedIElement != null)
            {
                nameOfObject = elementRuntime.AssociatedIElement.ToString();
            }
            if (logStringBuilder != null)
            {
                logStringBuilder.AppendLine("Interpolating " + nameOfObject + " between " + firstStateSave + " and " + secondStateSave + " with value " + interpolationValue);

                foreach (InstructionSave instruction in resultingStateSave.InstructionSaves)
                {
                    logStringBuilder.AppendLine("\t" + instruction);
                }
            }

            try
            {
                elementRuntime.SetState(resultingStateSave, elementRuntime.AssociatedIElement);
            }
            catch (Exception e)
            {
                throw new StateSettingException("Error in script trying to interpolate " + nameOfObject + " between " + firstStateSave + " and " + secondStateSave + " with value " + interpolationValue);
            }
        }