Skip to content

Commit e365104

Browse files
Store Protected Zones in Devtools [AARD-2064] (#1276)
Co-authored-by: Zach Rutman <92497727+rutmanz@users.noreply.github.com>
2 parents 91a6e62 + e99d6d8 commit e365104

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

fission/src/Window.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ declare interface Window {
22
convertAuthToken(code: string): void
33
gtag?: (command: "config" | "set" | "get" | "event" | "consent", ...args: unknown[]) => void
44
dataLayer?: unknown[][]
5+
World?: unknown
56
}

fission/src/mirabuf/FieldMiraEditor.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import type MirabufSceneObject from "@/mirabuf/MirabufSceneObject.ts"
2+
import { ContactType } from "@/mirabuf/ZoneTypes.ts"
23
import { mirabuf } from "@/proto/mirabuf"
4+
import { MatchModeType } from "@/systems/match_mode/MatchModeTypes.ts"
35
import {
46
defaultFieldPreferences,
57
type FieldPreferences,
8+
type ProtectedZonePreferences,
69
type ScoringZonePreferences,
710
} from "@/systems/preferences/PreferenceTypes"
811

912
export interface DevtoolMiraData {
1013
"devtool:scoring_zones": ScoringZonePreferences[]
11-
"devtool:camera_locations": unknown
14+
"devtool:protected_zones": ProtectedZonePreferences[]
1215
"devtool:spawn_locations": FieldPreferences["spawnLocations"]
1316
"devtool:a": unknown
1417
"devtool:b": unknown
@@ -50,6 +53,40 @@ export const devtoolHandlers = {
5053
)
5154
},
5255
},
56+
"devtool:protected_zones": {
57+
get(field) {
58+
return field.fieldPreferences?.protectedZones ?? defaultFieldPreferences().protectedZones
59+
},
60+
set(field, val) {
61+
val ??= defaultFieldPreferences().protectedZones
62+
if (!field.fieldPreferences || !this.validate(val)) {
63+
console.warn("validation failed", val, field.fieldPreferences)
64+
return
65+
}
66+
field.fieldPreferences.protectedZones = val
67+
field.updateProtectedZones()
68+
},
69+
validate(val): val is ProtectedZonePreferences[] {
70+
if (!Array.isArray(val)) return false
71+
return val.every(
72+
z =>
73+
typeof z === "object" &&
74+
z !== null &&
75+
typeof z.name === "string" &&
76+
(z.alliance === "red" || z.alliance === "blue") &&
77+
(typeof z.parentNode === "string" || z.parentNode === undefined) &&
78+
typeof z.penaltyPoints === "number" &&
79+
typeof z.contactType === "string" &&
80+
Object.values(ContactType).includes(z.contactType as ContactType) &&
81+
Array.isArray(z.activeDuring) &&
82+
z.activeDuring.every(
83+
(v: unknown) =>
84+
typeof v === "string" && Object.values(MatchModeType).includes(v as MatchModeType)
85+
) &&
86+
Array.isArray(z.deltaTransformation)
87+
)
88+
},
89+
},
5390
"devtool:spawn_locations": {
5491
get(field) {
5592
return field.fieldPreferences?.spawnLocations ?? defaultFieldPreferences().spawnLocations

fission/src/mirabuf/MirabufSceneObject.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
318318
}
319319

320320
// Centered in xz plane, bottom surface of object
321-
private getPositionTransform(vec: THREE.Vector3) {
321+
public getPositionTransform(vec: THREE.Vector3 = new THREE.Vector3()) {
322322
const box = this.computeBoundingBox()
323323
const transform = box.getCenter(vec)
324324
transform.setY(box.min.y)

fission/src/systems/World.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ class World {
8686
} catch (_) {
8787
World._analyticsSystem = undefined
8888
}
89+
90+
if (import.meta.env.DEV) {
91+
window.World = World
92+
}
8993
}
9094

9195
public static destroyWorld() {

0 commit comments

Comments
 (0)