diff --git a/src/app.ts b/src/app.ts index 92a1ad3..9406705 100644 --- a/src/app.ts +++ b/src/app.ts @@ -27,4 +27,4 @@ const config: Phaser.Types.Core.GameConfig = { scene: Scenes, } -new Phaser.Game(config) +const game = new Phaser.Game(config) // eslint-disable-line @typescript-eslint/no-unused-vars diff --git a/src/class/Band.ts b/src/class/Band.ts index 565aaf1..8d3fecc 100644 --- a/src/class/Band.ts +++ b/src/class/Band.ts @@ -1,5 +1,3 @@ -import bms from "bms" - export class Band { public startBeat: number public endBeat: number diff --git a/src/class/ChartPlayer.ts b/src/class/ChartPlayer.ts index d771d8a..e717c3a 100644 --- a/src/class/ChartPlayer.ts +++ b/src/class/ChartPlayer.ts @@ -101,23 +101,23 @@ export class ChartPlayer { let bandDisplaySizeX: number = 0 let positionX: number = 0 let visible: boolean = true - if (key == 4) { + if (key === 4) { if (laneIndex >= 1 && laneIndex <= 2) { positionX = 361 + 186 * (laneIndex - 1) } else if (laneIndex >= 4 && laneIndex <= 5) { positionX = 361 + 186 * (laneIndex - 2) } - } else if (key == 5) { + } else if (key === 5) { if (laneIndex >= 1 && laneIndex <= 5) { positionX = 343 + 148.5 * (laneIndex - 1) } - } else if (key == 6) { + } else if (key === 6) { if (laneIndex <= 2) { positionX = 330 + 124 * laneIndex } else if (laneIndex >= 4) { positionX = 330 + 124 * (laneIndex - 1) } - } else if (key == 7) { + } else if (key === 7) { positionX = 322 + 106 * laneIndex } if (playConfig.noteType === "rectangle") { @@ -128,10 +128,10 @@ export class ChartPlayer { displaySizeY = 40 bandDisplaySizeX = displaySizeX - if (laneIndex == 1 || laneIndex == 5) { + if (laneIndex === 1 || laneIndex === 5) { noteImage = "note-rectangle-2" longNoteImage = "longnote-2" - } else if (laneIndex == 3) { + } else if (laneIndex === 3) { noteImage = "note-rectangle-3" longNoteImage = "longnote-3" } else { @@ -164,7 +164,7 @@ export class ChartPlayer { bandDisplaySizeX = { 4: 185, 5: 147, 6: 120, 7: 103 }[key] } - if (isLongNoteEnd && isLatestEndLongNote[laneIndex] && beatLatestEndLongNote[laneIndex] != beat) { + if (isLongNoteEnd && isLatestEndLongNote[laneIndex] && beatLatestEndLongNote[laneIndex] !== beat) { isLatestEndLongNote[laneIndex] = false const band = new Band( @@ -208,7 +208,7 @@ export class ChartPlayer { } if (laneIndex >= 0 && laneIndex <= 7) { - if (!eachLinePositions.hasOwnProperty(beat)) { + if (!Object.prototype.hasOwnProperty.call(eachLinePositions, beat)) { eachLinePositions[beat] = [positionX, positionX] } eachLinePositions[beat][0] = Math.min(eachLinePositions[beat][0], positionX) @@ -259,7 +259,7 @@ export class ChartPlayer { playingSec: number, noteSpeed: number, keySoundPlayer: KeySoundPlayer, - ) { + ): void { for (const note of this.bgmLane) { if (note.sec < playingSec) { if (!note.isJudged) { @@ -324,7 +324,7 @@ export class ChartPlayer { this.judges[judgeIndex]++ this.combo++ for (const band of this.longNoteBands[laneIndex]) { - if (band.startBeat == note.beat) { + if (band.startBeat === note.beat) { band.image.visible = false break } @@ -390,7 +390,7 @@ export class ChartPlayer { return false } - public judgeKeyHold = (playingSec: number, laneIndex: number) => { + public judgeKeyHold = (playingSec: number, laneIndex: number): void => { this.isHolds[laneIndex] = false for (const note of this.lanes[laneIndex]) { if (!note.isJudged && note.isLongEnd) { @@ -415,7 +415,7 @@ export class ChartPlayer { this.latestJudgeSec = playingSec this.latestJudgeDiff = note.sec - playingSec for (const band of this.longNoteBands[laneIndex]) { - if (band.endBeat == note.beat) { + if (band.endBeat === note.beat) { band.image.visible = false break } diff --git a/src/class/DebugGUI.ts b/src/class/DebugGUI.ts index 6829f13..6490532 100644 --- a/src/class/DebugGUI.ts +++ b/src/class/DebugGUI.ts @@ -28,12 +28,12 @@ export class DebugGUI { sceneFolder.add(this.params, "result") } - public changeScene(key: string) { + public changeScene(key: string): void { this.destroy() this.scene.scene.start(key) } - public destroy() { + public destroy(): void { this.gui.destroy() } } diff --git a/src/class/JudgeMeter.ts b/src/class/JudgeMeter.ts index 3c6417a..686a0d2 100644 --- a/src/class/JudgeMeter.ts +++ b/src/class/JudgeMeter.ts @@ -14,7 +14,7 @@ export class JudgeMeter { this.rectangle = scene.add.rectangle(640 - deltaTime * 1200, 360, 1, 30, color).setDepth(20) } - public update() { + public update(): void { this.rectangle.setAlpha(1 - (new Date().getTime() - this.judgedTime) / 5000) } } diff --git a/src/class/KeySoundPlayer.ts b/src/class/KeySoundPlayer.ts index 1b94105..62a2c00 100644 --- a/src/class/KeySoundPlayer.ts +++ b/src/class/KeySoundPlayer.ts @@ -9,7 +9,7 @@ export class KeySoundPlayer { this.keySoundMap = bms.Keysounds.fromBMSChart(chart.bmsChart)._map } - public loadKeySounds(scene: Phaser.Scene, url: string) { + public loadKeySounds(scene: Phaser.Scene, url: string): void { Object.keys(this.keySoundMap).forEach((noteValue) => { const soundFileName = this.keySoundMap[noteValue] if (typeof soundFileName === "string") { @@ -29,7 +29,7 @@ export class KeySoundPlayer { }) } - public playKeySound(scene: Phaser.Scene, noteValue: string) { + public playKeySound(scene: Phaser.Scene, noteValue: string): void { if (this.keySoundSet.has(noteValue)) { scene.sound.play(noteValue) } diff --git a/src/class/MusicTile.ts b/src/class/MusicTile.ts index 5dfd94a..fbae519 100644 --- a/src/class/MusicTile.ts +++ b/src/class/MusicTile.ts @@ -74,19 +74,19 @@ export class MusicTile extends Phaser.GameObjects.Container { this.add(this.jacketImage) } - public setTitle(title: string) { + public setTitle(title: string): void { this.titleText.setText(title) } - public setArtist(artist: string) { + public setArtist(artist: string): void { this.artistText.setText(artist) } - public setNoter(noter: string) { + public setNoter(noter: string): void { this.noterText.setText(noter) } - public setMusic(music: Music) { + public setMusic(music: Music): void { this.titleText.setText(music.title) this.artistText.setText(music.artist) this.noterText.setText(music.noter) diff --git a/src/class/MusicTileManager.ts b/src/class/MusicTileManager.ts index e41f43c..29e5a6d 100644 --- a/src/class/MusicTileManager.ts +++ b/src/class/MusicTileManager.ts @@ -1,4 +1,4 @@ -import { type Music } from "./Music" +import { type Beatmap, type Music } from "./Music" import { MusicTile } from "./MusicTile" export class MusicTileManager { @@ -74,7 +74,7 @@ export class MusicTileManager { } } - public update(time: number) { + public update(time: number): void { for (const musicTileIndex of Array(7).keys()) { const musicTile = this.musicTiles[musicTileIndex] this.musicTiles[musicTileIndex].setAlpha(1 - (0.8 * Math.abs(musicTile.y - 315)) / 315) @@ -82,7 +82,7 @@ export class MusicTileManager { this.selectedMusicTile.setAlpha(0.5 + 0.5 * Math.abs(Math.sin((time * 2 * Math.PI * 0.25) / 1000))) } - public scroll(asc: boolean) { + public scroll(asc: boolean): void { if (asc) { this.scrollIndex = (this.scrollIndex + 1) % this.musicList.length for (const musicTileIndex of Array(7).keys()) { @@ -102,19 +102,19 @@ export class MusicTileManager { } } - public isPlayable(key: number, difficulty: number) { - return this.musicList[this.scrollIndex].hasOwnProperty(`beatmap_${key}k_${difficulty}`) + public isPlayable(key: number, difficulty: number): boolean { + return Object.prototype.hasOwnProperty.call(this.musicList[this.scrollIndex], `beatmap_${key}k_${difficulty}`) } - public getMusic() { + public getMusic(): Music { return this.musicList[this.scrollIndex] } - public getBeatmap(key: number, difficulty: number) { + public getBeatmap(key: number, difficulty: number): Beatmap { return this.musicList[this.scrollIndex][`beatmap_${key}k_${difficulty}`] } - public getJacketImageKey() { + public getJacketImageKey(): string { const selectedMusic = this.musicList[this.scrollIndex] return `jacket-${selectedMusic.folder}/${selectedMusic.jacket}` diff --git a/src/class/ToggleButton.ts b/src/class/ToggleButton.ts index 24eb624..ae964dd 100644 --- a/src/class/ToggleButton.ts +++ b/src/class/ToggleButton.ts @@ -43,7 +43,7 @@ export class ToggleButton extends Phaser.GameObjects.Container { this.add(this.rightZone) } - public setText(text: string) { + public setText(text: string): void { this.text.setText(text) } } diff --git a/src/class/User.ts b/src/class/User.ts index fa4054f..7770d8e 100644 --- a/src/class/User.ts +++ b/src/class/User.ts @@ -1,24 +1,24 @@ export class User { - public screen_name: string + public screenName: string public id: number public rank: number - public performance_point: number + public performancePoint: number constructor({ - screen_name, + screenName, id, rank, - performance_point, + performancePoint, }: { - screen_name: string + screenName: string id: number rank: number - performance_point: number + performancePoint: number }) { - this.screen_name = screen_name + this.screenName = screenName this.id = id this.rank = rank - this.performance_point = performance_point + this.performancePoint = performancePoint } get ordinalRank(): string { diff --git a/src/scene/ConfigScene.ts b/src/scene/ConfigScene.ts index ca4e220..daaf728 100644 --- a/src/scene/ConfigScene.ts +++ b/src/scene/ConfigScene.ts @@ -16,12 +16,12 @@ export class ConfigScene extends Phaser.Scene { super("config") } - init(data: any) { + init(data: any): void { this.playConfig = data.playConfig this.previewTimer = new Date() } - create() { + create(): void { const { width, height } = this.game.canvas this.add @@ -297,7 +297,7 @@ export class ConfigScene extends Phaser.Scene { }) } - update(time: number, dt: number) { + update(time: number, dt: number): void { if (this.playConfig.noteType === "circle") { this.previewNote.setTexture("note-circle-1").setDisplaySize(100, 100) } else if (this.playConfig.noteType === "rectangle") { diff --git a/src/scene/CreditScene.ts b/src/scene/CreditScene.ts index 8b8817a..5c66b48 100644 --- a/src/scene/CreditScene.ts +++ b/src/scene/CreditScene.ts @@ -3,9 +3,9 @@ export class CreditScene extends Phaser.Scene { super("credit") } - init() {} + init(): void {} - create() { + create(): void { const { width, height } = this.game.canvas this.add @@ -56,7 +56,8 @@ export class CreditScene extends Phaser.Scene { "", ] - const rightCredits = (process.env.CREDITS || "").split(/\\r\\n|\\n|\\r/) + const credits = process.env.CREDITS + const rightCredits = credits !== undefined && credits !== "" ? credits.split(/\\r\\n|\\n|\\r/) : [] const headerText = this.add .text(width / 2 - 260, height / 2 - 200 - 5, "RICORA Beats", { diff --git a/src/scene/LoadingScene.ts b/src/scene/LoadingScene.ts index abba6f1..60f7591 100644 --- a/src/scene/LoadingScene.ts +++ b/src/scene/LoadingScene.ts @@ -8,7 +8,7 @@ export class LoadingScene extends Phaser.Scene { super("loading") } - preload() { + preload(): void { this.load.image("logo", "./assets/skin/logo.png") this.load.image("frame-title", "./assets/skin/frame_title.png") @@ -144,13 +144,11 @@ export class LoadingScene extends Phaser.Scene { }) } - create() { - const { width, height } = this.game.canvas - + create(): void { this.add.text(0, 0, "Loading...").setDepth(1) // Web Font Loaderのロード完了判定がうまく動かないので選曲シーンで使用する文字を予め強制的に読み込む - new MusicTileManager(this, 0) + const musicTileManager = new MusicTileManager(this, 0) // eslint-disable-line @typescript-eslint/no-unused-vars this.add.rectangle(640, 360, 1280, 720, 0x000000).setDepth(0) this.load.on("complete", () => { @@ -160,7 +158,7 @@ export class LoadingScene extends Phaser.Scene { this.load.start() } - update() { + update(): void { if (this.hasLoadedFont && this.hasLoadedPhaser) { this.scene.start("title") } diff --git a/src/scene/LoginScene.ts b/src/scene/LoginScene.ts index b9162bd..940024b 100644 --- a/src/scene/LoginScene.ts +++ b/src/scene/LoginScene.ts @@ -10,9 +10,9 @@ export class LoginScene extends Phaser.Scene { super("login") } - init() {} + init(): void {} - create() { + create(): void { const { width, height } = this.game.canvas this.add @@ -39,68 +39,74 @@ export class LoginScene extends Phaser.Scene { .setAlpha(0) const loginFormElement = document.getElementById("login-form")?.getElementsByTagName("form")[0] - if (loginFormElement) { - loginFormElement.addEventListener("submit", async (event) => { + if (loginFormElement !== undefined) { + loginFormElement.addEventListener("submit", (event) => { event.preventDefault() - const formData = new FormData(loginFormElement) - const tokenResponse = await retryFetch(new URL("/token", process.env.SERVER_URL).toString(), { - method: "POST", - body: formData, - }) - if (tokenResponse.ok) { - const tokenResponseJSON = await tokenResponse.json() - localStorage.setItem("access_token", tokenResponseJSON.access_token) - localStorage.setItem("token_type", tokenResponseJSON.token_type) - - const userResponse = await retryFetch(new URL("/users/me", process.env.SERVER_URL).toString(), { - headers: { - "Content-Type": "application/json", - Authorization: `${tokenResponseJSON.token_type} ${tokenResponseJSON.access_token}`, - }, - }) - if (userResponse.ok) { - const userResponseJSON = await userResponse.json() - const user = new User({ - id: userResponseJSON.id, - screen_name: userResponseJSON.screen_name, - rank: userResponseJSON.rank, - performance_point: userResponseJSON.performance_point, - }) - localStorage.setItem("user", JSON.stringify(user)) - this.sound.play("decide") - window.setTimeout(() => { - this.scene.start("select") - }, 400) - } - } else if (tokenResponse.status === 401) { - const tokenResponseJSON = await tokenResponse.json() - alert(tokenResponseJSON.detail) - } + void submitLoginForm(event) }) } + const submitLoginForm = async (event: SubmitEvent): Promise => { + const formData = new FormData(loginFormElement) + const tokenResponse = await retryFetch(new URL("/token", process.env.SERVER_URL).toString(), { + method: "POST", + body: formData, + }) + if (tokenResponse.ok) { + const tokenResponseJSON = await tokenResponse.json() + localStorage.setItem("access_token", tokenResponseJSON.access_token) + localStorage.setItem("token_type", tokenResponseJSON.token_type) - const registerFormElement = document.getElementById("register-form")?.getElementsByTagName("form")[0] - if (registerFormElement) { - registerFormElement.addEventListener("submit", async (event) => { - event.preventDefault() - const formData = new FormData(registerFormElement) - const registerResponse = await retryFetch(new URL("/users/", process.env.SERVER_URL).toString(), { - method: "POST", + const userResponse = await retryFetch(new URL("/users/me", process.env.SERVER_URL).toString(), { headers: { "Content-Type": "application/json", + Authorization: `${tokenResponseJSON.token_type} ${tokenResponseJSON.access_token}`, }, - body: JSON.stringify(Object.fromEntries(formData)), }) - if (registerResponse.ok) { - const registerResponseJSON = await registerResponse.json() - alert( - `アカウントを作成しました。\nuser id: ${registerResponseJSON.id}\nscreen name: ${registerResponseJSON.screen_name}`, - ) - } else if (registerResponse.status === 400) { - const registerResponseJSON = await registerResponse.json() - alert(registerResponseJSON.detail) + if (userResponse.ok) { + const userResponseJSON = await userResponse.json() + const user = new User({ + id: userResponseJSON.id, + screenName: userResponseJSON.screen_name, + rank: userResponseJSON.rank, + performancePoint: userResponseJSON.performance_point, + }) + localStorage.setItem("user", JSON.stringify(user)) + this.sound.play("decide") + window.setTimeout(() => { + this.scene.start("select") + }, 400) } + } else if (tokenResponse.status === 401) { + const tokenResponseJSON = await tokenResponse.json() + alert(tokenResponseJSON.detail) + } + } + + const registerFormElement = document.getElementById("register-form")?.getElementsByTagName("form")[0] + if (registerFormElement !== undefined) { + registerFormElement.addEventListener("submit", (event) => { + event.preventDefault() + void submitRegistrationForm(event) + }) + } + const submitRegistrationForm = async (event: SubmitEvent): Promise => { + const formData = new FormData(registerFormElement) + const registerResponse = await retryFetch(new URL("/users/", process.env.SERVER_URL).toString(), { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(Object.fromEntries(formData)), }) + if (registerResponse.ok) { + const registerResponseJSON = await registerResponse.json() + alert( + `アカウントを作成しました。\nuser id: ${registerResponseJSON.id}\nscreen name: ${registerResponseJSON.screen_name}`, + ) + } else if (registerResponse.status === 400) { + const registerResponseJSON = await registerResponse.json() + alert(registerResponseJSON.detail) + } } const icon = this.add @@ -271,9 +277,9 @@ export class LoginScene extends Phaser.Scene { }) } - update(time: number, dt: number) { + update(time: number, dt: number): void { const loginFormElement = document.getElementById("login-form")?.parentElement?.parentElement - if (loginFormElement && loginFormElement.style.transformOrigin !== "") { + if (loginFormElement !== null && loginFormElement !== undefined && loginFormElement.style.transformOrigin !== "") { loginFormElement.style.transformOrigin = "" } } diff --git a/src/scene/PlayScene.ts b/src/scene/PlayScene.ts index ea18f7d..8f58bcc 100644 --- a/src/scene/PlayScene.ts +++ b/src/scene/PlayScene.ts @@ -89,7 +89,7 @@ export class PlayScene extends Phaser.Scene { super("play") } - init(data: any) { + init(data: any): void { this.debugGUI = new DebugGUI(this) this.loadEndTime = undefined @@ -130,10 +130,9 @@ export class PlayScene extends Phaser.Scene { this.playConfig = data.playConfig } - preload() {} + preload(): void {} - create() { - const urlParams = new URLSearchParams(document.location.search.substring(1)) + create(): void { const url = `./assets/beatmaps/${this.music.folder}/${this.beatmap.filename}` const { width, height } = this.game.canvas @@ -283,23 +282,23 @@ export class PlayScene extends Phaser.Scene { let positionX = -1280 const widths = { 4: 186, 5: 148.5, 6: 124, 7: 106 } - if (this.playConfig.key == 4) { + if (this.playConfig.key === 4) { if (laneIndex >= 1 && laneIndex <= 2) { positionX = 361 + 186 * (laneIndex - 1) } else if (laneIndex >= 4 && laneIndex <= 5) { positionX = 361 + 186 * (laneIndex - 2) } - } else if (this.playConfig.key == 5) { + } else if (this.playConfig.key === 5) { if (laneIndex >= 1 && laneIndex <= 5) { positionX = 343 + 148.5 * (laneIndex - 1) } - } else if (this.playConfig.key == 6) { + } else if (this.playConfig.key === 6) { if (laneIndex <= 2) { positionX = 330 + 124 * laneIndex } else if (laneIndex >= 4) { positionX = 330 + 124 * (laneIndex - 1) } - } else if (this.playConfig.key == 7) { + } else if (this.playConfig.key === 7) { positionX = 322 + 106 * laneIndex } this.keyFlashImages.push( @@ -544,7 +543,7 @@ export class PlayScene extends Phaser.Scene { }) } - update(time: number, dt: number) { + update(time: number, dt: number): void { this.laneMainFrameLight.setAlpha( 1 - 0.6 * ((this.beat % 1) % 1), // 0.95 + 0.6 * (-this.beat - Math.floor(1 - this.beat)) ) @@ -592,8 +591,8 @@ export class PlayScene extends Phaser.Scene { } } // change back light - if (this.chartPlayer.judges[3] == 0 && this.chartPlayer.judges[4] == 0) { - if (this.chartPlayer.judges[1] == 0 && this.chartPlayer.judges[2] == 0) { + if (this.chartPlayer.judges[3] === 0 && this.chartPlayer.judges[4] === 0) { + if (this.chartPlayer.judges[1] === 0 && this.chartPlayer.judges[2] === 0) { this.laneBackgroundLight.setTexture("frame-back-light-yellow") } else { this.laneBackgroundLight.setTexture("frame-back-light-blue") @@ -662,7 +661,7 @@ export class PlayScene extends Phaser.Scene { } } - private judgeKeyDown(laneIndex: number) { + private judgeKeyDown(laneIndex: number): void { if (this.chartPlayer !== undefined) { if (this.chartPlayer.judgeKeyDown(this, this.playingSec, laneIndex, this.keySoundPlayer)) { if (this.chartPlayer.latestJudgeIndex <= 2) { @@ -672,25 +671,25 @@ export class PlayScene extends Phaser.Scene { } } - private addBomb(laneIndex: number) { + private addBomb(laneIndex: number): void { let positionX = -1200 - if (this.playConfig.key == 4) { + if (this.playConfig.key === 4) { if (laneIndex >= 1 && laneIndex <= 2) { positionX = 361 + 186 * (laneIndex - 1) } else if (laneIndex >= 4 && laneIndex <= 5) { positionX = 361 + 186 * (laneIndex - 2) } - } else if (this.playConfig.key == 5) { + } else if (this.playConfig.key === 5) { if (laneIndex >= 1 && laneIndex <= 5) { positionX = 343 + 148.5 * (laneIndex - 1) } - } else if (this.playConfig.key == 6) { + } else if (this.playConfig.key === 6) { if (laneIndex <= 2) { positionX = 330 + 124 * laneIndex } else if (laneIndex >= 4) { positionX = 330 + 124 * (laneIndex - 1) } - } else if (this.playConfig.key == 7) { + } else if (this.playConfig.key === 7) { positionX = 322 + 106 * laneIndex } this.tweens.add({ diff --git a/src/scene/ResultScene.ts b/src/scene/ResultScene.ts index e94f799..6af136c 100644 --- a/src/scene/ResultScene.ts +++ b/src/scene/ResultScene.ts @@ -60,14 +60,14 @@ export class ResultScene extends Phaser.Scene { super("result") } - init(data: any) { + init(data: any): void { this.debugGUI = new DebugGUI(this) this.events.on(Phaser.Scenes.Events.TRANSITION_OUT, () => { this.debugGUI.destroy() }) this.playResult = - data.playResult || + data.playResult ?? new PlayResult({ music: { title: "test", @@ -105,7 +105,7 @@ export class ResultScene extends Phaser.Scene { JSON.stringify(this.playResult), ) } - const getRanking = async (userId?: number) => { + const getRanking = async (userId?: number): Promise => { const folder = this.playResult.music.folder const filename = this.playResult.music[`beatmap_${this.playResult.playConfig.key}k_${this.playResult.playConfig.difficulty}`] @@ -133,7 +133,7 @@ export class ResultScene extends Phaser.Scene { ranking.sort((a: any, b: any) => { return a.score < b.score ? 1 : -1 }) - if (userId) { + if (userId !== undefined) { let rank: number | undefined for (const [rankingIndex, score] of ranking.entries()) { if (score.player_id === userId) { @@ -183,18 +183,18 @@ export class ResultScene extends Phaser.Scene { }) } } - const sendScore = async () => { - const token_type = localStorage.getItem("token_type") - const access_token = localStorage.getItem("access_token") + const sendScore = async (): Promise => { + const tokenType = localStorage.getItem("token_type") + const accessToken = localStorage.getItem("access_token") - if (!token_type || !access_token) { + if (tokenType === null || accessToken === null) { await getRanking() return } const headers = { "Content-Type": "application/json", - Authorization: `${token_type} ${access_token}`, + Authorization: `${tokenType} ${accessToken}`, } const userResponse = await retryFetch(new URL("/users/me", process.env.SERVER_URL).toString(), { @@ -233,10 +233,10 @@ export class ResultScene extends Phaser.Scene { } await getRanking(user.id) } - sendScore() + void sendScore() } - create() { + create(): void { const { width, height } = this.game.canvas this.backgroundCamera = this.cameras.add(0, 0, 1280, 720) @@ -244,7 +244,7 @@ export class ResultScene extends Phaser.Scene { this.cameras.add(0, 0, 1280, 720, true) this.add.shader("background", width / 2 + 1280, height / 2 + 720, 1280, 720).setDepth(-5) - // @ts-expect-error + // @ts-expect-error: 型が不明なため this.plugins.get("rexKawaseBlurPipeline").add(this.backgroundCamera, { blur: 8, quality: 8, @@ -643,7 +643,7 @@ export class ResultScene extends Phaser.Scene { useHandCursor: true, }) .on("pointerdown", () => { - ;(async () => { + void (async () => { this.sound.play("decide") this.tweetButton.setAlpha(0.5) this.copySnapshot() @@ -703,7 +703,7 @@ export class ResultScene extends Phaser.Scene { this.cameras.main.fadeIn(500) } - update(time: number, dt: number) { + update(time: number, dt: number): void { this.particleEmitter.particleX = this.input.x this.particleEmitter.particleY = this.input.y switch (Math.floor(time / 40) % 4) { @@ -722,7 +722,7 @@ export class ResultScene extends Phaser.Scene { } } - private copySnapshot() { + private copySnapshot(): void { this.renderer.snapshot((image: HTMLImageElement | Phaser.Display.Color) => { if (image instanceof HTMLImageElement) { const base64ToBlob = (base64Data: string): Blob => { @@ -742,7 +742,7 @@ export class ResultScene extends Phaser.Scene { return new Blob(byteArrays, { type: contentType }) } - navigator.clipboard.write([ + void navigator.clipboard.write([ new ClipboardItem({ "image/png": base64ToBlob(image.src.replace("data:image/png;base64,", "")), } as any), diff --git a/src/scene/SelectScene.ts b/src/scene/SelectScene.ts index 29c93ca..adcf6b6 100644 --- a/src/scene/SelectScene.ts +++ b/src/scene/SelectScene.ts @@ -62,7 +62,7 @@ export class SelectScene extends Phaser.Scene { this.scrollIndex = 0 } - init(data: any) { + init(data: any): void { this.debugGUI = new DebugGUI(this) this.events.on(Phaser.Scenes.Events.TRANSITION_OUT, () => { this.debugGUI.destroy() @@ -78,8 +78,8 @@ export class SelectScene extends Phaser.Scene { localStoragePlayConfigJSON = JSON.parse(localStoragePlayConfig) } this.playConfig = - data.playConfig || - localStoragePlayConfigJSON || + data.playConfig ?? + localStoragePlayConfigJSON ?? new PlayConfig({ noteSpeed: 3.0, noteType: "circle", @@ -91,19 +91,19 @@ export class SelectScene extends Phaser.Scene { this.user = new User({ id: 0, - screen_name: "Guest", + screenName: "Guest", rank: 0, - performance_point: 0, + performancePoint: 0, }) - const checkAuthorization = async () => { - const token_type = localStorage.getItem("token_type") - const access_token = localStorage.getItem("access_token") + const checkAuthorization = async (): Promise => { + const tokenType = localStorage.getItem("token_type") + const accessToken = localStorage.getItem("access_token") - if (token_type && access_token) { + if (tokenType !== null && accessToken !== null) { const headers = { "Content-Type": "application/json", - Authorization: `${token_type} ${access_token}`, + Authorization: `${tokenType} ${accessToken}`, } const userResponse = await retryFetch(new URL("/users/me", process.env.SERVER_URL).toString(), { headers, @@ -112,9 +112,9 @@ export class SelectScene extends Phaser.Scene { const user = await userResponse.json() this.user = new User({ id: user.id, - screen_name: user.screen_name, + screenName: user.screen_name, rank: user.rank, - performance_point: user.performance_point, + performancePoint: user.performance_point, }) localStorage.setItem("user", JSON.stringify(user)) @@ -124,15 +124,15 @@ export class SelectScene extends Phaser.Scene { } }) this.loginLabel.setText("IRサイトを開く") - this.userScreenNameText.setText(`${this.user.screen_name}`) - this.userStatusText.setText(`${this.user.ordinalRank} / ${this.user.performance_point}pts.`) + this.userScreenNameText.setText(`${this.user.screenName}`) + this.userStatusText.setText(`${this.user.ordinalRank} / ${this.user.performancePoint}pts.`) } } } - checkAuthorization() + void checkAuthorization() } - create() { + create(): void { const { width, height } = this.game.canvas this.backgroundCamera = this.cameras.add(0, 0, 1280, 720) @@ -140,7 +140,7 @@ export class SelectScene extends Phaser.Scene { this.cameras.add(0, 0, 1280, 720, true) this.add.shader("background", width / 2 + 1280, height / 2 + 720, 1280, 720).setDepth(-5) - // @ts-expect-error + // @ts-expect-error: 型が不明なため this.plugins.get("rexKawaseBlurPipeline").add(this.backgroundCamera, { blur: 8, quality: 8, @@ -253,7 +253,7 @@ export class SelectScene extends Phaser.Scene { this.add .image(80 + 180 * diffIndex, 50, `diff-icon-${diffIndex + 1}`) .setOrigin(0, 0) - .setAlpha(diffIndex == this.difficulty - 1 ? 1 : 0.3) + .setAlpha(diffIndex === this.difficulty - 1 ? 1 : 0.3) .setDepth(10), ) } @@ -267,9 +267,9 @@ export class SelectScene extends Phaser.Scene { this.difficulty = (diffIndex + 1) as DIFFICULTY this.selectedDiffIcon.setTexture(`diff-icon-${diffIndex + 1}`) for (const diffIndex of Array(4).keys()) { - this.diffButtons[diffIndex].setAlpha(diffIndex == this.difficulty - 1 ? 1 : 0.3) + this.diffButtons[diffIndex].setAlpha(diffIndex === this.difficulty - 1 ? 1 : 0.3) } - this.getRanking() + void this.getRanking() }) } @@ -279,7 +279,7 @@ export class SelectScene extends Phaser.Scene { this.add .image(80 + 180 * keyIndex, 670, `key-icon-${keyIndex + 4}`) .setOrigin(0, 0) - .setAlpha(keyIndex == this.key - 4 ? 1 : 0.3) + .setAlpha(keyIndex === this.key - 4 ? 1 : 0.3) .setDepth(10), ) } @@ -293,9 +293,9 @@ export class SelectScene extends Phaser.Scene { this.key = (keyIndex + 4) as KEY this.selectedKeyIcon.setTexture(`key-icon-${keyIndex + 4}`) for (const keyIndex of Array(4).keys()) { - this.keyButtons[keyIndex].setAlpha(keyIndex == this.key - 4 ? 1 : 0.3) + this.keyButtons[keyIndex].setAlpha(keyIndex === this.key - 4 ? 1 : 0.3) } - this.getRanking() + void this.getRanking() }) } @@ -503,7 +503,7 @@ export class SelectScene extends Phaser.Scene { fullScreenButton.setAlpha(0.5) }) - const ascScrollZone = this.add + this.add .zone(100, 100, 570, 200) .setOrigin(0, 0) .setInteractive({ @@ -532,12 +532,12 @@ export class SelectScene extends Phaser.Scene { ((2 * this.musicTileManager.scrollIndex) / Math.max(this.musicTileManager.musicList.length - 1, 1) - 1), ) - this.getRanking() + void this.getRanking() }, }) this.playPreviewSound() }) - const descScrollZone = this.add + this.add .zone(100, 620, 570, 200) .setOrigin(0, 1) .setInteractive({ @@ -566,7 +566,7 @@ export class SelectScene extends Phaser.Scene { ((2 * this.musicTileManager.scrollIndex) / Math.max(this.musicTileManager.musicList.length - 1, 1) - 1), ) - this.getRanking() + void this.getRanking() }, }) this.playPreviewSound() @@ -629,10 +629,10 @@ export class SelectScene extends Phaser.Scene { }) this.cameras.main.fadeIn(500) this.playPreviewSound() - this.getRanking() + void this.getRanking() } - update(time: number, dt: number) { + update(time: number, dt: number): void { this.musicTileManager.update(time) this.particleEmitter.particleX = this.input.x @@ -642,12 +642,12 @@ export class SelectScene extends Phaser.Scene { this.isPlayable = this.musicTileManager.isPlayable(this.key, this.difficulty) if (this.isPlayable) { - if (this.playButton.alpha == 0.3) { + if (this.playButton.alpha === 0.3) { this.playButton.setAlpha(0.8) } this.playButton.setTexture("play-button-enable") this.nonPlayableText.setVisible(false) - this.beatmapLevelText.setText(this.musicTileManager.getBeatmap(this.key, this.difficulty).playlevel) + this.beatmapLevelText.setText(`${this.musicTileManager.getBeatmap(this.key, this.difficulty).playlevel}`) this.playButtonLight.setAlpha(0.2 + 0.8 * Math.abs(Math.sin((time * 2 * Math.PI * 0.25) / 1000))) } else { this.playButton.setTexture("play-button-disable").setAlpha(0.3) @@ -673,7 +673,7 @@ export class SelectScene extends Phaser.Scene { } } - private playPreviewSound() { + private playPreviewSound(): void { const music = this.musicList[this.musicTileManager.scrollIndex] const soundKey = `preview-${music.folder}/${music.preview}` if (this.cache.audio.exists(soundKey)) { @@ -681,7 +681,7 @@ export class SelectScene extends Phaser.Scene { } } - private stopPreviewSound() { + private stopPreviewSound(): void { const music = this.musicList[this.musicTileManager.scrollIndex] const soundKey = `preview-${music.folder}/${music.preview}` if (this.cache.audio.exists(soundKey)) { diff --git a/src/scene/TitleScene.ts b/src/scene/TitleScene.ts index 2273ef4..8f7f8af 100644 --- a/src/scene/TitleScene.ts +++ b/src/scene/TitleScene.ts @@ -17,14 +17,14 @@ export class TitleScene extends Phaser.Scene { super("title") } - init() { + init(): void { this.debugGUI = new DebugGUI(this) this.events.on(Phaser.Scenes.Events.TRANSITION_OUT, () => { this.debugGUI.destroy() }) } - preload() { + preload(): void { const musicList = this.cache.json.get("music-list") for (const music of musicList) { @@ -40,7 +40,7 @@ export class TitleScene extends Phaser.Scene { } } - create() { + create(): void { const { width, height } = this.game.canvas this.backgroundCamera = this.cameras.add(0, 0, 1280, 720) @@ -48,7 +48,7 @@ export class TitleScene extends Phaser.Scene { this.cameras.add(0, 0, 1280, 720, true) this.add.shader("background", width / 2 + 1280, height / 2 + 720, 1280, 720).setDepth(-5) - // @ts-expect-error + // @ts-expect-error: 型が不明なため this.plugins.get("rexKawaseBlurPipeline").add(this.backgroundCamera, { blur: 8, quality: 8, @@ -148,7 +148,7 @@ export class TitleScene extends Phaser.Scene { align: "center", }) .setVisible(false) - this.getAllUserNames() + void this.getAllUserNames() this.add .zone(640, 720, 1280, 640) @@ -166,7 +166,7 @@ export class TitleScene extends Phaser.Scene { this.cameras.main.fadeIn(500) if ( - navigator.userAgent.match(/iPhone|Android.+Mobile/) && + navigator.userAgent.match(/iPhone|Android.+Mobile/) !== null && !window.matchMedia("(display-mode: fullscreen)").matches ) { alert( @@ -175,7 +175,7 @@ export class TitleScene extends Phaser.Scene { } } - update(time: number, dt: number) { + update(time: number, dt: number): void { this.particleEmitter.particleX = this.input.x this.particleEmitter.particleY = this.input.y