Add initial Pico-8 cartridges for testing

- Created test_cart.p8 with basic drawing functionality and a print statement.
- Created test_unix.p8 with a simple initialization function.
This commit is contained in:
2026-03-21 18:38:43 +11:00
parent 71354ad463
commit f917cf6ad5
56 changed files with 5200 additions and 688 deletions

View File

@@ -0,0 +1,41 @@
/**
* @typedef {import('./LuaLiteralTypes.js').LuaLiteralHandler} LuaLiteralHandler
*/
/** @type {LuaLiteralHandler} */
export const LuaLiteralBoolean = {
/**
* @param {unknown} value
* @returns {string}
*/
format(value) {
if (typeof value === "string") {
return value === "false" ? "false" : "true";
}
return value ? "true" : "false";
},
/** @returns {string} */
defaultLiteral() {
return "false";
},
spawnableByDefault: true,
nodeModule: {
definition: {
id: "boolean_literal",
title: "Boolean",
category: "Values",
description: "Constant boolean literal.",
searchTags: ["boolean", "literal", "true", "false"],
inputs: [],
outputs: [{ id: "value", name: "Value", direction: "output", kind: "boolean" }],
properties: [{ key: "value", label: "Value", type: "boolean", defaultValue: true }],
},
behavior: {
evaluateValue: ({ node, formatLiteral }) =>
formatLiteral("boolean", node.properties.value ?? true),
},
},
};

View File

@@ -0,0 +1,39 @@
/**
* @typedef {import('./LuaLiteralTypes.js').LuaLiteralHandler} LuaLiteralHandler
*/
/** @type {LuaLiteralHandler} */
export const LuaLiteralColor = {
/**
* @param {unknown} value
* @returns {string}
*/
format(value) {
const n = Math.max(0, Math.min(15, Math.floor(Number(value) || 0)));
return String(n);
},
/** @returns {string} */
defaultLiteral() {
return "7";
},
spawnableByDefault: true,
nodeModule: {
definition: {
id: "color_literal",
title: "Color",
category: "Values",
description: "Constant color literal (0-15).",
searchTags: ["color", "literal", "constant", "value"],
inputs: [],
outputs: [{ id: "value", name: "Value", direction: "output", kind: "color" }],
properties: [{ key: "value", label: "Color", type: "number", defaultValue: 7 }],
},
behavior: {
evaluateValue: ({ node, formatLiteral }) =>
formatLiteral("color", node.properties.value ?? 7),
},
},
};

View File

@@ -0,0 +1,39 @@
/**
* @typedef {import('./LuaLiteralTypes.js').LuaLiteralHandler} LuaLiteralHandler
*/
/** @type {LuaLiteralHandler} */
export const LuaLiteralNumber = {
/**
* @param {unknown} value
* @returns {string}
*/
format(value) {
const numeric = Number(value);
return Number.isFinite(numeric) ? String(numeric) : "0";
},
/** @returns {string} */
defaultLiteral() {
return "0";
},
spawnableByDefault: true,
nodeModule: {
definition: {
id: "number_literal",
title: "Number",
category: "Values",
description: "Constant numeric literal.",
searchTags: ["number", "literal", "constant", "value"],
inputs: [],
outputs: [{ id: "value", name: "Value", direction: "output", kind: "number" }],
properties: [{ key: "value", label: "Number", type: "number", defaultValue: 0 }],
},
behavior: {
evaluateValue: ({ node, formatLiteral }) =>
formatLiteral("number", node.properties.value ?? 0),
},
},
};

View File

@@ -0,0 +1,38 @@
/**
* @typedef {import('./LuaLiteralTypes.js').LuaLiteralHandler} LuaLiteralHandler
*/
/** @type {LuaLiteralHandler} */
export const LuaLiteralString = {
/**
* @param {unknown} value
* @returns {string}
*/
format(value) {
return JSON.stringify(String(value ?? ""));
},
/** @returns {string} */
defaultLiteral() {
return '""';
},
spawnableByDefault: true,
nodeModule: {
definition: {
id: "string_literal",
title: "String",
category: "Values",
description: "Constant string literal.",
searchTags: ["string", "literal", "text", "value"],
inputs: [],
outputs: [{ id: "value", name: "Value", direction: "output", kind: "string" }],
properties: [{ key: "value", label: "Text", type: "string", defaultValue: "hello" }],
},
behavior: {
evaluateValue: ({ node, formatLiteral }) =>
formatLiteral("string", node.properties.value ?? ""),
},
},
};

View File

@@ -0,0 +1,27 @@
/**
* @typedef {import('./LuaLiteralTypes.js').LuaLiteralHandler} LuaLiteralHandler
*/
/** @type {LuaLiteralHandler} */
export const LuaLiteralTable = {
/**
* @param {unknown} value
* @returns {string}
*/
format(value) {
if (typeof value === "string") {
const trimmed = value.trim();
return trimmed.length ? trimmed : "{}";
}
return "{}";
},
/** @returns {string} */
defaultLiteral() {
return "{}";
},
spawnableByDefault: false,
nodeModule: null,
};

View File

@@ -0,0 +1,56 @@
import { LuaLiteralNumber } from "./LuaLiteralNumber.js";
import { LuaLiteralBoolean } from "./LuaLiteralBoolean.js";
import { LuaLiteralString } from "./LuaLiteralString.js";
import { LuaLiteralTable } from "./LuaLiteralTable.js";
import { LuaLiteralColor } from "./LuaLiteralColor.js";
/**
* @typedef {Object} LuaLiteralHandler
* @property {(value: unknown) => string} format Formats a raw value into a Lua literal string.
* @property {() => string} defaultLiteral Returns the default Lua literal string for this type.
* @property {boolean} [spawnableByDefault] Whether this type creates a spawnable literal node in the graph.
* @property {import('../../nodes/nodeTypes.js').NodeModule | null} [nodeModule] Node module definition, or null if no literal node exists.
*/
/** @type {Map<string, LuaLiteralHandler>} */
const HANDLERS = new Map([
["number", LuaLiteralNumber],
["boolean", LuaLiteralBoolean],
["string", LuaLiteralString],
["table", LuaLiteralTable],
["color", LuaLiteralColor],
]);
/**
* Formats a raw value into a Lua literal string for the given pin kind.
*
* @param {string} kind Pin kind.
* @param {unknown} value Raw value.
* @returns {string}
*/
export function formatLiteral(kind, value) {
const handler = HANDLERS.get(kind);
return handler ? handler.format(value) : LuaLiteralString.format(value);
}
/**
* Returns the default Lua literal string for the given pin kind.
*
* @param {string} kind Pin kind.
* @returns {string}
*/
export function defaultLiteralForKind(kind) {
const handler = HANDLERS.get(kind);
return handler ? handler.defaultLiteral() : "nil";
}
/**
* Returns all node modules defined by literal handlers that have a nodeModule.
*
* @returns {Array<import('../../nodes/nodeTypes.js').NodeModule>}
*/
export function getLiteralNodeModules() {
return [...HANDLERS.values()]
.map((handler) => handler.nodeModule)
.filter(Boolean);
}