Skip to content

Commit

Permalink
Merge pull request #826 from MikuroXina/refactor/huge
Browse files Browse the repository at this point in the history
Add typing of codes used by components
  • Loading branch information
dtinth committed Jan 7, 2023
2 parents 479898b + 076766f commit 68e0d52
Show file tree
Hide file tree
Showing 30 changed files with 775 additions and 979 deletions.
8 changes: 2 additions & 6 deletions bemuse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
"@reduxjs/toolkit": "^1.9.1",
"auth0-js": "^9.8.0",
"axios": "^1.1.3",
"baconjs": "^0.7.95",
"bemuse-indexer": "^51.0.2",
"bemuse-notechart": "^50.1.2",
"bemuse-types": "^50.0.2",
Expand All @@ -149,15 +148,15 @@
"fuzzysort": "~1.1.4",
"idb-keyval": "^6.0.2",
"immer": "~9.0.15",
"immutable": "^3.8.2",
"immutable": "^4.1.0",
"invariant": "^2.2.4",
"jquery": "^3.3.1",
"keycode": "^2.2.0",
"keytime": "^0.1.0",
"lazy-property": "^1.0.0",
"libarchive.js": "^1.3.0",
"lodash": "^4.17.11",
"markdown-it": "^6.0.0",
"markdown-it": "^13.0.1",
"mean": "^1.0.1",
"median": "0.0.2",
"mobx-react-lite": "^1.4.1",
Expand All @@ -168,16 +167,13 @@
"pixi.js": "^4.8.9",
"plugin-error": "~1.0.1",
"power-assert": "^1.6.1",
"prop-types": "^15.6.2",
"qs": "^6.5.2",
"react-dom": "^18.2.0",
"react-fns": "^1.4.0",
"react-query": "^3.25.1",
"react-redux": "^8.0.5",
"react-rx": "^2.1.3",
"react-toggled": "^1.2.7",
"react": "^18.2.0",
"recompose": "^0.26.0",
"redux": "^4.2.0",
"reselect": "^4.1.7",
"rxjs": "^7.8.0",
Expand Down
4 changes: 2 additions & 2 deletions bemuse/src/app/game-launcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ if (module.hot) {
module.hot.accept('bemuse/game/loaders/game-loader')
}

type LaunchOptions = {
server: { url: string }
export type LaunchOptions = {
server: { readonly url: string }
song: Song
chart: Chart
options: StoredOptions
Expand Down
2 changes: 1 addition & 1 deletion bemuse/src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function bootUp() {
)
store.dispatch(
musicSearchTextSlice.actions.MUSIC_SEARCH_TEXT_INITIALIZED({
text: getInitialGrepString(),
text: getInitialGrepString() ?? '',
})
)
store.dispatch(optionsSlice.actions.LOAD_FROM_STORAGE())
Expand Down
18 changes: 0 additions & 18 deletions bemuse/src/app/interactors/findMatchingSong.js

This file was deleted.

21 changes: 21 additions & 0 deletions bemuse/src/app/interactors/findMatchingSong.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Finds a song matching the title

import type { SongMetadataInCollection } from 'bemuse-types'

function findMatchingSong({
songs,
title,
getTitle,
}: {
songs: readonly SongMetadataInCollection[]
title: string
getTitle: (song: SongMetadataInCollection) => string
}) {
return songs.find((song) => titleFullyMatches(getTitle(song), title))
}

function titleFullyMatches(haystack: string, needle: string) {
return haystack.toLowerCase().trim() === needle.toLowerCase().trim()
}

export default findMatchingSong
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { timegate } from 'bemuse/game/judgments'
// For the purpose of displaying play accuracy statistics,
// given an array of deltas,
// we want to get filter it to contain only data for non-missed notes.
export function getNonMissedDeltas(deltas) {
export function getNonMissedDeltas(deltas: readonly number[]) {
return deltas.filter((delta) => Math.abs(delta) < timegate(4))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { AnyAction, Dispatch } from 'redux'

import { musicSearchTextSlice } from '../entities/MusicSearchText'

let _timeout
let _timeout: NodeJS.Timeout

export function handleSearchTextType(text, dispatch) {
export function handleSearchTextType(
text: string,
dispatch: Dispatch<AnyAction>
) {
dispatch(musicSearchTextSlice.actions.MUSIC_SEARCH_TEXT_TYPED({ text }))
if (_timeout) clearTimeout(_timeout)
_timeout = setTimeout(() => {
Expand Down
51 changes: 0 additions & 51 deletions bemuse/src/app/io/MusicSelectionIO.js

This file was deleted.

67 changes: 67 additions & 0 deletions bemuse/src/app/io/MusicSelectionIO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { AnyAction, Dispatch } from 'redux'
import { Chart, Song } from 'bemuse/collection-model/types'
import { OptionsState, optionsSlice } from '../entities/Options'
import { getChartLevel, musicSelectionSlice } from '../entities/MusicSelection'

import { ChartProps } from '../ui/MusicList'
import { SceneManager } from 'bemuse/scene-manager'
import { SongMetadataInCollection } from 'bemuse-types'
import { launch } from '../game-launcher'
import { rageQuitSlice } from '../redux/ReduxState'

export function selectSong(
song: SongMetadataInCollection,
dispatch: Dispatch<AnyAction>
) {
dispatch(musicSelectionSlice.actions.MUSIC_SONG_SELECTED({ songId: song.id }))
}

export function selectChart(
song: SongMetadataInCollection,
chart: ChartProps,
dispatch: Dispatch<AnyAction>
) {
dispatch(
musicSelectionSlice.actions.MUSIC_CHART_SELECTED({
songId: song.id,
chartId: chart.file,
chartLevel: getChartLevel(chart),
})
)
}

export function launchGame({
server,
song,
chart,
autoplayEnabled,
dispatch,
options,
sceneManager,
}: {
server: { readonly url: string }
song: Song
chart: Chart
autoplayEnabled: boolean
options: OptionsState
dispatch: Dispatch<AnyAction>
sceneManager: SceneManager
}) {
launch({
server,
song,
chart,
options,
saveSpeed: (speed) => {
dispatch(optionsSlice.actions.CHANGE_SPEED({ speed: speed.toString() }))
},
saveLeadTime: (leadTime) => {
dispatch(optionsSlice.actions.CHANGE_LEAD_TIME({ leadTime }))
},
onRagequitted: () => {
dispatch(rageQuitSlice.actions.RAGEQUITTED())
},
autoplayEnabled,
sceneManager,
})
}
24 changes: 24 additions & 0 deletions bemuse/src/app/io/customSongLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// The singleton IO context. This file is needed because many parts of
// our application still depends on a singleton.
//

import type { ICustomSongResources } from 'bemuse/resources/types'

import {
LoadSongOptions,
loadSongFromResources,
} from '../../custom-song-loader'

// Configure a custom song loader which loads custom song from resources.
export const customSongLoader = {
loadSongFromResources: async (
resources: ICustomSongResources,
options?: LoadSongOptions
) => {
const song = await loadSongFromResources(resources, options)
song.id = '__custom_' + Date.now()
song.custom = true
return song
},
} as const
export type CustomSongLoader = typeof customSongLoader
116 changes: 0 additions & 116 deletions bemuse/src/app/options.js

This file was deleted.

Loading

0 comments on commit 68e0d52

Please sign in to comment.