Skip to content

Instantly share code, notes, and snippets.

@Viza74
Created June 13, 2017 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Viza74/3af648c26a7dbd4d7c87003ac7833dd6 to your computer and use it in GitHub Desktop.
Save Viza74/3af648c26a7dbd4d7c87003ac7833dd6 to your computer and use it in GitHub Desktop.
Multi file "build system" for TIC-80 (VS Code/OSX)
#!/bin/sh
echo "--- Merging files..."
cat ./build/mergelist
cat ./build/mergelist | xargs -J % cat % > $1.lua
echo "\n--- Finished"
echo "$2/$1.tic -code $1.lua"
../tic.app/Contents/MacOS/tic $2/$1.tic -code $2/$1.lua -sprites sprites.gif
header.lua
globals.lua
pslib.lua
particles.lua
gameoverstate.lua
menustate.lua
gamestate.lua
bombstate.lua
compactstate.lua
swapstate.lua
shufflestate.lua
collectstate.lua
generatestate.lua
main.lua
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"tasks": [
{
"taskName": "Merge to single file and run",
"command": "./build/merge.sh",
"isShellCommand": true,
"args": ["${workspaceRootFolderName}", "${workspaceRoot}"],
"showOutput": "always",
"echoCommand": true,
"isBuildCommand": true
}
]
}
@Viza74
Copy link
Author

Viza74 commented Jun 13, 2017

How to use these:

In VS Code, open the command palette, and start typing "task". Find "Tasks: Configure task runner", and press enter.
At "Select task runner" choose "Others". VS Code will create a hidden directory with a tasks.json file in your opened directory. Replace its contents with the tasks.json from here.
Create a subdirectory named "build", and place merge.sh, and mergelist inside it.
Modify merge.sh according to where you keep your tic.app (I keep it one dir up from my TIC80 projects, hence the "../")
The mergelist file here is just an example, modify as your project needs.
You will also need a tic file (with the same name as the project directory) and a sprites.gif in your directory, the launcher will use the tic file, inject the merged lua file and the sprites.gif to run. So basically the tic file only contains the map, sound and music information.

To build and run just press Cmd+Shift+b
The traces will show up VS Code

The shortcomings of this method:

  • The are no source code mapping, so if you got an error when run in TIC80, the line number will point to the merged lua file, and you have to figure out in which of your files exactly that spot is. Usually not a big problem, but not too elegant. Ohh, the merged lua file saved in the project directory, as [name of the directory].lua
  • If you use a lua linter, it will report a bunch of undefined variables, since it has no way of knowing that there are multiple files.
  • You have to take care that if you modify something in the tic file when running in TIC80 (map, sound or music) be sure to save the file, and put it in the project directory - if you forget, every change will lost when you exit TIC80. Which is true in every other case too, I just mention it because it is easier to forget saving when a bunch of stuff (code and gfx) is saved otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment