Skip to content

Commit 36bd029

Browse files
Use results of 'instanceof' check expressions
1 parent a89d952 commit 36bd029

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

src/client/Main.ts

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,9 @@ class Client {
105105
gameVersion.innerText = version;
106106

107107
const newsModal = document.querySelector("news-modal") as NewsModal;
108-
if (!newsModal) {
108+
if (!newsModal || !(newsModal instanceof NewsModal)) {
109109
console.warn("News modal element not found");
110110
}
111-
newsModal instanceof NewsModal;
112111
const newsButton = document.querySelector("news-button") as NewsButton;
113112
if (!newsButton) {
114113
console.warn("News button element not found");
@@ -167,7 +166,9 @@ class Client {
167166
const spModal = document.querySelector(
168167
"single-player-modal",
169168
) as SinglePlayerModal;
170-
spModal instanceof SinglePlayerModal;
169+
if (!spModal || !(spModal instanceof SinglePlayerModal)) {
170+
console.warn("Singleplayer modal element not found");
171+
}
171172

172173
const singlePlayer = document.getElementById("single-player");
173174
if (singlePlayer === null) throw new Error("Missing single-player");
@@ -184,7 +185,9 @@ class Client {
184185
// });
185186

186187
const hlpModal = document.querySelector("help-modal") as HelpModal;
187-
hlpModal instanceof HelpModal;
188+
if (!hlpModal || !(hlpModal instanceof HelpModal)) {
189+
console.warn("Help modal element not found");
190+
}
188191
const helpButton = document.getElementById("help-button");
189192
if (helpButton === null) throw new Error("Missing help-button");
190193
helpButton.addEventListener("click", () => {
@@ -194,7 +197,10 @@ class Client {
194197
const flagInputModal = document.querySelector(
195198
"flag-input-modal",
196199
) as FlagInputModal;
197-
flagInputModal instanceof FlagInputModal;
200+
if (!flagInputModal || !(flagInputModal instanceof FlagInputModal)) {
201+
console.warn("Flag input modal element not found");
202+
}
203+
198204
const flgInput = document.getElementById("flag-input_");
199205
if (flgInput === null) throw new Error("Missing flag-input_");
200206
flgInput.addEventListener("click", () => {
@@ -204,10 +210,15 @@ class Client {
204210
this.patternsModal = document.querySelector(
205211
"territory-patterns-modal",
206212
) as TerritoryPatternsModal;
213+
if (
214+
!this.patternsModal ||
215+
!(this.patternsModal instanceof TerritoryPatternsModal)
216+
) {
217+
console.warn("Territory patterns modal element not found");
218+
}
207219
const patternButton = document.getElementById(
208220
"territory-patterns-input-preview-button",
209221
);
210-
this.patternsModal instanceof TerritoryPatternsModal;
211222
if (patternButton === null)
212223
throw new Error("territory-patterns-input-preview-button");
213224
this.patternsModal.previewButton = patternButton;
@@ -219,7 +230,12 @@ class Client {
219230
this.tokenLoginModal = document.querySelector(
220231
"token-login",
221232
) as TokenLoginModal;
222-
this.tokenLoginModal instanceof TokenLoginModal;
233+
if (
234+
!this.tokenLoginModal ||
235+
!(this.tokenLoginModal instanceof TokenLoginModal)
236+
) {
237+
console.warn("Token login modal element not found");
238+
}
223239

224240
const onUserMe = async (userMeResponse: UserMeResponse | false) => {
225241
document.dispatchEvent(
@@ -330,7 +346,9 @@ class Client {
330346
const settingsModal = document.querySelector(
331347
"user-setting",
332348
) as UserSettingModal;
333-
settingsModal instanceof UserSettingModal;
349+
if (!settingsModal || !(settingsModal instanceof UserSettingModal)) {
350+
console.warn("User settings modal element not found");
351+
}
334352
document
335353
.getElementById("settings-button")
336354
?.addEventListener("click", () => {
@@ -340,7 +358,9 @@ class Client {
340358
const hostModal = document.querySelector(
341359
"host-lobby-modal",
342360
) as HostPrivateLobbyModal;
343-
hostModal instanceof HostPrivateLobbyModal;
361+
if (!hostModal || !(hostModal instanceof HostPrivateLobbyModal)) {
362+
console.warn("Host private lobby modal element not found");
363+
}
344364
const hostLobbyButton = document.getElementById("host-lobby-button");
345365
if (hostLobbyButton === null) throw new Error("Missing host-lobby-button");
346366
hostLobbyButton.addEventListener("click", () => {
@@ -353,7 +373,9 @@ class Client {
353373
this.joinModal = document.querySelector(
354374
"join-private-lobby-modal",
355375
) as JoinPrivateLobbyModal;
356-
this.joinModal instanceof JoinPrivateLobbyModal;
376+
if (!this.joinModal || !(this.joinModal instanceof JoinPrivateLobbyModal)) {
377+
console.warn("Join private lobby modal element not found");
378+
}
357379
const joinPrivateLobbyButton = document.getElementById(
358380
"join-private-lobby-button",
359381
);
@@ -550,8 +572,9 @@ class Client {
550572
const startingModal = document.querySelector(
551573
"game-starting-modal",
552574
) as GameStartingModal;
553-
startingModal instanceof GameStartingModal;
554-
startingModal.show();
575+
if (startingModal && startingModal instanceof GameStartingModal) {
576+
startingModal.show();
577+
}
555578
},
556579
() => {
557580
this.joinModal.close();

0 commit comments

Comments
 (0)