mirror of
https://github.com/litruv/picoGraph.git
synced 2026-07-25 03:06:05 +10:00
Initial commit
moved from private version control
This commit is contained in:
41
scripts/nodes/library/system/assert.js
Normal file
41
scripts/nodes/library/system/assert.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Stops execution when a condition is false, printing an optional message.
|
||||
*/
|
||||
export const assertNode = createNodeModule(
|
||||
{
|
||||
id: "system_assert",
|
||||
title: "Assert",
|
||||
category: "System",
|
||||
description:
|
||||
"Assert that a condition is true, stopping the cart when it fails.",
|
||||
searchTags: ["assert", "debug", "check", "system"],
|
||||
inputs: [
|
||||
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
||||
{
|
||||
id: "condition",
|
||||
name: "Condition",
|
||||
direction: "input",
|
||||
kind: "boolean",
|
||||
defaultValue: true,
|
||||
},
|
||||
{ id: "message", name: "Message", direction: "input", kind: "string" },
|
||||
],
|
||||
outputs: [
|
||||
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
emitExec: ({ indent, indentLevel, resolveValueInput, emitNextExec }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const condition = resolveValueInput("condition", "true");
|
||||
const message = resolveValueInput("message", OMIT);
|
||||
const callArgs = message === OMIT ? condition : `${condition}, ${message}`;
|
||||
const lines = [`${indent(indentLevel)}assert(${callArgs})`];
|
||||
lines.push(...emitNextExec("exec_out"));
|
||||
return lines;
|
||||
},
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user