Skip to content

Commit

Permalink
Load default beatmaps from folder
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim committed Oct 25, 2021
1 parent ffab318 commit dc821d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
16 changes: 2 additions & 14 deletions src/UI/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ import Header from './Components/Header';
import OptionsContext, { Options } from './options';
import { fetchOSZ } from './util';

const DEFAULT_MAPS = [
'25828 44teru-k - F.I',
'108470 xi - Parousia',
'336099 LeaF - Wizdomiot [no video]',
'1183900 Powerless feat. Sennzai - Lost Desire',
'1281563 FELT - Vagueness & JOURNEY',
'1245686 TUYU - Kako ni Torawarete Iru [no video]',
'1329716 YOASOBI - Kaibutsu (TV Size) [no video]'
];

type Props = {
options: Options & {
setOptions: (o: Partial<Options>) => void;
Expand All @@ -39,10 +29,8 @@ export default function Menu({ options, onSelect }: Props) {

useEffect(() => {
// Load default maps on first load
DEFAULT_MAPS.forEach(async url => {
const { diffFiles, otherFiles } = await fetchOSZ(
`assets/beatmaps/${url}.osz`
);
DEFAULT_BEATMAPS.forEach(async url => {
const { diffFiles, otherFiles } = await fetchOSZ(`beatmaps/${url}`);

const texts = await Promise.all(diffFiles.map(f => f.text()));
const diffs = texts
Expand Down
2 changes: 2 additions & 0 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ declare module '*.module.scss' {
export default classes;
}

declare const DEFAULT_BEATMAPS: string[];

// File and Directory Entries API
// Used for drag & drop beatmaps

Expand Down
9 changes: 8 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const CssoWebpackPlugin = require('csso-webpack-plugin').default;
const fs = require('fs');
const { readdir } = require('fs/promises');
const { DefinePlugin } = require('webpack');

module.exports = async (env, argv) => {
const isDev = argv.mode !== 'production';
console.log(
`===================${isDev ? 'DEV' : 'PROD'}========================`
);

const files = await readdir('./public/beatmaps/');
const beatmaps = files.filter(file => file.endsWith('.osz'));

const config = {
entry: {
main: path.resolve('./src/index.tsx')
Expand Down Expand Up @@ -132,6 +136,9 @@ module.exports = async (env, argv) => {
new MiniCssExtractPlugin({
filename: isDev ? '[name].css' : '[name].[contenthash].css',
chunkFilename: isDev ? '[id].css' : '[id].[contenthash].css'
}),
new DefinePlugin({
DEFAULT_BEATMAPS: JSON.stringify(beatmaps)
})
],
stats: {
Expand Down

0 comments on commit dc821d7

Please sign in to comment.