From 89cc3195b108ee70fe5ca3db41f38ba22ccb99dd Mon Sep 17 00:00:00 2001 From: Azalea Colburn Date: Wed, 26 Jun 2024 13:35:14 -0700 Subject: [PATCH 1/3] create bun fallback for format scripts --- fission/package.json | 8 +- fission/prettier.config.js | 12 +- fission/src/Synthesis.tsx | 20 +-- fission/src/mirabuf/MirabufParser.ts | 2 +- fission/src/mirabuf/MirabufSceneObject.ts | 6 +- fission/src/systems/World.ts | 34 ++--- fission/src/systems/input/InputSystem.ts | 98 ++++++------- .../systems/simulation/SimulationSystem.ts | 22 +-- .../behavior/ArcadeDriveBehavior.ts | 49 ++++--- .../systems/simulation/behavior/Behavior.ts | 2 +- .../simulation/behavior/GenericArmBehavior.ts | 47 ++++--- .../behavior/GenericElevatorBehavior.ts | 45 +++--- .../systems/simulation/driver/SliderDriver.ts | 15 +- .../systems/simulation/driver/WheelDriver.ts | 12 +- .../simulation/stimulus/WheelStimulus.ts | 2 +- .../synthesis_brain/SynthesisBrain.ts | 130 ++++++++++-------- fission/src/ui/ToastContext.tsx | 8 +- fission/src/ui/components/Dropdown.tsx | 15 +- fission/src/ui/components/NumberInput.tsx | 2 +- fission/src/ui/components/Scene.tsx | 14 +- .../modals/configuring/ChangeInputsModal.tsx | 45 +++--- .../theme-editor/ThemeEditorModal.tsx | 6 +- 22 files changed, 322 insertions(+), 272 deletions(-) diff --git a/fission/package.json b/fission/package.json index 126efa86f7..f4c48b571a 100644 --- a/fission/package.json +++ b/fission/package.json @@ -9,10 +9,10 @@ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives", "preview": "vite preview --base=/fission/", "test": "vitest", - "lint:fix": "npm run lint --fix", - "prettier": "npx prettier src --check", - "prettier:fix": "npm run prettier --write", - "format": "npm run prettier:fix && npm run lint:fix", + "lint:fix": "npm run lint --fix || bun run lint --fix", + "prettier": "npx prettier src --check || bun x prettier src --check", + "prettier:fix": "npm run prettier --write || bun run prettier --write", + "format": "(npm run prettier:fix && npm run lint:fix) || (bun run prettier:fix && bun run lint:fix)", "build:prod": "tsc && vite build --base=/fission/", "assetpack": "run-script-os", "assetpack:nix": "curl -o public/assetpack.zip https://synthesis.autodesk.com/Downloadables/assetpack.zip && unzip -o public/assetpack.zip -d public/", diff --git a/fission/prettier.config.js b/fission/prettier.config.js index 11920b1227..1ab6c97d3c 100644 --- a/fission/prettier.config.js +++ b/fission/prettier.config.js @@ -9,7 +9,15 @@ const config = { bracketSpacing: true, bracketSameLine: false, arrowParens: "avoid", - printWidth: 120 + printWidth: 120, + overrides: [ + { + files: "*.json", + options: { + tabWidth: 2, + }, + }, + ], } -export default config; +export default config diff --git a/fission/src/Synthesis.tsx b/fission/src/Synthesis.tsx index 261efc1615..c6d0fb9a39 100644 --- a/fission/src/Synthesis.tsx +++ b/fission/src/Synthesis.tsx @@ -1,9 +1,9 @@ -import Scene from '@/components/Scene.tsx'; -import MirabufSceneObject from './mirabuf/MirabufSceneObject.ts'; -import { LoadMirabufRemote } from './mirabuf/MirabufLoader.ts'; -import { mirabuf } from './proto/mirabuf'; -import MirabufParser, { ParseErrorSeverity } from './mirabuf/MirabufParser.ts'; -import MirabufInstance from './mirabuf/MirabufInstance.ts'; +import Scene from "@/components/Scene.tsx" +import MirabufSceneObject from "./mirabuf/MirabufSceneObject.ts" +import { LoadMirabufRemote } 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" @@ -49,10 +49,10 @@ import ScoringZonesPanel from "@/panels/configuring/scoring/ScoringZonesPanel" import ZoneConfigPanel from "@/panels/configuring/scoring/ZoneConfigPanel" import ScoreboardPanel from "@/panels/information/ScoreboardPanel" import DriverStationPanel from "@/panels/simulation/DriverStationPanel" -import ManageAssembliesModal from '@/modals/spawning/ManageAssembliesModal.tsx'; -import World from '@/systems/World.ts'; -import { AddRobotsModal, AddFieldsModal, SpawningModal } from '@/modals/spawning/SpawningModals.tsx'; -import ImportMirabufModal from '@/modals/mirabuf/ImportMirabufModal.tsx'; +import ManageAssembliesModal from "@/modals/spawning/ManageAssembliesModal.tsx" +import World from "@/systems/World.ts" +import { AddRobotsModal, AddFieldsModal, SpawningModal } from "@/modals/spawning/SpawningModals.tsx" +import ImportMirabufModal from "@/modals/mirabuf/ImportMirabufModal.tsx" const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira" diff --git a/fission/src/mirabuf/MirabufParser.ts b/fission/src/mirabuf/MirabufParser.ts index 7936f8ca44..1d503f5623 100644 --- a/fission/src/mirabuf/MirabufParser.ts +++ b/fission/src/mirabuf/MirabufParser.ts @@ -191,7 +191,7 @@ class MirabufParser { // Build undirected graph const graph = new Graph() graph.AddNode(rootNode ? rootNode.id : this._rigidNodes[0].id) - const jointInstances = (Object.values(assembly.data!.joints!.jointInstances!) as mirabuf.joint.JointInstance[]) + const jointInstances = Object.values(assembly.data!.joints!.jointInstances!) as mirabuf.joint.JointInstance[] jointInstances.forEach((x: mirabuf.joint.JointInstance) => { const rA = this._partToNodeMap.get(x.parentPart) const rB = this._partToNodeMap.get(x.childPart) diff --git a/fission/src/mirabuf/MirabufSceneObject.ts b/fission/src/mirabuf/MirabufSceneObject.ts index b2783a81a5..14a1cf1d50 100644 --- a/fission/src/mirabuf/MirabufSceneObject.ts +++ b/fission/src/mirabuf/MirabufSceneObject.ts @@ -96,10 +96,10 @@ class MirabufSceneObject extends SceneObject { colliderMesh.position.setFromMatrixPosition(transform) colliderMesh.rotation.setFromRotationMatrix(transform) - const comTransform = JoltMat44_ThreeMatrix4(body.GetCenterOfMassTransform()); + const comTransform = JoltMat44_ThreeMatrix4(body.GetCenterOfMassTransform()) - comMesh.position.setFromMatrixPosition(comTransform); - comMesh.rotation.setFromRotationMatrix(comTransform); + comMesh.position.setFromMatrixPosition(comTransform) + comMesh.rotation.setFromRotationMatrix(comTransform) } }) } diff --git a/fission/src/systems/World.ts b/fission/src/systems/World.ts index e38fac6813..7470618dc8 100644 --- a/fission/src/systems/World.ts +++ b/fission/src/systems/World.ts @@ -1,9 +1,9 @@ import * as THREE from "three" -import PhysicsSystem from "./physics/PhysicsSystem"; -import SceneRenderer from "./scene/SceneRenderer"; -import SimulationSystem from "./simulation/SimulationSystem"; -import InputSystem from "./input/InputSystem"; +import PhysicsSystem from "./physics/PhysicsSystem" +import SceneRenderer from "./scene/SceneRenderer" +import SimulationSystem from "./simulation/SimulationSystem" +import InputSystem from "./input/InputSystem" class World { private static _isAlive: boolean = false @@ -37,10 +37,10 @@ class World { World._clock = new THREE.Clock() World._isAlive = true - World._sceneRenderer = new SceneRenderer(); - World._physicsSystem = new PhysicsSystem(); - World._simulationSystem = new SimulationSystem(); - World._inputSystem = new InputSystem(); + World._sceneRenderer = new SceneRenderer() + World._physicsSystem = new PhysicsSystem() + World._simulationSystem = new SimulationSystem() + World._inputSystem = new InputSystem() } public static DestroyWorld() { @@ -48,18 +48,18 @@ class World { World._isAlive = false - World._physicsSystem.Destroy(); - World._sceneRenderer.Destroy(); - World._simulationSystem.Destroy(); - World._inputSystem.Destroy(); + World._physicsSystem.Destroy() + World._sceneRenderer.Destroy() + World._simulationSystem.Destroy() + World._inputSystem.Destroy() } public static UpdateWorld() { - const deltaT = World._clock.getDelta(); - World._simulationSystem.Update(deltaT); - World._physicsSystem.Update(deltaT); - World._inputSystem.Update(deltaT); - World._sceneRenderer.Update(deltaT); + const deltaT = World._clock.getDelta() + World._simulationSystem.Update(deltaT) + World._physicsSystem.Update(deltaT) + World._inputSystem.Update(deltaT) + World._sceneRenderer.Update(deltaT) } } diff --git a/fission/src/systems/input/InputSystem.ts b/fission/src/systems/input/InputSystem.ts index cd7f4610e6..21aca82ee7 100644 --- a/fission/src/systems/input/InputSystem.ts +++ b/fission/src/systems/input/InputSystem.ts @@ -1,4 +1,4 @@ -import WorldSystem from "../WorldSystem"; +import WorldSystem from "../WorldSystem" declare global { type ModifierState = { @@ -16,115 +16,119 @@ declare global { } } -export const emptyModifierState: ModifierState = { ctrl: false, alt: false, shift: false, meta: false }; +export const emptyModifierState: ModifierState = { ctrl: false, alt: false, shift: false, meta: false } // When a robot is loaded, default inputs replace any unassigned inputs const defaultInputs: { [key: string]: Input } = { - "intake": { name: "intake", keyCode: "KeyE", isGlobal: true, modifiers: emptyModifierState }, - "shootGamepiece": { name: "shootGamepiece", keyCode: "KeyQ", isGlobal: true, modifiers: emptyModifierState }, - "enableGodMode": { name: "enableGodMode", keyCode: "KeyG", isGlobal: true, modifiers: emptyModifierState }, - - "arcadeForward": { name: "arcadeForward", keyCode: "KeyW", isGlobal: false, modifiers: emptyModifierState }, - "arcadeBackward": { name: "arcadeBackward", keyCode: "KeyS", isGlobal: false, modifiers: emptyModifierState }, - "arcadeLeft": { name: "arcadeLeft", keyCode: "KeyA", isGlobal: false, modifiers: emptyModifierState }, - "arcadeRight": { name: "arcadeRight", keyCode: "KeyD", isGlobal: false, modifiers: emptyModifierState }, + intake: { name: "intake", keyCode: "KeyE", isGlobal: true, modifiers: emptyModifierState }, + shootGamepiece: { name: "shootGamepiece", keyCode: "KeyQ", isGlobal: true, modifiers: emptyModifierState }, + enableGodMode: { name: "enableGodMode", keyCode: "KeyG", isGlobal: true, modifiers: emptyModifierState }, + + arcadeForward: { name: "arcadeForward", keyCode: "KeyW", isGlobal: false, modifiers: emptyModifierState }, + arcadeBackward: { name: "arcadeBackward", keyCode: "KeyS", isGlobal: false, modifiers: emptyModifierState }, + arcadeLeft: { name: "arcadeLeft", keyCode: "KeyA", isGlobal: false, modifiers: emptyModifierState }, + arcadeRight: { name: "arcadeRight", keyCode: "KeyD", isGlobal: false, modifiers: emptyModifierState }, } class InputSystem extends WorldSystem { - public static allInputs: { [key: string]: Input } = { } - private static _currentModifierState: ModifierState; + public static allInputs: { [key: string]: Input } = {} + private static _currentModifierState: ModifierState // Inputs global to all of synthesis like camera controls public static get globalInputs(): { [key: string]: Input } { - return Object.fromEntries( - Object.entries(InputSystem.allInputs) - .filter(([_, input]) => input.isGlobal)); + return Object.fromEntries(Object.entries(InputSystem.allInputs).filter(([_, input]) => input.isGlobal)) } // Robot specific controls like driving public static get robotInputs(): { [key: string]: Input } { - return Object.fromEntries( - Object.entries(InputSystem.allInputs) - .filter(([_, input]) => !input.isGlobal)); + return Object.fromEntries(Object.entries(InputSystem.allInputs).filter(([_, input]) => !input.isGlobal)) } // A list of keys currently being pressed - private static _keysPressed: { [key: string]: boolean } = {}; + private static _keysPressed: { [key: string]: boolean } = {} constructor() { - super(); + super() - this.HandleKeyDown = this.HandleKeyDown.bind(this); - document.addEventListener('keydown', this.HandleKeyDown); + this.HandleKeyDown = this.HandleKeyDown.bind(this) + document.addEventListener("keydown", this.HandleKeyDown) + + this.HandleKeyUp = this.HandleKeyUp.bind(this) + document.addEventListener("keyup", this.HandleKeyUp) - this.HandleKeyUp = this.HandleKeyUp.bind(this); - document.addEventListener('keyup', this.HandleKeyUp); - // TODO: Load saved inputs from mira (robot specific) & global inputs for (const key in defaultInputs) { if (Object.prototype.hasOwnProperty.call(defaultInputs, key)) { - InputSystem.allInputs[key] = defaultInputs[key]; + InputSystem.allInputs[key] = defaultInputs[key] } } } public Update(_: number): void { if (!document.hasFocus()) { - for (const keyCode in InputSystem._keysPressed) - delete InputSystem._keysPressed[keyCode]; - return; + for (const keyCode in InputSystem._keysPressed) delete InputSystem._keysPressed[keyCode] + return } - InputSystem._currentModifierState = { ctrl: InputSystem.isKeyPressed("ControlLeft") || InputSystem.isKeyPressed("ControlRight"), alt: InputSystem.isKeyPressed("AltLeft") || InputSystem.isKeyPressed("AltRight"), shift: InputSystem.isKeyPressed("ShiftLeft") || InputSystem.isKeyPressed("ShiftRight"), meta: InputSystem.isKeyPressed("MetaLeft") || InputSystem.isKeyPressed("MetaRight") } + InputSystem._currentModifierState = { + ctrl: InputSystem.isKeyPressed("ControlLeft") || InputSystem.isKeyPressed("ControlRight"), + alt: InputSystem.isKeyPressed("AltLeft") || InputSystem.isKeyPressed("AltRight"), + shift: InputSystem.isKeyPressed("ShiftLeft") || InputSystem.isKeyPressed("ShiftRight"), + meta: InputSystem.isKeyPressed("MetaLeft") || InputSystem.isKeyPressed("MetaRight"), + } } - public Destroy(): void { - document.removeEventListener('keydown', this.HandleKeyDown); - document.removeEventListener('keyup', this.HandleKeyUp); - } + public Destroy(): void { + document.removeEventListener("keydown", this.HandleKeyDown) + document.removeEventListener("keyup", this.HandleKeyUp) + } // Called when any key is pressed private HandleKeyDown(event: KeyboardEvent) { - InputSystem._keysPressed[event.code] = true; + InputSystem._keysPressed[event.code] = true } // Called when any key is released private HandleKeyUp(event: KeyboardEvent) { - InputSystem._keysPressed[event.code] = false; + InputSystem._keysPressed[event.code] = false } // Returns true if the given key is currently down private static isKeyPressed(key: string): boolean { - return !!InputSystem._keysPressed[key]; + return !!InputSystem._keysPressed[key] } // If an input exists, return true if it is pressed - public static getInput(inputName: string) : boolean { + public static getInput(inputName: string): boolean { // Checks if there is an input assigned to this action if (inputName in this.allInputs) { - const targetInput = this.allInputs[inputName]; + const targetInput = this.allInputs[inputName] // Check for input modifiers - if (!this.CompareModifiers(InputSystem._currentModifierState, targetInput.modifiers)) - return false; + if (!this.CompareModifiers(InputSystem._currentModifierState, targetInput.modifiers)) return false - return this.isKeyPressed(targetInput.keyCode); + return this.isKeyPressed(targetInput.keyCode) } // If the input does not exist, returns false - return false; + return false } // Combines two inputs into a positive/negative axis public static GetAxis(positive: string, negative: string) { - return (this.getInput(positive) ? 1 : 0) - (this.getInput(negative) ? 1 : 0); + return (this.getInput(positive) ? 1 : 0) - (this.getInput(negative) ? 1 : 0) } // Returns true if two modifier states are identical - private static CompareModifiers(state1: ModifierState, state2: ModifierState) : boolean { - return state1.alt == state2.alt && state1.ctrl == state2.ctrl && state1.meta == state2.meta && state1.shift == state2.shift; + private static CompareModifiers(state1: ModifierState, state2: ModifierState): boolean { + return ( + state1.alt == state2.alt && + state1.ctrl == state2.ctrl && + state1.meta == state2.meta && + state1.shift == state2.shift + ) } } -export default InputSystem; \ No newline at end of file +export default InputSystem diff --git a/fission/src/systems/simulation/SimulationSystem.ts b/fission/src/systems/simulation/SimulationSystem.ts index 0bc789040e..331739f8a7 100644 --- a/fission/src/systems/simulation/SimulationSystem.ts +++ b/fission/src/systems/simulation/SimulationSystem.ts @@ -58,9 +58,15 @@ class SimulationLayer { private _drivers: Driver[] private _stimuli: Stimulus[] - public get brain() { return this._brain; } - public get drivers() { return this._drivers; } - public get stimuli() { return this._stimuli; } + public get brain() { + return this._brain + } + public get drivers() { + return this._drivers + } + public get stimuli() { + return this._stimuli + } constructor(mechanism: Mechanism) { this._mechanism = mechanism @@ -101,13 +107,13 @@ class SimulationLayer { public SetBrain(brain: T | undefined) { if (this._brain) this._brain.Disable() - this._brain = brain; - + this._brain = brain + if (this._brain) { - this._brain.Enable(); + this._brain.Enable() } } } -export default SimulationSystem; -export {SimulationLayer}; \ No newline at end of file +export default SimulationSystem +export { SimulationLayer } diff --git a/fission/src/systems/simulation/behavior/ArcadeDriveBehavior.ts b/fission/src/systems/simulation/behavior/ArcadeDriveBehavior.ts index 4d5ed5497c..c9bb881a85 100644 --- a/fission/src/systems/simulation/behavior/ArcadeDriveBehavior.ts +++ b/fission/src/systems/simulation/behavior/ArcadeDriveBehavior.ts @@ -1,35 +1,42 @@ -import WheelDriver from "../driver/WheelDriver"; -import WheelRotationStimulus from "../stimulus/WheelStimulus"; -import Behavior from "./Behavior"; -import InputSystem from "@/systems/input/InputSystem"; +import WheelDriver from "../driver/WheelDriver" +import WheelRotationStimulus from "../stimulus/WheelStimulus" +import Behavior from "./Behavior" +import InputSystem from "@/systems/input/InputSystem" class ArcadeDriveBehavior extends Behavior { - leftWheels: WheelDriver[]; - rightWheels: WheelDriver[]; + leftWheels: WheelDriver[] + rightWheels: WheelDriver[] - private _driveSpeed = 30; - private _turnSpeed = 30; + private _driveSpeed = 30 + private _turnSpeed = 30 - constructor(leftWheels: WheelDriver[], rightWheels: WheelDriver[], leftStimuli: WheelRotationStimulus[], rightStimuli: WheelRotationStimulus[]) { - super(leftWheels.concat(rightWheels), leftStimuli.concat(rightStimuli)); - - this.leftWheels = leftWheels; - this.rightWheels = rightWheels; + constructor( + leftWheels: WheelDriver[], + rightWheels: WheelDriver[], + leftStimuli: WheelRotationStimulus[], + rightStimuli: WheelRotationStimulus[] + ) { + super(leftWheels.concat(rightWheels), leftStimuli.concat(rightStimuli)) + + this.leftWheels = leftWheels + this.rightWheels = rightWheels } // Sets the drivetrains target linear and rotational velocity private DriveSpeeds(linearVelocity: number, rotationVelocity: number) { - const leftSpeed = linearVelocity + rotationVelocity; - const rightSpeed = linearVelocity - rotationVelocity; - - this.leftWheels.forEach((wheel) => wheel.targetWheelSpeed = leftSpeed); - this.rightWheels.forEach((wheel) => wheel.targetWheelSpeed = rightSpeed); + const leftSpeed = linearVelocity + rotationVelocity + const rightSpeed = linearVelocity - rotationVelocity + + this.leftWheels.forEach(wheel => (wheel.targetWheelSpeed = leftSpeed)) + this.rightWheels.forEach(wheel => (wheel.targetWheelSpeed = rightSpeed)) } public Update(_: number): void { - this.DriveSpeeds(InputSystem.GetAxis("arcadeForward", "arcadeBackward")*this._driveSpeed, - InputSystem.GetAxis("arcadeRight", "arcadeLeft")*this._turnSpeed); + this.DriveSpeeds( + InputSystem.GetAxis("arcadeForward", "arcadeBackward") * this._driveSpeed, + InputSystem.GetAxis("arcadeRight", "arcadeLeft") * this._turnSpeed + ) } } -export default ArcadeDriveBehavior; \ No newline at end of file +export default ArcadeDriveBehavior diff --git a/fission/src/systems/simulation/behavior/Behavior.ts b/fission/src/systems/simulation/behavior/Behavior.ts index fcfc54cca3..2dd0fcb190 100644 --- a/fission/src/systems/simulation/behavior/Behavior.ts +++ b/fission/src/systems/simulation/behavior/Behavior.ts @@ -17,7 +17,7 @@ abstract class Behavior { this._stimuli = stimuli } - public abstract Update(deltaT: number): void; + public abstract Update(deltaT: number): void } export default Behavior diff --git a/fission/src/systems/simulation/behavior/GenericArmBehavior.ts b/fission/src/systems/simulation/behavior/GenericArmBehavior.ts index 6e5a0b7c0c..b2d50d8064 100644 --- a/fission/src/systems/simulation/behavior/GenericArmBehavior.ts +++ b/fission/src/systems/simulation/behavior/GenericArmBehavior.ts @@ -1,37 +1,46 @@ -import HingeDriver from "../driver/HingeDriver"; -import HingeStimulus from "../stimulus/HingeStimulus"; -import Behavior from "./Behavior"; -import InputSystem, { emptyModifierState } from "@/systems/input/InputSystem"; +import HingeDriver from "../driver/HingeDriver" +import HingeStimulus from "../stimulus/HingeStimulus" +import Behavior from "./Behavior" +import InputSystem, { emptyModifierState } from "@/systems/input/InputSystem" class GenericArmBehavior extends Behavior { - private _hingeDriver: HingeDriver; + private _hingeDriver: HingeDriver - private _positiveInput: string; - private _negativeInput: string; - - private _rotationalSpeed = 30; + private _positiveInput: string + private _negativeInput: string + + private _rotationalSpeed = 30 constructor(hingeDriver: HingeDriver, hingeStimulus: HingeStimulus, jointIndex: number) { - super([hingeDriver], [hingeStimulus]); - this._hingeDriver = hingeDriver; + super([hingeDriver], [hingeStimulus]) + this._hingeDriver = hingeDriver - this._positiveInput = "joint " + jointIndex + " Positive"; - this._negativeInput = "joint " + jointIndex + " Negative"; + this._positiveInput = "joint " + jointIndex + " Positive" + this._negativeInput = "joint " + jointIndex + " Negative" // TODO: load inputs from mira - InputSystem.allInputs[this._positiveInput] = { name: this._positiveInput, keyCode: "Digit" + jointIndex.toString(), isGlobal: false, modifiers: emptyModifierState }; - InputSystem.allInputs[this._negativeInput] = { name: this._negativeInput, keyCode: "Digit" + jointIndex.toString(), isGlobal: false, - modifiers: { ctrl: false, alt: false, shift: true, meta: false } }; + InputSystem.allInputs[this._positiveInput] = { + name: this._positiveInput, + keyCode: "Digit" + jointIndex.toString(), + isGlobal: false, + modifiers: emptyModifierState, + } + InputSystem.allInputs[this._negativeInput] = { + name: this._negativeInput, + keyCode: "Digit" + jointIndex.toString(), + isGlobal: false, + modifiers: { ctrl: false, alt: false, shift: true, meta: false }, + } } // Sets the arms target rotational velocity rotateArm(rotationalVelocity: number) { - this._hingeDriver.targetVelocity = rotationalVelocity; + this._hingeDriver.targetVelocity = rotationalVelocity } public Update(_: number): void { - this.rotateArm(InputSystem.GetAxis(this._positiveInput, this._negativeInput)*this._rotationalSpeed); + this.rotateArm(InputSystem.GetAxis(this._positiveInput, this._negativeInput) * this._rotationalSpeed) } } -export default GenericArmBehavior; \ No newline at end of file +export default GenericArmBehavior diff --git a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts b/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts index 1190cff16a..0d9ce8de79 100644 --- a/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts +++ b/fission/src/systems/simulation/behavior/GenericElevatorBehavior.ts @@ -1,37 +1,46 @@ -import SliderDriver from "../driver/SliderDriver"; -import SliderStimulus from "../stimulus/SliderStimulus"; -import Behavior from "./Behavior"; -import InputSystem, { emptyModifierState } from "@/systems/input/InputSystem"; +import SliderDriver from "../driver/SliderDriver" +import SliderStimulus from "../stimulus/SliderStimulus" +import Behavior from "./Behavior" +import InputSystem, { emptyModifierState } from "@/systems/input/InputSystem" class GenericElevatorBehavior extends Behavior { - private _sliderDriver: SliderDriver; + private _sliderDriver: SliderDriver - private _positiveInput: string; - private _negativeInput: string; + private _positiveInput: string + private _negativeInput: string - private _linearSpeed = 1; + private _linearSpeed = 1 constructor(sliderDriver: SliderDriver, sliderStimulus: SliderStimulus, jointIndex: number) { - super([sliderDriver], [sliderStimulus]); - this._sliderDriver = sliderDriver; + super([sliderDriver], [sliderStimulus]) + this._sliderDriver = sliderDriver - this._positiveInput = "joint " + jointIndex + " Positive"; - this._negativeInput = "joint " + jointIndex + " Negative"; + this._positiveInput = "joint " + jointIndex + " Positive" + this._negativeInput = "joint " + jointIndex + " Negative" // TODO: load inputs from mira - InputSystem.allInputs[this._positiveInput] = { name: this._positiveInput, keyCode: "Digit" + jointIndex.toString(), isGlobal: false, modifiers: emptyModifierState }; - InputSystem.allInputs[this._negativeInput] = { name: this._negativeInput, keyCode: "Digit" + jointIndex.toString(), isGlobal: false, - modifiers: { ctrl: false, alt: false, shift: true, meta: false } }; + InputSystem.allInputs[this._positiveInput] = { + name: this._positiveInput, + keyCode: "Digit" + jointIndex.toString(), + isGlobal: false, + modifiers: emptyModifierState, + } + InputSystem.allInputs[this._negativeInput] = { + name: this._negativeInput, + keyCode: "Digit" + jointIndex.toString(), + isGlobal: false, + modifiers: { ctrl: false, alt: false, shift: true, meta: false }, + } } // Changes the elevators target position moveElevator(positionDelta: number) { - this._sliderDriver.targetPosition += positionDelta; + this._sliderDriver.targetPosition += positionDelta } public Update(deltaT: number): void { - this.moveElevator(InputSystem.GetAxis(this._positiveInput, this._negativeInput)*this._linearSpeed*deltaT); + this.moveElevator(InputSystem.GetAxis(this._positiveInput, this._negativeInput) * this._linearSpeed * deltaT) } } -export default GenericElevatorBehavior; \ No newline at end of file +export default GenericElevatorBehavior diff --git a/fission/src/systems/simulation/driver/SliderDriver.ts b/fission/src/systems/simulation/driver/SliderDriver.ts index 5cd0282524..050a41c925 100644 --- a/fission/src/systems/simulation/driver/SliderDriver.ts +++ b/fission/src/systems/simulation/driver/SliderDriver.ts @@ -1,8 +1,8 @@ -import Jolt from "@barclah/jolt-physics"; -import Driver from "./Driver"; -import { SIMULATION_PERIOD } from "@/systems/physics/PhysicsSystem"; -import JOLT from "@/util/loading/JoltSyncLoader"; -import InputSystem from "@/systems/input/InputSystem"; +import Jolt from "@barclah/jolt-physics" +import Driver from "./Driver" +import { SIMULATION_PERIOD } from "@/systems/physics/PhysicsSystem" +import JOLT from "@/util/loading/JoltSyncLoader" +import InputSystem from "@/systems/input/InputSystem" class SliderDriver extends Driver { private _constraint: Jolt.SliderConstraint @@ -47,8 +47,9 @@ class SliderDriver extends Driver { } public Update(_: number): void { - this._targetPosition += ((InputSystem.getInput("sliderUp") ? 1 : 0) - (InputSystem.getInput("sliderDown") ? 1 : 0))*3; - this._constraint.SetTargetPosition(this._targetPosition); + this._targetPosition += + ((InputSystem.getInput("sliderUp") ? 1 : 0) - (InputSystem.getInput("sliderDown") ? 1 : 0)) * 3 + this._constraint.SetTargetPosition(this._targetPosition) } } diff --git a/fission/src/systems/simulation/driver/WheelDriver.ts b/fission/src/systems/simulation/driver/WheelDriver.ts index 5758e357ba..8de5244adf 100644 --- a/fission/src/systems/simulation/driver/WheelDriver.ts +++ b/fission/src/systems/simulation/driver/WheelDriver.ts @@ -15,17 +15,19 @@ class WheelDriver extends Driver { this._targetWheelSpeed = radsPerSec } - public get constraint(): Jolt.VehicleConstraint { return this._constraint } + public get constraint(): Jolt.VehicleConstraint { + return this._constraint + } public constructor(constraint: Jolt.VehicleConstraint) { super() - this._constraint = constraint; - this._wheel = JOLT.castObject(this._constraint.GetWheel(0), JOLT.WheelWV); + this._constraint = constraint + this._wheel = JOLT.castObject(this._constraint.GetWheel(0), JOLT.WheelWV) } - public Update(_: number): void { - this._wheel.SetAngularVelocity(this._targetWheelSpeed); + public Update(_: number): void { + this._wheel.SetAngularVelocity(this._targetWheelSpeed) } } diff --git a/fission/src/systems/simulation/stimulus/WheelStimulus.ts b/fission/src/systems/simulation/stimulus/WheelStimulus.ts index 27426933bd..cfb6206085 100644 --- a/fission/src/systems/simulation/stimulus/WheelStimulus.ts +++ b/fission/src/systems/simulation/stimulus/WheelStimulus.ts @@ -36,7 +36,7 @@ class WheelRotationStimulus extends EncoderStimulus { public Update(deltaT: number): void { if (this._accum) { - this._wheelRotationAccum += this._wheel.GetAngularVelocity() * deltaT; + this._wheelRotationAccum += this._wheel.GetAngularVelocity() * deltaT } } diff --git a/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts b/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts index 7ce89ec572..cbce7c4b61 100644 --- a/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts +++ b/fission/src/systems/simulation/synthesis_brain/SynthesisBrain.ts @@ -1,49 +1,48 @@ -import Mechanism from "@/systems/physics/Mechanism"; -import Brain from "../Brain"; -import Behavior from "../behavior/Behavior"; -import World from "@/systems/World"; -import WheelDriver from "../driver/WheelDriver"; -import WheelRotationStimulus from "../stimulus/WheelStimulus"; -import ArcadeDriveBehavior from "../behavior/ArcadeDriveBehavior"; -import { SimulationLayer } from "../SimulationSystem"; -import Jolt from "@barclah/jolt-physics"; -import JOLT from "@/util/loading/JoltSyncLoader"; -import HingeDriver from "../driver/HingeDriver"; -import HingeStimulus from "../stimulus/HingeStimulus"; -import GenericArmBehavior from "../behavior/GenericArmBehavior"; -import SliderDriver from "../driver/SliderDriver"; -import SliderStimulus from "../stimulus/SliderStimulus"; -import GenericElevatorBehavior from "../behavior/GenericElevatorBehavior"; - +import Mechanism from "@/systems/physics/Mechanism" +import Brain from "../Brain" +import Behavior from "../behavior/Behavior" +import World from "@/systems/World" +import WheelDriver from "../driver/WheelDriver" +import WheelRotationStimulus from "../stimulus/WheelStimulus" +import ArcadeDriveBehavior from "../behavior/ArcadeDriveBehavior" +import { SimulationLayer } from "../SimulationSystem" +import Jolt from "@barclah/jolt-physics" +import JOLT from "@/util/loading/JoltSyncLoader" +import HingeDriver from "../driver/HingeDriver" +import HingeStimulus from "../stimulus/HingeStimulus" +import GenericArmBehavior from "../behavior/GenericArmBehavior" +import SliderDriver from "../driver/SliderDriver" +import SliderStimulus from "../stimulus/SliderStimulus" +import GenericElevatorBehavior from "../behavior/GenericElevatorBehavior" class SynthesisBrain extends Brain { - private _behaviors: Behavior[] = []; - private _simLayer: SimulationLayer; + private _behaviors: Behavior[] = [] + private _simLayer: SimulationLayer - _leftWheelIndices: number[] = []; + _leftWheelIndices: number[] = [] // Tracks how many joins have been made for unique controls - _currentJointIndex = 1; + _currentJointIndex = 1 public constructor(mechanism: Mechanism) { - super(mechanism); + super(mechanism) - this._simLayer = World.SimulationSystem.GetSimulationLayer(mechanism)!; + this._simLayer = World.SimulationSystem.GetSimulationLayer(mechanism)! - if (!this._simLayer) { - console.log("SimulationLayer is undefined"); - return; + if (!this._simLayer) { + console.log("SimulationLayer is undefined") + return } - this.ConfigureArcadeDriveBehavior(); - this.ConfigureArmBehaviors(); - this.ConfigureElevatorBehaviors(); + this.ConfigureArcadeDriveBehavior() + this.ConfigureArmBehaviors() + this.ConfigureElevatorBehaviors() } - public Enable(): void { } + public Enable(): void {} - public Update(deltaT: number): void { - this._behaviors.forEach((b) => b.Update(deltaT)); + public Update(deltaT: number): void { + this._behaviors.forEach(b => b.Update(deltaT)) } public Disable(): void { @@ -52,59 +51,76 @@ class SynthesisBrain extends Brain { // Creates an instance of ArcadeDriveBehavior and automatically configures it public ConfigureArcadeDriveBehavior() { - const wheelDrivers: WheelDriver[] = this._simLayer.drivers.filter((driver) => driver instanceof WheelDriver) as WheelDriver[]; - const wheelStimuli: WheelRotationStimulus[] = this._simLayer.stimuli.filter((stimulus) => stimulus instanceof WheelRotationStimulus) as WheelRotationStimulus[]; + const wheelDrivers: WheelDriver[] = this._simLayer.drivers.filter( + driver => driver instanceof WheelDriver + ) as WheelDriver[] + const wheelStimuli: WheelRotationStimulus[] = this._simLayer.stimuli.filter( + stimulus => stimulus instanceof WheelRotationStimulus + ) as WheelRotationStimulus[] // Two body constraints are part of wheels and are used to determine which way a wheel is facing - const fixedConstraints: Jolt.TwoBodyConstraint[] = this._mechanism.constraints.filter((mechConstraint) => mechConstraint.constraint instanceof JOLT.TwoBodyConstraint).map((mechConstraint) => mechConstraint.constraint as Jolt.TwoBodyConstraint); + const fixedConstraints: Jolt.TwoBodyConstraint[] = this._mechanism.constraints + .filter(mechConstraint => mechConstraint.constraint instanceof JOLT.TwoBodyConstraint) + .map(mechConstraint => mechConstraint.constraint as Jolt.TwoBodyConstraint) - const leftWheels: WheelDriver[] = []; - const leftStimuli: WheelRotationStimulus[] = []; + const leftWheels: WheelDriver[] = [] + const leftStimuli: WheelRotationStimulus[] = [] - const rightWheels: WheelDriver[] = []; - const rightStimuli: WheelRotationStimulus[] = []; + const rightWheels: WheelDriver[] = [] + const rightStimuli: WheelRotationStimulus[] = [] // Determines which wheels and stimuli belong to which side of the robot for (let i = 0; i < wheelDrivers.length; i++) { - const wheelPos = fixedConstraints[i].GetConstraintToBody1Matrix().GetTranslation(); + const wheelPos = fixedConstraints[i].GetConstraintToBody1Matrix().GetTranslation() - const robotCOM = World.PhysicsSystem.GetBody(this._mechanism.constraints[0].childBody).GetCenterOfMassPosition() as Jolt.Vec3; - const rightVector = new JOLT.Vec3(1, 0, 0); + const robotCOM = World.PhysicsSystem.GetBody( + this._mechanism.constraints[0].childBody + ).GetCenterOfMassPosition() as Jolt.Vec3 + const rightVector = new JOLT.Vec3(1, 0, 0) const dotProduct = rightVector.Dot(wheelPos.Sub(robotCOM)) if (dotProduct < 0) { - rightWheels.push(wheelDrivers[i]); - rightStimuli.push(wheelStimuli[i]); - } - else { - leftWheels.push(wheelDrivers[i]); - leftStimuli.push(wheelStimuli[i]); + rightWheels.push(wheelDrivers[i]) + rightStimuli.push(wheelStimuli[i]) + } else { + leftWheels.push(wheelDrivers[i]) + leftStimuli.push(wheelStimuli[i]) } } - this._behaviors.push(new ArcadeDriveBehavior(leftWheels, rightWheels, leftStimuli, rightStimuli)); + this._behaviors.push(new ArcadeDriveBehavior(leftWheels, rightWheels, leftStimuli, rightStimuli)) } // Creates instances of ArmBehavior and automatically configures them public ConfigureArmBehaviors() { - const hingeDrivers: HingeDriver[] = this._simLayer.drivers.filter((driver) => driver instanceof HingeDriver) as HingeDriver[]; - const hingeStimuli: HingeStimulus[] = this._simLayer.stimuli.filter((stimulus) => stimulus instanceof HingeStimulus) as HingeStimulus[]; + const hingeDrivers: HingeDriver[] = this._simLayer.drivers.filter( + driver => driver instanceof HingeDriver + ) as HingeDriver[] + const hingeStimuli: HingeStimulus[] = this._simLayer.stimuli.filter( + stimulus => stimulus instanceof HingeStimulus + ) as HingeStimulus[] for (let i = 0; i < hingeDrivers.length; i++) { - this._behaviors.push(new GenericArmBehavior(hingeDrivers[i], hingeStimuli[i], this._currentJointIndex)); - this._currentJointIndex++; + this._behaviors.push(new GenericArmBehavior(hingeDrivers[i], hingeStimuli[i], this._currentJointIndex)) + this._currentJointIndex++ } } // Creates instances of ElevatorBehavior and automatically configures them public ConfigureElevatorBehaviors() { - const sliderDrivers: SliderDriver[] = this._simLayer.drivers.filter((driver) => driver instanceof SliderDriver) as SliderDriver[]; - const sliderStimuli: SliderStimulus[] = this._simLayer.stimuli.filter((stimulus) => stimulus instanceof SliderStimulus) as SliderStimulus[]; + const sliderDrivers: SliderDriver[] = this._simLayer.drivers.filter( + driver => driver instanceof SliderDriver + ) as SliderDriver[] + const sliderStimuli: SliderStimulus[] = this._simLayer.stimuli.filter( + stimulus => stimulus instanceof SliderStimulus + ) as SliderStimulus[] for (let i = 0; i < sliderDrivers.length; i++) { - this._behaviors.push(new GenericElevatorBehavior(sliderDrivers[i], sliderStimuli[i], this._currentJointIndex)); - this._currentJointIndex++; + this._behaviors.push( + new GenericElevatorBehavior(sliderDrivers[i], sliderStimuli[i], this._currentJointIndex) + ) + this._currentJointIndex++ } } } diff --git a/fission/src/ui/ToastContext.tsx b/fission/src/ui/ToastContext.tsx index 2730f7001f..a6ee866b88 100644 --- a/fission/src/ui/ToastContext.tsx +++ b/fission/src/ui/ToastContext.tsx @@ -1,10 +1,4 @@ -import React, { - createContext, - useState, - useContext, - useCallback, - ReactNode, -} from "react" +import React, { createContext, useState, useContext, useCallback, ReactNode } from "react" import Toast from "@/components/Toast" import { AnimatePresence, motion } from "framer-motion" diff --git a/fission/src/ui/components/Dropdown.tsx b/fission/src/ui/components/Dropdown.tsx index ab26a92236..05b684d4a0 100644 --- a/fission/src/ui/components/Dropdown.tsx +++ b/fission/src/ui/components/Dropdown.tsx @@ -39,9 +39,10 @@ const Dropdown: React.FC = ({ label, options, onSelect }) => {