private static string GenerateConfigurationCode() { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); var fileName = GlueState.Self.CurrentGlueProjectFileName; var projectName = FileManager.RemoveExtension(FileManager.RemovePath(fileName)); ICodeBlock codeBlock = topBlock.Namespace(GlueState.Self.ProjectNamespace); codeBlock = codeBlock.Class("", "GameNetworkConfiguration : RedGrin.NetworkConfiguration"); var constructor = codeBlock.Constructor("public", "GameNetworkConfiguration", ""); var portNumber = projectName.GetHashCode() % (ushort.MaxValue - 1024) + 1024; constructor.Line($"ApplicationName = \"{projectName}\";"); constructor.Line($"ApplicationPort = {portNumber};"); constructor.Line($"DeadReckonSeconds = 1.0f;"); constructor.Line($"EntityStateTypes = new System.Collections.Generic.List<System.Type>();"); var netEntities = GlueState.Self.CurrentGlueProject.Entities .Where(item => NetworkEntityViewModel.IsNetworked(item)); foreach (var netEntity in netEntities) { var netStateFullName = CodeGeneratorCommonLogic.GetNetStateFullName(netEntity); constructor.Line( $"EntityStateTypes.Add(typeof({netStateFullName}));"); } return(topBlock.ToString()); }
internal static ICodeBlock Class(this ICodeBlock pCodeBlock, string pName, bool Public = false, bool Private = false, bool Protected = false, bool Internal = false, bool ProtectedInternal = false, bool Static = false, bool Partial = false, bool Abstract = false, bool Sealed = false) { return(pCodeBlock.Class( StringHelper.Modifiers( Public: Public, Private: Private, Protected: Protected, Internal: Internal, ProtectedInternal: ProtectedInternal, Static: Static, Partial: Partial, Abstract: Abstract, Sealed: Sealed ) , pName , "")); }
public bool GenerateStandardElementSaveCodeFor(StandardElementSave standardElementSave, ICodeBlock codeBlock) { ///////////// EARLY OUT////////////// if (GueDerivingClassCodeGenerator.Self.ShouldGenerateRuntimeFor(standardElementSave) == false) { return(false); } //////////////END EARLY OUT/////////// string runtimeClassName = GueDerivingClassCodeGenerator.GetUnqualifiedRuntimeTypeFor(standardElementSave); // This needs to be public because it can be exposed as public in a public class //ICodeBlock currentBlock = codeBlock.Class("partial", runtimeClassName, " : Gum.Wireframe.GraphicalUiElement"); ICodeBlock currentBlock = codeBlock.Class("public partial", runtimeClassName, " : Gum.Wireframe.GraphicalUiElement"); GueDerivingClassCodeGenerator.Self.GenerateConstructor(standardElementSave, currentBlock, runtimeClassName); string containedGraphicalObjectName = CreateContainedObjectMembers(currentBlock, standardElementSave); GenerateStates(standardElementSave, currentBlock); GenerateVariableProperties(standardElementSave, currentBlock, containedGraphicalObjectName); GenerateAssignDefaultState(standardElementSave, currentBlock); return(true); }
private static string GenerateEmptyCustomNetStateCode(EntitySave entitySave) { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); string netStateNamespace = CodeGeneratorCommonLogic.GetNetStateNamespace(entitySave); ICodeBlock codeBlock = topBlock.Namespace(netStateNamespace); codeBlock = codeBlock.Class("public partial", entitySave.GetStrippedName() + "NetState"); return(topBlock.ToString()); }
private static string GenerateClaimEntityMessageCode() { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); ICodeBlock codeBlock = topBlock.Namespace(GlueState.Self.ProjectNamespace + ".Messages"); codeBlock = codeBlock.Class("", "ClaimEntity"); codeBlock.AutoProperty("public string", "EntityName"); codeBlock.AutoProperty("public long", "OwnerId"); codeBlock.AutoProperty("public long", "EntityId"); return(topBlock.ToString()); }
public string GetRuntimeRegistrationPartialClassContents() { CodeBlockBase codeBlock = new CodeBlockBase(null); ICodeBlock currentBlock = codeBlock.Namespace("FlatRedBall.Gum"); currentBlock = currentBlock.Class("public partial", "GumIdb", ""); currentBlock = currentBlock.Function("public static void", "RegisterTypes", ""); { AddAssignmentFunctionContents(currentBlock); } return(codeBlock.ToString()); }
private static string GenerateEmptyCustomEntityNetworkCode(EntitySave entitySave) { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); string entityNamespace = CodeGeneratorCommonLogic.GetElementNamespace(entitySave); ICodeBlock codeBlock = topBlock.Namespace(entityNamespace); codeBlock = codeBlock.Class("public partial", entitySave.GetStrippedName()); codeBlock.Function("void", "CustomUpdateFromState", $"{CodeGeneratorCommonLogic.GetNetStateFullName(entitySave)} state"); codeBlock.Function("void", "CustomGetState", $"{CodeGeneratorCommonLogic.GetNetStateFullName(entitySave)} state"); return(topBlock.ToString()); }
private ICodeBlock GenerateClassHeader(ICodeBlock codeBlock, ElementSave elementSave) { string runtimeClassName = GetUnqualifiedRuntimeTypeFor(elementSave); string inheritance = "Gum.Wireframe.GraphicalUiElement"; if (elementSave.BaseType != "Component" && !string.IsNullOrEmpty(elementSave.BaseType)) { inheritance = GueRuntimeNamespace + "." + elementSave.BaseType + "Runtime"; } var asComponentSave = elementSave as ComponentSave; if (asComponentSave != null) { var project = AppState.Self.GumProjectSave; var behaviors = project.Behaviors; foreach (var behaviorReference in asComponentSave.Behaviors) { inheritance += $", {GueRuntimeNamespace}.I{behaviorReference.BehaviorName}"; var behavior = behaviors.FirstOrDefault(item => item.Name == behaviorReference.BehaviorName); string behaviorInheritance = null; if (behavior != null) { behaviorInheritance = BehaviorCodeGenerator.GetInterfacesFromBehaviors(behavior); } if (!string.IsNullOrEmpty(behaviorInheritance)) { inheritance += $", {behaviorInheritance}"; } } } // If it's not public then exposing an instance in a public class makes the project not compile //ICodeBlock currentBlock = codeBlock.Class("partial", runtimeClassName, " : " + inheritance); ICodeBlock currentBlock = codeBlock.Class("public partial", runtimeClassName, " : " + inheritance); return(currentBlock); }
private static string GetGeneratedScreenCode(ScreenSave screenSave) { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); string screenNamespace = CodeGeneratorCommonLogic.GetElementNamespace(screenSave); ICodeBlock codeBlock = topBlock.Namespace(screenNamespace); codeBlock = codeBlock.Class("public partial", screenSave.GetStrippedName(), " : RedGrin.INetworkArena"); GenerateRequestCreateEntity(codeBlock); GenerateRequestDestroy(codeBlock); return(topBlock.ToString()); }
public string GetCustomCodeTemplateCode(ElementSave element) { // Example: /* * using System; * using System.Collections.Generic; * using System.Linq; * * namespace DesktopGlForms.GumRuntimes.DefaultForms * { * public partial class ButtonRuntime * { * partial void CustomInitialize() * { * * } * } * } * */ var codeBlockBase = new CodeBlockBaseNoIndent(null); ICodeBlock codeBlock = codeBlockBase; var toReturn = codeBlock; codeBlock.Line("using System;"); codeBlock.Line("using System.Collections.Generic;"); codeBlock.Line("using System.Linq;"); codeBlock.Line(); codeBlock = codeBlock.Namespace( GueDerivingClassCodeGenerator.Self.GetFullRuntimeNamespaceFor(element)); { string runtimeClassName = GueDerivingClassCodeGenerator.Self.GetUnqualifiedRuntimeTypeFor(element); codeBlock = codeBlock.Class("public partial", runtimeClassName); { codeBlock = codeBlock.Function("partial void", "CustomInitialize"); } } return(toReturn.ToString()); }
private static string GenerateNetStateGeneratedCode(EntitySave entitySave) { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); string netStateNamespace = CodeGeneratorCommonLogic.GetNetStateNamespace(entitySave); ICodeBlock codeBlock = topBlock.Namespace(netStateNamespace); codeBlock = codeBlock.Class("public partial", entitySave.GetStrippedName() + "NetState"); var variables = GetNetworkVariables(entitySave); foreach (var variable in variables) { codeBlock.AutoProperty($"public {variable.Type}", variable.Name); } return(topBlock.ToString()); }
private static string GetGeneratedEntityNetworkCode(EntitySave entitySave) { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); string entityNamespace = CodeGeneratorCommonLogic.GetElementNamespace(entitySave); ICodeBlock codeBlock = topBlock.Namespace(entityNamespace); codeBlock = codeBlock.Class("public partial", entitySave.GetStrippedName(), " : RedGrin.INetworkEntity"); codeBlock.AutoProperty("public long", "OwnerId"); codeBlock.AutoProperty("public long", "EntityId"); GenerateGetStateMethod(entitySave, codeBlock); GenerateUpdateFromStateMethod(entitySave, codeBlock); return(topBlock.ToString()); }
private ICodeBlock GenerateClassHeader(ICodeBlock codeBlock, ElementSave elementSave) { string runtimeClassName = GetUnqualifiedRuntimeTypeFor(elementSave); string inheritance = "Gum.Wireframe.GraphicalUiElement"; if (elementSave.BaseType != "Component" && !string.IsNullOrEmpty(elementSave.BaseType)) { inheritance = GueRuntimeNamespace + "." + elementSave.BaseType.Replace("/", ".") + "Runtime"; } var asComponentSave = elementSave as ComponentSave; // If it's not public then exposing an instance in a public class makes the project not compile //ICodeBlock currentBlock = codeBlock.Class("partial", runtimeClassName, " : " + inheritance); ICodeBlock currentBlock = codeBlock.Class("public partial", runtimeClassName, " : " + inheritance); return(currentBlock); }
public static void CreateEmptyCodeIfNecessary(IElement currentElement, string fullFileName, bool forceRegenerateContents) { bool doesFileExist = File.Exists(fullFileName); if (!doesFileExist) { PluginManager.ReceiveOutput("Forcing a regneration of " + fullFileName + " because Glue can't find it anywhere."); // There is no shared code file for this event, so we need to make one ProjectManager.CodeProjectHelper.CreateAndAddPartialCodeFile(fullFileName, true); } if (!doesFileExist || forceRegenerateContents) { string namespaceString = GlueCommands.Self.GenerateCodeCommands.GetNamespaceForElement(currentElement); ICodeBlock templateCodeBlock = new CodeDocument(); EventCodeGenerator.AddUsingStatementsToBlock(templateCodeBlock); ICodeBlock namespaceCB = templateCodeBlock.Namespace(namespaceString); ICodeBlock classCB = namespaceCB.Class("public partial", currentElement.ClassName, null); classCB ._() .End() .End(); string templateToSave = templateCodeBlock.ToString(); FlatRedBall.Glue.IO.FileWatchManager.IgnoreNextChangeOnFile(fullFileName); FileManager.SaveText(templateToSave, fullFileName); } // Add if it isn't part of the project const bool saveFile = false; // don't save it - we just want to make sure it's part of the project ProjectManager.CodeProjectHelper.CreateAndAddPartialCodeFile(fullFileName, saveFile); }
public string GetRuntimeRegistrationPartialClassContents(bool registerFormsAssociations) { CodeBlockBase codeBlock = new CodeBlockBase(null); ICodeBlock currentBlock = codeBlock.Namespace("FlatRedBall.Gum"); currentBlock = currentBlock.Class("public ", "GumIdbExtensions", ""); currentBlock = currentBlock.Function("public static void", "RegisterTypes", ""); { AddAssignmentFunctionContents(currentBlock); if (registerFormsAssociations) { currentBlock._(); AddFormsAssociations(currentBlock); } } return(codeBlock.ToString()); }
private string GetStringsGeneratedCodeFileContents(ReferencedFileSave referencedFileSave) { var glueState = Container.Get <IGlueState>(); var glueCommands = Container.Get <IGlueCommands>(); string toReturn = null; if (referencedFileSave != null) { var namespaceName = $"{glueState.ProjectNamespace}.DataTypes"; ICodeBlock document = new CodeDocument(0); ICodeBlock codeBlock = document.Namespace(namespaceName); codeBlock = codeBlock.Class("Strings"); string fileName = glueCommands.GetAbsoluteFileName(referencedFileSave); var doesFileExist = System.IO.File.Exists(fileName); if (System.IO.File.Exists(fileName)) { var runtime = CsvFileManager.CsvDeserializeToRuntime(fileName); foreach (var row in runtime.Records) { TryAddMemberForRow(codeBlock, row); } toReturn = document.ToString(); } } return(toReturn); }
private static string GenerateEmptyCustomScreenNetworkCode(ScreenSave screen) { ICodeBlock topBlock = new CodeBlockBaseNoIndent(null); string screenNamespace = CodeGeneratorCommonLogic.GetElementNamespace(screen); ICodeBlock codeBlock = topBlock.Namespace(screenNamespace); codeBlock = codeBlock.Class("public partial", screen.GetStrippedName()); codeBlock.Function("void", "CustomRequestCreateNetworkEntity", "ref RedGrin.INetworkEntity entity, object entityData") .Line(); codeBlock.Line(); codeBlock.Function("void", "CustomRequestDestroyNetworkEntity", "RedGrin.INetworkEntity entity") .Line(); return(topBlock.ToString()); }
public override void GenerateAdditionalClasses(ICodeBlock codeBlock, IElement element) { /////////////////Early Out////////////////////// if (TopDownEntityPropertyLogic.GetIfIsTopDown(element) == false) { return; } //////////////End Early Out////////////////////// /// var className = element.GetStrippedName(); codeBlock = codeBlock.Class("public partial", className, ": TopDown.ITopDownEntity"); codeBlock.Line("#region Top Down Fields"); WriteAnimationFields(element, codeBlock); codeBlock.Line("DataTypes.TopDownValues mCurrentMovement;"); codeBlock.Line("public float TopDownSpeedMultiplier { get; set; } = 1;"); codeBlock.Line("/// <summary>"); codeBlock.Line("/// The current movement variables used when applying input."); codeBlock.Line("/// </summary>"); codeBlock.Property("public DataTypes.TopDownValues", "CurrentMovement") .Get() .Line("return mCurrentMovement;").End() .Set("private") .Line("mCurrentMovement = value;"); codeBlock.Property("public FlatRedBall.Input.IInputDevice", "InputDevice") .Line("get;") .Line("private set;"); codeBlock.Line("TopDownDirection mDirectionFacing;"); codeBlock.Line("/// <summary>"); codeBlock.Line("/// Which direciton the character is facing."); codeBlock.Line("/// </summary>"); codeBlock.Property("public TopDownDirection", "DirectionFacing") .Get() .Line("return mDirectionFacing;"); codeBlock.Property("public PossibleDirections", "PossibleDirections") .AutoGet().End() .AutoSet(); codeBlock.Line("/// <summary>"); codeBlock.Line("/// The input object which controls the horizontal movement of the character."); codeBlock.Line("/// Common examples include a d-pad, analog stick, or keyboard keys."); codeBlock.Line("/// </summary>"); codeBlock.AutoProperty("public FlatRedBall.Input.I2DInput", "MovementInput"); codeBlock.Line("/// <summary>"); codeBlock.Line("/// Whether input is read to control the movement of the character."); codeBlock.Line("/// This can be turned off if the player should not be able to control"); codeBlock.Line("/// the character."); codeBlock.Line("/// </summary>"); codeBlock.AutoProperty("public bool", "InputEnabled"); codeBlock.Line("TopDown.DirectionBasedAnimationLayer mTopDownAnimationLayer;"); codeBlock.Line("#endregion"); }
private static ICodeBlock CreateClassForStateCategory(ICodeBlock currentBlock, List <StateSave> statesForThisCategory, string categoryClassName, IElement element) { if (statesForThisCategory.Count != 0) { string prefix = "public"; string postfix = null; if (IsStateDefinedInBase(element, categoryClassName)) { postfix = $" : {element.BaseElement.Replace("\\", ".")}.{categoryClassName}"; } currentBlock = currentBlock.Class(prefix, categoryClassName, postfix); currentBlock.Line($"public string Name;"); foreach (var variable in element.CustomVariables) { // todo - pass the category here and skip over excluded variables var isExcluded = false; if (!isExcluded) { string type = variable.Type; if (variable.GetIsFile()) { type = "string"; } else { type = CustomVariableCodeGenerator.GetMemberTypeFor(variable, element); } currentBlock.Line($"public {type} {variable.Name};"); } } for (int i = 0; i < statesForThisCategory.Count; i++) { var state = statesForThisCategory[i]; currentBlock.Line($"public static {categoryClassName} {state.Name} = new {categoryClassName}()"); var variableBlock = currentBlock.Block(); variableBlock.Line($"Name = \"{state.Name}\","); foreach (var instruction in state.InstructionSaves) { if (instruction.Value != null) { var rightSide = GetRightSideAssignmentValueAsString(element, instruction); var matchingVariable = element.GetCustomVariableRecursively(instruction.Member); if (matchingVariable?.GetIsFile() == true) { // If it's a file we are only going to reference the file name here as to not preload the file rightSide = $"\"{rightSide}\""; } variableBlock.Line($"{instruction.Member} = {rightSide},"); } } variableBlock.End().Line(";"); } currentBlock = currentBlock.End(); } return(currentBlock); }