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());
        }
Exemple #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());
        }
        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());
        }
Exemple #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());
        }
Exemple #6
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());
        }
Exemple #7
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());
        }