@@ -27,16 +27,17 @@ import { CellDefinition, loadCatalog } from "../model/catalog.ts"
2727export class FieldItems implements IStepper , ILoader {
2828 #items: Set < IItem > = new Set ( )
2929 #coordMap = { } as Record < string , IItem >
30- #activateScope : RectScope
30+ #deactivateScope : RectScope
3131
3232 constructor ( scope : RectScope ) {
33- this . #activateScope = scope
33+ this . #deactivateScope = scope
3434 }
3535
3636 checkDeactivate ( i : number , j : number ) {
37- this . #activateScope. setCenter ( CELL_SIZE * i , CELL_SIZE * j )
37+ this . #deactivateScope. setCenter ( i * CELL_SIZE , j * CELL_SIZE )
38+
3839 this . #items. values ( )
39- . filter ( ( item ) => ! this . #activateScope . overlaps ( item ) )
40+ . filter ( ( item ) => ! this . #deactivateScope . overlaps ( item ) )
4041 . forEach ( ( item ) => {
4142 console . log ( "deactivating item" , item . id )
4243 this . #deactivate( item . i , item . j )
@@ -106,16 +107,17 @@ export class FieldItems implements IStepper, ILoader {
106107export class FieldProps implements IStepper , ILoader {
107108 #props: Set < IProp > = new Set ( )
108109 #coordMap = { } as Record < string , IProp >
109- #activateScope : RectScope
110+ #deactivateScope : RectScope
110111
111112 constructor ( scope : RectScope ) {
112- this . #activateScope = scope
113+ this . #deactivateScope = scope
113114 }
114115
115116 checkDeactivate ( i : number , j : number ) {
116- this . #activateScope. setCenter ( CELL_SIZE * i , CELL_SIZE * j )
117+ this . #deactivateScope. setCenter ( i * CELL_SIZE , j * CELL_SIZE )
118+
117119 this . #props. values ( )
118- . filter ( ( obj ) => ! this . #activateScope . overlaps ( obj ) )
120+ . filter ( ( obj ) => ! this . #deactivateScope . overlaps ( obj ) )
119121 . forEach ( ( obj ) => {
120122 console . log ( "deactivating object" , obj . id )
121123 this . remove ( obj . i , obj . j )
@@ -207,7 +209,7 @@ class CoordCountMap {
207209export class FieldActors implements IStepper , ILoader {
208210 #actors: IActor [ ] = [ ]
209211 #coordCountMap = new CoordCountMap ( )
210- #activateScope : RectScope
212+ #deactivateScope : RectScope
211213 #idSet: Set < string > = new Set ( )
212214
213215 /**
@@ -219,8 +221,8 @@ export class FieldActors implements IStepper, ILoader {
219221 return this . #coordCountMap. get ( `${ i } .${ j } ` ) > 0
220222 }
221223
222- constructor ( chars : IActor [ ] = [ ] , activateScope : RectScope ) {
223- this . #activateScope = activateScope
224+ constructor ( chars : IActor [ ] = [ ] , deactivateScope : RectScope ) {
225+ this . #deactivateScope = deactivateScope
224226 for ( const actor of chars ) {
225227 this . add ( actor )
226228 }
@@ -264,10 +266,11 @@ export class FieldActors implements IStepper, ILoader {
264266 }
265267
266268 checkDeactivate ( i : number , j : number ) {
267- this . #activateScope. setCenter ( CELL_SIZE * i , CELL_SIZE * j )
269+ this . #deactivateScope. setCenter ( i * CELL_SIZE , j * CELL_SIZE )
270+
268271 const actors = [ ] as IActor [ ]
269272 for ( const actor of this . #actors) {
270- if ( this . #activateScope . overlaps ( actor ) ) {
273+ if ( this . #deactivateScope . overlaps ( actor ) ) {
271274 actors . push ( actor )
272275 continue
273276 }
@@ -384,6 +387,7 @@ export class Field implements IField {
384387 #loadScope = new BlockLoadScope ( )
385388 #unloadScope = new BlockUnloadScope ( )
386389 #activateScope: RectScope
390+ #deactivateScope: RectScope
387391 #mapLoader = new BlockMapLoader ( new URL ( "map/" , location . href ) . href )
388392 #initialBlocksLoaded = false
389393 #initialActivateReady = false
@@ -394,12 +398,17 @@ export class Field implements IField {
394398
395399 #time = 0
396400
397- constructor ( el : HTMLElement , activateScope : RectScope ) {
401+ constructor (
402+ el : HTMLElement ,
403+ activateScope : RectScope ,
404+ deactivateScope : RectScope ,
405+ ) {
398406 this . #el = el
399407 this . #activateScope = activateScope
400- this . #actors = new FieldActors ( [ ] , activateScope )
401- this . #items = new FieldItems ( activateScope )
402- this . #props = new FieldProps ( activateScope )
408+ this . #deactivateScope = deactivateScope
409+ this . #actors = new FieldActors ( [ ] , deactivateScope )
410+ this . #items = new FieldItems ( deactivateScope )
411+ this . #props = new FieldProps ( deactivateScope )
403412 }
404413
405414 get actors ( ) {
@@ -531,6 +540,8 @@ export class Field implements IField {
531540 initialLoad ?: boolean
532541 } ,
533542 ) {
543+ this . #activateScope. setCenter ( i * CELL_SIZE , j * CELL_SIZE )
544+
534545 const chunks = [ ...this . #getChunks( i , j ) ]
535546 const newCharSpawns = chunks . flatMap ( ( c ) => c . getCharacterSpawns ( ) )
536547 . filter ( ( spawn ) => ! this . #actors. has ( spawn . id ) ) // isn't spawned yet
0 commit comments