Refactor actions

This commit is contained in:
space-nuko
2023-05-22 14:33:59 -05:00
parent 77488c1b45
commit b5512e6673
15 changed files with 641 additions and 623 deletions

View File

@@ -0,0 +1,36 @@
import { BuiltInSlotType, LiteGraph, type SlotLayout } from "@litegraph-ts/core";
import ComfyGraphNode, { type ComfyGraphNodeProperties } from "../ComfyGraphNode";
export interface ComfyPlaySoundActionProperties extends ComfyGraphNodeProperties {
sound: string,
}
export default class ComfyPlaySoundAction extends ComfyGraphNode {
override properties: ComfyPlaySoundActionProperties = {
tags: [],
sound: "notification.mp3"
}
static slotLayout: SlotLayout = {
inputs: [
{ name: "sound", type: "string" },
{ name: "trigger", type: BuiltInSlotType.ACTION }
],
}
override onAction(action: any, param: any) {
const sound = this.getInputData(0) || this.properties.sound;
if (sound) {
const url = `${location.origin}/sound/${sound}`;
const audio = new Audio(url);
audio.play();
}
};
}
LiteGraph.registerNodeType({
class: ComfyPlaySoundAction,
title: "Comfy.PlaySoundAction",
desc: "Plays a sound located under the sound/ directory.",
type: "actions/play_sound"
})