Skip to content

Commit

Permalink
fix: Readd delete controls to buttons
Browse files Browse the repository at this point in the history
WIP!: Currently not working for removing input schemes from deleted
robots.
  • Loading branch information
HunterBarclay committed Oct 11, 2024
1 parent 306d807 commit 633d20d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
4 changes: 3 additions & 1 deletion fission/src/mirabuf/MirabufSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ class MirabufSceneObject extends SceneObject {
this._debugBodies?.clear()
this._physicsLayerReserve?.Release()

if (this._brain && this._brain instanceof SynthesisBrain) this._brain?.clearControls()
if (this._brain && this._brain instanceof SynthesisBrain) {
this._brain.clearControls()
}
}

public Eject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
import { DefaultSequentialConfig } from "@/systems/preferences/PreferenceTypes"
import InputSystem from "@/systems/input/InputSystem"
import MirabufSceneObject from "@/mirabuf/MirabufSceneObject"
import { Global_AddToast } from "@/ui/components/GlobalUIControls"

class SynthesisBrain extends Brain {
public static brainIndexMap = new Map<number, SynthesisBrain>()
Expand Down Expand Up @@ -94,7 +95,12 @@ class SynthesisBrain extends Brain {
}

public clearControls(): void {
InputSystem.brainIndexSchemeMap.delete(this._brainIndex)
if (InputSystem.brainIndexSchemeMap.delete(this._brainIndex)) {
Global_AddToast?.("info", "Controls", "Successfully cleared controls.")
} else {
Global_AddToast?.("warning", "Controls", "Failed to cleared controls.")
}

}

/** Creates an instance of ArcadeDriveBehavior and automatically configures it. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain"
import { SynthesisIcons } from "@/ui/components/StyledComponents"
import { useModalControlContext } from "@/ui/ModalContext"
import { usePanelControlContext } from "@/ui/PanelContext"
import { useEffect, useMemo } from "react"
import { useCallback, useEffect, useMemo } from "react"
import { ConfigurationType, setSelectedConfigurationType } from "../assembly-config/ConfigurationType"
import { setSelectedScheme } from "../assembly-config/interfaces/inputs/ConfigureInputsInterface"
import InputSchemeSelection from "./InputSchemeSelection"
Expand Down Expand Up @@ -56,6 +56,33 @@ const InitialConfigPanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [targetAssembly])

const closeFinish = useCallback(() => {
if (targetAssembly?.miraType == MiraType.ROBOT) {
const brainIndex = SynthesisBrain.GetBrainIndex(targetAssembly)

if (brainIndex == undefined) return

if (InputSystem.brainIndexSchemeMap.has(brainIndex)) return

const scheme = InputSchemeManager.availableInputSchemes[0]

InputSystem.brainIndexSchemeMap.set(brainIndex, scheme)

setSelectedConfigurationType(ConfigurationType.INPUTS)
setSelectedScheme(scheme)
}

closePanel(panelId)
}, [closePanel, panelId, targetAssembly])

const closeDelete = useCallback(() => {
if (targetAssembly) {
World.SceneRenderer.RemoveSceneObject(targetAssembly.id)
}

closePanel(panelId)
}, [closePanel, panelId, targetAssembly])

const brainIndex = useMemo(() => {
return SynthesisBrain.GetBrainIndex(targetAssembly)
}, [targetAssembly])
Expand All @@ -66,10 +93,13 @@ const InitialConfigPanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
panelId={panelId}
openLocation={"right"}
sidePadding={8}
acceptEnabled={false}
acceptEnabled={true}
acceptName="Finish"
onAccept={() => closeFinish()}
icon={SynthesisIcons.Gamepad}
cancelEnabled={true}
cancelName="Close"
cancelName="Delete"
onCancel={() => closeDelete()}
>
{/** A scroll view with buttons to select default and custom input schemes */}
<div className="flex overflow-y-auto flex-col gap-2 bg-background-secondary rounded-md p-2">
Expand All @@ -87,7 +117,7 @@ const InitialConfigPanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
{brainIndex != undefined ? (
<InputSchemeSelection
brainIndex={brainIndex}
onSelect={() => closePanel(panelId)}
onSelect={() => {}}
onEdit={() => openPanel("configure")}
onCreateNew={() => openModal("assign-new-scheme")}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function InputSchemeSelection({ brainIndex, onSelect, onEdit, onCreateNew }: Inp
{SelectButton(() => {
InputSystem.brainIndexSchemeMap.set(brainIndex, scheme)
onSelect?.()
update()
})}
{/** Edit button - same as select but opens the inputs modal */}
{EditButton(() => {
Expand Down

0 comments on commit 633d20d

Please sign in to comment.