From f0e597a3d8a72241ccc2703252746ea004e7404d Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 25 Mar 2025 17:47:42 -0400 Subject: [PATCH] refactor: improve captain data management and UI layout - Move captain configs to individual JSON files - Add dynamic captain indexing - Update UI to show missions above captain selector - Remove player labels for cleaner interface - Add captain selection filtering to prevent duplicate selections --- package.json | 5 +- scripts/generate-captains-index.js | 41 +++++ .../{burnham/config.json => burnham.json} | 14 +- src/assets/captains/index.json | 28 +++ .../{koloth/config.json => koloth.json} | 14 +- .../{picard/config.json => picard.json} | 14 +- .../captains/{sela/config.json => sela.json} | 14 +- .../{shran/config.json => shran.json} | 0 .../{sisko/config.json => sisko.json} | 0 src/pages/index.astro | 84 +++++---- src/utils/captainData.ts | 31 +++- src/utils/ui.ts | 171 ++++++++++++------ 12 files changed, 258 insertions(+), 158 deletions(-) create mode 100644 scripts/generate-captains-index.js rename src/assets/captains/{burnham/config.json => burnham.json} (80%) create mode 100644 src/assets/captains/index.json rename src/assets/captains/{koloth/config.json => koloth.json} (80%) rename src/assets/captains/{picard/config.json => picard.json} (78%) rename src/assets/captains/{sela/config.json => sela.json} (80%) rename src/assets/captains/{shran/config.json => shran.json} (100%) rename src/assets/captains/{sisko/config.json => sisko.json} (100%) diff --git a/package.json b/package.json index fa4aacf..b6080dc 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "version": "0.0.1", "scripts": { "dev": "astro dev", - "build": "astro build", + "build": "node scripts/generate-captains-index.js && astro build", "preview": "astro preview", - "astro": "astro" + "astro": "astro", + "generate-captains": "node scripts/generate-captains-index.js" }, "dependencies": { "@radix-ui/react-dialog": "^1.1.6", diff --git a/scripts/generate-captains-index.js b/scripts/generate-captains-index.js new file mode 100644 index 0000000..b746e27 --- /dev/null +++ b/scripts/generate-captains-index.js @@ -0,0 +1,41 @@ +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const CAPTAINS_DIR = path.join(__dirname, '../src/assets/captains'); +const INDEX_FILE = path.join(CAPTAINS_DIR, 'index.json'); + +function generateCaptainsIndex() { + try { + // Read all JSON files in the captains directory + const files = fs.readdirSync(CAPTAINS_DIR) + .filter(file => file.endsWith('.json') && file !== 'index.json'); + + // Parse each captain file to get their id and name + const captains = files.map(file => { + const content = fs.readFileSync(path.join(CAPTAINS_DIR, file), 'utf-8'); + const captain = JSON.parse(content); + return { + id: captain.id, + name: captain.name + }; + }); + + // Create the index object + const index = { + captains: captains + }; + + // Write the index file + fs.writeFileSync(INDEX_FILE, JSON.stringify(index, null, 4)); + console.log('Successfully generated captains index'); + } catch (error) { + console.error('Error generating captains index:', error); + process.exit(1); + } +} + +generateCaptainsIndex(); \ No newline at end of file diff --git a/src/assets/captains/burnham/config.json b/src/assets/captains/burnham.json similarity index 80% rename from src/assets/captains/burnham/config.json rename to src/assets/captains/burnham.json index 2a9bfba..0180d28 100644 --- a/src/assets/captains/burnham/config.json +++ b/src/assets/captains/burnham.json @@ -44,17 +44,5 @@ "name": "Time Crystal Recovery", "description": "Retrieve a valuable time crystal from a dangerous location.", "points": 3 - }, - "advancedMissions": [ - { - "name": "Red Angel Investigation", - "description": "Investigate the mysterious Red Angel phenomenon.", - "points": 5 - }, - { - "name": "Control Protocol Override", - "description": "Override the Control AI's protocols to save the galaxy.", - "points": 8 - } - ] + } } \ No newline at end of file diff --git a/src/assets/captains/index.json b/src/assets/captains/index.json new file mode 100644 index 0000000..9b535f1 --- /dev/null +++ b/src/assets/captains/index.json @@ -0,0 +1,28 @@ +{ + "captains": [ + { + "id": "burnham", + "name": "Burnham" + }, + { + "id": "koloth", + "name": "Koloth" + }, + { + "id": "picard", + "name": "Picard" + }, + { + "id": "sela", + "name": "Sela" + }, + { + "id": "shran", + "name": "Shran" + }, + { + "id": "sisko", + "name": "Sisko" + } + ] +} \ No newline at end of file diff --git a/src/assets/captains/koloth/config.json b/src/assets/captains/koloth.json similarity index 80% rename from src/assets/captains/koloth/config.json rename to src/assets/captains/koloth.json index 6eff0cb..9e127ed 100644 --- a/src/assets/captains/koloth/config.json +++ b/src/assets/captains/koloth.json @@ -44,17 +44,5 @@ "name": "Klingon Honor", "description": "Uphold Klingon honor in a challenging diplomatic situation.", "points": 3 - }, - "advancedMissions": [ - { - "name": "House Koloth", - "description": "Strengthen the position of House Koloth in the Klingon Empire.", - "points": 5 - }, - { - "name": "Klingon Empire Conquest", - "description": "Lead a successful military campaign to expand Klingon territory.", - "points": 8 - } - ] + } } \ No newline at end of file diff --git a/src/assets/captains/picard/config.json b/src/assets/captains/picard.json similarity index 78% rename from src/assets/captains/picard/config.json rename to src/assets/captains/picard.json index b8480fb..43774e8 100644 --- a/src/assets/captains/picard/config.json +++ b/src/assets/captains/picard.json @@ -44,17 +44,5 @@ "name": "Diplomatic Mission", "description": "Lead a diplomatic mission to establish peaceful relations with a new species.", "points": 2 - }, - "advancedMissions": [ - { - "name": "Scientific Discovery", - "description": "Make a groundbreaking scientific discovery that advances Federation knowledge.", - "points": 3 - }, - { - "name": "First Contact Protocol", - "description": "Successfully execute first contact protocols with a technologically advanced species.", - "points": 4 - } - ] + } } \ No newline at end of file diff --git a/src/assets/captains/sela/config.json b/src/assets/captains/sela.json similarity index 80% rename from src/assets/captains/sela/config.json rename to src/assets/captains/sela.json index 193c0ea..d8ae448 100644 --- a/src/assets/captains/sela/config.json +++ b/src/assets/captains/sela.json @@ -44,17 +44,5 @@ "name": "Romulan Infiltration", "description": "Lead a covert operation to infiltrate a strategic Federation outpost.", "points": 3 - }, - "advancedMissions": [ - { - "name": "Tal Shiar Operation", - "description": "Execute a complex Tal Shiar intelligence gathering mission.", - "points": 5 - }, - { - "name": "Romulan Empire Expansion", - "description": "Expand Romulan influence into a new sector of space.", - "points": 8 - } - ] + } } \ No newline at end of file diff --git a/src/assets/captains/shran/config.json b/src/assets/captains/shran.json similarity index 100% rename from src/assets/captains/shran/config.json rename to src/assets/captains/shran.json diff --git a/src/assets/captains/sisko/config.json b/src/assets/captains/sisko.json similarity index 100% rename from src/assets/captains/sisko/config.json rename to src/assets/captains/sisko.json diff --git a/src/pages/index.astro b/src/pages/index.astro index f002056..8a3e694 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,6 +1,7 @@ --- import Layout from '../layouts/Layout.astro'; import { UIService } from '../utils/ui'; +import { captainDataManager } from '../utils/captainData'; // Welcome to Astro! Wondering what to do next? Check out the Astro documentation at https://docs.astro.build // Don't want to use any of this? Delete everything in this file, the `assets`, `components`, and `layouts` directories, and start fresh. @@ -18,6 +19,9 @@ const captains: Captain[] = [ { id: 'shran', name: 'Shran' }, { id: 'koloth', name: 'Koloth' } ]; + +// Initialize UI service +const uiService = UIService.getInstance(); --- @@ -25,21 +29,26 @@ const captains: Captain[] = [

Star Trek Captain's Chair

- -
-
+ +
+
+ + + +
+ + +
- - -
-
- +
- - -
- -
-
+ +
+
+ + + +
+ + +
- - -
-
- +
- - -
@@ -319,7 +317,7 @@ const captains: Captain[] = [