Inheritance: ICodeGeneratorDataProvider
        public static void Generate()
        {
            var generatedFolder = getEntitasProjectDir() + "/Tests/Tests/Entitas/CodeGenerator/Fixtures/Generated/";

            var codeGenerators = new ICodeGenerator[] {
                new ComponentExtensionsGenerator(),
                new ComponentIndicesGenerator(),
                new ContextAttributesGenerator(),
                new ContextsGenerator(),
                new BlueprintsGenerator()
            };

            var types = new [] {
                typeof(AnimatingComponent),
                typeof(CComponent),
                typeof(ComponentWithFieldsAndProperties),
                typeof(CustomPrefixComponent),
                typeof(DefaultContextComponent),
                typeof(MovableComponent),
                typeof(MultipleContextAndDefaultContextComponent),
                typeof(NamespaceComponent),
                typeof(OtherContextComponent),
                typeof(PersonComponent),
                typeof(SomeClass),
                typeof(SomeClassHideInBlueprintInspector),
                typeof(SomeStruct),
                typeof(UserComponent)
            };

            var contexts = new [] {
                "ContextA",
                "ContextB",
                "ContextC",
                "OtherContext",
                "SomeContext",
                "SomeOtherContext"
            };

            var blueprints = new [] {
                "Gem",
                "Blocker"
            };

            var provider = new TypeReflectionProvider(types, contexts, blueprints);
            var files = CodeGenerator.Generate(provider, generatedFolder, codeGenerators);

            foreach(var file in files) {
                Console.WriteLine("Generated: " + file.fileName);
            }

            Console.WriteLine("Done. Press any key...");
            Console.Read();
        }
Exemple #2
0
        static void generate() {
            var generatedFolder = getEntitasProjectDir() + "/Readme/Readme/Generated/";

            var codeGenerators = new ICodeGenerator[] {
                new ComponentsGenerator(),
                new ComponentIndicesGenerator(),
                new PoolAttributeGenerator(),
                new PoolsGenerator()
            };

            var assembly = Assembly.GetAssembly(typeof(ReadmeSnippets));
            var provider = new TypeReflectionProvider(assembly.GetTypes(), new string[0]);
            CodeGenerator.Generate(provider, generatedFolder, codeGenerators);

            Console.WriteLine("Done. Press any key...");
            Console.Read();
        }
    static void generate()
    {
        var assembly = Assembly.GetAssembly(typeof(SomeComponent));
        var generatedFolder = getEntitasProjectDir() + "/Tests/Tests/Entitas/CodeGenerator/Fixtures/Generated/";

        var codeGenerators = new ICodeGenerator[] {
            new ComponentExtensionsGenerator(),
            new ComponentIndicesGenerator(),
            new PoolAttributesGenerator(),
            new PoolsGenerator()
        };

        var provider = new TypeReflectionProvider(assembly.GetTypes(), new string[0], new string[0]);
        var files = CodeGenerator.Generate(provider, generatedFolder, codeGenerators);

        foreach (var file in files) {
            Console.WriteLine("Generated: " + file.fileName);
        }

        Console.WriteLine("Done. Press any key...");
        Console.Read();
    }
    void when_providing()
    {
        context["pool names"] = () => {
            it["has no pool names if empty"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(object) }, new string[0]);
                provider.poolNames.should_be_empty();
            };

            it["has pool names if set"] = () => {
                var provider = new TypeReflectionProvider(
                                   new [] { typeof(TestPoolAttribute) },
                                   new [] { "Pool1", "Pool2" }
                               );
                provider.poolNames.Length.should_be(2);
                provider.poolNames[0].should_be("Pool1");
                provider.poolNames[1].should_be("Pool2");
            };
        };

        context["component infos"] = () => {

            it["finds no components if there are no types which implement IComponent"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(object) }, new string[0]);
                provider.componentInfos.should_be_empty();
            };

            it["finds no components and ignores IComponent itself"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(IComponent) }, new string[0]);
                provider.componentInfos.should_be_empty();
            };

            it["creates component info from found component"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(ComponentA) }, new string[0]);
                provider.componentInfos.Length.should_be(1);
                var info = provider.componentInfos[0];

                info.fullTypeName.should_be("ComponentA");
                info.typeName.should_be("ComponentA");
                info.fieldInfos.should_be_empty();
                info.pools.should_be_empty();
                info.isSingleEntity.should_be_false();
                info.singleComponentPrefix.should_be("is");
                info.generateMethods.should_be(true);
                info.generateIndex.should_be(true);
                info.isSingletonComponent.should_be(true);
            };

            it["creates component info from found component with namespace"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(NamespaceComponent) }, new string[0]);
                provider.componentInfos.Length.should_be(1);
                var info = provider.componentInfos[0];

                info.fullTypeName.should_be("My.Namespace.NamespaceComponent");
                info.typeName.should_be("NamespaceComponent");
                info.fieldInfos.should_be_empty();
                info.pools.should_be_empty();
                info.isSingleEntity.should_be_false();
                info.singleComponentPrefix.should_be("is");
                info.generateMethods.should_be(true);
                info.generateIndex.should_be(true);
                info.isSingletonComponent.should_be(true);
            };

            it["detects PoolAttribure"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(CComponent) }, new string[0]);
                provider.componentInfos.Length.should_be(1);
                var info = provider.componentInfos[0];

                info.fullTypeName.should_be("CComponent");
                info.typeName.should_be("CComponent");
                info.fieldInfos.should_be_empty();
                info.pools.Length.should_be(3);

                info.pools.should_contain("PoolA");
                info.pools.should_contain("PoolB");
                info.pools.should_contain("PoolC");

                info.isSingleEntity.should_be_false();
                info.singleComponentPrefix.should_be("is");
                info.generateMethods.should_be(true);
                info.generateIndex.should_be(true);
                info.isSingletonComponent.should_be(true);
            };

            it["detects SingleEntityAttribute "] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(AnimatingComponent) }, new string[0]);
                provider.componentInfos.Length.should_be(1);
                var info = provider.componentInfos[0];

                info.fullTypeName.should_be("AnimatingComponent");
                info.typeName.should_be("AnimatingComponent");
                info.fieldInfos.should_be_empty();
                info.pools.Length.should_be(0);
                info.isSingleEntity.should_be_true();
                info.singleComponentPrefix.should_be("is");
                info.generateMethods.should_be(true);
                info.generateIndex.should_be(true);
                info.isSingletonComponent.should_be(true);
            };

            it["detects DontGenerateAttribute "] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(DontGenerateComponent) }, new string[0]);
                provider.componentInfos.Length.should_be(1);
                var info = provider.componentInfos[0];

                info.fullTypeName.should_be("DontGenerateComponent");
                info.typeName.should_be("DontGenerateComponent");
                info.fieldInfos.should_be_empty();
                info.pools.Length.should_be(0);
                info.isSingleEntity.should_be_false();
                info.singleComponentPrefix.should_be("is");
                info.generateMethods.should_be(false);
                info.generateIndex.should_be(true);
                info.isSingletonComponent.should_be(true);
            };

            it["detects DontGenerateAttribute and don't generate index"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(DontGenerateIndexComponent) }, new string[0]);
                provider.componentInfos.Length.should_be(1);
                var info = provider.componentInfos[0];

                info.fullTypeName.should_be("DontGenerateIndexComponent");
                info.typeName.should_be("DontGenerateIndexComponent");
                info.fieldInfos.should_be_empty();
                info.pools.Length.should_be(0);
                info.isSingleEntity.should_be_false();
                info.singleComponentPrefix.should_be("is");
                info.generateMethods.should_be(false);
                info.generateIndex.should_be(false);
                info.isSingletonComponent.should_be(true);
            };

            it["detects CustomPrefixAttribute"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(CustomPrefixComponent) }, new string[0]);
                provider.componentInfos.Length.should_be(1);
                var info = provider.componentInfos[0];

                info.fullTypeName.should_be("CustomPrefixComponent");
                info.typeName.should_be("CustomPrefixComponent");
                info.fieldInfos.should_be_empty();
                info.pools.Length.should_be(0);
                info.isSingleEntity.should_be_true();
                info.singleComponentPrefix.should_be("My");
                info.generateMethods.should_be(true);
                info.generateIndex.should_be(true);
                info.isSingletonComponent.should_be(true);
            };

            it["sets fields"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(PersonComponent) }, new string[0]);
                provider.componentInfos.Length.should_be(1);
                var info = provider.componentInfos[0];

                info.fullTypeName.should_be("PersonComponent");
                info.typeName.should_be("PersonComponent");
                info.fieldInfos.Length.should_be(2);

                info.fieldInfos[0].type.should_be("int");
                info.fieldInfos[0].name.should_be("age");

                info.fieldInfos[1].type.should_be("string");
                info.fieldInfos[1].name.should_be("name");

                info.pools.Length.should_be(0);
                info.isSingleEntity.should_be_false();
                info.singleComponentPrefix.should_be("is");
                info.generateMethods.should_be(true);
                info.generateIndex.should_be(true);
                info.isSingletonComponent.should_be(false);
            };

            it["gets multiple component infos"] = () => {
                var provider = new TypeReflectionProvider(new [] { typeof(ComponentA), typeof(ComponentB) }, new string[0]);
                provider.componentInfos.Length.should_be(2);
                provider.componentInfos[0].fullTypeName.should_be("ComponentA");
                provider.componentInfos[1].fullTypeName.should_be("ComponentB");
            };
        };
    }
 public static CodeGenFile[] Generate(Assembly assembly, string[] poolNames, string directory, ICodeGenerator[] codeGenerators)
 {
     var provider = new TypeReflectionProvider(assembly.GetTypes(), poolNames);
     return CodeGenerator.Generate(provider, directory, codeGenerators);
 }
Exemple #6
0
        public static CodeGenFile[] Generate(Assembly assembly, string[] poolNames, string[] blueprintNames, string directory, ICodeGenerator[] codeGenerators)
        {
            var provider = new TypeReflectionProvider(assembly.GetTypes(), poolNames, blueprintNames);

            return(CodeGenerator.Generate(provider, directory, codeGenerators));
        }