diff --git a/build/assets/index-local.html b/build/assets/index-local.html deleted file mode 100644 index 79535ce..0000000 --- a/build/assets/index-local.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - <!--$TITLE$--> - - - - - - - - - - \ No newline at end of file diff --git a/build/assets/index.html b/build/assets/index.html index 2bac58c..3ecf98f 100644 --- a/build/assets/index.html +++ b/build/assets/index.html @@ -3,40 +3,16 @@ - + <!--$TITLE$--> - - + + - \ No newline at end of file diff --git a/build/build.ts b/build/build.ts index 9438d75..b6c6421 100644 --- a/build/build.ts +++ b/build/build.ts @@ -13,6 +13,7 @@ const publish = process.env.PUBLISH_LOCATION; const args = process.argv.slice(2); const local = args.includes('--local'); +const exported = args.includes('--exported'); let game = args.find(a => !a.startsWith('-')) ?? ''; while (!await isGame(game)) { @@ -22,7 +23,7 @@ while (!await isGame(game)) { }); } console.log(`Building ${game}...`); -const html = await buildHTML(game, { production: true, local }); +const html = await buildHTML(game, { production: true, local, exported }); if (!html) { process.exit(1); diff --git a/build/html.ts b/build/html.ts index d9c00f1..f9f7194 100644 --- a/build/html.ts +++ b/build/html.ts @@ -33,13 +33,53 @@ interface Args { production?: boolean; mobile?: boolean; local?: boolean; + exported?: boolean; } +const SW_SCRIPT = ``; + +const CSS_RELOAD_SCRIPT = ``; + async function buildBundle(game: string, production: boolean) { const srcDir = path.resolve(import.meta.dir, '..', 'src'); return Bun.build({ outdir: '/tmp', - entrypoints: [path.resolve(srcDir, 'index.ts')], + entrypoints: [ + path.resolve(srcDir, 'index.ts'), + path.resolve(srcDir, 'common', 'assets', 'global.css'), + ], sourcemap: production ? 'none' : 'inline', define: { global: 'window', @@ -56,13 +96,17 @@ async function buildBundle(game: string, production: boolean) { }); } -export async function buildHTML(game: string, { production = false, mobile = false, local = false }: Args = {}) { +export async function buildHTML(game: string, { + production = false, + mobile = false, + local = false, +}: Args = {}) { const assetsDir = path.resolve(import.meta.dir, 'assets'); const srcDir = path.resolve(import.meta.dir, '..', 'src'); const gameDir = path.resolve(srcDir, 'games', game); const gameAssetsDir = path.resolve(gameDir, 'assets'); - const html = await Bun.file(path.resolve(assetsDir, local ? 'index-local.html' : 'index.html')).text(); + const html = await Bun.file(path.resolve(assetsDir, 'index.html')).text(); const bundle = await buildBundle(game, production); if (bundle.success) { @@ -150,6 +194,12 @@ export async function buildHTML(game: string, { production = false, mobile = fal const eruda = await Bun.file(path.resolve(import.meta.dir, '..', 'node_modules', 'eruda', 'eruda.js')).text(); scriptPrefix = ``; } + if (!local) { + scriptPrefix += SW_SCRIPT; + } + if (local && !production) { + scriptPrefix += CSS_RELOAD_SCRIPT; + } // function to avoid $& being replaced // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement @@ -158,7 +208,7 @@ export async function buildHTML(game: string, { production = false, mobile = fal .replace('', () => title) .replace('', () => icon) .replace('', () => manifest) - .replace('/*$STYLE$*/', () => style); + .replace('', () => ``); return minify(resultHTML, { collapseWhitespace: production, diff --git a/src/common/assets/global.css b/src/common/assets/global.css index 10102b0..7c9f93b 100644 --- a/src/common/assets/global.css +++ b/src/common/assets/global.css @@ -27,18 +27,20 @@ scrollbar-color: var(--bg-active) transparent; } -html { - padding: 0; +html, +body { + width: 100vw; + height: 100vh; margin: 0; + padding: 0; + overflow: hidden; + font-family: sans-serif; } -body { +body { background: var(--bg); color: var(--text); font-family: 'Georgia', serif; font-size: 14px; line-height: 1.5; - width: 100dvw; - height: 100dvh; - overflow: hidden; } \ No newline at end of file diff --git a/src/games/hordeseer/components/modals/manage-workers-modal.tsx b/src/games/hordeseer/components/modals/manage-workers-modal.tsx index 3628f95..a860487 100644 --- a/src/games/hordeseer/components/modals/manage-workers-modal.tsx +++ b/src/games/hordeseer/components/modals/manage-workers-modal.tsx @@ -38,7 +38,7 @@ export const ManageWorkersModal = ({ open, onClose }: Props) => { const loading = useBool(false); useEffect(() => { - if (!open || !user || !apiKey) return; + if (!open || !user?.worker_ids || !apiKey || !user) return; let cancelled = false; loading.setTrue(); @@ -63,7 +63,7 @@ export const ManageWorkersModal = ({ open, onClose }: Props) => { .finally(() => { if (!cancelled) loading.setFalse(); }); return () => { cancelled = true; }; - }, [open, user?.worker_ids.join(',')]); + }, [open, user?.worker_ids?.join(',')]); const setEdit = (id: string, patch: Partial) => { setWorkers(prev => prev.map(w => @@ -110,7 +110,7 @@ export const ManageWorkersModal = ({ open, onClose }: Props) => { }; const confirmDelete = async (id: string) => { - if (!apiKey) return; + if (!apiKey || !user?.worker_ids) return; setWorkers(prev => prev.map(w => w.data.id === id ? { ...w, deleting: true, confirmDelete: false } : w )); diff --git a/src/games/hordeseer/components/navbar.tsx b/src/games/hordeseer/components/navbar.tsx index 86dd8cb..a2816a5 100644 --- a/src/games/hordeseer/components/navbar.tsx +++ b/src/games/hordeseer/components/navbar.tsx @@ -10,7 +10,7 @@ export const Navbar = () => {
- {state.user && ( + {state.user?.worker_ids && ( )}
diff --git a/src/games/hordeseer/utils/api.ts b/src/games/hordeseer/utils/api.ts index 00360b4..4dcdb03 100644 --- a/src/games/hordeseer/utils/api.ts +++ b/src/games/hordeseer/utils/api.ts @@ -25,7 +25,7 @@ export interface UserData { username: string; kudos: number; worker_count: number; - worker_ids: string[]; + worker_ids?: string[]; records: { contribution: { tokens: number }; fulfillment: { text: number };