private void ReactToFontSet(NamedObjectSave namedObjectSave, object oldValue) { string value = namedObjectSave.GetCustomVariable("Font").Value as string; if (!string.IsNullOrEmpty(value)) { IElement element = EditorLogic.CurrentElement; ReferencedFileSave referencedFileSave = element.GetReferencedFileSaveByInstanceNameRecursively(value); if (referencedFileSave != null) { string file = referencedFileSave.GetRelativePath(); file = ProjectManager.MakeAbsolute(file, true); string contents = FileManager.FromFileText(file); int size = StringFunctions.GetIntAfter( "size=", contents); float lineHeightInPixels = StringFunctions.GetIntAfter( "lineHeight=", contents); lineHeightInPixels /= 2.0f; namedObjectSave.SetPropertyValue("Scale", (float)lineHeightInPixels); namedObjectSave.SetPropertyValue("Spacing", (float)lineHeightInPixels); namedObjectSave.SetPropertyValue("NewLineDistance", (float)(lineHeightInPixels * 1.5f)); } } }
private void AdjustAxisAlignedRectangle(NamedObjectSave nos, IElement element) { if (Is2D(element)) { nos.SetPropertyValue("Width", 32f); nos.SetPropertyValue("Height", 32f); } }
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"); } }
public static void SetVariableOn(NamedObjectSave nos, string memberName, Type memberType, object value) { bool shouldConvertValue = false; if (memberType != null && value is string && memberType != typeof(Microsoft.Xna.Framework.Color) && !CustomVariableExtensionMethods.GetIsFile(memberType) && // If it's a file, we just want to set the string value and have the underlying system do the loading !CustomVariableExtensionMethods.GetIsObjectType(memberType.FullName) ) { bool isCsv = NamedObjectPropertyGridDisplayer.GetIfIsCsv(nos, memberName); shouldConvertValue = !isCsv && memberType != typeof(object) && // variable could be an object memberType != typeof(PositionedObject); // If the MemberType is object, then it's something we can't convert to - it's likely a state } if (shouldConvertValue) { value = PropertyValuePair.ConvertStringToType((string)value, memberType); } nos.SetPropertyValue(memberName, value); }
private void AdjustSprite(NamedObjectSave nos, IElement element) { if (Is2D(element)) { nos.SetPropertyValue("TextureScale", 1.0f); } }
private void AdjustSpriteFrame(NamedObjectSave nos, IElement element) { if (Is2D(element)) { nos.SetPropertyValue("PixelSize", .5f); } }
private void AdjustCircle(NamedObjectSave nos, IElement element) { if (Is2D(element)) { nos.SetPropertyValue("Radius", 16f); } }
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(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"); } }
private NamedObjectSave CreateNosFor(InstanceSave instance, IElement container) { NamedObjectSave nos = new NamedObjectSave(); string name = instance.Name; // See if this name is already used by RFS's var allRfss = container.GetAllReferencedFileSavesRecursively(); while (allRfss.Any(item => item.GetInstanceName() == name) || container.ReferencedFiles.Any(item => item.Name == name)) { name = name + instance.BaseType; } nos.InstanceName = name; RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer); if (instance.BaseType == "Sprite") { nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; float width = rvf.GetValue <float>("Width"); float height = rvf.GetValue <float>("Height"); if (width == 0 && height == 0) { nos.SetPropertyValue("TextureScale", 1.0f); } else { // Eventually handle width/height nos.SetPropertyValue("Width", width); nos.SetPropertyValue("Height", height); } SetPositionValuesOn(nos, instance); string texture = rvf.GetValue <string>("SourceFile"); string fileInstanceName = FileManager.RemoveExtension(FileManager.RemovePath(texture)); var added = nos.SetPropertyValue("Texture", fileInstanceName); added.Type = "Texture2D"; } return(nos); }
private void CreateScreenSave() { mScreenSave = new ScreenSave(); mScreenSave.Name = "ScreenSaveInVariableSettingTest"; ObjectFinder.Self.GlueProject.Screens.Add(mScreenSave); NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.Entity; nos.SourceClassType = mEntitySave.Name; nos.UpdateCustomProperties(); nos.InstanceName = "TestObject1"; nos.SetPropertyValue("X", 150); mScreenSave.NamedObjects.Add(nos); }
private void CreateNamedObjectWithSetVariable() { mNamedObjectWithSetVariable = new NamedObjectSave(); mNamedObjectWithSetVariable.InstanceName = "SpriteObject"; // This will be complicated because it requires FRB to be instantiated! //mNamedObjectWithSetVariable.SourceType = SourceType.File; //mNamedObjectWithSetVariable.SourceFile = "Entities/StateTestEntity/SceneFile.scnx"; //mNamedObjectWithSetVariable.SourceName = "Untextured (Sprite)"; mNamedObjectWithSetVariable.SourceType = SourceType.FlatRedBallType; mNamedObjectWithSetVariable.SourceClassType = "Sprite"; mNamedObjectWithSetVariable.UpdateCustomProperties(); mNamedObjectWithSetVariable.SetPropertyValue("Y", 10.0f); mEntitySave.NamedObjects.Add(mNamedObjectWithSetVariable); }
public void TestSetPropertyValue() { NamedObjectSave nos = new NamedObjectSave(); nos.SourceType = SourceType.FlatRedBallType; nos.SourceClassType = "Sprite"; nos.UpdateCustomProperties(); nos.SetPropertyValue("Texture", "redball"); if (nos.InstructionSaves.Count == 0) { throw new Exception("There should be a Texture instruction save"); } if (nos.InstructionSaves.First(instruction => instruction.Member == "Texture").Type != "Texture2D") { throw new Exception("The instruction should be of type Texture2D, but it's not"); } }
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( containerEntity, null, null, null, null); }
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 }