Ejemplo n.º 1
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());
 }
        public static string Replace(this string template, ComponentData data, string contextName, EventData eventData)
        {
            var eventListener = data.EventListener(contextName, eventData);

            return(template
                   .Replace(data, contextName)
                   .Replace("${EventComponentName}", data.EventComponentName(eventData))
                   .Replace("${EventListenerComponent}", eventListener.AddComponentSuffix())
                   .Replace("${Event}", data.Event(contextName, eventData))
                   .Replace("${EventListener}", eventListener)
                   .Replace("${eventListener}", eventListener.LowercaseFirst())
                   .Replace("${EventType}", GetEventTypeSuffix(eventData)));
        }
        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)));
        }
Ejemplo n.º 4
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);
        }
        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());
        }