Esempio n. 1
0
        string getFilter(ComponentData data, string contextName, EventData eventData)
        {
            var filter = string.Empty;

            if (data.GetMemberData().Length == 0)
            {
                switch (eventData.eventType)
                {
                case EventType.Added:
                    filter = "entity." + data.PrefixedComponentName();
                    break;

                case EventType.Removed:
                    filter = "!entity." + data.PrefixedComponentName();
                    break;
                }
            }
            else
            {
                switch (eventData.eventType)
                {
                case EventType.Added:
                    filter = "entity.has" + data.ComponentName();
                    break;

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

            if (eventData.eventTarget == EventTarget.Self)
            {
                filter += " && entity.has" + data.EventListener(contextName, eventData);
            }

            return(filter);
        }
 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()));
 }
Esempio n. 3
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());
        }