The goal of this project is to be able to use Typescript to programmatically create playable Scratch games.
In the future, you will be able to use Lua to create scratch games with this. But currently, it only supports the bare minimum of a scratch project.
Usage is very clunky currently, this will be fixed in 0.2.0
Particullarily, inputs will be changed instead of using raw format, and use spread operator instead.
import scratch from "scratch-compiler";
const testCode = new scratch.ScriptBuilder(scratch.Opcode.EVENT_WHENFLAGCLICKED)
.next(scratch.Opcode.LOOKS_SAYFORSECS, {
MESSAGE: [scratch.ScratchType.SHADOW, [scratch.ScratchType.STRING, "Hello!"]], // Shadow blocks exist because of Blockly
SECS: [scratch.ScratchType.SHADOW, [scratch.ScratchType.NUMBER, "2"]]
});
const testSprite = new scratch.ScratchSprite("TestSprite", 0, 1)
.addCostume("costume1.svg") // Path is relative
.addCode(testCode);
const stage = new scratch.ScratchStage(0) // Argument is costume number
.addCostume("stage1.svg");
new scratch.ProjectBuilder()
.addTarget(stage) // Targets are sprites and stages.
.addTarget(testSprite)
.build("project"); // project filename (without .sb3 extension)
- ✅ Targets (Sprites and Stages)
- ✅ Scripts
- ✅ Extensions
- ✅ Costumes
- ❌ Sounds
If there's any features missing, please make an issue to let me know!
- For some reason, some assets are ignored entirely, being replaced with working ones for some odd reason.
If you discovered a bug not listed here, please make an issue!