Example #1
0
        public static string Event(this MainEntity ent, Contexts contexts, string contextName, EventInfo eventInfo)
        {
            var optionalContextName = ent.hasContextNamesComp && ent.contextNamesComp.Values.Count > 1 ? contextName : string.Empty;
            var theAnyPrefix        = eventInfo.EventTarget == EventTarget.Any ? "Any" : "";

            return(optionalContextName + theAnyPrefix + ent.ComponentName(contexts) + ent.GetEventTypeSuffix(eventInfo));
        }
Example #2
0
        public static string Replace(this string template, Contexts contexts, MainEntity ent, string contextName)
        {
            if (ent.hasComp)
            {
                var componentName = ent.ComponentName(contexts);
                template = template
                           .Replace(contextName)
                           .Replace("${ComponentType}", ent.comp.FullTypeName)
                           .Replace("${ComponentName}", componentName)
                           .Replace("${validComponentName}", componentName.LowercaseFirst())
                           .Replace("${componentName}", componentName.LowercaseFirst())
                           .Replace("${Index}", contextName + LOOKUP + "." + componentName)
                           .Replace("${prefixedComponentName}", ent.PrefixedComponentName(contexts));
            }

            if (ent.hasPublicFieldsComp)
            {
                template = template
                           .Replace("${newMethodParameters}", GetMethodParameters(ent.publicFieldsComp.Values, true))
                           .Replace("${methodParameters}", GetMethodParameters(ent.publicFieldsComp.Values, false))
                           .Replace("${newMethodArgs}", GetMethodArgs(ent.publicFieldsComp.Values, true))
                           .Replace("${methodArgs}", GetMethodArgs(ent.publicFieldsComp.Values, false));
            }
            return(template);
        }
Example #3
0
        public static string GetEventMethodArgs(this MainEntity ent, EventInfo eventInfo, string args)
        {
            if (!ent.hasPublicFieldsComp)
            {
                return(string.Empty);
            }

            return(eventInfo.EventType == EventType.Removed
                ? string.Empty
                : args);
        }
Example #4
0
        public static string Replace(this string template, Contexts contexts, MainEntity ent, string contextName,
                                     EventInfo eventInfo)
        {
            var eventListener = ent.EventListener(contexts, contextName, eventInfo);

            return(template
                   .Replace(contexts, ent, contextName)
                   .Replace("${EventListenerComponent}", eventListener.AddComponentSuffix())
                   .Replace("${Event}", ent.Event(contexts, contextName, eventInfo))
                   .Replace("${EventListener}", eventListener)
                   .Replace("${eventListener}", eventListener.LowercaseFirst(  ))
                   .Replace("${EventType}", ent.GetEventTypeSuffix(eventInfo)));
        }
Example #5
0
        private void                                    ProvideComp(MainEntity ent)
        {
            var t = ent.typeComp.Value;

            if (t.ImplementsInterface <IComponent>(  ) &&
                !Attribute.GetCustomAttributes(t).OfType <DontGenerateAttribute>().Any())
            {
                ent.AddComp(t.Name, t.ToCompilableString(  ));
                ent.isAlreadyImplementedComp = true;
            }
            else
            {
                ent.AddNonIComp(t.Name, t.ToCompilableString());
            }
        }
Example #6
0
        private void                                    ProvideEventComp(MainEntity ent)
        {
            var type       = ent.typeComp.Value;
            var eventInfos = Attribute.GetCustomAttributes(type)
                             .OfType <EventAttribute>()
                             .Select(attr => new EventInfo(attr.eventTarget, attr.eventType, attr.priority))
                             .ToList();

            if (eventInfos.Count <= 0)
            {
                return;
            }

            ent.AddEventComp(eventInfos);
            CodeGeneratorExtentions.ProvideEventCompNewEnts(_contexts, ent);
        }
Example #7
0
        private void                                    ProvideContextNamesComp(MainEntity ent)
        {
            var t            = ent.typeComp.Value;
            var contextNames = Attribute
                               .GetCustomAttributes(t)
                               .OfType <Entitas.CodeGeneration.Attributes.ContextAttribute>()
                               .Select(attr => attr.contextName)
                               .ToList();

            if (contextNames.Count == 0)
            {
                ent.AddContextNamesComp(new List <string> {
                    "Undefined"
                });
                return;
            }

            ent.AddContextNamesComp(contextNames);
        }
Example #8
0
        private String                                  GetFilter(MainEntity ent, string contextName, EventInfo eventInfo)
        {
            var filter = string.Empty;

            if (!ent.hasPublicFieldsComp)
            {
                switch (eventInfo.EventType)
                {
                case EventType.Added:
                    filter = "entity." + ent.PrefixedComponentName(_contexts);
                    break;

                case EventType.Removed:
                    filter = "!entity." + ent.PrefixedComponentName(_contexts);
                    break;
                }
            }
            else
            {
                switch (eventInfo.EventType)
                {
                case EventType.Added:
                    filter = "entity.has" + ent.ComponentName(_contexts);
                    break;

                case EventType.Removed:
                    filter = "!entity.has" + ent.ComponentName(_contexts);
                    break;
                }
            }

            if (eventInfo.EventTarget == EventTarget.Self)
            {
                filter += " && entity.has" + ent.EventListener(_contexts, contextName, eventInfo);
            }

            return(filter);
        }
Example #9
0
        private void CreateFileEnt(MainEntity ent, EventInfo eventInfo, string contextName)
        {
            var methodArgs = ent.GetEventMethodArgs(eventInfo, ", " + (!ent.hasPublicFieldsComp
                                ? ent.PrefixedComponentName(_contexts)
                                : GetMethodArgs(ent.publicFieldsComp.Values.ToArray( ))));

            var filePath = "Events" + Path.DirectorySeparatorChar + "Systems" + Path.DirectorySeparatorChar +
                           ent.Event(_contexts, contextName, eventInfo) + "EventSystem.cs";

            var template = eventInfo.EventTarget == EventTarget.Self
                                ? TEMPLATE_SELF
                                : TEMPLATE_ANY;

            var cachedAccess = !ent.hasPublicFieldsComp
                                ? string.Empty
                                : "var component = e." + ent.ComponentName(_contexts).LowercaseFirst( ) + ";";

            if (eventInfo.EventType == EventType.Removed)
            {
                methodArgs   = string.Empty;
                cachedAccess = string.Empty;
            }

            var contents = template
                           .Replace("${GroupEvent}", eventInfo.EventType.ToString( ))
                           .Replace("${filter}", GetFilter(ent, contextName, eventInfo))
                           .Replace("${cachedAccess}", cachedAccess)
                           .Replace("${methodArgs}", methodArgs)
                           .Replace(_contexts, ent, contextName, eventInfo);

            var generatedBy = GetType( ).FullName;

            var fileEnt = _contexts.main.CreateEntity( );

            fileEnt.AddGeneratedFileComp(filePath, contents.WrapInNamespace(_contexts), generatedBy);
        }
Example #10
0
        public static void                                    ProvideEventCompNewEnts(Contexts contexts, MainEntity ent)
        {
            foreach (var contextName in ent.contextNamesComp.Values)
            {
                foreach (var eventInfo in ent.eventComp.Values)
                {
                    var componentName         = ent.comp.FullTypeName.ToComponentName(contexts.settings.isIgnoreNamespaces);
                    var optionalContextName   = ent.contextNamesComp.Values.Count > 1 ? contextName : string.Empty;
                    var eventTypeSuffix       = ent.GetEventTypeSuffix(eventInfo);
                    var theAnySuffix          = eventInfo.EventTarget == EventTarget.Any ? "Any" : "";
                    var listenerComponentName = optionalContextName + theAnySuffix + componentName + eventTypeSuffix + "Listener";
                    var eventCompFullTypeName = listenerComponentName.AddComponentSuffix();

                    var eventListenerCompEnt = contexts.main.CreateEntity(  );
                    eventListenerCompEnt.isEventListenerComp = true;

                    eventListenerCompEnt.AddComp(listenerComponentName, eventCompFullTypeName);
                    eventListenerCompEnt.AddContextNamesComp(new List <String> {
                        contextName
                    });
                    eventListenerCompEnt.AddPublicFieldsComp(new List <FieldInfo>
                    {
                        new FieldInfo("System.Collections.Generic.List<I" + listenerComponentName + ">", "value")
                    });
                }
            }
        }
Example #11
0
 public static string EventListener(this MainEntity ent, Contexts contexts, string contextName, EventInfo eventInfo)
 {
     return(ent.Event(contexts, contextName, eventInfo) + "Listener");
 }
Example #12
0
        public static string PrefixedComponentName(this MainEntity ent, Contexts contexts)
        {
            var uniquePrefix = ent.hasUniquePrefixComp ? ent.uniquePrefixComp.Value : "";

            return(uniquePrefix.LowercaseFirst() + ent.ComponentName(contexts));
        }
Example #13
0
 public static string ComponentNameWithContext(this MainEntity ent, string contextName)
 {
     return(contextName + ent.comp.Name);
 }
Example #14
0
 public static string ComponentName(this MainEntity ent, Contexts contexts)
 {
     return(ent.comp.FullTypeName.ToComponentName(contexts.settings.isIgnoreNamespaces));
 }
Example #15
0
 public static string GetEventTypeSuffix(this MainEntity ent, EventInfo eventInfo)
 {
     return(eventInfo.EventType == EventType.Removed ? "Removed" : string.Empty);
 }