public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element) { var currentBlock = codeBlock; if (element.HasStates) { List<StateSave> statesForThisCategory = GetSharedVariableStates(element); const string enumName = "VariableState"; currentBlock = AppendEnum(currentBlock, statesForThisCategory, enumName, element); GenerateCurrentStateProperty(element, codeBlock, "VariableState", statesForThisCategory); //Build State Categories var stateCategories = GetAllStateCategoryNames(element, false); foreach (var stateCategory in stateCategories) { var states = GetAllStatesForCategory(element, stateCategory); AppendEnum(currentBlock, states, stateCategory, element); GenerateCurrentStateProperty(element, codeBlock, stateCategory, states); } } return codeBlock; }
public override ICodeBlock GenerateInitialize(ICodeBlock codeBlock, SaveClasses.IElement element) { // Before August 23, 2010 Custom Variables used to be set // here in Initialize before the AddToManagers method. This // is problematic because: // 1. We probably want these // variables reset whenever // this object is recycled. // 2. If we set the position of // the Entity before its children // have been attached, then the attachment // will not work as expected. Therefore, I've // decided to move custom variable code to AddToManagers. // UPDATE: Actually, we do want variables set here so that they // are available in Custom Initialize. // UPDATE2: This was moved to its own method so that inheritance works. // UPDATE3: It turns out there's 2 types of variables. // 1. Variables that are not set by derived. These variables should get set // in the base class or else they'll never get set for derived objects. // 2. Variables that are set by derived. These variables should get set in the // "SetCustomVariables" method so that they get overridden by derived objects. // This means that we're going to set variables that are not set by derived here, and the // rest will get set in SetCustomVariables. // UPDATE4: This has all moved to PostInitialize, which is called // bottom-up. This means there is no more split on variables. // UPDATE5: This has been moved out of BaseElementTreeNode int CustomVariableCodeGenerator. return codeBlock; }
public override ICodeBlock GenerateInitialize(ICodeBlock codeBlock, SaveClasses.IElement element) { // Do the named object saves // We're going to do all "Entire File" NOS's first so that they aren't null before for (int i = 0; i < element.NamedObjects.Count; i++) { NamedObjectSave nos = element.NamedObjects[i]; if (nos.IsEntireFile) { WriteCodeForNamedObjectInitialize(nos, element, codeBlock, null); } } // Now do non-entire files: for (int i = 0; i < element.NamedObjects.Count; i++) { NamedObjectSave nos = element.NamedObjects[i]; if (!nos.IsEntireFile) { WriteCodeForNamedObjectInitialize(nos, element, codeBlock, null); } } return codeBlock; }
public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element) { #region Get the ContentManager variable to use string contentManagerName = "ContentManagerName"; if (element is ScreenSave) { contentManagerName = (element as ScreenSave).ContentManagerForCodeGeneration; } #endregion if (element is EntitySave) { codeBlock.Line("static object mLockObject = new object();"); codeBlock.Line("static System.Collections.Generic.List<string> mRegisteredUnloads = new System.Collections.Generic.List<string>();"); #region Keep track of whether we've already registered an unload method and if StaticContent has been loaded codeBlock.Line("static System.Collections.Generic.List<string> LoadedContentManagers = new System.Collections.Generic.List<string>();"); #endregion } for (int i = 0; i < element.ReferencedFiles.Count; i++) { AppendFieldOrPropertyForReferencedFile(codeBlock, element.ReferencedFiles[i], element.Name, element, contentManagerName); //stringBuilder.AppendLine(GetFieldForReferencedFile(mSaveObject.ReferencedFiles[i])); } return codeBlock; }
public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element) { codeBlock.Line("#if DEBUG"); codeBlock.Line("static bool HasBeenLoadedWithGlobalContentManager = false;"); codeBlock.Line("#endif"); return codeBlock; }
public string GetAbsoluteFileName(SaveClasses.ReferencedFileSave rfs) { if(rfs == null) { throw new ArgumentNullException("rfs", "The argument ReferencedFileSave should not be null"); } return ProjectManager.MakeAbsolute(rfs.Name, true); }
public override CodeGeneration.CodeBuilder.ICodeBlock GenerateActivity(CodeGeneration.CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element) { // We used to call TimedEmit here // but we only want to call it if the // NOS is non-null. That means we are going // to call the TimedEmit generating code from // within the NamedObjectSaveCodeGenerator's GenerateActivity return codeBlock; }
private static CodeBuilder.ICodeBlock GenerateSetToIgnorePausing(CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element, bool hasBase) { string virtualOrOverride = "virtual"; if (hasBase) { virtualOrOverride = "override"; } codeBlock = codeBlock.Function("public " + virtualOrOverride + " void", "SetToIgnorePausing", ""); if (hasBase) { codeBlock.Line("base.SetToIgnorePausing();"); } else { codeBlock.Line("FlatRedBall.Instructions.InstructionManager.IgnorePausingFor(this);"); } foreach (NamedObjectSave nos in element.AllNamedObjects) { if (nos.IsFullyDefined && !nos.IsDisabled && !nos.IsContainer) { NamedObjectSaveCodeGenerator.AddIfConditionalSymbolIfNecesssary(codeBlock, nos); bool shouldWrapInNullCheck = nos.SetByDerived || nos.SetByContainer || nos.Instantiate == false; if (shouldWrapInNullCheck) { codeBlock = codeBlock.If(nos.InstanceName + " != null"); } if (nos.GetAssetTypeInfo() != null && nos.GetAssetTypeInfo().CanIgnorePausing) { codeBlock.Line("FlatRedBall.Instructions.InstructionManager.IgnorePausingFor(" + nos.InstanceName + ");"); } else if (nos.SourceType == SourceType.Entity) { codeBlock.Line(nos.InstanceName + ".SetToIgnorePausing();"); } if (shouldWrapInNullCheck) { codeBlock = codeBlock.End(); } NamedObjectSaveCodeGenerator.AddEndIfIfNecessary(codeBlock, nos); } } codeBlock = codeBlock.End(); return codeBlock; }
public override CodeBuilder.ICodeBlock GenerateInitialize(CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element) { if(IsLoadingScreen(element)) { codeBlock.Line("mSavedTargetElapedTime = FlatRedBallServices.Game.TargetElapsedTime.TotalSeconds;"); codeBlock.Line("FlatRedBall.FlatRedBallServices.Game.TargetElapsedTime = TimeSpan.FromSeconds(.1);"); } return codeBlock; }
private static void GenerateInterpolationAdditionalMethods(ICodeBlock codeBlock, SaveClasses.IElement element, List<StateSave> sharedVariableStates) { StateCodeGenerator.GenerateInterpolateToStateMethod(element, codeBlock, "VariableState", sharedVariableStates); StateCodeGenerator.GenerateInterpolateBetweenMethod(element, codeBlock, "VariableState", sharedVariableStates); foreach (StateSaveCategory category in element.StateCategoryList.Where((category)=> category.SharesVariablesWithOtherCategories == false)) { StateCodeGenerator.GenerateInterpolateToStateMethod(element, codeBlock, category.Name, category.States); StateCodeGenerator.GenerateInterpolateBetweenMethod(element, codeBlock, category.Name, category.States); } }
private void UpdateTabTitle(SaveClasses.ReferencedFileSave file) { int count = file.ProjectsToExcludeFrom.Count; if (count == 0) { pluginTab.Text = "Platform Inclusions"; } else { pluginTab.Text = "Excluded from " + count + " platforms"; } }
public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element) { for (int i = 0; i < element.CustomVariables.Count; i++) { CustomVariable customVariable = element.CustomVariables[i]; if (CodeWriter.IsVariableHandledByCustomCodeGenerator(customVariable, element) == false) { AppendCodeForMember(element, codeBlock, customVariable); } } return codeBlock; }
public override CodeBuilder.ICodeBlock GenerateFields(CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element) { if (element is EntitySave) { EntitySave asEntity = element as EntitySave; if (asEntity.CreatedByOtherEntities && asEntity.GetAllBaseEntities().Count(item=>item.CreatedByOtherEntities) == 0) { codeBlock.AutoProperty("public int", "Index"); codeBlock.AutoProperty("public bool", "Used"); } } return codeBlock; }
public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element) { #region Generate NamedObject Fields codeBlock.Line(""); for (int i = 0; i < element.NamedObjects.Count; i++) { var namedObject = element.NamedObjects[i]; GenerateFieldAndPropertyForNamedObject(namedObject, codeBlock); } #endregion return codeBlock; }
public override ICodeBlock GenerateFields(ICodeBlock codeBlock, SaveClasses.IElement element) { EntitySave asEntitySave = element as EntitySave; if (asEntitySave != null && asEntitySave.ImplementsICollidable) { codeBlock.Line("private FlatRedBall.Math.Geometry.ShapeCollection mGeneratedCollision;"); var propBlock = codeBlock.Property("public FlatRedBall.Math.Geometry.ShapeCollection", "Collision"); propBlock.Get().Line("return mGeneratedCollision;"); return codeBlock; } else { return base.GenerateFields(codeBlock, element); } }
public override ICodeBlock GenerateLoadStaticContent(ICodeBlock codeBlock, SaveClasses.IElement element) { #region For debugging record if we're using a global content manager codeBlock.Line("#if DEBUG"); codeBlock.If("contentManagerName == FlatRedBall.FlatRedBallServices.GlobalContentManager") .Line("HasBeenLoadedWithGlobalContentManager = true;"); codeBlock.ElseIf("HasBeenLoadedWithGlobalContentManager") .Line("throw new System.Exception(\"This type has been loaded with a Global content manager, then loaded with a non-global. This can lead to a lot of bugs\");"); codeBlock.Line("#endif"); #endregion return codeBlock; }
public override ICodeBlock GenerateLoadStaticContent(ICodeBlock codeBlock, SaveClasses.IElement element) { for (int i = 0; i < element.CustomVariables.Count; i++) { CustomVariable customVariable = element.CustomVariables[i]; // If a CustomVariable references a CSV and if that CustomVariable is shared static, // we can't assign it until the CSV is loaded. Therefore, we will do it in LoadStaticContent if (customVariable.IsShared && (!customVariable.DefinedByBase || customVariable.IsTunneling || customVariable.CreatesEvent) && ShouldAssignToCsv(customVariable, customVariable.DefaultValue as string) && !ReferencesCsvFromGlobalContent(customVariable)) { string variableAssignment = " = " + GetAssignmentToCsvItem(customVariable, element, (string)customVariable.DefaultValue); codeBlock.Line(customVariable.Name + variableAssignment + ";"); } } return codeBlock; }
public override CodeBuilder.ICodeBlock GenerateAdditionalMethods(CodeBuilder.ICodeBlock codeBlock, SaveClasses.IElement element) { if(element is EntitySave) { bool hasBase = element.InheritsFromElement(); if (hasBase == false) { codeBlock.Line("protected bool mIsPaused;"); var function = codeBlock.Function("public override void", "Pause", "FlatRedBall.Instructions.InstructionList instructions"); function.Line("base.Pause(instructions);"); function.Line("mIsPaused = true;"); foreach (var nos in element.AllNamedObjects) { GeneratePauseForNos(nos, function); } } codeBlock = GenerateSetToIgnorePausing(codeBlock, element, hasBase); } return codeBlock; }
public static List<StateSave> GetSharedVariableStates(SaveClasses.IElement element) { if (element == null) { throw new ArgumentNullException("element argument cannot be null"); } var statesForThisCategory = new List<StateSave>(); var currentElement = element; //Get states for parent entities if (!string.IsNullOrEmpty(currentElement.BaseElement)) { IElement baseElement = ObjectFinder.Self.GetIElement(currentElement.BaseElement); if (baseElement != null) { statesForThisCategory.AddRange(GetSharedVariableStates(baseElement)); } } for (int i = 0; i < element.States.Count; i++) { statesForThisCategory.Add(element.States[i]); } statesForThisCategory.AddRange(element.StateCategoryList.Where(category => category.SharesVariablesWithOtherCategories).SelectMany(category => category.States)); return statesForThisCategory; }
public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, SaveClasses.IElement element) { if (element.HasStates) { List<StateSave> sharedVariableStates = GetSharedVariableStates(element); if (sharedVariableStates.Count != 0) { #region Create the static state that should be set prior to loading string propertyPrefix = "public static "; if (!string.IsNullOrEmpty(element.BaseElement)) { IElement baseElement = ObjectFinder.Self.GetIElement(element.BaseElement); if (baseElement != null && baseElement.DefinesCategoryEnumRecursive("VariableState")) { propertyPrefix += "new "; } } codeBlock .Line("static VariableState mLoadingState = VariableState.Uninitialized;") .Property(propertyPrefix + "VariableState", "LoadingState") .Get() .Line("return mLoadingState;") .End() .Set() .Line("mLoadingState = value;") .End() .End(); #endregion } GenerateInterpolationAdditionalMethods(codeBlock, element, sharedVariableStates); GeneratePreloadStateContent(codeBlock, element, sharedVariableStates); } return codeBlock; }
public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, SaveClasses.IElement element) { //throw new NotImplementedException(); return codeBlock; }
public void ReactToNewFile(SaveClasses.ReferencedFileSave newFile) { }
public override ICodeBlock GenerateInitialize(ICodeBlock codeBlock, SaveClasses.IElement element) { for (int i = 0; i < element.ReferencedFiles.Count; i++) { ReferencedFileSave rfs = element.ReferencedFiles[i]; // Only do non-static stuff if (!rfs.IsSharedStatic) { ReferencedFileSaveCodeGenerator.GetInitializationForReferencedFile(rfs, element, codeBlock, element.UseGlobalContent, LoadType.CompleteLoad); } } return codeBlock; }
public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, SaveClasses.IElement element) { for (int i = 0; i < element.ReferencedFiles.Count; i++) { codeBlock.InsertBlock(GetActivityForReferencedFile(element.ReferencedFiles[i], element)); } return codeBlock; }
public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, SaveClasses.IElement element) { return codeBlock; }
public override ICodeBlock GenerateActivity(ICodeBlock codeBlock, SaveClasses.IElement element) { return codeBlock; }
public override ICodeBlock GenerateAddToManagers(ICodeBlock codeBlock, SaveClasses.IElement element) { return codeBlock; }
public override ICodeBlock GenerateAdditionalMethods(ICodeBlock codeBlock, SaveClasses.IElement element) { bool inherits = !string.IsNullOrEmpty(element.BaseElement) && !element.InheritsFromFrbType(); ReferencedFileSaveCodeGenerator.GenerateGetStaticMemberMethod(element.ReferencedFiles, codeBlock, false, inherits); string functionName = "GetFile"; GenerateGetFileMethodByName(element.ReferencedFiles, codeBlock, inherits, functionName, false); GenerateGetMember(codeBlock, element); return codeBlock; }
public override ICodeBlock GenerateInitialize(ICodeBlock codeBlock, SaveClasses.IElement element) { return codeBlock; }
private static void GenerateGetMember(ICodeBlock codeBlock, SaveClasses.IElement element) { #region GetMember (Instance members) // GlobalContent is a static class, so it can't have a non-static GetMember method // Update June 25, 2011: This has been moved // to a code generator which only works on Elements // so we know we're not global content //if (!isGlobalContent) //{ var func = codeBlock.Function("object", "GetMember", "string memberName"); ICodeBlock switchBlock = null; bool hasPrependedSwitch = false; foreach (ReferencedFileSave rfs in element.ReferencedFiles) { // Localization databases currently don't create members if (rfs.LoadedAtRuntime && !rfs.IsDatabaseForLocalizing && (rfs.GetAssetTypeInfo() == null || !string.IsNullOrEmpty( rfs.GetAssetTypeInfo().QualifiedRuntimeTypeName.QualifiedType)) ) { if (!hasPrependedSwitch) { // We do the switch here // so that if there are no // RFS's that the user can get, // we don't want to generate a switch. // This eliminates warnings. hasPrependedSwitch = true; switchBlock = func.Switch("memberName"); } AddIfConditionalSymbolIfNecesssary(switchBlock, rfs); string instanceName = rfs.GetInstanceName(); switchBlock.CaseNoBreak("\"" + instanceName + "\"") .Line("return " + instanceName + ";"); AddEndIfIfNecessary(switchBlock, rfs); } //stringBuilder.AppendLine("\t\t\t\t\tbreak;"); } func.Line("return null;"); #endregion }