|
| 1 | +## 1. Core “Source of Truth” |
| 2 | + |
| 3 | +**`state.js`** – Holds global state: |
| 4 | + |
| 5 | +- `currentPair` → current left/right items |
| 6 | + |
| 7 | +- `currentRanks` → battle ranks of current pair |
| 8 | + |
| 9 | +- `currentMode` → "swiss", "gauntlet", "champion" |
| 10 | + |
| 11 | +- `battleType` → "performers", "images", "scenes" |
| 12 | + |
| 13 | +- `gauntletChampion` → current champion (Gauntlet/Champion mode) |
| 14 | + |
| 15 | +- `gauntletWins`, `gauntletDefeated` → track progress |
| 16 | + |
| 17 | +- `selectedGenders` → filters for performers |
| 18 | + |
| 19 | + |
| 20 | +**`resetBattleState()`** → resets gauntlet-specific progress without touching global app config. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## 2. UI Components |
| 25 | + |
| 26 | +### a) Cards (`ui-cards.js`) |
| 27 | + |
| 28 | +- **Render functions:** |
| 29 | + |
| 30 | + - `createSceneCard(scene)` |
| 31 | + |
| 32 | + - `createPerformerCard(performer)` |
| 33 | + |
| 34 | + - `createImageCard(image)` |
| 35 | + |
| 36 | + - `createVictoryScreen(champion)` |
| 37 | + |
| 38 | +- Adds streak badges, rank displays, ratings, and click handlers. |
| 39 | + |
| 40 | +- Integrated with `state` for streaks and gauntlet wins. |
| 41 | + |
| 42 | + |
| 43 | +### b) Dashboard (`ui-dashboard.js`) |
| 44 | + |
| 45 | +- Main UI shell for the modal and main page: |
| 46 | + |
| 47 | + - Mode toggles: Swiss / Gauntlet / Champion |
| 48 | + |
| 49 | + - Gender filters (for performers) |
| 50 | + |
| 51 | + - Skip button (Swiss only) |
| 52 | + |
| 53 | +- **Event listeners:** |
| 54 | + |
| 55 | + - Gender toggle → updates `state.selectedGenders` |
| 56 | + |
| 57 | + - Mode switch → updates `state.currentMode` and resets gauntlet state |
| 58 | + |
| 59 | + - Skip button → triggers `handleSkip()` |
| 60 | + |
| 61 | +- Calls `loadNewPair()` from the battle engine whenever mode/filter changes. |
| 62 | + |
| 63 | + |
| 64 | +### c) Badge / Placement (`ui-badge.js`) |
| 65 | + |
| 66 | +- **Performer page:** injects Battle Rank badge |
| 67 | + |
| 68 | + - Calls `getPerformerBattleRank(id)` from API |
| 69 | + |
| 70 | + - Displays emoji based on percentile |
| 71 | + |
| 72 | +- **Placement screen:** shows final ranking after a gauntlet |
| 73 | + |
| 74 | +- **Rating animation:** visual feedback for winner/loser changes |
| 75 | + |
| 76 | + |
| 77 | +### d) Modal (`ui-modal.js`) |
| 78 | + |
| 79 | +- Floating button (“🔥”) triggers **ranking modal** |
| 80 | + |
| 81 | +- Keyboard navigation: |
| 82 | + |
| 83 | + - Left/Right → choose left/right card |
| 84 | + |
| 85 | + - Space → skip |
| 86 | + |
| 87 | +- Modal integrates with `ui-dashboard.js` for dynamic content |
| 88 | + |
| 89 | + |
| 90 | +### e) Stats (`ui-stats.js`) |
| 91 | + |
| 92 | +- Opens stats modal: |
| 93 | + |
| 94 | + - Leaderboards (collapsible, 250-performer groups) |
| 95 | + |
| 96 | + - Rating distribution bars |
| 97 | + |
| 98 | + - Tabs: Leaderboard / Rating Distribution |
| 99 | + |
| 100 | +- Fetches performers via API → parses Elo ratings → renders tables and graphs |
| 101 | + |
| 102 | + |
| 103 | +### f) UI Manager (`ui-manager.js`) |
| 104 | + |
| 105 | +- Barrel export to unify: |
| 106 | + |
| 107 | + - Cards, Dashboard, Modal, Badge, Stats |
| 108 | + |
| 109 | +- Lets other modules import everything via `ui-manager.js` |
| 110 | + |
| 111 | + |
| 112 | +--- |
| 113 | + |
| 114 | +## 3. Battle Engine & API |
| 115 | + |
| 116 | +- **`battle-engine.js`** (not included here but referenced): |
| 117 | + |
| 118 | + - `loadNewPair()` → fetches next pair for voting |
| 119 | + |
| 120 | + - Updates `state.currentPair` and `state.currentRanks` |
| 121 | + |
| 122 | +- **`api-client.js`**: |
| 123 | + |
| 124 | + - Fetch performers/scenes/images |
| 125 | + |
| 126 | + - Fetch performer battle rank |
| 127 | + |
| 128 | + - Fetch all performer stats |
| 129 | + |
| 130 | +- **`math-utils.js`**: |
| 131 | + |
| 132 | + - Parse Elo ratings |
| 133 | + |
| 134 | + - Calculate win rates and streaks |
| 135 | + |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## 4. Flow Diagram (Textual) |
| 140 | + |
| 141 | +Page Load / Performer Page |
| 142 | + │ |
| 143 | + ▼ |
| 144 | + state initialized |
| 145 | + │ |
| 146 | + ▼ |
| 147 | + injectBattleRankBadge() ──► fetchPerformerBattleRank(id) |
| 148 | + │ |
| 149 | + ▼ |
| 150 | + Badge displayed on page |
| 151 | + |
| 152 | +User clicks "🔥" floating button |
| 153 | + │ |
| 154 | + ▼ |
| 155 | + openRankingModal() ──► createMainUI() |
| 156 | + │ |
| 157 | + ▼ |
| 158 | + attachEventListeners() |
| 159 | + │ |
| 160 | + ├─ Gender toggle → update state.selectedGenders → loadNewPair() |
| 161 | + ├─ Mode toggle → update state.currentMode → reset gauntlet → loadNewPair() / showPerformerSelection() |
| 162 | + ├─ Skip button → handleSkip() |
| 163 | + ▼ |
| 164 | + loadNewPair() ──► battle-engine selects next pair → state.currentPair updated |
| 165 | + │ |
| 166 | + ▼ |
| 167 | + renderCard(left/right) ──► ui-cards.js |
| 168 | + │ |
| 169 | + ▼ |
| 170 | + User votes → update ratings, optionally showRatingAnimation() |
| 171 | + │ |
| 172 | + ▼ |
| 173 | + If Gauntlet ends → showPlacementScreen() / createVictoryScreen() |
| 174 | + │ |
| 175 | + ▼ |
| 176 | + Optional: openStatsModal() → fetchAllPerformerStats() → generateStatTables() / generateBarGroups() |
| 177 | + |
| 178 | +--- |
| 179 | + |
| 180 | +## 5. Mode-specific Behaviors |
| 181 | + |
| 182 | +|Mode|Behavior| |
| 183 | +|---|---| |
| 184 | +|Swiss|Random pairs, skip allowed, gender filters active| |
| 185 | +|Gauntlet|Champion seeded, defeated opponents tracked, final placement screen after all matches| |
| 186 | +|Champion|Continuous battle until a new champion is crowned| |
| 187 | + |
| 188 | +--- |
| 189 | + |
| 190 | +## 6. Keyboard Controls |
| 191 | + |
| 192 | +- **Left Arrow** → choose left card |
| 193 | + |
| 194 | +- **Right Arrow** → choose right card |
| 195 | + |
| 196 | +- **Space** → skip current pair (Swiss mode only) |
0 commit comments