CodeGenFile[] generateExtensions(ComponentData data)
        {
            if (data.GetContextNames().Length > 1)
            {
                return(new[] { generateInterface(data) }.Concat(
                           data.GetContextNames().Select(contextName => generateEntityInterfaceExtension(contextName, data))
                           ).ToArray());
            }

            return(new CodeGenFile[0]);
        }
        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
                       ));
        }
Example #3
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()));
        }
        public static string Replace(this string template, ComponentData data, string contextName, EventData eventData)
        {
            var eventListener      = data.EventListener(contextName, eventData);
            var lowerEventListener = data.GetContextNames().Length > 1
                ? contextName.LowercaseFirst() + data.ComponentName() + GetEventTypeSuffix(eventData).AddListenerSuffix()
                : data.ComponentName().LowercaseFirst() + GetEventTypeSuffix(eventData).AddListenerSuffix();

            return(template
                   .Replace(data, contextName)
                   .Replace("${EventListenerComponent}", eventListener.AddComponentSuffix())
                   .Replace("${Event}", data.Event(contextName, eventData))
                   .Replace("${EventListener}", eventListener)
                   .Replace("${eventListener}", lowerEventListener)
                   .Replace("${EventType}", GetEventTypeSuffix(eventData)));
        }
Example #5
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
                       ));
        }
        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());
        }
Example #7
0
        CodeGenFile generateComponentClass(ComponentData data)
        {
            var fullComponentName = data.GetFullTypeName().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[] generate(ComponentData data)
 {
     return(data.GetContextNames()
            .SelectMany(contextName => generate(contextName, data))
            .ToArray());
 }
 CodeGenFile[] generateMatcher(ComponentData data)
 {
     return(data.GetContextNames()
            .Select(context => generateMatcher(context, data))
            .ToArray());
 }
 CodeGenFile[] generateExtensions(ComponentData data)
 {
     return(data.GetContextNames()
            .Select(contextName => generateExtension(contextName, data))
            .ToArray());
 }
 CodeGenFile[] generateComponentMonoBehaviours(ComponentData data)
 {
     return(data.GetContextNames()
            .Select(contextName => generateComponentMonoBehaviousClass(contextName, data))
            .ToArray());
 }
        public static string Event(this ComponentData data, string contextName, EventData eventData)
        {
            var optionalContextName = data.GetContextNames().Length > 1 ? contextName : string.Empty;

            return(optionalContextName + data.ComponentName() + GetEventTypeSuffix(eventData));
        }
        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
                       ));
        }
Example #16
0
 string[] generateSystemListForData(ComponentData data)
 {
     return(data.GetContextNames()
            .Select(contextName => generateAddSystem(contextName, data))
            .ToArray());
 }
Example #17
0
 CodeGenFile[] generate(ComponentData data)
 {
     return(new[] { generateInterface(data) }
            .Concat(data.GetContextNames().Select(contextName => generateEntityInterface(contextName, data)))
            .ToArray());
 }