@@ -11,28 +11,29 @@ import PathManager from './PathManager'
11
11
import OrbitalLocationLayer from './orbital'
12
12
import WormHoleLayer from './wormHole'
13
13
import TooltipLayer from './tooltip'
14
- import { EventEmitter } from "./eventEmitter.js" ;
15
14
import type { Store } from "vuex" ;
16
15
import type { State } from "../store" ;
17
16
import type { DrawingContext , GameContainer } from "./container" ;
18
17
import type { Game , Player , Star as StarData , Carrier as CarrierData } from "../types/game" ;
19
- import type { Location , UserGameSettings } from "@solaris-common" ;
18
+ import type { Location , MapObject , UserGameSettings } from "@solaris-common" ;
20
19
import { Chunks } from './chunks'
21
20
import Carrier from "./carrier" ;
21
+ import type { EventBus } from '../eventBus'
22
+ import MapEventBusEventNames from '../eventBusEventNames/map'
23
+ import MapCommandEventBusEventNames from "../eventBusEventNames/mapCommand" ;
22
24
23
25
enum Mode {
24
26
Galaxy = 'galaxy' ,
25
27
Waypoints = 'waypoints' ,
26
28
Ruler = 'ruler' ,
27
29
}
28
30
29
-
30
-
31
- export class Map extends EventEmitter {
31
+ export class Map {
32
32
// Represents the current game mode, these are as follows:
33
33
// galaxy - Normal galaxy view
34
34
// waypoints - Displays waypoints overlay for a given carrier
35
35
mode = Mode . Galaxy ;
36
+ eventBus : EventBus ;
36
37
app : PIXI . Application ;
37
38
store : Store < State > ;
38
39
context : DrawingContext ;
@@ -68,16 +69,16 @@ export class Map extends EventEmitter {
68
69
currentViewportCenter : PIXI . Point | undefined ;
69
70
lastPointerDownPosition : PIXI . Point | undefined ;
70
71
chunks : Chunks | undefined ;
72
+ unsubscribe : ( ( ) => void ) | undefined ;
71
73
72
- constructor ( app , store : Store < State > , gameContainer , context : DrawingContext ) {
73
- super ( )
74
-
74
+ constructor ( app : PIXI . Application , store : Store < State > , gameContainer , context : DrawingContext , eventBus : EventBus ) {
75
75
this . app = app
76
76
this . store = store
77
77
this . context = context
78
78
this . gameContainer = gameContainer ;
79
79
this . container = new PIXI . Container ( )
80
80
this . container . sortableChildren = true
81
+ this . eventBus = eventBus ;
81
82
82
83
this . stars = [ ]
83
84
@@ -132,6 +133,11 @@ export class Map extends EventEmitter {
132
133
this . userSettings = userSettings
133
134
this . game = game
134
135
136
+ if ( this . unsubscribe ) {
137
+ this . unsubscribe ( ) ;
138
+ this . unsubscribe = undefined ;
139
+ }
140
+
135
141
this . app . ticker . maxFPS = userSettings . technical . fpsLimit || 60 ;
136
142
137
143
this . pathManager = new PathManager ( game , userSettings , this )
@@ -236,9 +242,51 @@ export class Map extends EventEmitter {
236
242
this . tooltipLayer = new TooltipLayer ( )
237
243
this . tooltipLayer . setup ( this . game , this . context )
238
244
this . tooltipContainer ! . addChild ( this . tooltipLayer . container )
245
+
246
+ this . unsubscribe = this . subscribe ( ) ;
247
+ }
248
+
249
+ subscribe ( ) {
250
+ const panToLocation = ( { location } : { location : Location } ) => this . panToLocation ( location ) ;
251
+ const panToObject = ( { object } : { object : MapObject < string > } ) => this . panToObject ( object ) ;
252
+ const panToUser = ( ) => this . panToUser ( this . game ! ) ;
253
+ const panToPlayer = ( { player } : { player : Player } ) => this . panToPlayer ( this . game ! , player ) ;
254
+ const clearHighlightedLocations = ( ) => this . clearCarrierHighlights ( ) ;
255
+ const highlightLocation = ( { object, opacity } : { object : MapObject < string > , opacity : number } ) => this . highlightLocation ( object , opacity ) ;
256
+ const clickStar = ( { starId } : { starId : string } ) => this . clickStar ( starId ) ;
257
+ const clickCarrier = ( { carrierId } : { carrierId : string } ) => this . clickCarrier ( carrierId ) ;
258
+ const removeLastRulerWaypoint = ( ) => this . removeLastRulerPoint ( ) ;
259
+ const showIgnoreBulkUpgrade = ( ) => this . showIgnoreBulkUpgrade ( ) ;
260
+ const hideIgnoreBulkUpgrade = ( ) => this . hideIgnoreBulkUpgrade ( ) ;
261
+
262
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandPanToLocation , panToLocation ) ;
263
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandPanToObject , panToObject ) ;
264
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandPanToUser , panToUser ) ;
265
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandPanToPlayer , panToPlayer ) ;
266
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandClearHighlightedLocations , clearHighlightedLocations ) ;
267
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandHighlightLocation , highlightLocation ) ;
268
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandClickStar , clickStar ) ;
269
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandClickCarrier , clickCarrier ) ;
270
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandRemoveLastRulerPoint , removeLastRulerWaypoint ) ;
271
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandShowIgnoreBulkUpgrade , showIgnoreBulkUpgrade ) ;
272
+ this . eventBus . on ( MapCommandEventBusEventNames . MapCommandHideIgnoreBulkUpgrade , hideIgnoreBulkUpgrade ) ;
273
+
274
+ return ( ) => {
275
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandPanToLocation , panToLocation ) ;
276
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandPanToObject , panToObject ) ;
277
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandPanToUser , panToUser ) ;
278
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandPanToPlayer , panToPlayer ) ;
279
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandClearHighlightedLocations , clearHighlightedLocations ) ;
280
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandHighlightLocation , highlightLocation ) ;
281
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandClickStar , clickStar ) ;
282
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandClickCarrier , clickCarrier ) ;
283
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandRemoveLastRulerPoint , removeLastRulerWaypoint ) ;
284
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandShowIgnoreBulkUpgrade , showIgnoreBulkUpgrade ) ;
285
+ this . eventBus . off ( MapCommandEventBusEventNames . MapCommandHideIgnoreBulkUpgrade , hideIgnoreBulkUpgrade ) ;
286
+ }
239
287
}
240
288
241
- setupStar ( game , userSettings , starData ) {
289
+ setupStar ( game : Game , userSettings : UserGameSettings , starData : StarData ) {
242
290
let star = this . stars . find ( x => x . data . _id === starData . _id )
243
291
244
292
if ( ! star ) {
@@ -581,6 +629,10 @@ export class Map extends EventEmitter {
581
629
this . panToPlayer ( game , player )
582
630
}
583
631
632
+ panToObject ( object : { location : Location } ) {
633
+ this . panToLocation ( object . location )
634
+ }
635
+
584
636
panToStar ( star : StarData ) {
585
637
this . panToLocation ( star . location )
586
638
}
@@ -732,7 +784,7 @@ export class Map extends EventEmitter {
732
784
733
785
if ( ! dic . tryMultiSelect || ! this . tryMultiSelect ( e . location ) ) {
734
786
selectedStar ! . toggleSelected ( )
735
- this . emit ( 'onStarClicked' , e )
787
+ this . eventBus . emit ( MapEventBusEventNames . MapOnStarClicked , { star : e } )
736
788
}
737
789
} else if ( this . mode === 'waypoints' ) {
738
790
this . waypoints ! . onStarClicked ( e )
@@ -766,7 +818,7 @@ export class Map extends EventEmitter {
766
818
dic . permitCallback && dic . permitCallback ( )
767
819
768
820
if ( this . mode === 'galaxy' ) {
769
- this . emit ( 'onStarRightClicked' , e )
821
+ this . eventBus . emit ( MapEventBusEventNames . MapOnStarRightClicked , { star : e } )
770
822
}
771
823
}
772
824
} )
@@ -796,7 +848,7 @@ export class Map extends EventEmitter {
796
848
}
797
849
798
850
if ( ! dic . tryMultiSelect || ! this . tryMultiSelect ( e . location ) ) {
799
- this . emit ( 'onCarrierClicked' , e )
851
+ this . eventBus . emit ( MapEventBusEventNames . MapOnCarrierClicked , { carrier : e } )
800
852
} else {
801
853
selectedCarrier ! . unselect ( )
802
854
}
@@ -809,7 +861,7 @@ export class Map extends EventEmitter {
809
861
810
862
onCarrierRightClicked ( e ) {
811
863
if ( this . mode === 'galaxy' ) {
812
- this . emit ( 'onCarrierRightClicked' , e )
864
+ this . eventBus . emit ( MapEventBusEventNames . MapOnCarrierRightClicked , { carrier : e } ) ;
813
865
}
814
866
}
815
867
@@ -844,23 +896,25 @@ export class Map extends EventEmitter {
844
896
}
845
897
846
898
onWaypointCreated ( e ) {
847
- this . emit ( 'onWaypointCreated' , e )
899
+ this . eventBus . emit ( MapEventBusEventNames . MapOnWaypointCreated , { waypoint : e } )
848
900
}
849
901
850
902
onWaypointOutOfRange ( e ) {
851
- this . emit ( 'onWaypointOutOfRange' , e )
903
+ this . eventBus . emit ( MapEventBusEventNames . MapOnWaypointOutOfRange )
852
904
}
853
905
854
906
onRulerPointCreated ( e ) {
855
- this . emit ( 'onRulerPointCreated' , e )
907
+ console . log ( e ) ;
908
+
909
+ this . eventBus . emit ( MapEventBusEventNames . MapOnRulerPointCreated , { rulerPoint : e } ) ;
856
910
}
857
911
858
912
onRulerPointRemoved ( e ) {
859
- this . emit ( 'onRulerPointRemoved' , e )
913
+ this . eventBus . emit ( MapEventBusEventNames . MapOnRulerPointRemoved , { rulerPoint : e } ) ;
860
914
}
861
915
862
916
onRulerPointsCleared ( e ) {
863
- this . emit ( 'onRulerPointsCleared' , e )
917
+ this . eventBus . emit ( MapEventBusEventNames . MapOnRulerPointsCleared ) ;
864
918
}
865
919
866
920
tryMultiSelect ( location ) {
@@ -925,7 +979,9 @@ export class Map extends EventEmitter {
925
979
}
926
980
} )
927
981
928
- this . emit ( 'onObjectsClicked' , eventObj )
982
+ this . eventBus . emit ( MapEventBusEventNames . MapOnObjectsClicked , {
983
+ objects : eventObj
984
+ } )
929
985
930
986
return true
931
987
}
0 commit comments