@@ -11,6 +11,7 @@ import { BodyAssociate, LayerReserve } from "@/systems/physics/PhysicsSystem"
11
11
import Mechanism from "@/systems/physics/Mechanism"
12
12
import {
13
13
Alliance ,
14
+ Station ,
14
15
EjectorPreferences ,
15
16
FieldPreferences ,
16
17
IntakePreferences ,
@@ -42,6 +43,7 @@ import {
42
43
import { SimConfigData } from "@/ui/panels/simulation/SimConfigShared"
43
44
import WPILibBrain from "@/systems/simulation/wpilib_brain/WPILibBrain"
44
45
import { OnContactAddedEvent } from "@/systems/physics/ContactEvents"
46
+ import FieldMiraEditor from "./FieldMiraEditor"
45
47
46
48
const DEBUG_BODIES = false
47
49
@@ -73,6 +75,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
73
75
private _mechanism : Mechanism
74
76
private _brain : Brain | undefined
75
77
private _alliance : Alliance | undefined
78
+ private _station : Station | undefined
76
79
77
80
private _debugBodies : Map < string , RnDebugMeshes > | null
78
81
private _physicsLayerReserve : LayerReserve | undefined
@@ -90,14 +93,14 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
90
93
91
94
private _nameTag : SceneOverlayTag | undefined
92
95
private _centerOfMassIndicator : THREE . Mesh | undefined
93
- private _centerOfMassListenerUnsubscribe : ( ( ) => void ) | undefined
94
96
private _intakeActive = false
95
97
private _ejectorActive = false
96
98
97
99
private _lastEjectableToastTime = 0
98
100
private static readonly EJECTABLE_TOAST_COOLDOWN_MS = 500
99
101
100
102
private _collision ?: ( event : OnContactAddedEvent ) => void
103
+ private _cacheId ?: string
101
104
102
105
public get intakeActive ( ) {
103
106
return this . _intakeActive
@@ -145,7 +148,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
145
148
}
146
149
147
150
public get activeEjectables ( ) : Jolt . BodyID [ ] {
148
- return this . _ejectables . map ( e => e . gamePieceBodyId ! )
151
+ return this . _ejectables . map ( e => e . gamePieceBodyId ! ) . filter ( x => x !== undefined )
149
152
}
150
153
151
154
public get miraType ( ) : MiraType {
@@ -164,6 +167,10 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
164
167
return this . _alliance
165
168
}
166
169
170
+ public get station ( ) {
171
+ return this . _station
172
+ }
173
+
167
174
public set brain ( brain : Brain | undefined ) {
168
175
this . _brain = brain
169
176
const simLayer = World . simulationSystem . getSimulationLayer ( this . _mechanism ) !
@@ -174,11 +181,25 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
174
181
this . _alliance = alliance
175
182
}
176
183
177
- public constructor ( mirabufInstance : MirabufInstance , assemblyName : string , progressHandle ?: ProgressHandle ) {
184
+ public set station ( station : Station | undefined ) {
185
+ this . _station = station
186
+ }
187
+
188
+ public get cacheId ( ) {
189
+ return this . _cacheId
190
+ }
191
+
192
+ public constructor (
193
+ mirabufInstance : MirabufInstance ,
194
+ assemblyName : string ,
195
+ progressHandle ?: ProgressHandle ,
196
+ cacheId ?: string
197
+ ) {
178
198
super ( )
179
199
180
200
this . _mirabufInstance = mirabufInstance
181
201
this . _assemblyName = assemblyName
202
+ this . _cacheId = cacheId
182
203
183
204
progressHandle ?. update ( "Creating mechanism..." , 0.9 )
184
205
@@ -221,18 +242,8 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
221
242
} )
222
243
material . depthTest = false
223
244
this . _centerOfMassIndicator = new THREE . Mesh ( new THREE . SphereGeometry ( 0.02 ) , material )
224
- this . _centerOfMassIndicator . visible = PreferencesSystem . getGlobalPreference ( "ShowCenterOfMassIndicators" )
225
-
245
+ this . _centerOfMassIndicator . visible = false
226
246
World . sceneRenderer . scene . add ( this . _centerOfMassIndicator )
227
-
228
- this . _centerOfMassListenerUnsubscribe = PreferencesSystem . addPreferenceEventListener (
229
- "ShowCenterOfMassIndicators" ,
230
- e => {
231
- if ( this . _centerOfMassIndicator ) {
232
- this . _centerOfMassIndicator . visible = e . prefValue
233
- }
234
- }
235
- )
236
247
}
237
248
}
238
249
@@ -353,13 +364,14 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
353
364
} )
354
365
this . _debugBodies ?. clear ( )
355
366
this . _physicsLayerReserve ?. release ( )
356
- this . _centerOfMassIndicator ?. geometry ?. dispose ( )
367
+ if ( this . _centerOfMassIndicator ) {
368
+ World . sceneRenderer . scene . remove ( this . _centerOfMassIndicator )
369
+ this . _centerOfMassIndicator = undefined
370
+ }
371
+
357
372
if ( this . _brain && this . _brain instanceof SynthesisBrain ) {
358
373
this . _brain . clearControls ( )
359
374
}
360
- if ( this . _centerOfMassListenerUnsubscribe ) {
361
- this . _centerOfMassListenerUnsubscribe ( )
362
- }
363
375
}
364
376
365
377
public eject ( ) {
@@ -453,6 +465,7 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
453
465
if ( this . _centerOfMassIndicator ) {
454
466
const netCoM = totalMass > 0 ? weightedCOM . Div ( totalMass ) : weightedCOM
455
467
this . _centerOfMassIndicator . position . set ( netCoM . GetX ( ) , netCoM . GetY ( ) , netCoM . GetZ ( ) )
468
+ this . _centerOfMassIndicator . visible = PreferencesSystem . getGlobalPreference ( "ShowCenterOfMassIndicators" )
456
469
}
457
470
}
458
471
@@ -660,6 +673,21 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
660
673
}
661
674
662
675
this . _fieldPreferences = PreferencesSystem . getFieldPreferences ( this . assemblyName )
676
+
677
+ // For fields, sync devtool data with field preferences
678
+ if ( this . miraType === MiraType . FIELD ) {
679
+ const parts = this . _mirabufInstance . parser . assembly . data ?. parts
680
+ if ( parts ) {
681
+ const editor = new FieldMiraEditor ( parts )
682
+ const devtoolScoringZones = editor . getUserData ( "devtool:scoring_zones" )
683
+
684
+ if ( devtoolScoringZones && Array . isArray ( devtoolScoringZones ) ) {
685
+ this . _fieldPreferences . scoringZones = devtoolScoringZones
686
+ PreferencesSystem . setFieldPreferences ( this . assemblyName , this . _fieldPreferences )
687
+ PreferencesSystem . savePreferences ( )
688
+ }
689
+ }
690
+ }
663
691
}
664
692
665
693
public updateSimConfig ( config : SimConfigData | undefined ) {
@@ -792,15 +820,16 @@ class MirabufSceneObject extends SceneObject implements ContextSupplier {
792
820
793
821
export async function createMirabuf (
794
822
assembly : mirabuf . Assembly ,
795
- progressHandle ?: ProgressHandle
823
+ progressHandle ?: ProgressHandle ,
824
+ cacheId ?: string
796
825
) : Promise < MirabufSceneObject | null | undefined > {
797
826
const parser = new MirabufParser ( assembly , progressHandle )
798
827
if ( parser . maxErrorSeverity >= ParseErrorSeverity . UNIMPORTABLE ) {
799
828
console . error ( `Assembly Parser produced significant errors for '${ assembly . info ! . name ! } '` )
800
829
return
801
830
}
802
831
803
- return new MirabufSceneObject ( new MirabufInstance ( parser ) , assembly . info ! . name ! , progressHandle )
832
+ return new MirabufSceneObject ( new MirabufInstance ( parser ) , assembly . info ! . name ! , progressHandle , cacheId )
804
833
}
805
834
806
835
/**
0 commit comments