-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #826 from MikuroXina/refactor/huge
Add typing of codes used by components
- Loading branch information
Showing
30 changed files
with
775 additions
and
979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
bemuse/src/app/io/MusicSearchIO.js → bemuse/src/app/io/MusicSearchIO.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.