예제 #1
0
 public static void SetFlagPrefix(this ComponentData data, string prefix)
 {
     data[COMPONENT_FLAG_PREFIX] = prefix;
 }
예제 #2
0
        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));
        }
예제 #3
0
 CodeGenFile[] generate(ComponentData data)
 {
     return(data.GetContextNames()
            .SelectMany(contextName => generate(contextName, data))
            .ToArray());
 }
        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
                       ));
        }
예제 #5
0
 public static string ComponentNameWithContext(this ComponentData data, string contextName)
 {
     return(contextName + data.ComponentName());
 }
 public static string GetTypeName(this ComponentData data)
 {
     return((string)data[COMPONENT_TYPE]);
 }
 public void Provide(Type type, ComponentData data)
 {
     data.SetlTypeName(type.ToCompilableString());
 }
 public static void SetContextNames(this ComponentData data, string[] contextNames)
 {
     data[COMPONENT_CONTEXTS] = contextNames;
 }
 public static string ComponentNameValidLowercaseFirst(this ComponentData data)
 {
     return(ComponentName(data).LowercaseFirst().AddPrefixIfIsKeyword());
 }
        public void Provide(Type type, ComponentData data)
        {
            var contextNames = GetContextNamesOrDefault(type);

            data.SetContextNames(contextNames);
        }
 public static string[] GetContextNames(this ComponentData data)
 {
     return((string[])data[COMPONENT_CONTEXTS]);
 }
예제 #12
0
 public static void IsUnique(this ComponentData data, bool isUnique)
 {
     data[COMPONENT_IS_UNIQUE] = isUnique;
 }
예제 #13
0
 public static bool IsUnique(this ComponentData data)
 {
     return((bool)data[COMPONENT_IS_UNIQUE]);
 }
예제 #14
0
 public void Provide(Type type, ComponentData data)
 {
     data.SetFlagPrefix(getFlagPrefix(type));
 }
예제 #15
0
 public static MemberData[] GetMemberData(this ComponentData data)
 {
     return((MemberData[])data[COMPONENT_MEMBER_INFOS]);
 }
 public static string EventListener(this ComponentData data, string contextName, EventData eventData)
 {
     return(data.Event(contextName, eventData).AddListenerSuffix());
 }
예제 #17
0
 public static void SetMemberData(this ComponentData data, MemberData[] memberInfos)
 {
     data[COMPONENT_MEMBER_INFOS] = memberInfos;
 }
예제 #18
0
 public static bool ShouldGenerateMethods(this ComponentData data)
 {
     return((bool)data[COMPONENT_GENERATE_METHODS]);
 }
 public static void SetlTypeName(this ComponentData data, string fullTypeName)
 {
     data[COMPONENT_TYPE] = fullTypeName;
 }
예제 #20
0
 public static void ShouldGenerateMethods(this ComponentData data, bool generate)
 {
     data[COMPONENT_GENERATE_METHODS] = generate;
 }
 CodeGenFile[] generateExtensions(ComponentData data)
 {
     return(data.GetContextNames()
            .Select(contextName => generateExtension(contextName, data))
            .ToArray());
 }
예제 #22
0
 public static bool ShouldGenerateIndex(this ComponentData data)
 {
     return((bool)data[COMPONENT_GENERATE_INDEX]);
 }
예제 #23
0
 public static string ComponentName(this ComponentData data)
 {
     return(data.GetTypeName().ToComponentName(ignoreNamespaces));
 }
예제 #24
0
 public static void ShouldGenerateIndex(this ComponentData data, bool generate)
 {
     data[COMPONENT_GENERATE_INDEX] = generate;
 }
예제 #25
0
 public static string PrefixedComponentName(this ComponentData data)
 {
     return(data.GetUniquePrefix().LowercaseFirst() + data.ComponentName());
 }
예제 #26
0
 public void Provide(Type type, ComponentData data)
 {
     data.ShouldGenerateIndex(getGenerateIndex(type));
 }
예제 #27
0
 public static string EventListener(this ComponentData data, string contextName, EventData eventData)
 {
     return(data.Event(contextName, eventData) + "Listener");
 }
예제 #28
0
 public ComponentData(ComponentData data) : base(data)
 {
 }
예제 #29
0
 CodeGenFile[] generate(ComponentData data)
 {
     return(new[] { generateInterface(data) }
            .Concat(data.GetContextNames().Select(contextName => generateEntityInterface(contextName, data)))
            .ToArray());
 }
예제 #30
0
 public static string GetFlagPrefix(this ComponentData data)
 {
     return((string)data[COMPONENT_FLAG_PREFIX]);
 }