mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-24 02:36:04 +10:00
Initial commit
moved from private version control
This commit is contained in:
46
scripts/nodes/library/graphics/cursor.js
Normal file
46
scripts/nodes/library/graphics/cursor.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Positions the print cursor and optionally sets the draw color.
|
||||
*/
|
||||
export const cursorNode = createNodeModule(
|
||||
{
|
||||
id: "graphics_cursor",
|
||||
title: "Set Cursor",
|
||||
category: "Graphics",
|
||||
description:
|
||||
"Move the print cursor and optionally change the active color.",
|
||||
searchTags: ["cursor", "print", "text", "position"],
|
||||
inputs: [
|
||||
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
||||
{ id: "x", name: "X", direction: "input", kind: "number" },
|
||||
{ id: "y", name: "Y", direction: "input", kind: "number" },
|
||||
{ id: "color", name: "Color", direction: "input", kind: "number" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
emitExec: ({ indent, indentLevel, resolveValueInput, emitNextExec }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const x = resolveValueInput("x", OMIT);
|
||||
const y = resolveValueInput("y", OMIT);
|
||||
const color = resolveValueInput("color", OMIT);
|
||||
|
||||
let call = "cursor()";
|
||||
if (x !== OMIT) {
|
||||
const args = [x, y === OMIT ? "0" : y];
|
||||
if (color !== OMIT) {
|
||||
args.push(color);
|
||||
}
|
||||
call = `cursor(${args.join(", ")})`;
|
||||
}
|
||||
|
||||
const lines = [`${indent(indentLevel)}${call}`];
|
||||
lines.push(...emitNextExec("exec_out"));
|
||||
return lines;
|
||||
},
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user