public static void GenMatcher(FileGenerator file)
 {
     file.AddLine("public sealed partial class GameMatcher");
     using (new FileGenerator.Scop(file))
     {
         //AllOf
         file.AddLine("public static ECSCore.IAllOfMatcher<GameEntity> AllOf(params int[] indices)");
         using (new FileGenerator.Scop(file))
         {
             file.AddLine("return ECSCore.Matcher<GameEntity>.AllOf(indices);");
         }
         file.AddLine("public static ECSCore.IAllOfMatcher<GameEntity> AllOf(params ECSCore.IMatcher<GameEntity>[] matchers)");
         using (new FileGenerator.Scop(file))
         {
             file.AddLine("return ECSCore.Matcher<GameEntity>.AllOf(matchers);");
         }
         //AnyOf
         file.AddLine("public static ECSCore.IAnyOfMatcher<GameEntity> AnyOf(params int[] indices)");
         using (new FileGenerator.Scop(file))
         {
             file.AddLine("return ECSCore.Matcher<GameEntity>.AnyOf(indices);");
         }
         file.AddLine("public static ECSCore.IAnyOfMatcher<GameEntity> AnyOf(params ECSCore.IMatcher<GameEntity>[] matchers)");
         using (new FileGenerator.Scop(file))
         {
             file.AddLine("return ECSCore.Matcher<GameEntity>.AnyOf(matchers);");
         }
     }
 }
Example #2
0
 public static void Gen(List <ComonentInfo> list, FileGenerator file, bool isView)
 {
     if (isView)
     {
         file.AddLine("public partial class ViewContext");
     }
     else
     {
         file.AddLine("public partial class GameContext");
     }
     using (new FileGenerator.Scop(file))
     {
         foreach (var info in list)
         {
             if (!info.IsUnique)
             {
                 continue;
             }
             if (info.Fields.Count > 0)
             {
                 string memberName = ComponentGenerator.LowerFirstCase(info.ShowName);
                 //member
                 file.AddFormat("public {2} {3} {0}get; private set;{1}", "{", "}", info.FullName, memberName);
                 //set
                 file.AddFormat("public void Set{0}({1})", info.ShowName, ComponentGenerator.GenParamList(info));
                 using (new FileGenerator.Scop(file))
                 {
                     file.AddFormat("if({0} == null)", memberName);
                     using (new FileGenerator.Scop(file))
                     {
                         file.AddFormat("{0} = new {1}();", memberName, info.FullName);
                     }
                     file.AddFormat("var component = {0};", memberName);
                     ComponentGenerator.GenAssignment(info, file);
                 }
                 //remove
                 file.AddFormat("public void Remove{0}()", info.ShowName);
                 using (new FileGenerator.Scop(file))
                 {
                     file.AddFormat("{0} = null;", memberName);
                 }
             }
             else
             {
                 file.AddFormat("public bool is{2} {0}get; set;{1}", "{", "}", info.ShowName);
             }
         }
     }
 }
Example #3
0
        private static void GenFlagComponent(ComonentInfo info, FileGenerator file, bool isView)
        {
            file.AddFormat("static readonly {0} {1} = new {0}();", info.FullName, LowerFirstCase(info.FullName));
            string lookupName = string.Format("{0}ComponentsLookup.{1}", isView ? "View" : "Game", info.ShowName);

            file.AddFormat("public bool is{0}", info.ShowName);
            using (new FileGenerator.Scop(file))
            {
                file.AddFormat("get {0} return HasComponent({2}); {1}", "{", "}", lookupName);
                file.AddLine("set");
                using (new FileGenerator.Scop(file))
                {
                    file.AddFormat("if (value != is{0})", info.ShowName);
                    using (new FileGenerator.Scop(file))
                    {
                        file.AddFormat("var index = {0};", lookupName);
                        file.AddLine("if (value)");
                        using (new FileGenerator.Scop(file))
                        {
                            file.AddLine("var componentPool = GetComponentPool(index);");
                            file.AddLine("var component = componentPool.Count > 0 ? componentPool.Pop() : blockMoveComponent;");
                            file.AddLine("AddComponent(index, component);");
                        }
                        file.AddLine("else");
                        using (new FileGenerator.Scop(file))
                        {
                            file.AddLine("RemoveComponent(index);");
                        }
                    }
                }
            }
        }
Example #4
0
        private static void GenNormalComponent(ComonentInfo info, FileGenerator file, bool isView)
        {
            string lookupName = string.Format("{0}ComponentsLookup.{1}", isView ? "View" : "Game", info.ShowName);

            file.AddFormat("{2} {3} {0} get {0} return ({2})GetComponent({4}); {1} {1}"
                           , "{", "}"
                           , info.FullName, LowerFirstCase(info.ShowName)
                           , lookupName);
            file.AddFormat("public bool has{2} {0} get {0} return HasComponent({3});{1} {1}"
                           , "{", "}"
                           , info.ShowName, lookupName);
            file.AddLine();

            //AddComponent
            file.AddFormat("public void Add{0}({1})", info.ShowName, GenParamList(info));
            using (new FileGenerator.Scop(file))
            {
                file.AddFormat("var index = {0};", lookupName);
                file.AddFormat("var component = CreateComponent<{0}>(index);", info.FullName);
                GenAssignment(info, file);
                file.AddLine("AddComponent(index, component);");
            }
            file.AddLine();

            //ReplaceComponent
            file.AddFormat("public void Replace{0}({1})", info.ShowName, GenParamList(info));
            using (new FileGenerator.Scop(file))
            {
                file.AddFormat("var index = {0};", lookupName);
                file.AddFormat("{0} component = null;", info.FullName);
                file.AddLine("if (HasComponent(index))");
                using (new FileGenerator.Scop(file))
                {
                    file.AddFormat("component = ({0})GetComponent(index);", info.FullName);
                }
                file.AddLine("else");
                using (new FileGenerator.Scop(file))
                {
                    file.AddFormat("component = CreateComponent<{0}>(index);", info.FullName);
                }
                GenAssignment(info, file);
                file.AddLine("ReplaceComponent(index, component);");
            }
            file.AddLine();

            //RemoveComponent
            file.AddFormat("public void Remove{0}()", info.ShowName);
            using (new FileGenerator.Scop(file))
            {
                file.AddFormat("RemoveComponent({0});", lookupName);
            }
        }
Example #5
0
        public static void Gen(ComonentInfo info, FileGenerator file, bool isView)
        {
            if (info.IsUnique)
            {
                return;
            }

            file.AddLine("public partial class GameEntity");
            using (new FileGenerator.Scop(file))
            {
                if (info.Fields.Count > 0)
                {
                    GenNormalComponent(info, file, isView);
                }
                else
                {
                    GenFlagComponent(info, file, isView);
                }
            }
            GenMatcher(info, file, isView);
        }
 public static void GenViewContext(FileGenerator file, ComponentList components)
 {
     file.AddLine("public partial class ViewContext : GameContext");
     using (new FileGenerator.Scop(file))
     {
         GenEntityIndexKey(file, components.ViewComponents);
         file.AddLine("public ViewContext()");
         file.AddLine("   : base(ViewComponentsLookup.TotalComponents, ViewComponentsLookup.componentNames, ViewComponentsLookup.componentTypes, \"View\")");
         file.BeginScop();
         file.EndScop();
         file.AddLine();
         file.AddLine("protected override void InitializeEntityIndices()");
         using (new FileGenerator.Scop(file))
         {
             file.AddLine("base.InitializeEntityIndices();");
             GenEntityIndex(file, components.ViewComponents, true);
         }
         file.AddLine();
         GenGetEntityIndex(file, components.ViewComponents, true);
     }
 }
Example #7
0
        public static void GenMatcher(ComonentInfo info, FileGenerator file, bool isView)
        {
            string lookupName = string.Format("{0}ComponentsLookup.{1}", isView ? "View" : "Game", info.ShowName);

            if (isView)
            {
                file.AddLine("public sealed partial class ViewMatcher");
            }
            else
            {
                file.AddLine("public sealed partial class GameMatcher");
            }
            using (new FileGenerator.Scop(file))
            {
                file.AddFormat("static ECSCore.IMatcher<GameEntity> _matcher{0};", info.ShowName);
                file.AddLine();
                file.AddFormat("public static ECSCore.IMatcher<GameEntity> {0}", info.ShowName);
                using (new FileGenerator.Scop(file))
                {
                    file.AddLine("get");
                    using (new FileGenerator.Scop(file))
                    {
                        file.AddFormat("if (_matcher{0} == null)", info.ShowName);
                        using (new FileGenerator.Scop(file))
                        {
                            file.AddFormat("var matcher = (ECSCore.Matcher<GameEntity>)ECSCore.Matcher<GameEntity>.AllOf({0});", lookupName);
                            if (isView)
                            {
                                file.AddLine("matcher.componentNames = ViewComponentsLookup.componentNames;");
                            }
                            else
                            {
                                file.AddLine("matcher.componentNames = GameComponentsLookup.componentNames;");
                            }
                            file.AddFormat("_matcher{0} = matcher;", info.ShowName);
                        }
                        file.AddFormat("return _matcher{0};", info.ShowName);
                    }
                }
            }
        }
        public static void GenGameContext(FileGenerator file, ComponentList components)
        {
            file.AddLine("public partial class GameEntity : ECSCore.Entity");
            file.BeginScop();
            file.EndScop();
            file.AddLine();

            file.AddLine("public partial class GameContext : ECSCore.Context<GameEntity>");
            using (new FileGenerator.Scop(file))
            {
                GenEntityIndexKey(file, components.GameComponents);
                file.AddLine("public GameContext(int totalComponents, string[] names, System.Type[] types, string name)");
                file.AddLine("    : base(totalComponents, 0, new ECSCore.ContextInfo(name, names, types),");
                file.AddLine("          (entity) =>\n#if (!UNITY_EDITOR)");
                file.AddLine("            new UnsafeAERC(),\n#else");
                file.AddLine("            new ECSCore.SafeAERC(entity),\n#endif");
                file.AddLine("             () => new GameEntity())");
                using (new FileGenerator.Scop(file))
                {
                    file.AddLine("InitializeEntityIndices();");
                }
                file.AddLine();

                file.AddLine("public GameContext(int totalComponents, string[] names, System.Type[] types)");
                file.AddLine("   : this(totalComponents, names, types, \"Game\")");
                file.BeginScop();
                file.EndScop();
                file.AddLine();

                file.AddLine("public GameContext()");
                file.AddLine("   : this(GameComponentsLookup.TotalComponents, GameComponentsLookup.componentNames, GameComponentsLookup.componentTypes, \"Game\")");
                file.BeginScop();
                file.EndScop();
                file.AddLine();

                file.AddLine("protected virtual void InitializeEntityIndices()");
                using (new FileGenerator.Scop(file))
                {
                    GenEntityIndex(file, components.GameComponents, false);
                }
                file.AddLine();
                GenGetEntityIndex(file, components.GameComponents, false);
            }
            GenMatcher(file);
        }