sounds, better files

This commit is contained in:
2024-08-18 19:11:41 +00:00
parent 9ed2f70701
commit 08489ed67b
86 changed files with 4226 additions and 86 deletions

View File

@@ -0,0 +1,44 @@
import { PlaylistGroupNode, PlaylistGroupNodeOptions } from "./PlaylistGroupNode";
import { SfxGroupNode, SfxGroupNodeOptions } from "./SfxGroupNode";
import { SoundGroupNode } from "./SoundGroupNode";
import { TabSourceNode, TabSourceNodeOptions } from "./TabSourceNode";
import { SoundboardContext } from "./types";
type SerializedNode<T extends SoundGroupNode<any>> = ReturnType<T['serializeOptions']>
export type SupportedDefinitions = SerializedNode<PlaylistGroupNode> | SerializedNode<SfxGroupNode> | SerializedNode<TabSourceNode>
export class AudioNodeManager {
deserializeNodes(definition: string, ctx: SoundboardContext) {
const definitions = JSON.parse(definition) as SupportedDefinitions[];
return definitions.map((definition) => this.deserializeNode(definition, ctx));
}
deserializeNode(definition: SupportedDefinitions, ctx: SoundboardContext) {
if (definition.type === 'playlist') {
return new PlaylistGroupNode(definition, ctx);
} else if (definition.type === 'sfx') {
return new SfxGroupNode(definition, ctx);
} else if (definition.type === 'tabSource') {
return new TabSourceNode(definition, ctx);
} else {
throw new Error('Invalid node type');
}
}
restore(ctx: SoundboardContext) {
const nodes = localStorage.getItem('audioNodes');
if (nodes) {
return this.deserializeNodes(nodes, ctx);
}
return [];
}
store(nodes: SoundGroupNode<any>[]) {
const definitions = nodes.map(node => node.serializeOptions());
localStorage.setItem('audioNodes', JSON.stringify(definitions));
}
}