diff --git a/vite/public/cuelist.json b/vite/public/cuelist.json index 5896d03..c3faadc 100644 --- a/vite/public/cuelist.json +++ b/vite/public/cuelist.json @@ -136,7 +136,7 @@ "name": "Q6", "type": "space", "description": "Ending", - "audioFile": "assets/q6.mp3" + "audioFile": "assets/q6.mp3" } ] } diff --git a/vite/src/comps/light.jsx b/vite/src/comps/light.jsx new file mode 100644 index 0000000..16cce8e --- /dev/null +++ b/vite/src/comps/light.jsx @@ -0,0 +1,54 @@ +import gsap from "gsap" +import { forwardRef, useEffect, useImperativeHandle, useRef } from "react" +import { sendOsc } from "../util/osc"; + +const FADE_TIME=3; + +export const Light=forwardRef((props, ref)=>{ + + const refVal=useRef({val: 0}); + const refInput=useRef(); + const refContainer=useRef(); + + function fade(from, to){ + + const time= parseFloat(refInput.current.value) || FADE_TIME; + gsap.fromTo(refVal.current,{val: from}, { + val: to, + duration: time, + onUpdate: () => { + // console.log(refVal.current.val); + sendOsc('/light', refVal.current.val.toString()); + refContainer.current.style.background= `rgba(0, 255, 0, ${refVal.current.val})`; // Update background color based on value + }, + }); + } + useImperativeHandle(ref, () => ({ + fadeIn: ()=>{ + console.log('fadeIn'); + fade(0, 1); + }, + fadeOut: ()=>{ + console.log('fadeOut'); + fade(1, 0); + } + })); + useEffect(()=>{ + + refInput.current.value=FADE_TIME; + + },[]); + + return ( +
+ + + + + + + + +
+ ) +}); \ No newline at end of file diff --git a/vite/src/comps/numpad.jsx b/vite/src/comps/numpad.jsx index 1719cd9..d731dcc 100644 --- a/vite/src/comps/numpad.jsx +++ b/vite/src/comps/numpad.jsx @@ -31,7 +31,7 @@ export default function NumPad({onSend}){ } return; }else if(e.key===KEY_BACKSPACE || e.key==='Backspace' || e.key==='Delete'){ - setInput((prev)=>prev?.slice(0,-1)); + setInput((prev)=>''); return; } diff --git a/vite/src/pages/flow.jsx b/vite/src/pages/flow.jsx index 7fc81d8..4f2cde6 100644 --- a/vite/src/pages/flow.jsx +++ b/vite/src/pages/flow.jsx @@ -7,6 +7,7 @@ import { Status, useChat } from "../util/useChat"; import { getSummary } from "../util/chat"; import { saveHistory } from "../util/output"; import NumPad from "../comps/numpad"; +import { Light } from "../comps/light"; const EmojiType={ @@ -28,6 +29,7 @@ export function Flow(){ const refTimer=useRef(); const refAudio=useRef(); const refInput=useRef(); + const refLight=useRef(); const refCurrentCue= useRef(null); @@ -89,7 +91,7 @@ export function Flow(){ sendMessage(); setChatWelcome(true); }else{ - const message= refInput.current.value?.trim(); + const message= refInput.current?.value?.trim(); if(message && message.length>0) { sendMessage(message); @@ -119,6 +121,9 @@ export function Flow(){ console.log('onCueEnd:', cue.id); + if(cue.callback=='start_conversation') refLight.current.fadeIn(); // Fade in light for conversation start + if(cue.callback=='summary') refLight.current.fadeOut(); // Fade out light for conversation end + if(cue.auto) { playCue(cuelist.find(c => c.id === cue.nextcue)); @@ -250,7 +255,7 @@ export function Flow(){ return (
-
+
{refCurrentCue.current?.name}
@@ -260,6 +265,7 @@ export function Flow(){ saveHistory(history); }}>Save Log +
@@ -282,7 +288,7 @@ export function Flow(){ - +
{description} {EmojiType[type]} {auto ? '⤵️' : ''}{audioFile || props.duration}{audioFile || props.duration} {props.callback && `<${props.callback}>`}