|
1 | 1 | import type MirabufSceneObject from "@/mirabuf/MirabufSceneObject.ts" |
| 2 | +import { ContactType } from "@/mirabuf/ZoneTypes.ts" |
2 | 3 | import { mirabuf } from "@/proto/mirabuf" |
| 4 | +import { MatchModeType } from "@/systems/match_mode/MatchModeTypes.ts" |
3 | 5 | import { |
4 | 6 | defaultFieldPreferences, |
5 | 7 | type FieldPreferences, |
| 8 | + type ProtectedZonePreferences, |
6 | 9 | type ScoringZonePreferences, |
7 | 10 | } from "@/systems/preferences/PreferenceTypes" |
8 | 11 |
|
9 | 12 | export interface DevtoolMiraData { |
10 | 13 | "devtool:scoring_zones": ScoringZonePreferences[] |
11 | | - "devtool:camera_locations": unknown |
| 14 | + "devtool:protected_zones": ProtectedZonePreferences[] |
12 | 15 | "devtool:spawn_locations": FieldPreferences["spawnLocations"] |
13 | 16 | "devtool:a": unknown |
14 | 17 | "devtool:b": unknown |
@@ -50,6 +53,40 @@ export const devtoolHandlers = { |
50 | 53 | ) |
51 | 54 | }, |
52 | 55 | }, |
| 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 | + }, |
53 | 90 | "devtool:spawn_locations": { |
54 | 91 | get(field) { |
55 | 92 | return field.fieldPreferences?.spawnLocations ?? defaultFieldPreferences().spawnLocations |
|
0 commit comments