Skip to content

Commit 0d845cd

Browse files
Merge pull request #1462 from solaris-games/dev
Fixes for 252
2 parents dea27cc + 398ee72 commit 0d845cd

File tree

9 files changed

+60
-18
lines changed

9 files changed

+60
-18
lines changed

client/src/game/map.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,10 @@ export class Map {
636636

637637
drawWormHoles () {
638638
if (this._isWormHolesEnabled()) {
639+
if (!this.wormHoleLayer) {
640+
this.wormHoleLayer = new WormHoleLayer();
641+
}
642+
639643
this.wormHoleLayer!.setup(this.game)
640644
this.wormHoleLayer!.draw()
641645
}
@@ -948,8 +952,6 @@ export class Map {
948952
}
949953

950954
onRulerPointCreated (e) {
951-
console.log(e);
952-
953955
this.eventBus.emit(MapEventBusEventNames.MapOnRulerPointCreated, { rulerPoint: e });
954956
}
955957

client/src/game/tooltip.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ export default class {
2121
}
2222

2323
destroy() {
24-
this.clear();
2524
this.game = undefined;
25+
this.clear();
2626
}
2727

2828
clear() {
@@ -37,6 +37,10 @@ export default class {
3737
_drawTooltip(tooltipData) {
3838
this.container.removeChildren()
3939

40+
if (!this.game) {
41+
return;
42+
}
43+
4044
const player = GameHelper.getPlayerById(this.game!, tooltipData.playerId)!
4145

4246
const paddingX = 2

client/src/services/typedapi/spectator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const inviteSpectators = (axios: Axios) => async (gameId: string, usernam
1313
}
1414

1515
export const uninviteSpectator = (axios: Axios) => async (gameId: string, userId: string): Promise<ResponseResult<{}>> => {
16-
return doPut(axios)(routes.uninviteSpectator, { gameId }, {}, {}, { withCredentials: true });
16+
return doPut(axios)(routes.uninviteSpectator, { gameId, userId }, {}, {}, { withCredentials: true });
1717
}
1818

1919
export const clearSpectators = (axios: Axios) => async (gameId: string): Promise<ResponseResult<{}>> => {

client/src/views/game/Create.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ export default {
989989
e.preventDefault();
990990
991991
const template = await import(`../../config/gamesettings/${this.settingsTemplateName}.json`);
992-
this.settings = template;
992+
this.settings = JSON.parse(JSON.stringify(template)); // deep clone
993993
},
994994
async handleSubmit (e) {
995995
e.preventDefault();

client/src/views/game/components/GameContainer.vue

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const polling = ref(0);
3636
const el: Ref<HTMLElement | null> = ref(null);
3737
3838
onMounted(() => {
39+
let unsubscribe;
40+
3941
createGameContainer(store, (msg) => toast.error(msg), eventBus).then((gameContainer) => {
4042
const checkPerformance = () => {
4143
const webGLSupport = gameContainer.checkPerformance();
@@ -100,7 +102,9 @@ onMounted(() => {
100102
emit("onObjectsClicked", objects);
101103
};
102104
103-
watch(computed(() => store.state.game), (newGame) => updateGame(newGame));
105+
const unwatch = watch(computed(() => store.state.game), (newGame) => {
106+
updateGame(newGame)
107+
}); // watcher is created async, so we have to do the cleanup ourselves
104108
105109
window.addEventListener('resize', handleResize)
106110
@@ -125,7 +129,11 @@ onMounted(() => {
125129
touchPlayer();
126130
}
127131
128-
onBeforeUnmount(() => {
132+
unsubscribe = () => {
133+
unwatch();
134+
135+
window.removeEventListener('resize', handleResize);
136+
129137
clearInterval(polling.value);
130138
131139
gameContainer.destroy();
@@ -136,7 +144,13 @@ onMounted(() => {
136144
eventBus.off(MapEventBusEventNames.MapOnCarrierRightClicked, onCarrierRightClickedHandler);
137145
eventBus.off(MapEventBusEventNames.MapOnWaypointCreated, onWaypointCreatedHandler);
138146
eventBus.off(MapEventBusEventNames.MapOnObjectsClicked, onObjectsClickedHandler);
139-
});
147+
};
148+
});
149+
150+
onBeforeUnmount(() => {
151+
if (unsubscribe) {
152+
unsubscribe();
153+
}
140154
});
141155
});
142156
</script>

client/src/views/game/components/carrier/CarrierWaypoints.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export default {
216216
this.recalculateTotalEta()
217217
this.recalculateLooped()
218218
},
219-
onWaypointOutOfRange ({ waypoint }) {
219+
onWaypointOutOfRange () {
220220
this.$toast.error(`This waypoint is out of hyperspace range.`)
221221
},
222222
recalculateTotalEta () {

client/src/views/game/components/spectators/InviteSpectator.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,14 @@ const handleSubmit = async e => {
7474
7575
if (isOk(response)) {
7676
toast.success(`You invited ${usernamesText} to spectate you in this game.`);
77-
78-
emit('onSpectatorsInvited');
79-
80-
usernames.value = '';
8177
} else {
8278
console.log(formatError(response));
8379
errors.value = extractErrors(response)
8480
}
8581
82+
usernames.value = '';
83+
emit('onSpectatorsInvited');
84+
8685
isLoading.value = false;
8786
}
8887
</script>

common/src/api/controllers/spectator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import {type GameSpectator} from "../types/common/game";
44
export const createSpectatorRoutes = <ID>() => ({
55
listSpectators: new GetRoute<{ gameId: string }, {}, GameSpectator<ID>[] | null>("/api/game/:gameId/spectators"),
66
inviteSpectators: new PutRoute<{ gameId: string }, {}, { usernames: string[] }, {}>("/api/game/:gameId/spectators/invite"),
7-
uninviteSpectator: new PutRoute<{ gameId: string }, {}, {}, {}>("/api/game/:gameId/spectators/uninvite/:userId"),
7+
uninviteSpectator: new PutRoute<{ gameId: string, userId: string }, {}, {}, {}>("/api/game/:gameId/spectators/uninvite/:userId"),
88
clearSpectators: new DeleteRoute<{ gameId: string }, {}, {}>("/api/game/:gameId/spectators"),
99
});

server/services/spectator.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Game, GameSpectator } from "./types/Game";
66
import { Player } from "./types/Player";
77
import UserService from "./user";
88
import {notNull} from "./utils";
9+
import {User} from "./types/User";
910

1011
export default class SpectatorService {
1112
gameRepo: Repository<Game>;
@@ -31,11 +32,29 @@ export default class SpectatorService {
3132
throw new ValidationError(`Spectating is not enabled in this game.`);
3233
}
3334

34-
const users = (await Promise.all(usernames.map(username => this.userService.getByUsername(username, { _id: 1 })))).filter(notNull);
35+
const requestUser = async (username: string): Promise<{ username: string, user: User | null }> => {
36+
const user = await this.userService.getByUsername(username, { _id: 1 });
37+
return {
38+
username,
39+
user
40+
};
41+
};
42+
43+
const attemptedUsers: { username: string, user: User | null }[] = await Promise.all(usernames.map((username) => requestUser(username)));
3544

36-
if (users.length !== usernames.length) {
37-
const missingUsernames = usernames.filter(username => !users.find(user => user.username === username));
38-
throw new ValidationError(`The following users do not exist: ${missingUsernames.join(', ')}`);
45+
const users: User[] = [];
46+
const missingUsernames: string[] = [];
47+
48+
for (const { username, user } of attemptedUsers) {
49+
if (user) {
50+
users.push(user);
51+
} else {
52+
missingUsernames.push(username);
53+
}
54+
}
55+
56+
if (!users.length) {
57+
throw new ValidationError(`No users found for the provided usernames: ${missingUsernames.join(', ')}`);
3958
}
4059

4160
await this.gameRepo.updateOne({
@@ -48,6 +67,10 @@ export default class SpectatorService {
4867
}
4968
}
5069
});
70+
71+
if (missingUsernames.length !== 0) {
72+
throw new ValidationError(`The following usernames were not found: ${missingUsernames.join(', ')}`);
73+
}
5174
}
5275

5376
async uninvite(game: Game, player: Player, userId: DBObjectId) {

0 commit comments

Comments
 (0)