void CreateContainerElementRuntime() { EntitySave containerEntitySave = new EntitySave { Name = "ContainerVariableSetting" }; ObjectFinder.Self.GlueProject.Entities.Add(containerEntitySave); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.Entity; nos.InstanceName = mEntitySave.Name + "Instance"; nos.SourceClassType = mEntitySave.Name; containerEntitySave.NamedObjects.Add(nos); nos.UpdateCustomProperties(); nos.SetPropertyValue("CurrentStateSaveCategoryState", "SecondState"); mContainedElementRuntime = new ElementRuntime(); mContainedElementRuntime.Initialize(containerEntitySave, null, null, null, null); // This thing is attached - we need to check its relativeX //if (mContainedElementRuntime.ContainedElements[0].X != -10.0f) if (mContainedElementRuntime.ContainedElements[0].RelativeX != -10.0f) { throw new Exception("Categorized states on contained NamedObjectSave Elements aren't setting values properly"); } }
public void TestSceneTypes() { EntitySave entitySave = new EntitySave(); entitySave.Name = "NosSceneTest"; NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.InstanceName = "NamedScene"; nos.SourceClassType = "Scene"; entitySave.NamedObjects.Add(nos); ElementRuntime elementRuntime = new ElementRuntime(); elementRuntime.Initialize(entitySave, null, null, null, null); if (elementRuntime.ContainedElements.Count == 0) { throw new Exception("ElementRuntimes with Scene NOS's should create ElementRuntimes for the Scene NOS"); } if (elementRuntime.ContainedElements[0].DirectObjectReference is Scene == false) { throw new Exception("Scene NOS's should create Scenes"); } if (((Scene)elementRuntime.ContainedElements[0].DirectObjectReference).Name != nos.InstanceName) { throw new Exception("Name on Scenes are not being set from NOS's"); } }
public void Initialize() { OverallInitializer.Initialize(); mBaseEntity = new EntitySave(); mBaseEntity.Name = "BaseEntityInheritanceTests"; ObjectFinder.Self.GlueProject.Entities.Add(mBaseEntity); NamedObjectSave nos = new NamedObjectSave(); nos.InstanceName = "SpriteInstance"; nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.SetByDerived = true; mBaseEntity.NamedObjects.Add(nos); nos = new NamedObjectSave(); nos.InstanceName = "RectInstance"; nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "AxisAlignedRectangle"; nos.ExposedInDerived = true; mBaseEntity.NamedObjects.Add(nos); mDerivedEntity = new EntitySave(); mDerivedEntity.Name = "DerivedentityInheritanceTests"; mDerivedEntity.BaseEntity = mBaseEntity.Name; mDerivedEntity.UpdateFromBaseType(); ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntity); mDerivedElementRuntime = new ElementRuntime(); mDerivedElementRuntime.Initialize(mDerivedEntity, null, null, null, null); }
private void CreateElementRuntime() { mElementRuntime = new ElementRuntime(); mElementRuntime.Initialize(mEntitySave, null, null, null, null); mContainerElementRuntime = new ElementRuntime(); mContainerElementRuntime.Initialize(mContainer, null, null, null, null); }
public void TestLayerOrthoValues() { EntitySave entitySave = new EntitySave(); entitySave.Name = "LayerTestTestLayerOrthoValuesEntity"; NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Layer"; nos.InstanceName = "Layer1"; nos.IndependentOfCamera = true; nos.Is2D = true; nos.LayerCoordinateUnit = LayerCoordinateUnit.Pixel; nos.LayerCoordinateType = LayerCoordinateType.MatchCamera; entitySave.NamedObjects.Add(nos); nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Layer"; nos.InstanceName = "Layer2"; nos.IndependentOfCamera = true; nos.Is2D = true; nos.LayerCoordinateUnit = LayerCoordinateUnit.Pixel; nos.LayerCoordinateType = LayerCoordinateType.MatchCamera; nos.DestinationRectangle = new FloatRectangle(0, 0, 80, 64); entitySave.NamedObjects.Add(nos); SpriteManager.Camera.Orthogonal = true; SpriteManager.Camera.OrthogonalWidth = 800; SpriteManager.Camera.OrthogonalHeight = 640; ElementRuntime elementRuntime = new ElementRuntime(); elementRuntime.Initialize(entitySave, null, null, null, null); Layer layer = (elementRuntime.ContainedElements[0].DirectObjectReference as Layer); if (layer.LayerCameraSettings.OrthogonalWidth != 800 || layer.LayerCameraSettings.OrthogonalHeight != 640) { throw new Exception("A Layer using MatchCamera coordinate types is not matching the Camera's ortho values"); } layer = (elementRuntime.ContainedElements[1].DirectObjectReference as Layer); if (layer.LayerCameraSettings.OrthogonalWidth != 80 || layer.LayerCameraSettings.OrthogonalHeight != 64) { throw new Exception("A Layer using MatchCamera with a destination rectangle does not have proper coordinates"); } }
public void TestRelativeAbsoluteConversion() { NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.UpdateCustomProperties(); nos.InstanceName = "SpriteObject"; nos.SetPropertyValue("ScaleX", 2.0f); nos.SetPropertyValue("X", 4.0f); nos.SetPropertyValue("RotationZ", 4.0f); nos.SetPropertyValue("RotationZVelocity", 4.0f); mEntitySave.NamedObjects.Add(nos); CustomVariable customVariable = new CustomVariable(); customVariable.SourceObject = nos.InstanceName; customVariable.SourceObjectProperty = "ScaleY"; customVariable.DefaultValue = 8.0f; mEntitySave.CustomVariables.Add(customVariable); ElementRuntime elementRuntime = new ElementRuntime(); elementRuntime.Initialize(mEntitySave, null, null, null, null); Sprite sprite = elementRuntime.ContainedElements[0].DirectObjectReference as Sprite; sprite.ForceUpdateDependencies(); if (elementRuntime.X != 0) { throw new Exception("NOS variables are being applied to the container instead of just to the NOS"); } if (sprite.X != 4.0f) { throw new Exception("Absolute values should get set when setting X on objects even though they're attached"); } if (sprite.RotationZ != 4.0f) { throw new Exception("Absolute values should get set when setting RotationZ on objects even though they're attached"); } if (sprite.RelativeRotationZVelocity != 4.0f) { throw new Exception("Setting RotationZVelocity should set RelativeRotationZVelocity"); } if (sprite.ScaleX != 2.0f) { throw new Exception("Scale values aren't properly showing up on Sprites"); } if (sprite.ScaleY != 8.0f) { throw new Exception("Scale values aren't properly showing up on Sprites"); } }
private void CreateDerivedElementRuntime() { mDerivedEntitySave = new EntitySave(); mDerivedEntitySave.Name = "DerivedVariableSettingEntity"; mDerivedEntitySave.BaseEntity = mEntitySave.Name; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntitySave); mDerivedEntitySave.UpdateFromBaseType(); mDerivedEntitySave.GetCustomVariable("CurrentState").DefaultValue = "Uncategorized"; mDerivedElementRuntime = new ElementRuntime(); mDerivedElementRuntime.Initialize(mDerivedEntitySave, null, null, null, null); }
public void TestScreenSave() { ElementRuntime er = new ElementRuntime(); er.Initialize(mScreenSave, null, null, null, null); float objectX = er.ContainedElements[0].X; if (objectX != 150) { throw new Exception("variables on named objects in Screens aren't being applied"); } }
public void TestPercentageLayers() { EntitySave entitySave = new EntitySave(); entitySave.Name = "LayerTestTestPercentageLayersEntity"; NamedObjectSave nos = new NamedObjectSave(); nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Layer"; nos.InstanceName = "PercentageLayer"; nos.IndependentOfCamera = true; nos.Is2D = true; nos.LayerCoordinateUnit = LayerCoordinateUnit.Percent; nos.LayerCoordinateType = LayerCoordinateType.MatchCamera; nos.DestinationRectangle = new FloatRectangle(0, 0, 10, 10); entitySave.NamedObjects.Add(nos); NamedObjectSave percentageLayerNos = nos; SpriteManager.Camera.Orthogonal = true; SpriteManager.Camera.OrthogonalWidth = 800; SpriteManager.Camera.OrthogonalHeight = 640; ElementRuntime elementRuntime = new ElementRuntime(); elementRuntime.Initialize(entitySave, null, null, null, null); var layer = (elementRuntime.ContainedElements[0].DirectObjectReference as Layer); float destinationWidth = layer.LayerCameraSettings.RightDestination - layer.LayerCameraSettings.LeftDestination; if (System.Math.Abs(destinationWidth - (percentageLayerNos.DestinationRectangle.Value.Width * Camera.Main.DestinationRectangle.Width / 100.0f)) > .01) { throw new Exception("Percentage based layers are not properly setting the destination rectangle"); } if (System.Math.Abs(layer.LayerCameraSettings.OrthogonalWidth - destinationWidth) > .01) { throw new Exception("Percentage based 2D layers are not properly setting their orthogonal values"); } }
public void TestStateVariables() { EntitySave entitySave = new EntitySave(); entitySave.Name = "CustomVariableTestStateVariableEntity"; ObjectFinder.Self.GlueProject.Entities.Add(entitySave); StateSaveCategory category1 = new StateSaveCategory(); category1.Name = "Category1"; category1.SharesVariablesWithOtherCategories = false; StateSave stateSave = new StateSave(); stateSave.Name = "Disabled"; category1.States.Add(stateSave); StateSaveCategory category2 = new StateSaveCategory(); category2.Name = "Category2"; category2.SharesVariablesWithOtherCategories = false; stateSave = new StateSave(); stateSave.Name = "Disabled"; category2.States.Add(stateSave); entitySave.StateCategoryList.Add(category1); entitySave.StateCategoryList.Add(category2); CustomVariable customVariable = new CustomVariable(); customVariable.Type = "Category2"; customVariable.DefaultValue = "Disabled"; customVariable.Name = "CurrentCategory2State"; entitySave.CustomVariables.Add(customVariable); ElementRuntime elementRuntime = new ElementRuntime(); elementRuntime.Initialize(entitySave, null, null, null, null); StateSave foundStateSave = elementRuntime.GetStateSaveFromCustomVariableValue(customVariable, customVariable.DefaultValue); if (foundStateSave != category2.States[0]) { throw new Exception("States in categories are not being found properly when referenced through custom variables"); } }
public void TestEventRaisingForNull() { var entitySave = new EntitySave { Name = "EventRaisingEntity" }; var xVariable = new CustomVariable { Name = "X", Type = "float", DefaultValue = "" }; entitySave.CustomVariables.Add(xVariable); mElementRuntime = new ElementRuntime(); mElementRuntime.Initialize(entitySave, null, null, null, null); mElementRuntime.AfterVariableApply += AfterVariableSet; }
void CreateParentElementRuntime() { EntitySave containerEntity = new EntitySave(); ObjectFinder.Self.GlueProject.Entities.Add(containerEntity); containerEntity.Name = "ContainerEntity"; NamedObjectSave first = new NamedObjectSave(); first.SourceType = SourceType.Entity; first.SourceClassType = "ExpressionParserTestEntity"; first.InstanceName = "FirstObject"; first.UpdateCustomProperties(); first.SetPropertyValue("CsvTypeVariable", "CsvValue1"); containerEntity.NamedObjects.Add(first); mParentElementRuntime = new ElementRuntime(); mParentElementRuntime.Initialize( containerEntity, null, null, null, null); }
private static ElementRuntime CreateNewOrGetExistingElementRuntime(NamedObjectSave namedObjectSave, Layer layerToPutOn, PositionedObjectList <ElementRuntime> listToPopulate, ElementRuntime parent) { ElementRuntime newOrExisting = null; for (int i = 0; i < listToPopulate.Count; i++) { if (listToPopulate[i].AssociatedNamedObjectSave == namedObjectSave) { newOrExisting = listToPopulate[i]; break; } } if (newOrExisting == null) { newOrExisting = new ElementRuntime(); newOrExisting.Initialize(null, layerToPutOn, namedObjectSave, parent.CreationOptions.OnBeforeVariableSet, parent.CreationOptions.OnAfterVariableSet); newOrExisting.Name = namedObjectSave.InstanceName; listToPopulate.Add(newOrExisting); } return(newOrExisting); }
void CreateElementRuntime(string name) { var entitySave = new EntitySave { Name = name }; ObjectFinder.Self.GlueProject.Entities.Add(entitySave); #region Create CustomVariables var xVariable = new CustomVariable { Name = "X", Type = "float", DefaultValue = 3.0f }; entitySave.CustomVariables.Add(xVariable); var yVariable = new CustomVariable { Name = "Y", Type = "float", DefaultValue = 4.0f }; entitySave.CustomVariables.Add(yVariable); var customVariable = new CustomVariable { Name = "SomeNewVar", Type = "double", DefaultValue = 3.333 }; entitySave.CustomVariables.Add(customVariable); var csvTypeVAriable = new CustomVariable { Name = "CsvTypeVariable", Type = "CsvType.csv", DefaultValue = null }; entitySave.CustomVariables.Add(csvTypeVAriable); var csvTypeVariable2 = new CustomVariable { Name = "EnemyInfoVariable", Type = "EnemyInfo.csv", DefaultValue = "Imp" }; entitySave.CustomVariables.Add(csvTypeVariable2); var scaleXVariable = new CustomVariable { Name = "ScaleX", Type = "float", DefaultValue = 10.0f }; entitySave.CustomVariables.Add(scaleXVariable); #endregion #region Create the NamedObjectsSave NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.InstanceName = "SpriteObject"; nos.UpdateCustomProperties(); nos.SetPropertyValue("ScaleX", 3.0f); entitySave.NamedObjects.Add(nos); #endregion #region Create the ReferencedFileSaves ReferencedFileSave rfs = new ReferencedFileSave(); rfs.Name = "Content/Entities/ReferencedFileSaveTestsBaseEntity/SceneFile.scnx"; entitySave.ReferencedFiles.Add(rfs); rfs = new ReferencedFileSave(); rfs.Name = "Content/EnemyInfo.csv"; rfs.CreatesDictionary = true; entitySave.ReferencedFiles.Add(rfs); #endregion mElementRuntime = new ElementRuntime() { X = (float)xVariable.DefaultValue, Y = (float)yVariable.DefaultValue }; mElementRuntime.Initialize(entitySave, null, null, null, null); #region Create the uncategorized states var leftX = new InstructionSave { Member = "X", Value = -10, Type = "float" }; var rightX = new InstructionSave { Member = "X", Value = 10, Type = "float" }; var someNewVarSetLeft = new InstructionSave { Member = "SomeNewVar", Value = -10.0, Type = "double" }; var someNewVarSetRight = new InstructionSave { Member = "SomeNewVar", Value = 10.0, Type = "double" }; var leftState = new StateSave { Name = "Left" }; leftState.InstructionSaves.Add(leftX); leftState.InstructionSaves.Add(someNewVarSetLeft); var rightState = new StateSave { Name = "Right" }; rightState.InstructionSaves.Add(rightX); rightState.InstructionSaves.Add(someNewVarSetRight); entitySave.States.Add(leftState); entitySave.States.Add(rightState); #endregion #region Create the categorized states StateSaveCategory category = new StateSaveCategory(); category.SharesVariablesWithOtherCategories = false; category.Name = "StateCategory"; var topY = new InstructionSave { Member = "Y", Value = 10, Type = "float" }; var bottomY = new InstructionSave { Member = "Y", Value = 10, Type = "float" }; var topState = new StateSave { Name = "Top" }; topState.InstructionSaves.Add(topY); var bottomState = new StateSave { Name = "Bottom" }; bottomState.InstructionSaves.Add(rightX); category.States.Add(topState); category.States.Add(bottomState); entitySave.StateCategoryList.Add(category); #endregion }
void CreateElementRuntime() { mEntitySave = new EntitySave { Name = "VariableSettingEntity" }; ObjectFinder.Self.GlueProject.Entities.Add(mEntitySave); var xVariable = new CustomVariable { Name = "X", Type = "float", DefaultValue = 0 }; mEntitySave.CustomVariables.Add(xVariable); // Needs the Z variable exposed so that the uncategorized state below can use it: var zVariable = new CustomVariable { Name = "Z", Type = "float", DefaultValue = 0 }; mEntitySave.CustomVariables.Add(zVariable); CustomVariable stateVariable = new CustomVariable { Name = "CurrentStateSaveCategoryState", Type = "StateSaveCategory", DefaultValue = "FirstState" }; stateVariable.SetByDerived = true; mEntitySave.CustomVariables.Add(stateVariable); CustomVariable uncategorizedStateVariable = new CustomVariable { Name = "CurrentState", Type = "VariableState", //DefaultValue = "Uncategorized", // Don't set a default value - the derived will do this SetByDerived = true }; mEntitySave.CustomVariables.Add(uncategorizedStateVariable); StateSave uncategorized = new StateSave(); uncategorized.Name = "Uncategorized"; InstructionSave instruction = new InstructionSave(); instruction.Member = "Z"; instruction.Value = 8.0f; uncategorized.InstructionSaves.Add(instruction); mEntitySave.States.Add(uncategorized); StateSave stateSave = new StateSave(); stateSave.Name = "FirstState"; instruction = new InstructionSave(); instruction.Member = "X"; instruction.Value = 10; stateSave.InstructionSaves.Add(instruction); StateSave secondStateSave = new StateSave(); secondStateSave.Name = "SecondState"; instruction = new InstructionSave(); instruction.Member = "X"; instruction.Value = -10; secondStateSave.InstructionSaves.Add(instruction); StateSaveCategory category = new StateSaveCategory(); category.Name = "StateSaveCategory"; category.States.Add(stateSave); category.States.Add(secondStateSave); mEntitySave.StateCategoryList.Add(category); mElementRuntime = new ElementRuntime(); mElementRuntime.Initialize(mEntitySave, null, null, null, null); mElementRuntime.AfterVariableApply += AfterVariableSet; }