mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-24 10:46:06 +10:00
Initial commit
moved from private version control
This commit is contained in:
43
scripts/nodes/library/strings/chr.js
Normal file
43
scripts/nodes/library/strings/chr.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Converts ordinal values to characters using chr.
|
||||
*/
|
||||
export const stringChrNode = createNodeModule(
|
||||
{
|
||||
id: "string_chr",
|
||||
title: "Character From Ordinals",
|
||||
category: "Strings",
|
||||
description: "Build a string from ordinal values using CHR().",
|
||||
searchTags: ["chr", "string", "character"],
|
||||
inputs: [
|
||||
{ id: "value", name: "Value", direction: "input", kind: "any" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "string" },
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
key: "extraValues",
|
||||
label: "Additional Values",
|
||||
type: "string",
|
||||
placeholder: "e.g. 65, 66, 67",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ node, resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "0");
|
||||
const args = [value];
|
||||
const extras = String(node.properties.extraValues ?? "").trim();
|
||||
if (extras.length) {
|
||||
extras
|
||||
.split(",")
|
||||
.map((entry) => entry.trim())
|
||||
.filter((entry) => entry.length > 0)
|
||||
.forEach((entry) => args.push(entry));
|
||||
}
|
||||
return `chr(${args.join(", ")})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
34
scripts/nodes/library/strings/index.js
Normal file
34
scripts/nodes/library/strings/index.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import { stringTostrNode } from "./tostr.js";
|
||||
import { stringTonumNode } from "./tonum.js";
|
||||
import { stringChrNode } from "./chr.js";
|
||||
import { stringOrdNode } from "./ord.js";
|
||||
import { stringSubNode } from "./sub.js";
|
||||
import { stringSplitNode } from "./split.js";
|
||||
import { stringTypeNode } from "./typeOf.js";
|
||||
|
||||
/**
|
||||
* All string-related node modules backed by PICO-8 helpers.
|
||||
*/
|
||||
export const stringNodes = [
|
||||
stringTostrNode,
|
||||
stringTonumNode,
|
||||
stringChrNode,
|
||||
stringOrdNode,
|
||||
stringSubNode,
|
||||
stringSplitNode,
|
||||
stringTypeNode,
|
||||
];
|
||||
|
||||
/**
|
||||
* Checklist tracking coverage of documented string helpers.
|
||||
* @type {Array<{ function: string, nodeId: string, implemented: boolean }>}
|
||||
*/
|
||||
export const stringFunctionChecklist = [
|
||||
{ function: "TOSTR", nodeId: "string_tostr", implemented: true },
|
||||
{ function: "TONUM", nodeId: "string_tonum", implemented: true },
|
||||
{ function: "CHR", nodeId: "string_chr", implemented: true },
|
||||
{ function: "ORD", nodeId: "string_ord", implemented: true },
|
||||
{ function: "SUB", nodeId: "string_sub", implemented: true },
|
||||
{ function: "SPLIT", nodeId: "string_split", implemented: true },
|
||||
{ function: "TYPE", nodeId: "string_type", implemented: true },
|
||||
];
|
||||
55
scripts/nodes/library/strings/ord.js
Normal file
55
scripts/nodes/library/strings/ord.js
Normal file
@@ -0,0 +1,55 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Converts characters to ordinal values using ord.
|
||||
*/
|
||||
export const stringOrdNode = createNodeModule(
|
||||
{
|
||||
id: "string_ord",
|
||||
title: "Ordinals From String",
|
||||
category: "Strings",
|
||||
description:
|
||||
"Return ordinal codes for characters in a string using ORD().",
|
||||
searchTags: ["ord", "string", "character"],
|
||||
inputs: [
|
||||
{ id: "string", name: "String", direction: "input", kind: "string" },
|
||||
{
|
||||
id: "index",
|
||||
name: "Index",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Optional starting index",
|
||||
},
|
||||
{
|
||||
id: "count",
|
||||
name: "Count",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Optional result count",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const str = resolveValueInput("string", "\"\"");
|
||||
const index = resolveValueInput("index", OMIT);
|
||||
const count = resolveValueInput("count", OMIT);
|
||||
|
||||
if (index === OMIT && count === OMIT) {
|
||||
return `ord(${str})`;
|
||||
}
|
||||
|
||||
if (count === OMIT) {
|
||||
return `ord(${str}, ${index === OMIT ? "nil" : index})`;
|
||||
}
|
||||
|
||||
const indexArg = index === OMIT ? "nil" : index;
|
||||
return `ord(${str}, ${indexArg}, ${count})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
54
scripts/nodes/library/strings/split.js
Normal file
54
scripts/nodes/library/strings/split.js
Normal file
@@ -0,0 +1,54 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Splits strings into tables using split.
|
||||
*/
|
||||
export const stringSplitNode = createNodeModule(
|
||||
{
|
||||
id: "string_split",
|
||||
title: "Split String",
|
||||
category: "Strings",
|
||||
description: "Split a string into tokens using SPLIT().",
|
||||
searchTags: ["split", "string", "table", "parse"],
|
||||
inputs: [
|
||||
{ id: "string", name: "String", direction: "input", kind: "string" },
|
||||
{
|
||||
id: "separator",
|
||||
name: "Separator",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
description: "Optional separator (string or number)",
|
||||
},
|
||||
{
|
||||
id: "convert",
|
||||
name: "Convert Numbers",
|
||||
direction: "input",
|
||||
kind: "boolean",
|
||||
description: "Override numeric conversion (defaults true)",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "table" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const str = resolveValueInput("string", "\"\"");
|
||||
const sep = resolveValueInput("separator", OMIT);
|
||||
const convert = resolveValueInput("convert", OMIT);
|
||||
|
||||
if (sep === OMIT && convert === OMIT) {
|
||||
return `split(${str})`;
|
||||
}
|
||||
|
||||
if (convert === OMIT) {
|
||||
return `split(${str}, ${sep === OMIT ? "nil" : sep})`;
|
||||
}
|
||||
|
||||
const sepArg = sep === OMIT ? "nil" : sep;
|
||||
return `split(${str}, ${sepArg}, ${convert})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
48
scripts/nodes/library/strings/sub.js
Normal file
48
scripts/nodes/library/strings/sub.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Extracts substrings using sub.
|
||||
*/
|
||||
export const stringSubNode = createNodeModule(
|
||||
{
|
||||
id: "string_sub",
|
||||
title: "Substring",
|
||||
category: "Strings",
|
||||
description: "Extract a substring using SUB().",
|
||||
searchTags: ["sub", "substring", "string"],
|
||||
inputs: [
|
||||
{ id: "string", name: "String", direction: "input", kind: "string" },
|
||||
{
|
||||
id: "start",
|
||||
name: "Start",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
},
|
||||
{
|
||||
id: "stop",
|
||||
name: "Stop",
|
||||
direction: "input",
|
||||
kind: "any",
|
||||
description: "Optional end position or truthy for single character",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "string" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const str = resolveValueInput("string", "\"\"");
|
||||
const start = resolveValueInput("start", "1");
|
||||
const stop = resolveValueInput("stop", OMIT);
|
||||
|
||||
if (stop === OMIT) {
|
||||
return `sub(${str}, ${start})`;
|
||||
}
|
||||
|
||||
return `sub(${str}, ${start}, ${stop})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
39
scripts/nodes/library/strings/tonum.js
Normal file
39
scripts/nodes/library/strings/tonum.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Converts values to numbers using tonum.
|
||||
*/
|
||||
export const stringTonumNode = createNodeModule(
|
||||
{
|
||||
id: "string_tonum",
|
||||
title: "To Number",
|
||||
category: "Strings",
|
||||
description: "Convert a value to a number with optional format flags.",
|
||||
searchTags: ["tonum", "string", "number", "convert"],
|
||||
inputs: [
|
||||
{ id: "value", name: "Value", direction: "input", kind: "any" },
|
||||
{
|
||||
id: "flags",
|
||||
name: "Flags",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Optional format flags bitfield",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "number" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const value = resolveValueInput("value", "nil");
|
||||
const flags = resolveValueInput("flags", OMIT);
|
||||
if (flags === OMIT) {
|
||||
return `tonum(${value})`;
|
||||
}
|
||||
return `tonum(${value}, ${flags})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
39
scripts/nodes/library/strings/tostr.js
Normal file
39
scripts/nodes/library/strings/tostr.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Converts values to strings using tostr.
|
||||
*/
|
||||
export const stringTostrNode = createNodeModule(
|
||||
{
|
||||
id: "string_tostr",
|
||||
title: "To String",
|
||||
category: "Strings",
|
||||
description: "Convert a value to a string with optional format flags.",
|
||||
searchTags: ["tostr", "string", "convert"],
|
||||
inputs: [
|
||||
{ id: "value", name: "Value", direction: "input", kind: "any" },
|
||||
{
|
||||
id: "flags",
|
||||
name: "Flags",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Optional format flags bitfield",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "string" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const value = resolveValueInput("value", "nil");
|
||||
const flags = resolveValueInput("flags", OMIT);
|
||||
if (flags === OMIT) {
|
||||
return `tostr(${value})`;
|
||||
}
|
||||
return `tostr(${value}, ${flags})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
25
scripts/nodes/library/strings/typeOf.js
Normal file
25
scripts/nodes/library/strings/typeOf.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Returns the type of a value using type.
|
||||
*/
|
||||
export const stringTypeNode = createNodeModule(
|
||||
{
|
||||
id: "string_type",
|
||||
title: "Type Of",
|
||||
category: "Strings",
|
||||
description: "Return the type name of a value using TYPE().",
|
||||
searchTags: ["type", "string", "introspection"],
|
||||
inputs: [{ id: "value", name: "Value", direction: "input", kind: "any" }],
|
||||
outputs: [
|
||||
{ id: "result", name: "Result", direction: "output", kind: "string" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
evaluateValue: ({ resolveValueInput }) => {
|
||||
const value = resolveValueInput("value", "nil");
|
||||
return `type(${value})`;
|
||||
},
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user