Skip to content

Commit

Permalink
fix(vite-server)!: Vite server working with Chrome.
Browse files Browse the repository at this point in the history
Removed circular dependencies and isolated key structures into separate
files. Cleanup still needed.
  • Loading branch information
HunterBarclay committed Aug 30, 2024
1 parent e6617c5 commit d83d091
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { useModalControlContext } from "@/ui/ModalContext"
import { usePanelControlContext } from "@/ui/PanelContext"
import { Box } from "@mui/material"
import { useEffect, useReducer } from "react"
import { ConfigurationType, setSelectedConfigurationType } from "./assembly-config/ConfigurePanel"
import { setSelectedScheme } from "./assembly-config/interfaces/inputs/ConfigureInputsInterface"
import { ConfigurationType, setSelectedConfigurationType } from "./assembly-config/ConfigurationType"

/** We store the selected brain index globally to specify which robot the input scheme should be bound to. */
let selectedBrainIndexGlobal: number | undefined = undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** An event to save whatever configuration interface is open when it is closed */
export class ConfigurationSavedEvent extends Event {
public constructor() {
super("ConfigurationSaved")

window.dispatchEvent(this)
}

public static Listen(func: (e: Event) => void) {
window.addEventListener("ConfigurationSaved", func)
}

public static RemoveListener(func: (e: Event) => void) {
window.removeEventListener("ConfigurationSaved", func)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// eslint-disable-next-line react-refresh/only-export-components
export enum ConfigurationType {
ROBOT,
FIELD,
INPUTS,
}

let selectedConfigurationType: ConfigurationType = ConfigurationType.ROBOT
// eslint-disable-next-line react-refresh/only-export-components
export function setSelectedConfigurationType(type: ConfigurationType) {
selectedConfigurationType = type
}

export function getConfigurationType() {
return selectedConfigurationType
}
114 changes: 41 additions & 73 deletions fission/src/ui/panels/configuring/assembly-config/ConfigurePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import Panel, { PanelPropsImpl } from "@/ui/components/Panel"
import SelectMenu, { SelectMenuOption } from "@/ui/components/SelectMenu"
import { ToggleButton, ToggleButtonGroup } from "@/ui/components/ToggleButtonGroup"
import { useEffect, useMemo, useReducer, useState } from "react"
// import ConfigureScoringZonesInterface from "./interfaces/scoring/ConfigureScoringZonesInterface"
// import ChangeInputsInterface from "./interfaces/inputs/ConfigureInputsInterface"
import ConfigureScoringZonesInterface from "./interfaces/scoring/ConfigureScoringZonesInterface"
import ChangeInputsInterface from "./interfaces/inputs/ConfigureInputsInterface"
import InputSystem from "@/systems/input/InputSystem"
import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain"
import { usePanelControlContext } from "@/ui/PanelContext"
import Button from "@/ui/components/Button"
// import { setSelectedBrainIndexGlobal } from "../ChooseInputSchemePanel"
// import ConfigureSchemeInterface from "./interfaces/inputs/ConfigureSchemeInterface"
import { setSelectedBrainIndexGlobal } from "../ChooseInputSchemePanel"
import ConfigureSchemeInterface from "./interfaces/inputs/ConfigureSchemeInterface"
import { SynthesisIcons } from "@/ui/components/StyledComponents"
// import ConfigureSubsystemsInterface from "./interfaces/ConfigureSubsystemsInterface"
// import SequentialBehaviorsInterface from "./interfaces/SequentialBehaviorsInterface"
// import ConfigureShotTrajectoryInterface from "./interfaces/ConfigureShotTrajectoryInterface"
import ConfigureSubsystemsInterface from "./interfaces/ConfigureSubsystemsInterface"
import SequentialBehaviorsInterface from "./interfaces/SequentialBehaviorsInterface"
import ConfigureShotTrajectoryInterface from "./interfaces/ConfigureShotTrajectoryInterface"
import ConfigureGamepiecePickupInterface from "./interfaces/ConfigureGamepiecePickupInterface"
import { ConfigurationSavedEvent } from "./ConfigurationSavedEvent"
import { ConfigurationType, getConfigurationType, setSelectedConfigurationType } from "./ConfigurationType"

enum ConfigMode {
SUBSYSTEMS,
Expand All @@ -29,23 +31,6 @@ enum ConfigMode {
SCORING_ZONES,
}

// eslint-disable-next-line react-refresh/only-export-components
export enum ConfigurationType {
ROBOT,
FIELD,
INPUTS,
}

let selectedConfigurationType: ConfigurationType = ConfigurationType.ROBOT
// eslint-disable-next-line react-refresh/only-export-components
export function setSelectedConfigurationType(type: ConfigurationType) {
selectedConfigurationType = type
}

function getConfigurationType() {
return selectedConfigurationType
}

/** Option for selecting a robot of field */
class AssemblySelectionOption extends SelectMenuOption {
assemblyObject: MirabufSceneObject
Expand Down Expand Up @@ -173,60 +158,43 @@ const ConfigInterface: React.FC<ConfigInterfaceProps> = ({ configMode, assembly,
switch (configMode) {
case ConfigMode.INTAKE:
return <ConfigureGamepiecePickupInterface selectedRobot={assembly} />
// case ConfigMode.EJECTOR:
// return <ConfigureShotTrajectoryInterface selectedRobot={assembly} />
// case ConfigMode.SUBSYSTEMS:
// return <ConfigureSubsystemsInterface selectedRobot={assembly} />
// case ConfigMode.CONTROLS: {
// const brainIndex = (assembly.brain as SynthesisBrain).brainIndex
// const scheme = InputSystem.brainIndexSchemeMap.get(brainIndex)
case ConfigMode.EJECTOR:
return <ConfigureShotTrajectoryInterface selectedRobot={assembly} />
case ConfigMode.SUBSYSTEMS:
return <ConfigureSubsystemsInterface selectedRobot={assembly} />
case ConfigMode.CONTROLS: {
const brainIndex = (assembly.brain as SynthesisBrain).brainIndex
const scheme = InputSystem.brainIndexSchemeMap.get(brainIndex)

// return (
// <>
// <Button
// value="Set Scheme"
// onClick={() => {
// setSelectedBrainIndexGlobal(brainIndex)
// openPanel("choose-scheme")
// }}
// />
// {scheme && <ConfigureSchemeInterface selectedScheme={scheme} />}
// </>
// )
// }
// case ConfigMode.SEQUENTIAL:
// return <SequentialBehaviorsInterface selectedRobot={assembly} />
// case ConfigMode.SCORING_ZONES: {
// const zones = assembly.fieldPreferences?.scoringZones
// if (zones == undefined) {
// console.error("Field does not contain scoring zone preferences!")
// return <Label>ERROR: Field does not contain scoring zone configuration!</Label>
// }
// return <ConfigureScoringZonesInterface selectedField={assembly} initialZones={zones} />
// }
return (
<>
<Button
value="Set Scheme"
onClick={() => {
setSelectedBrainIndexGlobal(brainIndex)
openPanel("choose-scheme")
}}
/>
{scheme && <ConfigureSchemeInterface selectedScheme={scheme} />}
</>
)
}
case ConfigMode.SEQUENTIAL:
return <SequentialBehaviorsInterface selectedRobot={assembly} />
case ConfigMode.SCORING_ZONES: {
const zones = assembly.fieldPreferences?.scoringZones
if (zones == undefined) {
console.error("Field does not contain scoring zone preferences!")
return <Label>ERROR: Field does not contain scoring zone configuration!</Label>
}
return <ConfigureScoringZonesInterface selectedField={assembly} initialZones={zones} />
}
default:
return <></>
// throw new Error(`Config mode ${configMode} has no associated interface`)
}
}

/** An event to save whatever configuration interface is open when it is closed */
export class ConfigurationSavedEvent extends Event {
public constructor() {
super("ConfigurationSaved")

window.dispatchEvent(this)
}

public static Listen(func: (e: Event) => void) {
window.addEventListener("ConfigurationSaved", func)
}

public static RemoveListener(func: (e: Event) => void) {
window.removeEventListener("ConfigurationSaved", func)
}
}

const ConfigurePanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
const { openPanel, closePanel } = usePanelControlContext()
const [configurationType, setConfigurationType] = useState<ConfigurationType>(getConfigurationType())
Expand Down Expand Up @@ -273,8 +241,8 @@ const ConfigurePanel: React.FC<PanelPropsImpl> = ({ panelId }) => {
<ToggleButton value={ConfigurationType.INPUTS}>Inputs</ToggleButton>
</ToggleButtonGroup>
{configurationType == ConfigurationType.INPUTS ? (
// <ChangeInputsInterface />
<></>
<ChangeInputsInterface />
// <></>
) : (
<>
{/** Select menu to pick a robot or field */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
ThreeMatrix4_Array,
} from "@/util/TypeConversions"
import { useTheme } from "@/ui/ThemeContext"
import { ConfigurationSavedEvent } from "../ConfigurePanel"
import Button from "@/ui/components/Button"
import { Spacer } from "@/ui/components/StyledComponents"
import { ConfigurationSavedEvent } from "../ConfigurationSavedEvent"

// slider constants
const MIN_ZONE_SIZE = 0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "@/util/TypeConversions"
import { useTheme } from "@/ui/ThemeContext"
import { RigidNodeId } from "@/mirabuf/MirabufParser"
import { ConfigurationSavedEvent } from "../ConfigurePanel"
import { ConfigurationSavedEvent } from "../ConfigurationSavedEvent"
import Button from "@/ui/components/Button"
import { Spacer } from "@/ui/components/StyledComponents"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import MirabufSceneObject from "@/mirabuf/MirabufSceneObject"
import SelectMenu, { SelectMenuOption } from "@/ui/components/SelectMenu"
import React, { useMemo, useState } from "react"
import { ConfigurationSavedEvent } from "../ConfigurePanel"
import { ConfigurationSavedEvent } from "../ConfigurationSavedEvent"
import World from "@/systems/World"
import SliderDriver from "@/systems/simulation/driver/SliderDriver"
import HingeDriver from "@/systems/simulation/driver/HingeDriver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
import SequenceableBehavior from "@/systems/simulation/behavior/synthesis/SequenceableBehavior"
import GenericArmBehavior from "@/systems/simulation/behavior/synthesis/GenericArmBehavior"
import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain"
import { ConfigurationSavedEvent } from "../ConfigurePanel"
import { ConfigurationSavedEvent } from "../ConfigurationSavedEvent"
import { SectionLabel, Spacer, SynthesisIcons } from "@/ui/components/StyledComponents"

/** Grey label for a child behavior name */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from "react"
import { ConfigurationSavedEvent } from "../../ConfigurePanel"
import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent"
import SelectMenu, { SelectMenuOption } from "@/ui/components/SelectMenu"
import InputSystem from "@/systems/input/InputSystem"
import InputSchemeManager, { InputScheme } from "@/systems/input/InputSchemeManager"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import InputSchemeManager, { InputScheme } from "@/systems/input/InputSchemeMana
import Checkbox from "@/ui/components/Checkbox"
import EditInputInterface from "./EditInputInterface"
import { useCallback, useEffect, useRef, useState } from "react"
import { ConfigurationSavedEvent } from "../../ConfigurePanel"
import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent"
import { SectionDivider } from "@/ui/components/StyledComponents"

interface ConfigSchemeProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
import { Box } from "@mui/material"
import { ButtonIcon, SectionDivider, SectionLabel, SynthesisIcons } from "@/ui/components/StyledComponents"
import { LabelSize } from "@/ui/components/Label"
import { ConfigurationSavedEvent } from "../../ConfigurePanel"
import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent"

const saveZones = (zones: ScoringZonePreferences[] | undefined, field: MirabufSceneObject | undefined) => {
if (!zones || !field) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
import World from "@/systems/World"
import MirabufSceneObject from "@/mirabuf/MirabufSceneObject"
import { Box } from "@mui/material"
import { ConfigurationSavedEvent } from "../../ConfigurePanel"
import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent"
import { AddButtonInteractiveColor, DeleteButton, EditButton } from "@/ui/components/StyledComponents"

const saveZones = (zones: ScoringZonePreferences[] | undefined, field: MirabufSceneObject | undefined) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ToggleButton, ToggleButtonGroup } from "@/ui/components/ToggleButtonGro
import { Alliance, ScoringZonePreferences } from "@/systems/preferences/PreferenceTypes"
import { RigidNodeId } from "@/mirabuf/MirabufParser"
import { DeltaFieldTransforms_PhysicalProp as DeltaFieldTransforms_VisualProperties } from "@/util/threejs/MeshCreation"
import { ConfigurationSavedEvent } from "../../ConfigurePanel"
import { ConfigurationSavedEvent } from "../../ConfigurationSavedEvent"

/**
* Saves ejector configuration to selected field.
Expand Down

0 comments on commit d83d091

Please sign in to comment.