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:
16
scripts/nodes/library/audio/index.js
Normal file
16
scripts/nodes/library/audio/index.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import { sfxNode } from "./sfx.js";
|
||||
import { musicNode } from "./music.js";
|
||||
|
||||
/**
|
||||
* All audio-related node modules backed by PICO-8 helpers.
|
||||
*/
|
||||
export const audioNodes = [sfxNode, musicNode];
|
||||
|
||||
/**
|
||||
* Checklist tracking coverage of documented audio helpers.
|
||||
* @type {Array<{ function: string, nodeId: string, implemented: boolean }>}
|
||||
*/
|
||||
export const audioFunctionChecklist = [
|
||||
{ function: "SFX", nodeId: "audio_sfx", implemented: true },
|
||||
{ function: "MUSIC", nodeId: "audio_music", implemented: true },
|
||||
];
|
||||
64
scripts/nodes/library/audio/music.js
Normal file
64
scripts/nodes/library/audio/music.js
Normal file
@@ -0,0 +1,64 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Plays or stops music using the PICO-8 music helper.
|
||||
*/
|
||||
export const musicNode = createNodeModule(
|
||||
{
|
||||
id: "audio_music",
|
||||
title: "Play Music",
|
||||
category: "Audio",
|
||||
description:
|
||||
"Start, fade, or stop music playback using MUSIC().",
|
||||
searchTags: ["music", "audio", "song", "pattern"],
|
||||
inputs: [
|
||||
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
||||
{
|
||||
id: "pattern",
|
||||
name: "Pattern",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Pattern index or command",
|
||||
defaultValue: 0,
|
||||
},
|
||||
{
|
||||
id: "fade",
|
||||
name: "Fade (ms)",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Fade duration in milliseconds",
|
||||
},
|
||||
{
|
||||
id: "mask",
|
||||
name: "Channel Mask",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Bitmask reserving channels",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
emitExec: ({ indent, indentLevel, resolveValueInput, emitNextExec }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const pattern = resolveValueInput("pattern", "0");
|
||||
const fade = resolveValueInput("fade", OMIT);
|
||||
const mask = resolveValueInput("mask", OMIT);
|
||||
|
||||
const args = [pattern];
|
||||
if (fade !== OMIT || mask !== OMIT) {
|
||||
const fadeArg = fade === OMIT ? "nil" : fade;
|
||||
args.push(fadeArg);
|
||||
if (mask !== OMIT) {
|
||||
args.push(mask);
|
||||
}
|
||||
}
|
||||
|
||||
const line = `${indent(indentLevel)}music(${args.join(", ")})`;
|
||||
return [line, ...emitNextExec("exec_out")];
|
||||
},
|
||||
}
|
||||
);
|
||||
76
scripts/nodes/library/audio/sfx.js
Normal file
76
scripts/nodes/library/audio/sfx.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import { createNodeModule } from "../../nodeTypes.js";
|
||||
|
||||
/**
|
||||
* Plays or controls a sound effect using the PICO-8 sfx helper.
|
||||
*/
|
||||
export const sfxNode = createNodeModule(
|
||||
{
|
||||
id: "audio_sfx",
|
||||
title: "Play SFX",
|
||||
category: "Audio",
|
||||
description:
|
||||
"Trigger a sound effect, control looping, or stop playback via SFX().",
|
||||
searchTags: ["sfx", "audio", "sound", "effect"],
|
||||
inputs: [
|
||||
{ id: "exec_in", name: "Exec", direction: "input", kind: "exec" },
|
||||
{
|
||||
id: "id",
|
||||
name: "SFX",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Sound effect slot or command",
|
||||
defaultValue: 0,
|
||||
},
|
||||
{
|
||||
id: "channel",
|
||||
name: "Channel",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Playback channel (-1 auto)",
|
||||
},
|
||||
{
|
||||
id: "offset",
|
||||
name: "Offset",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Note offset",
|
||||
},
|
||||
{
|
||||
id: "length",
|
||||
name: "Length",
|
||||
direction: "input",
|
||||
kind: "number",
|
||||
description: "Number of notes to play",
|
||||
},
|
||||
],
|
||||
outputs: [
|
||||
{ id: "exec_out", name: "Exec", direction: "output", kind: "exec" },
|
||||
],
|
||||
properties: [],
|
||||
},
|
||||
{
|
||||
emitExec: ({ indent, indentLevel, resolveValueInput, emitNextExec }) => {
|
||||
const OMIT = "__pg_omit__";
|
||||
const id = resolveValueInput("id", "0");
|
||||
const channel = resolveValueInput("channel", OMIT);
|
||||
const offset = resolveValueInput("offset", OMIT);
|
||||
const length = resolveValueInput("length", OMIT);
|
||||
|
||||
const args = [id];
|
||||
if (channel !== OMIT || offset !== OMIT || length !== OMIT) {
|
||||
const channelArg = channel === OMIT ? "nil" : channel;
|
||||
args.push(channelArg);
|
||||
if (offset !== OMIT || length !== OMIT) {
|
||||
const offsetArg = offset === OMIT ? "nil" : offset;
|
||||
args.push(offsetArg);
|
||||
if (length !== OMIT) {
|
||||
args.push(length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const line = `${indent(indentLevel)}sfx(${args.join(", ")})`;
|
||||
return [line, ...emitNextExec("exec_out")];
|
||||
},
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user