Skip to content
On this page

typesprite.config.mjs

TypeSpriteJS is pre-configured with reasonable defaults. Those defaults can be changed by creating an optional typesprite.config.mjs file.

Starters can skip this and read on.

Create a config:

To start simply create a file called typesprite.config.mjs in your game directory and write somthing in the lines of this:

js
import {defineConfig} from 'typesprite'

export default (defineConfig(({command}) => {
    // command:
    // npm run dev     => dev
    // npm run build   => build
    
    return {
        // config goes here 
    }
}))

File ending is important:

Please make sure to use an MJS and not a JS as file ending. There is still some strangeness when it comes to new import(...) and Ecmascript-modules in node.

Restart required

Currently the dev-server requires you to restart it when you modify the config file

Asset Paths

assetPaths is a list of the root directories in your game directory that will be part of the TypeSpriteJS-discorvery process.

Default is ['assets']. But this can be changed like this:

js
import {defineConfig} from 'typesprite'

export default (defineConfig(({command}) => {
    return {
        assetPaths: [
            'assets', // default
            'src',    // set 'src' as additional asset path
        ],
    }
}))

All files and files in sub folders will be considered as assets. E.g. if you create a world file (\*.edf) into an asset folder it'll be automatically started when the game starts. All Components-Class-Files have to be in one of those folders (as long as they are not yet )

Simply name the directories. Don't use ./ or ../

Dev-Server Port

Changes the port of the dev-server.

js
import {defineConfig} from 'typesprite'

export default (defineConfig(({command}) => {
    return {
        servePort: 5002
    }
}))

During development TypeSpriteJS requires a running dev-server to take care of Typescript and Javascript transpiling and the asset generation.

Aseprite executable path

TypeSpriteJS can handle *.ase and *.aseprite files as part of it's asset-pipline. It makes use of aseprites CLI and you need to provide the path to the executable.

js
import {defineConfig} from 'typesprite'

export default defineConfig(({command}) => {
    return {
        asepritePath: "/Applications/Aseprite.app/Contents/MacOS/aseprite",
    }
})

If you like to make this work multiplatform, you can write a more fleixble approach that might look like this.

Multiplatform Example
js
import {defineConfig} from 'typesprite'

function findAsepritePath() {
    switch(process.platform) {
        case "linux":
            return "/path/to/aseprite";
        case "win32":
            return "C:\\Program Files\\Aseprite\\Aseprite.exe";
        case "darwin":
            return "/Applications/Aseprite.app/Contents/MacOS/aseprite";
    }
}

export default (defineConfig(({command}) => {
    return {
        asepritePath: findAsepritePath(),
        // ... more! 
    }
}))

It would also be possible to use environment variables etc.

Game Entry Point

When the game starts per default the engines starts all worlds (*.edf) it can find within the assets folder.

This behavior can be overwritten. Different approaches are available:

js
import {defineConfig} from 'typesprite'

export default (defineConfig(({command}) => {
    return {
        run: {
            startWorlds: "myWorld",           // myWorld.edf starts on startup
            mainloopType: MainLoopType.Fixed, // Example of an additional run property
            // more options available here!
        } 
    }
}))
js
import {defineConfig} from 'typesprite'

export default (defineConfig(({command}) => {
    return {
        run: {
            // This is useful if you like to make sure that certain objects
            // are created/inited as a group before another.
            //
            // e.g. in core you could load textures that should never unload.
            // As long as you never stop that world they stay in memory.
            // You could also put all persistant objects
            startWorlds: [    
                ["core"],    // 'core.edf' will start first 
                ["company"], // 'company.edf' will be loaded once 'core.edf' is fully loaded.
            ],
            
            mainloopType: MainLoopType.Fixed, // Example of an additional run property
            // more options available here!
        } 
    }
}))
js
import {defineConfig} from 'typesprite'

export default (defineConfig(({command}) => {
    return {
        run: "assets/main.ts", 
        // When a main-file is provided you have to instantiate a custom
        // GameRunner object and do the configuration and do things
        // like Component registration yourself. 
        //
        // Only for advanced use cases.
    }
}))

Read more here: Run-Config Details.