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());
        }
Пример #2
0
        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());
        }
Пример #3
0
        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());
        }
Пример #4
0
        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 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());
        }
Пример #6
0
        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());
        }
Пример #7
0
        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());
        }
Пример #8
0
        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 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());
        }
Пример #10
0
        private static ICodeBlock GetLoadGlobalContentCode()
        {
            ICodeBlock codeBlock = new CodeDocument();

            if (ProjectManager.GlueProjectSave.GlobalContentSettingsSave.LoadAsynchronously)
            {
                codeBlock
                .Struct("", "NamedDelegate")
                .Line("public string Name;")
                .Line("public System.Action LoadMethod;")
                .End()
                ._()
                .Line("static List<NamedDelegate> LoadMethodList = new List<NamedDelegate>();")
                ._();
            }

            string className = "GlobalContent";

            #region Instantiate the ClassProperties
            ClassProperties classProperties = new ClassProperties();
            classProperties.Members        = new List <FlatRedBall.Instructions.Reflection.TypedMemberBase>();
            classProperties.UntypedMembers = new Dictionary <string, string>();
            #endregion

            classProperties.NamespaceName = ProjectManager.ProjectNamespace;
            classProperties.ClassName     = className;
            classProperties.IsStatic      = true;
            classProperties.Partial       = true;

            classProperties.UsingStatements = new List <string>();



            #region Add using statements

            // todo: remove these, we don't need them anymore and they could cause ambiguity
            classProperties.UsingStatements.Add("System.Collections.Generic");
            classProperties.UsingStatements.Add("System.Threading");
            classProperties.UsingStatements.Add("FlatRedBall");
            classProperties.UsingStatements.Add("FlatRedBall.Math.Geometry");
            classProperties.UsingStatements.Add("FlatRedBall.ManagedSpriteGroups");
            classProperties.UsingStatements.Add("FlatRedBall.Graphics.Animation");
            classProperties.UsingStatements.Add("FlatRedBall.Graphics.Particle");
            classProperties.UsingStatements.Add("FlatRedBall.AI.Pathfinding");
            classProperties.UsingStatements.Add("FlatRedBall.Utilities");
            classProperties.UsingStatements.Add("BitmapFont = FlatRedBall.Graphics.BitmapFont");
            classProperties.UsingStatements.Add("FlatRedBall.Localization");



            bool shouldAddUsingForDataTypes = false;

            for (int i = 0; i < ProjectManager.GlueProjectSave.GlobalFiles.Count; i++)
            {
                if (FileManager.GetExtension(ProjectManager.GlueProjectSave.GlobalFiles[i].Name) == "csv")
                {
                    shouldAddUsingForDataTypes = true;
                    break;
                }
            }

            if (shouldAddUsingForDataTypes)
            {
                classProperties.UsingStatements.Add(ProjectManager.ProjectNamespace + ".DataTypes");
                classProperties.UsingStatements.Add("FlatRedBall.IO.Csv");
            }

            #endregion

            var contents = GetGlobalContentFilesMethods();

            codeBlock.InsertBlock(contents);

            classProperties.MethodContent = codeBlock;

            var toReturn = CodeWriter.CreateClass(classProperties);

            var block = new CodeBlockBaseNoIndent(null);
            block.Line("#if ANDROID || IOS || DESKTOP_GL");
            block.Line("// Android doesn't allow background loading. iOS doesn't allow background rendering (which is used by converting textures to use premult alpha)");
            block.Line("#define REQUIRES_PRIMARY_THREAD_LOADING");
            block.Line("#endif");


            toReturn.PreCodeLines.Add(block);

            return(toReturn);
        }