Skip to content

Commit

Permalink
⚙ ESLintを整備 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
3w36zj6 authored Nov 8, 2023
1 parent aeda32f commit e6eb70c
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 179 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type {import("eslint").ESLint.ConfigData} */
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: ["standard-with-typescript", "prettier"],
overrides: [],
parserOptions: {
sourceType: "module",
},
rules: {},
}
Binary file modified bun.lockb
Binary file not shown.
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@
"build": "webpack --mode=development",
"dev": "webpack-dev-server --mode=development",
"format": "prettier --write './**/*.{js,ts,json,yaml,yml,md,html,css,scss}' --ignore-path '.gitignore'",
"format:check": "prettier --check './**/*.{js,ts,json,yaml,yml,md,html,css,scss}' --ignore-path '.gitignore'"
"format:check": "prettier --check './**/*.{js,ts,json,yaml,yml,md,html,css,scss}' --ignore-path '.gitignore'",
"lint": "eslint './src/**/*.ts' --ignore-path '.gitignore'",
"lint:fix": "eslint --fix './src/**/*.ts' --ignore-path '.gitignore'"
},
"keywords": [],
"author": "",
"devDependencies": {
"@types/webfontloader": "^1.6.34",
"@typescript-eslint/eslint-plugin": "^6.10.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint-config-standard-with-typescript": "^39.1.1",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-n": "^16.3.0",
"eslint-plugin-promise": "^6.1.1",
"phaser": "^3.55.2",
"prettier": "^3.0.3",
"ts-loader": "^8.0.11",
"typescript": "^4.1.2",
"ts-loader": "^9.5.0",
"typescript": "^5.2.2",
"webpack": "^5.0.0-rc.6",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.8.1"
Expand Down
33 changes: 17 additions & 16 deletions src/class/ChartPlayer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Chart } from "./Chart"
import { KeySoundPlayer } from "./KeySoundPlayer"
import { type Chart } from "./Chart"
import { type KeySoundPlayer } from "./KeySoundPlayer"
import { Note } from "./Note"
import { Band } from "./Band"
import { Measure } from "./Measure"
import { JudgeMeter } from "./JudgeMeter"

import { PlayConfig } from "./PlayConfig"
import { type PlayConfig } from "./PlayConfig"

import bms from "bms"

Expand All @@ -14,7 +14,7 @@ export class ChartPlayer {
public lanes: Note[][] = []
public bgmLane: Note[] = []
public measures: Measure[] = []
public longNoteBands: Band[][] = new Array()
public longNoteBands: Band[][] = []

public isHolds = new Array<boolean>(7).fill(false)

Expand All @@ -36,11 +36,11 @@ export class ChartPlayer {

constructor(scene: Phaser.Scene, chart: Chart, key: Key, playConfig: PlayConfig) {
for (const laneIndex of Array(7).keys()) {
this.lanes[laneIndex] = new Array()
this.longNoteBands[laneIndex] = new Array()
this.lanes[laneIndex] = []
this.longNoteBands[laneIndex] = []
}

const replacementNormalNote: { [key: number]: number } = {
const replacementNormalNote: Record<number, number> = {
11: 0,
12: 1,
13: 2,
Expand All @@ -50,7 +50,7 @@ export class ChartPlayer {
19: 6,
}

const replacementLongNote: { [key: number]: number } = {
const replacementLongNote: Record<number, number> = {
51: 0,
52: 1,
53: 2,
Expand All @@ -60,12 +60,12 @@ export class ChartPlayer {
59: 6,
}

let isLatestEndLongNote: boolean[] = new Array<boolean>(7).fill(false)
let beatLatestEndLongNote: number[] = new Array<number>(7).fill(-1)
const isLatestEndLongNote: boolean[] = new Array<boolean>(7).fill(false)
const beatLatestEndLongNote: number[] = new Array<number>(7).fill(-1)

for (const object of chart.bmsChart.objects._objects) {
let laneIndex: number = replacementNormalNote[parseInt(object.channel)]
let noteValue: number = parseInt(object.value, 36)
const noteValue: number = parseInt(object.value, 36)
let isLongNoteStart: boolean = false
let isLongNoteEnd: boolean = false
let isBGM: boolean = false
Expand Down Expand Up @@ -94,19 +94,19 @@ export class ChartPlayer {
let positionX: number = 0
let visible: boolean = true
if (key == 4) {
if (1 <= laneIndex && laneIndex <= 2) {
if (laneIndex >= 1 && laneIndex <= 2) {
positionX = 361 + 186 * (laneIndex - 1)
} else if (4 <= laneIndex && laneIndex <= 5) {
} else if (laneIndex >= 4 && laneIndex <= 5) {
positionX = 361 + 186 * (laneIndex - 2)
}
} else if (key == 5) {
if (1 <= laneIndex && laneIndex <= 5) {
if (laneIndex >= 1 && laneIndex <= 5) {
positionX = 343 + 148.5 * (laneIndex - 1)
}
} else if (key == 6) {
if (laneIndex <= 2) {
positionX = 330 + 124 * laneIndex
} else if (4 <= laneIndex) {
} else if (laneIndex >= 4) {
positionX = 330 + 124 * (laneIndex - 1)
}
} else if (key == 7) {
Expand Down Expand Up @@ -177,7 +177,7 @@ export class ChartPlayer {

if (isBGM) {
this.bgmLane.push(note)
} else if (0 <= laneIndex && laneIndex <= 7) {
} else if (laneIndex >= 0 && laneIndex <= 7) {
this.lanes[laneIndex].push(note)
this.lastBeat = Math.max(this.lastBeat, beat)
}
Expand Down Expand Up @@ -360,6 +360,7 @@ export class ChartPlayer {
}
}
}

public hasFinished(beat: number): boolean {
return beat > this.lastBeat
}
Expand Down
2 changes: 1 addition & 1 deletion src/class/JudgeMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class JudgeMeter {
this.judgedTime = new Date().getTime()

let color = 0xffffff
if (18 <= deltaTime * 1000) {
if (deltaTime * 1000 >= 18) {
color = 0x2fdfe2
} else if (deltaTime * 1000 <= -18) {
color = 0xe530e5
Expand Down
7 changes: 4 additions & 3 deletions src/class/KeySoundPlayer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import bms from "bms"
import { Chart } from "./Chart"
import { type Chart } from "./Chart"

export class KeySoundPlayer {
private keySoundSet = new Set<string>()
private keySoundMap
private readonly keySoundSet = new Set<string>()
private readonly keySoundMap

constructor(chart: Chart) {
this.keySoundMap = bms.Keysounds.fromBMSChart(chart.bmsChart)._map
}

public loadKeySounds(scene: Phaser.Scene, url: string) {
Object.keys(this.keySoundMap).forEach((noteValue) => {
const soundFileName = this.keySoundMap[noteValue]
Expand Down
19 changes: 10 additions & 9 deletions src/class/MusicTile.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Music } from "./Music"
import { type Music } from "./Music"

export class MusicTile extends Phaser.GameObjects.Container {
private frame: Phaser.GameObjects.Image
private titleText: Phaser.GameObjects.Text
private titleIcon: Phaser.GameObjects.Image
private artistText: Phaser.GameObjects.Text
private artistIcon: Phaser.GameObjects.Image
private noterText: Phaser.GameObjects.Text
private noterIcon: Phaser.GameObjects.Image
private jacketImage: Phaser.GameObjects.Image
private readonly frame: Phaser.GameObjects.Image
private readonly titleText: Phaser.GameObjects.Text
private readonly titleIcon: Phaser.GameObjects.Image
private readonly artistText: Phaser.GameObjects.Text
private readonly artistIcon: Phaser.GameObjects.Image
private readonly noterText: Phaser.GameObjects.Text
private readonly noterIcon: Phaser.GameObjects.Image
private readonly jacketImage: Phaser.GameObjects.Image

constructor(public scene: Phaser.Scene) {
// Phaser.GameObjects.Container
Expand Down Expand Up @@ -81,6 +81,7 @@ export class MusicTile extends Phaser.GameObjects.Container {
public setArtist(artist: string) {
this.artistText.setText(artist)
}

public setNoter(noter: string) {
this.noterText.setText(noter)
}
Expand Down
12 changes: 7 additions & 5 deletions src/class/MusicTileManager.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Music, Beatmap } from "./Music"
import { type Music, Beatmap } from "./Music"
import { MusicTile } from "./MusicTile"

export class MusicTileManager {
private musicTiles: MusicTile[]
private readonly musicTiles: MusicTile[]
public musicList: Music[]
private selectedMusicTile: Phaser.GameObjects.Image
private readonly selectedMusicTile: Phaser.GameObjects.Image
public scrollIndex: number
private ascTweens: Phaser.Tweens.Tween[]
private descTweens: Phaser.Tweens.Tween[]
private readonly ascTweens: Phaser.Tweens.Tween[]
private readonly descTweens: Phaser.Tweens.Tween[]

constructor(
public scene: Phaser.Scene,
Expand Down Expand Up @@ -71,6 +71,7 @@ export class MusicTileManager {
)
}
}

public update(time: number) {
for (const musicTileIndex of Array(7).keys()) {
const musicTile = this.musicTiles[musicTileIndex]
Expand Down Expand Up @@ -102,6 +103,7 @@ export class MusicTileManager {
public isPlayable(key: number, difficulty: number) {
return this.musicList[this.scrollIndex].hasOwnProperty(`beatmap_${key}k_${difficulty}`)
}

public getMusic() {
return this.musicList[this.scrollIndex]
}
Expand Down
4 changes: 2 additions & 2 deletions src/class/PlayResult.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PlayConfig } from "./PlayConfig"
import { Music } from "./Music"
import { type PlayConfig } from "./PlayConfig"
import { type Music } from "./Music"
export class PlayResult {
public music: Music
public playConfig: PlayConfig
Expand Down
8 changes: 4 additions & 4 deletions src/class/ToggleButton.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export class ToggleButton extends Phaser.GameObjects.Container {
private frame: Phaser.GameObjects.Image
private text: Phaser.GameObjects.Text
private readonly frame: Phaser.GameObjects.Image
private readonly text: Phaser.GameObjects.Text

private leftIcon: Phaser.GameObjects.Image
private rightIcon: Phaser.GameObjects.Image
private readonly leftIcon: Phaser.GameObjects.Image
private readonly rightIcon: Phaser.GameObjects.Image

public leftZone: Phaser.GameObjects.Zone
public rightZone: Phaser.GameObjects.Zone
Expand Down
2 changes: 1 addition & 1 deletion src/class/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class User {
get ordinalRank(): string {
const rankMod10 = this.rank % 10
const rankMod100 = this.rank % 100
if (11 <= rankMod100 && rankMod100 <= 13) {
if (rankMod100 >= 11 && rankMod100 <= 13) {
return `${this.rank}th`
} else if (rankMod10 === 1) {
return `${this.rank}st`
Expand Down
2 changes: 1 addition & 1 deletion src/scene/ConfigScene.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PlayConfig, NoteType } from "../class/PlayConfig"
import { type PlayConfig, type NoteType } from "../class/PlayConfig"
import { ToggleButton } from "../class/ToggleButton"

export class ConfigScene extends Phaser.Scene {
Expand Down
2 changes: 1 addition & 1 deletion src/scene/CreditScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class CreditScene extends Phaser.Scene {
"",
]

const rightCredits = (process.env.CREDITS as string).split(/\\r\\n|\\n|\\r/)
const rightCredits = (process.env.CREDITS || "").split(/\\r\\n|\\n|\\r/)

this.add
.text(width / 2 - 260, height / 2 - 200 - 5, "RICORA Beats", {
Expand Down
6 changes: 3 additions & 3 deletions src/scene/LoginScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class LoginScene extends Phaser.Scene {
loginFormElement.addEventListener("submit", async (event) => {
event.preventDefault()
const formData = new FormData(loginFormElement)
const tokenResponse = await retryFetch(new URL("/token", process.env.SERVER_URL as string).toString(), {
const tokenResponse = await retryFetch(new URL("/token", process.env.SERVER_URL).toString(), {
method: "POST",
body: formData,
})
Expand All @@ -47,7 +47,7 @@ export class LoginScene extends Phaser.Scene {
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 as string).toString(), {
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}`,
Expand Down Expand Up @@ -79,7 +79,7 @@ export class LoginScene extends Phaser.Scene {
registerFormElement.addEventListener("submit", async (event) => {
event.preventDefault()
const formData = new FormData(registerFormElement)
const registerResponse = await retryFetch(new URL("/users/", process.env.SERVER_URL as string).toString(), {
const registerResponse = await retryFetch(new URL("/users/", process.env.SERVER_URL).toString(), {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand Down
Loading

0 comments on commit e6eb70c

Please sign in to comment.