1.0.2 • Published 4 years ago

minmod.ts v1.0.2

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
4 years ago

MinMod.ts

A mod compiler for Mindustry.

Usage

Once installed, you can use this simple build script to compile a mod.

const minmod = require("minmod.ts");
const fs = require("fs");

const compiler = new minmod.Compiler();
compiler.set_source_path("mod"); //"mod" is the folder that the mod is in
compiler.add_plugins(minmod.DefaultPlugins);

compiler.compile().then(data => fs.writeFileSync("./mod.zip", data)); //"mod.zip" is where the compiler outputs

A mod is structured like a regular Mindustry mod. However, you can use TypeScript files, along with a tsconfig.json

│   mod.json
│   tsconfig.json
│
├───content
│   └───blocks
│           scatter-silo.hjson
│
├───scripts
│   │   main.ts
│   └───fx
│           launchFXdrawer.ts
├───sprites
│   └───blocks
│           scatter-silo.png
│
└───sprites-override
    └───blocks
        └───turrets
            └───bases
                    block-3.png

The TypeScript plugin will compile with main.ts as the entry point.

Plugins

The DefaultPlugins export comes with a few plugins:

  • A TypeScript plugin that compiles TypeScript files
  • A JSONPlugin that minifies JSON files
  • A HJSONPlugin that converts HJSON files to minified JSON files
  • A YAMLPlugin that converts YAML files to minified JSON files}
  • A CopyPlugin to copy PNG files over
  • A CopyPlugin to copy MSAV files over

You can also add your own plugins. Here is an example plugin that appends "egg" to the end of each .egg file.

const minmod = require("minmod.ts");
const fs = require("fs");

class EggPlugin extends minmod.Plugin {
    constructor() {
        super();
    }
    matches(file_name) {
        // This is for checking if a file should be handled by this plugin
        return file_name.endsWith(".egg");
    }
    async compile(path, entry_path, out) {
        // "path" contains the path to the file
        // "entry_path" contains output path for the file
        // "out" is the zip file
        const content = fs.readFileSync(path, "utf-8");
        out.file(entry_path, content + " egg");
    }
    async finalise() {
        // This gets called when the compiler finishes things up
    }
}

const compiler = new minmod.Compiler();
compiler.set_source_path("mod");
compiler.add_plugins(minmod.DefaultPlugins);
compiler.add_plugin(new EggPlugin());

compiler.compile().then(data => fs.writeFileSync("./mod.zip", data));