Beispiel #1
0
    private static void Run(Options options)
    {
        string outputDirectory = Path.GetDirectoryName(Path.GetFullPath(options.Output));

        Directory.CreateDirectory(outputDirectory);

        string[] files = Directory.GetFiles(outputDirectory);

        for (int i = 0; i < files.Length; i++)
        {
            File.Delete(files[i]);
        }

        LdtkTypeConverter typeConverter = new LdtkTypeConverter()
        {
            PointAsVector2 = options.PointAsVector2
        };

        LdtkGeneratorContext ctx = new LdtkGeneratorContext()
        {
            LevelClassName = options.LevelClassName,
            TypeConverter  = typeConverter
        };

        ctx.CodeSettings.Namespace = options.Namespace;

        ICodeOutput output;

        if (options.SingleFile)
        {
            SingleFileOutput singleFileOutput = new SingleFileOutput()
            {
                OutputDir = outputDirectory,
                Filename  = Path.GetFileNameWithoutExtension(options.Input)
            };
            output = singleFileOutput;
        }
        else
        {
            MultiFileOutput multiFileOutput = new MultiFileOutput()
            {
                PrintFragments = true,
                OutputDir      = outputDirectory,
            };
            output = multiFileOutput;
        }

        LDtkWorld ldtkWorld = JsonSerializer.Deserialize <LDtkWorld>(File.ReadAllText(options.Input), LDtkWorld.SerializeOptions);

        LdtkCodeGenerator cg = new LdtkCodeGenerator();

        cg.GenerateCode(ldtkWorld, ctx, output);
    }
Beispiel #2
0
    static void Main(string[] args)
    {
        string   text     = File.ReadAllText("Entities.ldtk");
        LdtkJson ldtkJson = LdtkJson.FromJson(text);

        LdtkGeneratorContext ctx = new LdtkGeneratorContext();

        ctx.TypeConverter          = new LdtkTypeConverter();
        ctx.CodeSettings.Namespace = "MyNamespace.Test";

        SingleFileOutput fOut = new SingleFileOutput();

        fOut.OutputDir = "src-gen";
        fOut.Filename  = "MyFileCode.cs";

        LdtkCodeGenerator cg = new LdtkCodeGenerator();

        cg.GenerateCode(ldtkJson, ctx, fOut);
    }