CodeGenFile generateInterface(ComponentData data)
        {
            var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var memberData    = data.GetMemberData();
            var interfaceName = "I" + componentName.RemoveComponentSuffix();

            var template = memberData.Length == 0
                ? FLAG_INTERFACE_TEMPLATE
                : STANDARD_INTERFACE_TEMPLATE;

            var fileContent = template
                              .Replace("${InterfaceName}", interfaceName)
                              .Replace("${ComponentType}", data.GetTypeName())
                              .Replace("${ComponentName}", componentName)
                              .Replace("${componentName}", componentName.LowercaseFirst())
                              .Replace("${prefixedName}", data.GetUniquePrefix().LowercaseFirst() + componentName)
                              .Replace("${memberArgs}", getMemberArgs(memberData));

            return(new CodeGenFile(
                       "Components" + Path.DirectorySeparatorChar +
                       "Interfaces" + Path.DirectorySeparatorChar +
                       interfaceName + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
        CodeGenFile generateExtension(string contextName, ComponentData data)
        {
            var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var index         = contextName + ComponentLookupGenerator.COMPONENTS_LOOKUP + "." + componentName;
            var memberData    = data.GetMemberData();
            var template      = memberData.Length == 0
                ? FLAG_COMPONENT_TEMPLATE
                : STANDARD_COMPONENT_TEMPLATE;

            var fileContent = template
                              .Replace("${ContextName}", contextName)
                              .Replace("${ComponentType}", data.GetTypeName())
                              .Replace("${ComponentName}", componentName)
                              .Replace("${componentName}", componentName.LowercaseFirst())
                              .Replace("${prefixedName}", data.GetUniquePrefix().LowercaseFirst() + componentName)
                              .Replace("${Index}", index)
                              .Replace("${memberArgs}", getMemberArgs(memberData))
                              .Replace("${memberAssignment}", getMemberAssignment(memberData));

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       contextName + componentName.AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
        public static string EventComponentName(this ComponentData data, EventData eventData)
        {
            var componentName      = data.GetTypeName().ToComponentName(ignoreNamespaces);
            var shortComponentName = data.GetTypeName().ToComponentName(true);
            var eventComponentName = componentName.Replace(
                shortComponentName,
                eventData.GetEventPrefix() + shortComponentName
                );

            return(eventComponentName);
        }
        CodeGenFile generateInterface(string contextName, ComponentData data)
        {
            var optionalContextName = data.GetContextNames().Length > 1 ? contextName : string.Empty;
            var componentName       = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var memberData          = data.GetMemberData();

            if (memberData.Length == 0)
            {
                memberData = new[] { new MemberData("bool", data.GetUniquePrefix().LowercaseFirst() + componentName) };
            }

            var eventTypeSuffix = string.Empty;
            var memberArgs      = ", " + getMemberArgs(memberData);

            if (data.GetMemberData().Length == 0)
            {
                switch (data.GetEventType())
                {
                case EventType.Added:
                    eventTypeSuffix = "Added";
                    memberArgs      = string.Empty;
                    break;

                case EventType.Removed:
                    eventTypeSuffix = "Removed";
                    memberArgs      = string.Empty;
                    break;
                }
            }
            else
            {
                switch (data.GetEventType())
                {
                case EventType.Removed:
                    eventTypeSuffix = "Removed";
                    memberArgs      = string.Empty;
                    break;

                case EventType.AddedOrRemoved:
                    eventTypeSuffix = "AddedOrRemoved";
                    break;
                }
            }

            var fileContent = INTERFACE_TEMPLATE
                              .Replace("${ContextName}", contextName)
                              .Replace("${OptionalContextName}", optionalContextName)
                              .Replace("${ComponentName}", componentName)
                              .Replace("${ComponentName}", componentName)
                              .Replace("${EventType}", eventTypeSuffix)
                              .Replace("${memberArgs}", memberArgs);

            return(new CodeGenFile(
                       "Events" + Path.DirectorySeparatorChar +
                       "Interfaces" + Path.DirectorySeparatorChar +
                       "I" + contextName + componentName + "Listener.cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
Beispiel #5
0
 string generateAddSystem(string contextName, ComponentData data)
 {
     return(SYSTEM_ADD_TEMPLATE
            .Replace("${ContextName}", contextName)
            .Replace("${ComponentName}", data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces))
            .Replace("${priority}", data.GetEventData().priority.ToString()));
 }
Beispiel #6
0
        string generateAddSystem(string contextName, ComponentData data)
        {
            var optionalContextName = data.GetContextNames().Length > 1 ? contextName : string.Empty;

            return(SYSTEM_ADD_TEMPLATE
                   .Replace("${OptionalContextName}", optionalContextName)
                   .Replace("${ComponentName}", data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces))
                   .Replace("${priority}", data.GetEventPriority().ToString()));
        }
Beispiel #7
0
        CodeGenFile generateComponentClass(ComponentData data)
        {
            var fullComponentName = data.GetTypeName().RemoveDots();

            return(new CodeGenFile(
                       "Components" + Path.DirectorySeparatorChar + fullComponentName + ".cs",
                       COMPONENT_TEMPLATE
                       .Replace("${FullComponentName}", fullComponentName)
                       .Replace("${Type}", data.GetObjectType()),
                       GetType().FullName
                       ));
        }
 public static string Replace(this string template, ComponentData data, string contextName)
 {
     return(template
            .Replace(contextName)
            .Replace("${ComponentType}", data.GetTypeName())
            .Replace("${ComponentName}", data.ComponentName())
            .Replace("${componentName}", data.ComponentName().LowercaseFirst())
            .Replace("${validComponentName}", data.ComponentNameValidLowercaseFirst())
            .Replace("${prefixedComponentName}", data.PrefixedComponentName())
            .Replace("${newMethodParameters}", GetMethodParameters(data.GetMemberData(), true))
            .Replace("${methodParameters}", GetMethodParameters(data.GetMemberData(), false))
            .Replace("${newMethodArgs}", GetMethodArgs(data.GetMemberData(), true))
            .Replace("${methodArgs}", GetMethodArgs(data.GetMemberData(), false))
            .Replace("${Index}", contextName + LOOKUP + "." + data.ComponentName()));
 }
Beispiel #9
0
        ComponentData createDataForEvents(ComponentData data)
        {
            var dataForEvent = new ComponentData(data);

            dataForEvent.SetEventData(null);
            var componentName = dataForEvent.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);

            componentName += "Listener";
            dataForEvent.SetlTypeName(componentName.AddComponentSuffix());
            dataForEvent.SetMemberData(new[] {
                new MemberData("I" + componentName, "value")
            });

            return(dataForEvent);
        }
Beispiel #10
0
        CodeGenFile generateComponentMonoBehaviousClass(string contextName, ComponentData data, int index)
        {
            var memberData    = data.GetMemberData();
            var componentType = data.GetTypeName();

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar + "ComponentsMonoBehaviours" + Path.DirectorySeparatorChar + contextName + componentType + "MonoBehaviour.cs",
                       COMPONENT_TEMPLATE
                       .Replace("${Context}", contextName)
                       .Replace("${ComponentType}", componentType)
                       .Replace("${ComponentIndex}", index.ToString())
                       .Replace("${memberArgs}", getMemberArgs(memberData))
                       .Replace("${memberAssignment}", getMemberAssignment(memberData)),
                       GetType().FullName
                       ));
        }
        CodeGenFile generateEntityInterfaceExtension(string contextName, ComponentData data)
        {
            var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var interfaceName = "I" + componentName.RemoveComponentSuffix();

            var fileContent = ENTITY_INTERFACE_EXTENSION
                              .Replace("${InterfaceName}", "I" + componentName.RemoveComponentSuffix())
                              .Replace("${ContextName}", contextName);

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       contextName + componentName.AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
Beispiel #12
0
        CodeGenFile generateComponent(string contextName, ComponentData data)
        {
            var optionalContextName = data.GetContextNames().Length > 1 ? contextName : string.Empty;
            var componentName       = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);

            var fileContent = COMPONENT_TEMPLATE
                              .Replace("${OptionalContextName}", optionalContextName)
                              .Replace("${ComponentName}", componentName);

            return(new CodeGenFile(
                       "Events" + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       optionalContextName + componentName + "Listener".AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
        CodeGenFile generateSystem(string contextName, ComponentData data)
        {
            var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var memberData    = data.GetMemberData();

            var groupEvent = memberData.Length == 0
                ? "AddedOrRemoved"
                : "Added";

            var filter = memberData.Length == 0
                ? "true"
                : "entity.has" + componentName;

            var cachedAccess = memberData.Length == 0
                ? "var " + data.GetUniquePrefix() + componentName + " = e." + data.GetUniquePrefix() + componentName + ";"
                : "var component = e." + componentName.LowercaseFirst() + ";";

            var methodArgs = memberData.Length == 0
                ? data.GetUniquePrefix() + componentName
                : getMethodArgs(memberData);

            var template = data.GetEventData().bindToEntity
                ? ENTITY_SYSTEM_TEMPLATE
                : SYSTEM_TEMPLATE;

            var fileContent = template
                              .Replace("${ContextName}", contextName)
                              .Replace("${contextName}", contextName.LowercaseFirst())
                              .Replace("${ComponentName}", componentName)
                              .Replace("${componentName}", componentName.LowercaseFirst())
                              .Replace("${GroupEvent}", groupEvent)
                              .Replace("${filter}", filter)
                              .Replace("${cachedAccess}", cachedAccess)
                              .Replace("${methodArgs}", methodArgs);

            return(new CodeGenFile(
                       "Events" + Path.DirectorySeparatorChar +
                       "Systems" + Path.DirectorySeparatorChar +
                       contextName + componentName + "EventSystem.cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
        ComponentData[] createDataForEvents(ComponentData data)
        {
            var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);

            return(data.GetContextNames()
                   .Select(contextName => {
                var dataForEvent = new ComponentData(data);
                dataForEvent.IsEvent(false);
                var optionalContextName = dataForEvent.GetContextNames().Length > 1 ? contextName : string.Empty;
                var listenerComponentName = optionalContextName + componentName + "Listener";
                dataForEvent.SetlTypeName(listenerComponentName.AddComponentSuffix());
                dataForEvent.SetMemberData(new[] {
                    new MemberData("I" + listenerComponentName, "value")
                });
                dataForEvent.SetContextNames(new[] { contextName });
                return dataForEvent;
            })
                   .ToArray());
        }
        CodeGenFile generateMatcher(string contextName, ComponentData data)
        {
            var componentName  = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var index          = contextName + ComponentLookupGenerator.COMPONENTS_LOOKUP + "." + componentName;
            var componentNames = contextName + ComponentLookupGenerator.COMPONENTS_LOOKUP + ".componentNames";

            var fileContent = STANDARD_COMPONENT_TEMPLATE
                              .Replace("${ContextName}", contextName)
                              .Replace("${ComponentName}", componentName)
                              .Replace("${Index}", index)
                              .Replace("${ComponentNames}", componentNames);

            return(new CodeGenFile(
                       contextName + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       contextName + componentName.AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
        CodeGenFile generateComponentClass(ComponentData data)
        {
            var fullComponentName = data.GetTypeName().RemoveDots();
            var contexts          = string.Join(", ", data.GetContextNames());
            var unique            = data.IsUnique() ? "[Entitas.CodeGeneration.Attributes.UniqueAttribute]" : string.Empty;

            if (!string.IsNullOrEmpty(contexts))
            {
                contexts = "[" + contexts + "]";
            }

            return(new CodeGenFile(
                       "Components" + Path.DirectorySeparatorChar + fullComponentName + ".cs",
                       COMPONENT_TEMPLATE
                       .Replace("${FullComponentName}", fullComponentName)
                       .Replace("${Type}", data.GetObjectType())
                       .Replace("${Contexts}", contexts)
                       .Replace("${Unique}", unique),
                       GetType().FullName
                       ));
        }
        ComponentData[] createDataForEvents(ComponentData data)
        {
            var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);

            return(data.GetContextNames()
                   .SelectMany(contextName =>
                               data.GetEventData().Select(eventData => {
                var dataForEvent = new ComponentData(data);
                dataForEvent.IsEvent(false);
                dataForEvent.IsUnique(false);
                var eventTypeSuffix = eventData.GetEventTypeSuffix();
                var optionalContextName = dataForEvent.GetContextNames().Length > 1 ? contextName : string.Empty;
                var listenerComponentName = optionalContextName + componentName + eventTypeSuffix + "Listener";
                dataForEvent.SetTypeName(listenerComponentName.AddComponentSuffix());
                dataForEvent.SetMemberData(new[] {
                    new MemberData("System.Collections.Generic.List<I" + listenerComponentName + ">", "value")
                });
                dataForEvent.SetContextNames(new[] { contextName });
                return dataForEvent;
            }).ToArray()
                               ).ToArray());
        }
        CodeGenFile generateComponent(ComponentData data)
        {
            var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var contexts      = string.Join(", ", data.GetContextNames());

            if (!string.IsNullOrEmpty(contexts))
            {
                contexts = "[" + contexts + "]";
            }

            var fileContent = COMPONENT_TEMPLATE
                              .Replace("${Contexts}", contexts)
                              .Replace("${ComponentName}", componentName);

            return(new CodeGenFile(
                       "Events" + Path.DirectorySeparatorChar +
                       "Components" + Path.DirectorySeparatorChar +
                       componentName + "Listener".AddComponentSuffix() + ".cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
        CodeGenFile generateInterface(ComponentData data)
        {
            var componentName = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var memberData    = data.GetMemberData();

            if (memberData.Length == 0)
            {
                memberData = new[] { new MemberData("bool", data.GetUniquePrefix().LowercaseFirst() + componentName) };
            }

            var fileContent = INTERFACE_TEMPLATE
                              .Replace("${ComponentName}", componentName)
                              .Replace("${memberArgs}", getMemberArgs(memberData));

            return(new CodeGenFile(
                       "Events" + Path.DirectorySeparatorChar +
                       "Interfaces" + Path.DirectorySeparatorChar +
                       "I" + componentName + "Listener.cs",
                       fileContent,
                       GetType().FullName
                       ));
        }
 public static string ComponentName(this ComponentData data)
 {
     return(data.GetTypeName().ToComponentName(ignoreNamespaces));
 }
        CodeGenFile generateSystem(string contextName, ComponentData data)
        {
            var optionalContextName = data.GetContextNames().Length > 1 ? contextName : string.Empty;
            var componentName       = data.GetTypeName().ToComponentName(_ignoreNamespacesConfig.ignoreNamespaces);
            var memberData          = data.GetMemberData();

            var methodArgs = ", " + (memberData.Length == 0
                                 ? data.GetUniquePrefix() + componentName
                                 : getMethodArgs(memberData));

            var eventTypeSuffix = string.Empty;
            var filter          = string.Empty;

            if (data.GetMemberData().Length == 0)
            {
                switch (data.GetEventType())
                {
                case EventType.Added:
                    eventTypeSuffix = "Added";
                    methodArgs      = string.Empty;
                    filter          = "entity." + data.GetUniquePrefix() + componentName;
                    break;

                case EventType.Removed:
                    eventTypeSuffix = "Removed";
                    methodArgs      = string.Empty;
                    filter          = "!entity." + data.GetUniquePrefix() + componentName;
                    break;

                case EventType.AddedOrRemoved:
                    filter = "true";
                    break;
                }
            }
            else
            {
                switch (data.GetEventType())
                {
                case EventType.Added:
                    filter = "entity.has" + componentName;
                    break;

                case EventType.Removed:
                    eventTypeSuffix = "Removed";
                    methodArgs      = string.Empty;
                    filter          = "!entity.has" + componentName;
                    break;

                case EventType.AddedOrRemoved:
                    eventTypeSuffix = "AddedOrRemoved";
                    filter          = "true";
                    break;
                }
            }

            if (data.GetEventBindToEntity())
            {
                if (filter == "true")
                {
                    filter = "entity.has${OptionalContextName}${ComponentName}Listener";
                }
                else
                {
                    filter += " && entity.has${OptionalContextName}${ComponentName}Listener";
                }
            }

            filter = filter
                     .Replace("${OptionalContextName}", optionalContextName)
                     .Replace("${ComponentName}", componentName);

            var cachedAccess = memberData.Length == 0
                ? "var " + data.GetUniquePrefix() + componentName + " = e." + data.GetUniquePrefix() + componentName + ";"
                : "var component = e." + componentName.LowercaseFirst() + ";";

            var template = data.GetEventBindToEntity()
                ? ENTITY_SYSTEM_TEMPLATE
                : SYSTEM_TEMPLATE;

            var fileContent = template
                              .Replace("${ContextName}", contextName)
                              .Replace("${contextName}", contextName.LowercaseFirst())
                              .Replace("${OptionalContextName}", optionalContextName)
                              .Replace("${optionalContextName}", optionalContextName == string.Empty ? string.Empty : optionalContextName.LowercaseFirst())
                              .Replace("${ComponentName}", componentName)
                              .Replace("${contextDependentComponentName}", optionalContextName == string.Empty ? componentName.LowercaseFirst() : componentName)
                              .Replace("${GroupEvent}", data.GetEventType().ToString())
                              .Replace("${filter}", filter)
                              .Replace("${cachedAccess}", cachedAccess)
                              .Replace("${EventType}", eventTypeSuffix)
                              .Replace("${methodArgs}", methodArgs);

            return(new CodeGenFile(
                       "Events" + Path.DirectorySeparatorChar +
                       "Systems" + Path.DirectorySeparatorChar +
                       optionalContextName + componentName + "EventSystem.cs",
                       fileContent,
                       GetType().FullName
                       ));
        }