Skip to content

Commit fece4aa

Browse files
Merge pull request #1419 from solaris-games/dev
Update 251.3
2 parents 55ef15b + 7fb7dfa commit fece4aa

File tree

91 files changed

+1210
-626
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+1210
-626
lines changed

client/src/eventBusEventNames/map.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { makeCastFunc } from "@solaris-common";
2+
import type { EventBusEventName } from "./eventBusEventName";
3+
import type { Star, Carrier } from "../types/game";
4+
import type { TempWaypoint } from "../types/waypoint";
5+
import type {RulerPoint} from "@/types/ruler";
6+
7+
export type MapEventBusEventType = { mapEventBusEventType: 'mapEventBusEventType' };
8+
export type MapEventBusEventName<TData> = EventBusEventName<MapEventBusEventType, TData> & { mapEventBusEventType: 'mapEventBusEventType' };
9+
10+
const toEventName: <TData>(value: string) => MapEventBusEventName<TData> = makeCastFunc();
11+
12+
type StarClicked = {
13+
type: 'star',
14+
data: Star,
15+
}
16+
17+
type CarrierClicked = {
18+
type: 'carrier',
19+
data: Carrier,
20+
}
21+
22+
type ObjectClickedData = StarClicked | CarrierClicked;
23+
24+
export type ObjectClicked = {
25+
distance: number,
26+
} & ObjectClickedData;
27+
28+
export default class MapEventBusEventNames {
29+
private constructor() {};
30+
31+
public static readonly MapOnStarClicked: MapEventBusEventName<{ star: Star }> = toEventName('onStarClicked');
32+
public static readonly MapOnStarRightClicked: MapEventBusEventName<{ star: Star }> = toEventName("onStarRightClicked");
33+
public static readonly MapOnCarrierClicked: MapEventBusEventName<{ carrier: Carrier }> = toEventName('onCarrierClicked');
34+
public static readonly MapOnCarrierRightClicked: MapEventBusEventName<{ carrier: Carrier }> = toEventName("onCarrierRightClicked");
35+
public static readonly MapOnWaypointCreated: MapEventBusEventName<{ waypoint: TempWaypoint }> = toEventName("onWaypointCreated");
36+
public static readonly MapOnObjectsClicked: MapEventBusEventName<{ objects: ObjectClicked[] }> = toEventName("onObjectsClicked");
37+
public static readonly MapOnWaypointOutOfRange: MapEventBusEventName<{}> = toEventName("onWaypointOutOfRange");
38+
public static readonly MapOnRulerPointCreated: MapEventBusEventName<{ rulerPoint: RulerPoint }> = toEventName("onRulerPointCreated");
39+
public static readonly MapOnRulerPointRemoved: MapEventBusEventName<{ rulerPoint: RulerPoint }> = toEventName("onRulerPointRemoved");
40+
public static readonly MapOnRulerPointsCleared: MapEventBusEventName<{}> = toEventName("onRulerPointsCleared");
41+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type {EventBusEventName} from "./eventBusEventName";
2+
import {type MapObject, makeCastFunc, type Location} from "@solaris-common";
3+
import type {Player} from "../types/game";
4+
5+
export type MapCommandEventBusEventType = { mapCommandEventBusEventType: 'mapCommandEventBusEventType' };
6+
export type MapCommandEventBusEventName<TData> = EventBusEventName<MapCommandEventBusEventType, TData> & { mapEventBusEventType: 'mapEventBusEventType' };
7+
8+
const toEventName: <TData>(value: string) => MapCommandEventBusEventName<TData> = makeCastFunc();
9+
10+
export default class MapCommandEventBusEventNames {
11+
private constructor() {};
12+
13+
public static readonly MapCommandPanToUser: MapCommandEventBusEventName<{}> = toEventName('panToUser');
14+
public static readonly MapCommandPanToObject: MapCommandEventBusEventName<{ object: MapObject<string> }> = toEventName('panToObject');
15+
public static readonly MapCommandPanToLocation: MapCommandEventBusEventName<{ location: Location }> = toEventName('panToLocation');
16+
public static readonly MapCommandPanToPlayer: MapCommandEventBusEventName<{ player: Player }> = toEventName('panToPlayer');
17+
public static readonly MapCommandClearHighlightedLocations: MapCommandEventBusEventName<{}> = toEventName('clearHighlightedLocations');
18+
public static readonly MapCommandHighlightLocation: MapCommandEventBusEventName<{ object: MapObject<string>, opacity: number }> = toEventName('highlightLocation');
19+
public static readonly MapCommandClickStar: MapCommandEventBusEventName<{ starId: string }> = toEventName('clickStar');
20+
public static readonly MapCommandClickCarrier: MapCommandEventBusEventName<{ carrierId: string }> = toEventName('clickCarrier');
21+
public static readonly MapCommandRemoveLastRulerPoint: MapCommandEventBusEventName<{}> = toEventName('removeLastRulerPoint');
22+
public static readonly MapCommandShowIgnoreBulkUpgrade: MapCommandEventBusEventName<{}> = toEventName('showIgnoreBulkUpgrade');
23+
public static readonly MapCommandHideIgnoreBulkUpgrade: MapCommandEventBusEventName<{}> = toEventName('hideIgnoreBulkUpgrade');
24+
}

client/src/eventBusEventNames/menu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { makeCastFunc } from "@solaris-common";
2-
import MENU_STATES from '../services/data/menuStates';
2+
import MENU_STATES from '../services/data/menuStates.js';
33
import type { EventBusEventName } from "./eventBusEventName";
44

55
export type MenuEventBusEventType = { menuEventBusEventType: 'menuEventBusEventType' };

client/src/eventBusEventNames/player.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const toEventName: <TData>(value: string) => PlayerEventBusEventName<TData> = ma
1212
export default class PlayerEventBusEventNames {
1313
private constructor() { };
1414

15-
public static readonly GameMessageSent: PlayerEventBusEventName<ConversationMessageSentResult<string>> = toEventName('gameMessageSent');
1615
public static readonly GameConversationRead: PlayerEventBusEventName<{ conversationId: string, readByPlayerId: string }> = toEventName('gameConversationRead');
1716

1817
public static readonly GameConversationLeft: PlayerEventBusEventName<{ conversationId: string, playerId: string }> = toEventName('gameConversationLeft');

client/src/eventBusEventNames/user.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type {EventBusEventName} from "./eventBusEventName";
2+
import {type ConversationMessageSentResult, makeCastFunc} from "@solaris-common";
3+
4+
export type UserEventBusEventType = { playerEventBusEventType: 'playerEventBusEventType' };
5+
export type UserEventBusEventName<TData> = EventBusEventName<UserEventBusEventType, TData> & { playerEventBusEventName: 'playerEventBusEventName' }
6+
7+
const toEventName: <TData>(value: string) => UserEventBusEventName<TData> = makeCastFunc();
8+
9+
export default class UserEventBusEventNames {
10+
public static readonly GameMessageSent: UserEventBusEventName<ConversationMessageSentResult<string>> = toEventName('gameMessageSent');
11+
}

client/src/game/container.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {UserGameSettings} from "@solaris-common";
99
import type {Game, Player, Star, Carrier} from "../types/game";
1010
import { screenshot } from './screenshot';
1111
import { DebugTools } from './debugTools';
12+
import type { EventBus } from '../eventBus';
1213

1314
export class DrawingContext {
1415
store: Store<State>;
@@ -35,11 +36,11 @@ export class GameContainer {
3536
userSettings: UserGameSettings | undefined;
3637
game: Game | undefined;
3738
debugTools: DebugTools | undefined;
39+
eventBus: EventBus | undefined;
3840

3941
reportGameError: ((err: string) => void) | undefined;
4042

4143
constructor () {
42-
4344
}
4445

4546
checkPerformance(): { webgl: boolean, performance: boolean } {
@@ -59,8 +60,9 @@ export class GameContainer {
5960
}
6061
}
6162

62-
async setupApp (store, userSettings, reportGameError) {
63+
async setupApp (store, userSettings, reportGameError, eventBus: EventBus) {
6364
this.store = store
65+
this.eventBus = eventBus;
6466
this.reportGameError = reportGameError;
6567

6668
this.context = new DrawingContext(store)
@@ -108,11 +110,13 @@ export class GameContainer {
108110
this.app!.stage.addChild(this.viewport)
109111

110112
// Add a new map to the viewport
111-
this.map = new Map(this.app, this.store, this, this.context!)
113+
this.map = new Map(this.app, this.store, this, this.context!, eventBus);
112114
this.viewport.addChild(this.map.container)
113115
}
114116

115117
destroy () {
118+
console.warn('Destroying game container')
119+
116120
if (this.viewport) {
117121
this.viewport.destroy()
118122
this.viewport = undefined
@@ -186,7 +190,7 @@ export class GameContainer {
186190
this.viewport!.on('pointerdown', this.map!.onViewportPointerDown.bind(this.map))
187191
}
188192

189-
setup (game: Game, userSettings: UserGameSettings, context: DrawingContext) {
193+
setup (game: Game, userSettings: UserGameSettings) {
190194
this.game = game;
191195
this.userSettings = userSettings
192196

@@ -234,12 +238,12 @@ export class GameContainer {
234238
}
235239

236240
reloadStar (star) {
237-
let starObject = this.map!.setupStar(this.game, this.userSettings, star)
241+
const starObject = this.map!.setupStar(this.game!, this.userSettings!, star)
238242
this.map!.drawStar(starObject)
239243
}
240244

241245
reloadCarrier (carrier) {
242-
let carrierObject = this.map!.setupCarrier(this.game, this.userSettings, carrier)
246+
const carrierObject = this.map!.setupCarrier(this.game, this.userSettings, carrier)
243247
this.map!.drawCarrier(carrierObject)
244248
}
245249

@@ -248,7 +252,7 @@ export class GameContainer {
248252
}
249253

250254
getViewportZoomPercentage () {
251-
let viewportWidth = this.viewport!.right - this.viewport!.left
255+
const viewportWidth = this.viewport!.right - this.viewport!.left
252256
return (this.viewport!.screenWidth / viewportWidth) * 100
253257
}
254258

@@ -301,6 +305,14 @@ export class GameContainer {
301305
panToCarrier(carrier: Carrier) {
302306
this.map!.panToCarrier(carrier);
303307
}
308+
309+
fitGalaxy(x, y) {
310+
console.log(this)
311+
312+
this.viewport!.moveCenter(x, y)
313+
this.viewport!.fitWorld()
314+
this.viewport!.zoom(this.starFieldRight, true)
315+
}
304316
}
305317

306318
export default new GameContainer()

client/src/game/map.ts

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,29 @@ import PathManager from './PathManager'
1111
import OrbitalLocationLayer from './orbital'
1212
import WormHoleLayer from './wormHole'
1313
import TooltipLayer from './tooltip'
14-
import {EventEmitter} from "./eventEmitter.js";
1514
import type {Store} from "vuex";
1615
import type {State} from "../store";
1716
import type {DrawingContext, GameContainer} from "./container";
1817
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";
2019
import { Chunks } from './chunks'
2120
import Carrier from "./carrier";
21+
import type { EventBus } from '../eventBus'
22+
import MapEventBusEventNames from '../eventBusEventNames/map'
23+
import MapCommandEventBusEventNames from "../eventBusEventNames/mapCommand";
2224

2325
enum Mode {
2426
Galaxy = 'galaxy',
2527
Waypoints = 'waypoints',
2628
Ruler = 'ruler',
2729
}
2830

29-
30-
31-
export class Map extends EventEmitter {
31+
export class Map {
3232
// Represents the current game mode, these are as follows:
3333
// galaxy - Normal galaxy view
3434
// waypoints - Displays waypoints overlay for a given carrier
3535
mode = Mode.Galaxy;
36+
eventBus: EventBus;
3637
app: PIXI.Application;
3738
store: Store<State>;
3839
context: DrawingContext;
@@ -68,16 +69,16 @@ export class Map extends EventEmitter {
6869
currentViewportCenter: PIXI.Point | undefined;
6970
lastPointerDownPosition: PIXI.Point | undefined;
7071
chunks: Chunks | undefined;
72+
unsubscribe: (() => void) | undefined;
7173

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) {
7575
this.app = app
7676
this.store = store
7777
this.context = context
7878
this.gameContainer = gameContainer;
7979
this.container = new PIXI.Container()
8080
this.container.sortableChildren = true
81+
this.eventBus = eventBus;
8182

8283
this.stars = []
8384

@@ -132,6 +133,11 @@ export class Map extends EventEmitter {
132133
this.userSettings = userSettings
133134
this.game = game
134135

136+
if (this.unsubscribe) {
137+
this.unsubscribe();
138+
this.unsubscribe = undefined;
139+
}
140+
135141
this.app.ticker.maxFPS = userSettings.technical.fpsLimit || 60;
136142

137143
this.pathManager = new PathManager( game, userSettings, this )
@@ -236,9 +242,51 @@ export class Map extends EventEmitter {
236242
this.tooltipLayer = new TooltipLayer()
237243
this.tooltipLayer.setup(this.game, this.context)
238244
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+
}
239287
}
240288

241-
setupStar (game, userSettings, starData) {
289+
setupStar (game: Game, userSettings: UserGameSettings, starData: StarData) {
242290
let star = this.stars.find(x => x.data._id === starData._id)
243291

244292
if (!star) {
@@ -581,6 +629,10 @@ export class Map extends EventEmitter {
581629
this.panToPlayer(game, player)
582630
}
583631

632+
panToObject(object: { location: Location }) {
633+
this.panToLocation(object.location)
634+
}
635+
584636
panToStar (star: StarData) {
585637
this.panToLocation(star.location)
586638
}
@@ -732,7 +784,7 @@ export class Map extends EventEmitter {
732784

733785
if (!dic.tryMultiSelect || !this.tryMultiSelect(e.location)) {
734786
selectedStar!.toggleSelected()
735-
this.emit('onStarClicked', e)
787+
this.eventBus.emit(MapEventBusEventNames.MapOnStarClicked, { star: e })
736788
}
737789
} else if (this.mode === 'waypoints') {
738790
this.waypoints!.onStarClicked(e)
@@ -766,7 +818,7 @@ export class Map extends EventEmitter {
766818
dic.permitCallback && dic.permitCallback()
767819

768820
if (this.mode === 'galaxy') {
769-
this.emit('onStarRightClicked', e)
821+
this.eventBus.emit(MapEventBusEventNames.MapOnStarRightClicked, { star: e })
770822
}
771823
}
772824
})
@@ -796,7 +848,7 @@ export class Map extends EventEmitter {
796848
}
797849

798850
if (!dic.tryMultiSelect || !this.tryMultiSelect(e.location)) {
799-
this.emit('onCarrierClicked', e)
851+
this.eventBus.emit(MapEventBusEventNames.MapOnCarrierClicked, { carrier: e })
800852
} else {
801853
selectedCarrier!.unselect()
802854
}
@@ -809,7 +861,7 @@ export class Map extends EventEmitter {
809861

810862
onCarrierRightClicked (e) {
811863
if (this.mode === 'galaxy') {
812-
this.emit('onCarrierRightClicked', e)
864+
this.eventBus.emit(MapEventBusEventNames.MapOnCarrierRightClicked, { carrier: e });
813865
}
814866
}
815867

@@ -844,23 +896,25 @@ export class Map extends EventEmitter {
844896
}
845897

846898
onWaypointCreated (e) {
847-
this.emit('onWaypointCreated', e)
899+
this.eventBus.emit(MapEventBusEventNames.MapOnWaypointCreated, { waypoint: e })
848900
}
849901

850902
onWaypointOutOfRange (e) {
851-
this.emit('onWaypointOutOfRange', e)
903+
this.eventBus.emit(MapEventBusEventNames.MapOnWaypointOutOfRange)
852904
}
853905

854906
onRulerPointCreated (e) {
855-
this.emit('onRulerPointCreated', e)
907+
console.log(e);
908+
909+
this.eventBus.emit(MapEventBusEventNames.MapOnRulerPointCreated, { rulerPoint: e });
856910
}
857911

858912
onRulerPointRemoved (e) {
859-
this.emit('onRulerPointRemoved', e)
913+
this.eventBus.emit(MapEventBusEventNames.MapOnRulerPointRemoved, { rulerPoint: e });
860914
}
861915

862916
onRulerPointsCleared (e) {
863-
this.emit('onRulerPointsCleared', e)
917+
this.eventBus.emit(MapEventBusEventNames.MapOnRulerPointsCleared);
864918
}
865919

866920
tryMultiSelect (location) {
@@ -925,7 +979,9 @@ export class Map extends EventEmitter {
925979
}
926980
})
927981

928-
this.emit('onObjectsClicked', eventObj)
982+
this.eventBus.emit(MapEventBusEventNames.MapOnObjectsClicked, {
983+
objects: eventObj
984+
})
929985

930986
return true
931987
}

0 commit comments

Comments
 (0)