Skip to content

Commit

Permalink
Scoring Zones Configuration (#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
HunterBarclay authored Jul 17, 2024
2 parents 5fa5cad + 067baf3 commit 502303c
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 281 deletions.
9 changes: 6 additions & 3 deletions fission/src/Synthesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import SpawnLocationsPanel from "@/panels/SpawnLocationPanel"
import ConfigureGamepiecePickupPanel from "@/panels/configuring/ConfigureGamepiecePickupPanel"
import ConfigureShotTrajectoryPanel from "@/panels/configuring/ConfigureShotTrajectoryPanel"
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 PokerPanel from "@/panels/PokerPanel.tsx"
Expand All @@ -59,6 +58,7 @@ import ImportMirabufPanel from "@/ui/panels/mirabuf/ImportMirabufPanel.tsx"
import Skybox from "./ui/components/Skybox.tsx"
import ConfigureRobotModal from "./ui/modals/configuring/ConfigureRobotModal.tsx"
import ResetAllInputsModal from "./ui/modals/configuring/ResetAllInputsModal.tsx"
import ZoneConfigPanel from "./ui/panels/configuring/scoring/ZoneConfigPanel.tsx"

const DEFAULT_MIRA_PATH = "/api/mira/Robots/Team 2471 (2018)_v7.mira"

Expand Down Expand Up @@ -167,6 +167,7 @@ function Synthesis() {
closePanel={(id: string) => {
closePanel(id)
}}
closeAllPanels={closeAllPanels}
>
<ToastProvider key="toast-provider">
<Scene useStats={true} key="scene-in-toast-provider" />
Expand Down Expand Up @@ -216,6 +217,8 @@ const initialModals = [
<ManageAssembliesModal key="manage-assemblies" modalId="manage-assemblies" />,
<ImportLocalMirabufModal key="import-local-mirabuf" modalId="import-local-mirabuf" />,
<ConfigureRobotModal key="config-robot" modalId="config-robot" />,
<ScoringZonesPanel panelId="scoring-zones" openLocation="right" />,
<ZoneConfigPanel panelId="zone-config" openLocation="right" />,
<ResetAllInputsModal key="reset-inputs" modalId="reset-inputs" />,
]

Expand All @@ -236,8 +239,8 @@ const initialPanels: ReactElement[] = [
openLocation="right"
sidePadding={8}
/>,
<ScoringZonesPanel key="scoring-zones" panelId="scoring-zones" />,
<ZoneConfigPanel key="zone-config" panelId="zone-config" />,
<ScoringZonesPanel key="scoring-zones" panelId="scoring-zones" openLocation="right" sidePadding={8} />,
<ZoneConfigPanel key="zone-config" panelId="zone-config" openLocation="right" sidePadding={8} />,
<ImportMirabufPanel key="import-mirabuf" panelId="import-mirabuf" />,
<PokerPanel key="poker" panelId="poker" />,
]
Expand Down
10 changes: 9 additions & 1 deletion fission/src/mirabuf/MirabufSceneObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Mechanism from "@/systems/physics/Mechanism"
import SynthesisBrain from "@/systems/simulation/synthesis_brain/SynthesisBrain"
import InputSystem from "@/systems/input/InputSystem"
import TransformGizmos from "@/ui/components/TransformGizmos"
import { EjectorPreferences, IntakePreferences } from "@/systems/preferences/PreferenceTypes"
import { EjectorPreferences, FieldPreferences, IntakePreferences } from "@/systems/preferences/PreferenceTypes"
import PreferencesSystem from "@/systems/preferences/PreferencesSystem"
import { MiraType } from "./MirabufLoader"
import IntakeSensorSceneObject from "./IntakeSensorSceneObject"
Expand All @@ -39,6 +39,8 @@ class MirabufSceneObject extends SceneObject {
private _intakePreferences: IntakePreferences | undefined
private _ejectorPreferences: EjectorPreferences | undefined

private _fieldPreferences: FieldPreferences | undefined

private _intakeSensor?: IntakeSensorSceneObject
private _ejectable?: EjectableSceneObject

Expand All @@ -62,6 +64,10 @@ class MirabufSceneObject extends SceneObject {
return this._ejectorPreferences
}

get fieldPreferences() {
return this._fieldPreferences
}

public get activeEjectable(): Jolt.BodyID | undefined {
return this._ejectable?.gamePieceBodyId
}
Expand Down Expand Up @@ -339,6 +345,8 @@ class MirabufSceneObject extends SceneObject {
private getPreferences(): void {
this._intakePreferences = PreferencesSystem.getRobotPreferences(this.assemblyName)?.intake
this._ejectorPreferences = PreferencesSystem.getRobotPreferences(this.assemblyName)?.ejector

this._fieldPreferences = PreferencesSystem.getFieldPreferences(this.assemblyName)
}

private EnablePhysics() {
Expand Down
12 changes: 6 additions & 6 deletions fission/src/systems/preferences/PreferenceTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Vector3Tuple, Vector4Tuple } from "three"
import { Vector3Tuple } from "three"
import { InputScheme } from "../input/DefaultInputs"

export type GlobalPreference =
Expand Down Expand Up @@ -43,18 +43,18 @@ export type RobotPreferences = {
ejector: EjectorPreferences
}

export type Alliance = "Blue" | "Red"
export type Alliance = "red" | "blue"

export type ScoringZonePreferences = {
name: string
alliance: Alliance
parent: string
parentNode: string | undefined
points: number
destroyGamepiece: boolean
persistentPoints: boolean
localPosition: Vector3Tuple
localRotation: Vector4Tuple
localScale: Vector3Tuple

deltaTransformation: number[]
//scale: [number, number, number]
}

export type FieldPreferences = {
Expand Down
3 changes: 1 addition & 2 deletions fission/src/systems/preferences/PreferencesSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class PreferencesSystem {

/** Gets preferences for every robot in local storage */
public static getAllFieldPreferences(): { [key: string]: FieldPreferences } {
let allFieldPrefs = this.getPreference<{ [key: string]: FieldPreferences }>(RobotPreferencesKey)
let allFieldPrefs = this.getPreference<{ [key: string]: FieldPreferences }>(FieldPreferencesKey)

if (allFieldPrefs == undefined) {
allFieldPrefs = {}
Expand All @@ -110,7 +110,6 @@ class PreferencesSystem {
const loadedPrefs = window.localStorage.getItem(this._localStorageKey)

if (loadedPrefs == undefined) {
console.log("Preferences not found in local storage!")
this._preferences = {}
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class SynthesisBrain extends Brain {
// The total number of robots spawned
private static _currentRobotIndex: number = 0

// A list of all the fields spawned
public static fieldsSpawned: string[] = []

public constructor(mechanism: Mechanism, assemblyName: string) {
super(mechanism)

Expand All @@ -63,6 +66,7 @@ class SynthesisBrain extends Brain {
this.configureInputs()
} else {
this.configureField()
SynthesisBrain.fieldsSpawned.push(assemblyName)
}

SynthesisBrain._currentRobotIndex++
Expand Down Expand Up @@ -219,10 +223,9 @@ class SynthesisBrain extends Brain {
}

private configureField() {
const fieldPrefs = PreferencesSystem.getFieldPreferences(this._assemblyName)
console.log("Loaded field prefs " + fieldPrefs)
PreferencesSystem.getFieldPreferences(this._assemblyName)

/** Put any scoring zone or other field configuration here */
/** Put any field configuration here */
}

private getNumberedAssemblyName(): string {
Expand Down
1 change: 1 addition & 0 deletions fission/src/ui/PanelContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { createContext, useState, useEffect, useCallback, useContext, Rea
type PanelControlContextType = {
openPanel: (panelId: string) => void
closePanel: (panelId: string) => void
closeAllPanels: () => void
children?: ReactNode
}

Expand Down
2 changes: 1 addition & 1 deletion fission/src/ui/components/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type CheckboxProps = {
const Checkbox: React.FC<CheckboxProps> = ({ label, className, defaultState, stateOverride, onClick }) => {
const [state] = useState(defaultState)
return (
<Stack direction={StackDirection.Horizontal}>
<Stack direction={StackDirection.Horizontal} className="items-center">
<Label size={LabelSize.Medium} className={`mr-8 ${className} whitespace-nowrap`}>
{label}
</Label>
Expand Down
9 changes: 8 additions & 1 deletion fission/src/ui/components/MainHUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BiMenuAltLeft } from "react-icons/bi"
import { GrFormClose } from "react-icons/gr"
import { GiSteeringWheel } from "react-icons/gi"
import { HiDownload } from "react-icons/hi"
import { IoBug, IoGameControllerOutline, IoPeople, IoRefresh, IoTimer } from "react-icons/io5"
import { IoBasketball, IoBug, IoGameControllerOutline, IoPeople, IoRefresh, IoTimer } from "react-icons/io5"
import { useModalControlContext } from "@/ui/ModalContext"
import { usePanelControlContext } from "@/ui/PanelContext"
import { motion } from "framer-motion"
Expand Down Expand Up @@ -172,6 +172,13 @@ const MainHUD: React.FC = () => {
icon={<GiSteeringWheel />}
onClick={() => MirabufCachingService.RemoveAll()}
/>
<MainHUDButton
value={"Edit Scoring Zones"}
icon={<IoBasketball />}
onClick={() => {
openPanel("scoring-zones")
}}
/>
<MainHUDButton value={"Drivetrain"} icon={<FaCar />} onClick={() => openModal("drivetrain")} />
<MainHUDButton
value={"Toasts"}
Expand Down
8 changes: 1 addition & 7 deletions fission/src/ui/components/SelectButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@ function SelectNode(e: MouseEvent) {

const res = World.PhysicsSystem.RayCast(ThreeVector3_JoltVec3(origin), ThreeVector3_JoltVec3(dir))

if (res) {
const body = World.PhysicsSystem.GetBody(res.data.mBodyID)
if (!body.IsDynamic()) {
return null
}
return body
}
if (res) return World.PhysicsSystem.GetBody(res.data.mBodyID)

return null
}
Expand Down
14 changes: 13 additions & 1 deletion fission/src/ui/components/TransformGizmos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { ThreeMatrix4_JoltMat44, ThreeQuaternion_JoltQuat } from "@/util/TypeCon
import MirabufSceneObject from "@/mirabuf/MirabufSceneObject"
import { RigidNodeReadOnly } from "@/mirabuf/MirabufParser"

export type GizmoTransformMode = "translate" | "rotate" | "scale"

class TransformGizmos {
private _mesh: THREE.Mesh
private _gizmos: TransformControls[] = []
Expand Down Expand Up @@ -38,7 +40,7 @@ class TransformGizmos {
*
* @param mode The type of gizmo to create
*/
public CreateGizmo(mode: "translate" | "rotate" | "scale", size: number = 1.5) {
public CreateGizmo(mode: GizmoTransformMode, size: number = 1.5) {
const gizmo = World.SceneRenderer.AddTransformGizmo(this._mesh, mode, size)
this._gizmos.push(gizmo)
}
Expand All @@ -51,6 +53,16 @@ class TransformGizmos {
World.SceneRenderer.RemoveObject(this._mesh)
}

/**
* Removes active gizmos and creates a new one
*
* @param mode The type of gizmo to create
*/
public SwitchGizmo(mode: GizmoTransformMode, size: number = 1.5) {
World.SceneRenderer.RemoveTransformGizmos(this._mesh)
this.CreateGizmo(mode, size)
}

/**
* Updates the position and rotation of the gizmos to match the mesh's position
*
Expand Down
4 changes: 2 additions & 2 deletions fission/src/ui/modals/configuring/ChangeInputsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect, useState } from "react"
import Modal, { ModalPropsImpl } from "@/components/Modal"
import { FaGamepad } from "react-icons/fa6"
import Stack, { StackDirection } from "../../components/Stack"
import Label, { LabelSize } from "../../components/Label"
import Stack, { StackDirection } from "@/ui/components/Stack"
import Label, { LabelSize } from "@/ui/components/Label"
import LabeledButton, { LabelPlacement } from "../../components/LabeledButton"
import InputSystem, { AxisInput, ButtonInput, ModifierState, EmptyModifierState } from "@/systems/input/InputSystem"
import Dropdown from "@/ui/components/Dropdown"
Expand Down
Loading

0 comments on commit 502303c

Please sign in to comment.