예제 #1
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);");
                        }
                    }
                }
            }
        }
예제 #2
0
 private static void GenEntityIndex(FileGenerator file, List <ComonentInfo> list, bool isView)
 {
     foreach (var component in list)
     {
         if (component.IsUnique)
         {
             continue;
         }
         foreach (var field in component.Fields)
         {
             if (field.IndexType == ComonentInfo.EntityIndexType.None)
             {
                 continue;
             }
             if (field.IndexType == ComonentInfo.EntityIndexType.Index)
             {
                 file.AddFormat("AddEntityIndex(new ECSCore.EntityIndex<GameEntity, {0}>(", field.TypeName);
             }
             else
             {
                 file.AddFormat("AddEntityIndex(new ECSCore.PrimaryEntityIndex<GameEntity, {0}>(", field.TypeName);
             }
             file.AddFormat("    {0}_{1},", component.ShowName, field.Name);
             file.AddFormat("    GetGroup({0}Matcher.{1}),", isView ? "View" : "Game", component.ShowName);
             file.AddFormat("    (e, c) => (({0})c).{1}));", component.FullName, field.Name);
         }
     }
 }
예제 #3
0
 public static void GenAssignment(ComonentInfo info, FileGenerator file)
 {
     foreach (var field in info.Fields)
     {
         file.AddFormat("component.{0} = new{0};", field.Name);
     }
 }
예제 #4
0
 private static void GenGetEntityIndex(FileGenerator file, List <ComonentInfo> list, bool isView)
 {
     foreach (var component in list)
     {
         if (component.IsUnique)
         {
             continue;
         }
         foreach (var field in component.Fields)
         {
             if (field.IndexType == ComonentInfo.EntityIndexType.None)
             {
                 continue;
             }
             if (field.IndexType == ComonentInfo.EntityIndexType.Index)
             {
                 string paramName = ComponentGenerator.LowerFirstCase(field.Name);
                 file.AddFormat("public System.Collections.Generic.HashSet<GameEntity> GetEntitiesWith{0}{1}({2} {3})",
                                component.ShowName, field.Name, field.TypeName, paramName);
                 using (new FileGenerator.Scop(file))
                 {
                     file.AddFormat("return ((ECSCore.EntityIndex<GameEntity, {0}>)GetEntityIndex({1}_{2})).GetEntities({3});",
                                    field.TypeName, component.ShowName, field.Name, paramName);
                 }
             }
             else
             {
                 string paramName = ComponentGenerator.LowerFirstCase(field.Name);
                 file.AddFormat("public GameEntity GetEntityWith{0}{1}({2} {3})",
                                component.ShowName, field.Name, field.TypeName, paramName);
                 using (new FileGenerator.Scop(file))
                 {
                     file.AddFormat("return ((ECSCore.PrimaryEntityIndex<GameEntity, {0}>)GetEntityIndex({1}_{2})).GetEntity({3});",
                                    field.TypeName, component.ShowName, field.Name, paramName);
                 }
             }
         }
     }
 }
예제 #5
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);
             }
         }
     }
 }
예제 #6
0
 private static void GenEntityIndexKey(FileGenerator file, List <ComonentInfo> list)
 {
     foreach (var component in list)
     {
         if (component.IsUnique)
         {
             continue;
         }
         foreach (var field in component.Fields)
         {
             if (field.IndexType == ComonentInfo.EntityIndexType.None)
             {
                 continue;
             }
             file.AddFormat("public const string {0}_{1} = \"{0}.{1}\";", component.ShowName, field.Name);
         }
     }
 }
예제 #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);
                    }
                }
            }
        }
예제 #8
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);
            }
        }