Esempio n. 1
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()));
 }
Esempio n. 2
0
 CodeGenFile[] generate(string contextName, ComponentData data)
 {
     return(data.GetEventData()
            .Select(eventData => new CodeGenFile(
                        "Events" + Path.DirectorySeparatorChar +
                        "Components" + Path.DirectorySeparatorChar +
                        data.EventListener(contextName, eventData).AddComponentSuffix() + ".cs",
                        TEMPLATE.Replace(data, contextName, eventData),
                        GetType().FullName
                        )).ToArray());
 }
        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()
                   .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());
        }
Esempio n. 5
0
        CodeGenFile[] generate(string contextName, ComponentData data)
        {
            return(data.GetEventData()
                   .Select(eventData => {
                var methodArgs = data.GetEventMethodArgs(eventData, ", " + (data.GetMemberData().Length == 0
                                                                            ? data.PrefixedComponentName()
                                                                            : getMethodArgs(data.GetMemberData())));

                var cachedAccess = data.GetMemberData().Length == 0
                        ? string.Empty
                        : "var component = e." + data.ComponentName().LowercaseFirst() + ";";

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

                var template = eventData.eventTarget == EventTarget.Self
                        ? SELF_TARGET_TEMPLATE
                        : ANY_TARGET_TEMPLATE;

                var fileContent = template
                                  .Replace("${GroupEvent}", eventData.eventType.ToString())
                                  .Replace("${filter}", getFilter(data, contextName, eventData))
                                  .Replace("${cachedAccess}", cachedAccess)
                                  .Replace("${methodArgs}", methodArgs)
                                  .Replace(data, contextName, eventData);

                return new CodeGenFile(
                    "Events" + Path.DirectorySeparatorChar +
                    "Systems" + Path.DirectorySeparatorChar +
                    data.Event(contextName, eventData) + "EventSystem.cs",
                    fileContent,
                    GetType().FullName
                    );
            }).ToArray());
        }
        CodeGenFile[] generate(string contextName, ComponentData data)
        {
            return(data.GetEventData()
                   .Select(eventData => {
                var memberData = data.GetMemberData();
                if (memberData.Length == 0)
                {
                    memberData = new[] { new MemberData("bool", data.PrefixedComponentName()) };
                }

                var fileContent = TEMPLATE
                                  .Replace("${methodParameters}", data.GetEventMethodArgs(eventData, ", " + memberData.GetMethodParameters(false)))
                                  .Replace(data, contextName, eventData);

                return new CodeGenFile(
                    "Events" + Path.DirectorySeparatorChar +
                    "Interfaces" + Path.DirectorySeparatorChar +
                    "I" + data.EventListener(contextName, eventData) + ".cs",
                    fileContent,
                    GetType().FullName
                    );
            }).ToArray());
        }