From 3b9b0057f6a4ffc23dd040f805b4bc72e1454ecd Mon Sep 17 00:00:00 2001 From: LucaHaverty Date: Tue, 16 Jul 2024 10:51:13 -0700 Subject: [PATCH 1/9] Panel to pick a control scheme and brain configuration events --- fission/src/Synthesis.tsx | 14 +- fission/src/mirabuf/MirabufSceneObject.ts | 4 - fission/src/systems/input/DefaultInputs.ts | 127 +++++++++++++++++- fission/src/systems/input/InputSystem.ts | 4 +- .../systems/preferences/PreferencesSystem.ts | 2 +- .../synthesis_brain/SynthesisBrain.ts | 34 ++++- .../modals/configuring/ChangeInputsModal.tsx | 4 +- .../configuring/ResetAllInputsModal.tsx | 2 +- .../configuring/ChooseInputSchemePanel.tsx | 27 ++++ .../ui/panels/mirabuf/ImportMirabufPanel.tsx | 5 +- 10 files changed, 192 insertions(+), 31 deletions(-) create mode 100644 fission/src/ui/panels/configuring/ChooseInputSchemePanel.tsx diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index d303e6c0b3..d9ad0a1d8b 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -1,9 +1,4 @@ import Scene from "@/components/Scene.tsx" -import MirabufSceneObject from "./mirabuf/MirabufSceneObject.ts" -import MirabufCachingService, { MiraType } from "./mirabuf/MirabufLoader.ts" -import { mirabuf } from "./proto/mirabuf" -import MirabufParser, { ParseErrorSeverity } from "./mirabuf/MirabufParser.ts" -import MirabufInstance from "./mirabuf/MirabufInstance.ts" import { AnimatePresence } from "framer-motion" import { ReactElement, useEffect } from "react" import { ModalControlProvider, useModalManager } from "@/ui/ModalContext" @@ -57,6 +52,7 @@ import APS from "./aps/APS.ts" import ImportMirabufPanel from "@/ui/panels/mirabuf/ImportMirabufPanel.tsx" import Skybox from "./ui/components/Skybox.tsx" import PokerPanel from "@/panels/PokerPanel.tsx" +import ChooseInputSchemePanel from "./ui/panels/configuring/ChooseInputSchemePanel.tsx" const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira" @@ -96,7 +92,8 @@ function Synthesis() { console.debug(`Selected Mirabuf File: ${mira_path}`) } - const setup = async () => { + // TODO: do we actually want to spawn a robot right away when synthesis loads? + /* const setup = async () => { const info = await MirabufCachingService.CacheRemote(mira_path, MiraType.ROBOT) .catch(_ => MirabufCachingService.CacheRemote(DEFAULT_MIRA_PATH, MiraType.ROBOT)) .catch(console.error) @@ -117,9 +114,9 @@ function Synthesis() { const mirabufSceneObject = new MirabufSceneObject(new MirabufInstance(parser), miraAssembly.info!.name!) World.SceneRenderer.RegisterSceneObject(mirabufSceneObject) })() - } + } */ - setup() + //setup() let mainLoopHandle = 0 const mainLoop = () => { @@ -226,6 +223,7 @@ const initialPanels: ReactElement[] = [ , , , + , ] export default Synthesis diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index a7d05a7bb8..9a400048f3 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -229,10 +229,6 @@ class MirabufSceneObject extends SceneObject { World.PhysicsSystem.DisablePhysicsForBody(this._mechanism.GetBodyByNodeId(rn.id)!) }) } - - public GetRootNodeId(): Jolt.BodyID | undefined { - return this._mechanism.GetBodyByNodeId(this._mechanism.rootBody) - } } export async function CreateMirabuf(assembly: mirabuf.Assembly): Promise { diff --git a/fission/src/systems/input/DefaultInputs.ts b/fission/src/systems/input/DefaultInputs.ts index ef436a0b48..be6087069e 100644 --- a/fission/src/systems/input/DefaultInputs.ts +++ b/fission/src/systems/input/DefaultInputs.ts @@ -2,13 +2,17 @@ import { AxisInput, Input, EmptyModifierState } from "./InputSystem" export type InputScheme = { schemeName: string + descriptiveName: string + customized: boolean usesGamepad: boolean inputs: Input[] } class DefaultInputs { private static wasd: InputScheme = { - schemeName: "WASD", + schemeName: "Ernie", + descriptiveName: "WASD", + customized: false, usesGamepad: false, inputs: [ new AxisInput("arcadeDrive", "KeyW", "KeyS"), @@ -48,7 +52,9 @@ class DefaultInputs { } private static arrowKeys: InputScheme = { - schemeName: "Arrow Keys", + schemeName: "Luna", + descriptiveName: "Arrow Keys", + customized: false, usesGamepad: false, inputs: [ new AxisInput("arcadeDrive", "ArrowUp", "ArrowDown"), @@ -88,7 +94,9 @@ class DefaultInputs { } private static fullController: InputScheme = { - schemeName: "Full Controller", + schemeName: "Jax", + descriptiveName: "Full Controller", + customized: false, usesGamepad: true, inputs: [ new AxisInput("arcadeDrive", "", "", 1, true), @@ -103,7 +111,9 @@ class DefaultInputs { } private static leftStick: InputScheme = { - schemeName: "Left Stick", + schemeName: "Hunter", + descriptiveName: "Left Stick", + customized: false, usesGamepad: true, inputs: [ new AxisInput("arcadeDrive", "", "", 1, true), @@ -115,7 +125,9 @@ class DefaultInputs { } private static rightStick: InputScheme = { - schemeName: "Right Stick", + schemeName: "Carmela", + descriptiveName: "Right Stick", + customized: false, usesGamepad: true, inputs: [ new AxisInput("arcadeDrive", "", "", 3, true), @@ -126,13 +138,116 @@ class DefaultInputs { ], } - public static ALL_INPUT_SCHEMES: InputScheme[] = [ + public static AVAILABLE_INPUT_SCHEMES: InputScheme[] = [ this.wasd, this.arrowKeys, this.fullController, this.leftStick, this.rightStick, ] + + public static NAMES: string[] = [ + "Kennedy", + "Duke", + "Bria", + "Creed", + "Angie", + "Moises", + "Hattie", + "Quinton", + "Luisa", + "Ocean", + "Marlowe", + "Jimmy", + "Brielle", + "Forest", + "Katherine", + "Cade", + "Kori", + "Myles", + "Valeria", + "Braylon", + "Gracelyn", + "Killian", + "Holland", + "Jake", + "Jovie", + "William", + "Makenzie", + "Eden", + "Mabel", + "Ian", + "Leilany", + "Jayson", + "Kylie", + "Cal", + "Juliet", + "Emory", + "Eden", + "Nathanael", + "Eloise", + "Darian", + "Shelby", + "Neil", + "Scarlett", + "Ace", + "Florence", + "Alessandro", + "Sariyah", + "Joey", + "Aubrie", + "Edward", + "Octavia", + "Bode", + "Aaliyah", + "Francis", + "Camilla", + "Wilson", + "Elaina", + "Kayson", + "Kara", + "Rey", + "Madison", + "Emir", + "Alaya", + "Finley", + "Jayleen", + "Joseph", + "Arianna", + "Samson", + "Ezra", + "Amias", + "Ellen", + "Zion", + "Harley", + "Abraham", + "Elaine", + "Conner", + "Jolene", + "Kylan", + "Aislinn", + "Omar", + "Skyla", + "Shepard", + "Jaylin", + "Osiris", + "Lilyana", + "Noe", + "Crystal", + "Jeffrey", + "Emily", + "Rayan", + "Elise", + "Forrest", + "Aarya", + "Beckett", + "Jacqueline", + "Kyle", + "Kailey", + "Hank", + "Alanna", + "Marco", + ] } export default DefaultInputs diff --git a/fission/src/systems/input/InputSystem.ts b/fission/src/systems/input/InputSystem.ts index 442c330a89..d5b650ddf7 100644 --- a/fission/src/systems/input/InputSystem.ts +++ b/fission/src/systems/input/InputSystem.ts @@ -248,7 +248,9 @@ class InputSystem extends WorldSystem { if (targetScheme == null || targetInput == null) return 0 - return targetInput.getValue(targetScheme.usesGamepad) + // TODO + //return targetInput.getValue(targetScheme.usesGamepad) + return 0.0 } // Returns true if two modifier states are identical diff --git a/fission/src/systems/preferences/PreferencesSystem.ts b/fission/src/systems/preferences/PreferencesSystem.ts index 9a34a08bb6..f79964f2ae 100644 --- a/fission/src/systems/preferences/PreferencesSystem.ts +++ b/fission/src/systems/preferences/PreferencesSystem.ts @@ -25,7 +25,7 @@ class PreferencesSystem { private static _localStorageKey = "Preferences" /** Event dispatched when any global preference is updated */ - public static addEventListener(callback: (e: PreferenceEvent) => unknown) { + public static addEventListener(callback: (e: PreferenceEvent) => void) { window.addEventListener("preferenceChanged", callback as EventListener) } diff --git a/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts b/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts index 9b33a0cbc5..fbe4941c77 100644 --- a/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts +++ b/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts @@ -18,7 +18,26 @@ import { AxisInput, ButtonInput, Input } from "@/systems/input/InputSystem" import DefaultInputs, { InputScheme } from "@/systems/input/DefaultInputs" import PreferencesSystem from "@/systems/preferences/PreferencesSystem" +class BrainConfiguredEvent extends Event { + public brainIndex: number + public schemeName: string + + constructor(brainIndex: number, schemeName: string) { + super("brainConfigured") + this.brainIndex = brainIndex + this.schemeName = schemeName + } +} + class SynthesisBrain extends Brain { + public static triggerBrainConfiguredEvent(schemeName: string, brainIndex: number) { + window.dispatchEvent(new BrainConfiguredEvent(brainIndex, schemeName)) + } + + private static addBrainConfiguredEventListener(callback: (e: BrainConfiguredEvent) => void) { + window.addEventListener("brainConfigured", callback as EventListener) + } + private _behaviors: Behavior[] = [] private _simLayer: SimulationLayer @@ -60,12 +79,13 @@ class SynthesisBrain extends Brain { this.configureArcadeDriveBehavior() this.configureArmBehaviors() this.configureElevatorBehaviors() - this.configureInputs() } else { this.configureField() } SynthesisBrain._currentRobotIndex++ + + SynthesisBrain.addBrainConfiguredEventListener(this.configureInputs) } public Enable(): void {} @@ -84,7 +104,7 @@ class SynthesisBrain extends Brain { } // Creates an instance of ArcadeDriveBehavior and automatically configures it - public configureArcadeDriveBehavior() { + private configureArcadeDriveBehavior() { const wheelDrivers: WheelDriver[] = this._simLayer.drivers.filter( driver => driver instanceof WheelDriver ) as WheelDriver[] @@ -136,7 +156,7 @@ class SynthesisBrain extends Brain { } // Creates instances of ArmBehavior and automatically configures them - public configureArmBehaviors() { + private configureArmBehaviors() { const hingeDrivers: HingeDriver[] = this._simLayer.drivers.filter( driver => driver instanceof HingeDriver ) as HingeDriver[] @@ -159,7 +179,7 @@ class SynthesisBrain extends Brain { } // Creates instances of ElevatorBehavior and automatically configures them - public configureElevatorBehaviors() { + private configureElevatorBehaviors() { const sliderDrivers: SliderDriver[] = this._simLayer.drivers.filter( driver => driver instanceof SliderDriver ) as SliderDriver[] @@ -181,7 +201,7 @@ class SynthesisBrain extends Brain { } } - private configureInputs() { + private configureInputs(_: BrainConfiguredEvent) { // Check for existing inputs const robotConfig = PreferencesSystem.getRobotPreferences(this._assemblyName) if (robotConfig.inputsSchemes[this._assemblyIndex] != undefined) { @@ -191,10 +211,12 @@ class SynthesisBrain extends Brain { // Configure with default inputs - const scheme = DefaultInputs.ALL_INPUT_SCHEMES[SynthesisBrain._currentRobotIndex] + const scheme = DefaultInputs.AVAILABLE_INPUT_SCHEMES[SynthesisBrain._currentRobotIndex] robotConfig.inputsSchemes[this._assemblyIndex] = { schemeName: this._assemblyName, + descriptiveName: "", + customized: false, usesGamepad: scheme?.usesGamepad ?? false, inputs: [], } diff --git a/fission/src/ui/modals/configuring/ChangeInputsModal.tsx b/fission/src/ui/modals/configuring/ChangeInputsModal.tsx index 4f1d6d24ad..6f6cca9a93 100644 --- a/fission/src/ui/modals/configuring/ChangeInputsModal.tsx +++ b/fission/src/ui/modals/configuring/ChangeInputsModal.tsx @@ -389,7 +389,7 @@ const ChangeInputsModal: React.FC = ({ modalId }) => { scheme.schemeName )} onSelect={value => { @@ -400,7 +400,7 @@ const ChangeInputsModal: React.FC = ({ modalId }) => {