From f62bf53bd166dbb0bd32664fe0d379e69426ab34 Mon Sep 17 00:00:00 2001 From: YeonV Date: Thu, 14 Nov 2024 00:48:44 +0100 Subject: [PATCH] First Draft of "OneEffect" (pre-alpha; dev-only) --- src/components/Gamepad/OneEffect.tsx | 229 +++++++++++++++++++++++++++ src/pages/Pages.tsx | 2 + src/store/api/storeVirtuals.tsx | 2 +- 3 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 src/components/Gamepad/OneEffect.tsx diff --git a/src/components/Gamepad/OneEffect.tsx b/src/components/Gamepad/OneEffect.tsx new file mode 100644 index 00000000..42f58f5f --- /dev/null +++ b/src/components/Gamepad/OneEffect.tsx @@ -0,0 +1,229 @@ +import { + Accordion, + AccordionDetails, + AccordionSummary, + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + MenuItem, + Select, + Stack, + ToggleButton, + ToggleButtonGroup, + Typography +} from '@mui/material' +import { useEffect, useState } from 'react' +import { Edit, ExpandMore } from '@mui/icons-material' +import useStore from '../../store/useStore' +import BladeIcon from '../Icons/BladeIcon/BladeIcon' +import SliderInput from '../SchemaForm/components/Number/SliderInput' +import { useHotkeys } from 'react-hotkeys-hook' + +const OneEffect = ({ + setPayload, + noButton, +}: any) => { + const [dialogOpen, setDialogOpen] = useState(false) + + const [virtId, setVirtId] = useState('') + const [type, setType] = useState('') + const [config, setConfig] = useState({}) + const [active, setActive] = useState(false) + const [fallbackBool, setFallbackBool] = useState(false) + const [fallbackUseNumber, setFallbackUseNumber] = useState(false) + const [fallbackNumber, setFallbackNumber] = useState(0) + + const effects = useStore((state) => state.schemas.effects) + const virtuals = useStore((state) => state.virtuals) + const presets = useStore((state) => state.presets) + const setEffect = useStore((state) => state.setEffect) + const getPresets = useStore((state) => state.getPresets) + + const p = { ...presets.ledfx_presets, ...presets.user_presets } + + const handleClose = () => { + setDialogOpen(false) + } + const handleSave = () => { + setPayload({ }) + setDialogOpen(false) + } + // const handleTest = (virtId: string, type: string, config: EffectConfig, active: boolean, fallback: boolean | number) => { + const handleTest = () => { + setEffect(virtId, type, JSON.parse(config), active, fallbackUseNumber ? fallbackNumber / 1000 : fallbackBool) + } + useHotkeys(['ctrl+alt+e'], () => setDialogOpen(!dialogOpen)) + + useEffect(() => { + if (virtId && type && virtId !== '' && type !== '') { + getPresets(type) + } + }, [virtId, type]) + + return ( + <> + {!noButton && } + + + One Effect + + + + + Virtual ID + + + + Type + + + + Preset + + + + + Active + setActive(v)} + aria-label="Platform" + > + True + False + + + + Fallback Type + setFallbackUseNumber(v)} + aria-label="Platform" + > + Number + Boolean + + + {fallbackUseNumber + ? + : + Fallback + setFallbackBool(v)} + aria-label="Platform" + > + true + false + + } + + + } + aria-controls="panel1-content" + id="panel1-header" + > + Output JSON + + +
+                {`{
+  "virtId": "${virtId}",
+  "type": "${type}",
+  "config": ${typeof config === 'string' ? JSON.stringify(JSON.parse(config), null, 4) : JSON.stringify(config, null, 4)},
+  "active": ${active},
+  "fallback": ${(fallbackUseNumber ? fallbackNumber / 1000 : fallbackBool)}
+}`}
+              
+
+
+ + + + + {!noButton && } + +
+
+ + ) +} +export default OneEffect diff --git a/src/pages/Pages.tsx b/src/pages/Pages.tsx index b03b7746..9c54405c 100644 --- a/src/pages/Pages.tsx +++ b/src/pages/Pages.tsx @@ -34,6 +34,7 @@ import HostManager from '../components/Dialogs/HostManager' import Graph from './Graph/Graph' import MGraphFloating from '../components/Integrations/Spotify/Widgets/MGraphFlotaing/MGraphFloating' import Keybinding from '../components/Integrations/Spotify/Widgets/Keybinding/Keybinding' +import OneEffect from '../components/Gamepad/OneEffect' const Routings = ({ handleWs }: any) => { const theme = useTheme() @@ -151,6 +152,7 @@ const Routings = ({ handleWs }: any) => { {mp && } {mg && setMg(false)} />} {keybinding && setKeybinding(false)} />} + diff --git a/src/store/api/storeVirtuals.tsx b/src/store/api/storeVirtuals.tsx index 3417887c..b6f0b7ea 100644 --- a/src/store/api/storeVirtuals.tsx +++ b/src/store/api/storeVirtuals.tsx @@ -179,7 +179,7 @@ const storeVirtuals = (set: any) => ({ type: string, config: any, active: boolean, - fallback?: boolean + fallback?: boolean | number ) => { const resp = await Ledfx(`/api/virtuals/${virtId}/effects`, 'POST', { type,