10 KiB
Production Play Screen Implementation Plan
Overview
Create a new production play screen at templates/game/play.html with a 3-column layout optimized for immersive gameplay, separate from the dev console.
Layout Structure
+-------------+------------------------+------------------+
| LEFT | MIDDLE | RIGHT |
| (280px) | (1fr flex) | (320px) |
+-------------+------------------------+------------------+
| Character | Location Header | [History] |
| - Name/Lv | - Name, Type, Turn # | [Quests] |
| - HP/MP | Ambient Details | [NPCs] |
| - Stats | ---------------- | [Map] |
| ---------- | DM Response Area | |
| Actions | (main narrative) | Each accordion |
| [Free] | | independently |
| [Premium] | | refreshable |
| [Elite] | | |
| ---------- | | |
| [Talk NPC] | | |
| [Travel] | | |
+-------------+------------------------+------------------+
Files to Create
Templates
| File | Purpose |
|---|---|
templates/game/play.html |
Main 3-column layout |
templates/game/partials/character_panel.html |
Left: actions + character stats |
templates/game/partials/narrative_panel.html |
Middle: DM response + location |
templates/game/partials/sidebar_history.html |
Right accordion: turn history |
templates/game/partials/sidebar_quests.html |
Right accordion: active quests |
templates/game/partials/sidebar_npcs.html |
Right accordion: NPCs at location |
templates/game/partials/sidebar_map.html |
Right accordion: discovered locations |
templates/game/partials/job_polling.html |
Job status polling partial |
templates/game/partials/travel_modal.html |
Travel destination modal |
templates/game/partials/npc_chat_modal.html |
NPC dialogue modal |
CSS
| File | Purpose |
|---|---|
static/css/play.css |
All play screen styles |
Flask Views
| File | Purpose |
|---|---|
app/views/game_views.py |
New blueprint for production game routes |
Modify
| File | Change |
|---|---|
app/__init__.py |
Register game_bp blueprint |
Flask Routes
# Main routes
GET /play/session/<session_id> # Main play screen
GET /play/session/<id>/character-panel # Refresh character stats
GET /play/session/<id>/narrative # Refresh narrative
GET /play/session/<id>/history # Refresh history accordion
GET /play/session/<id>/quests # Refresh quests accordion
GET /play/session/<id>/npcs # Refresh NPCs accordion
GET /play/session/<id>/map # Refresh map accordion
# Action routes
POST /play/session/<id>/action # Submit action -> job polling
GET /play/session/<id>/job/<job_id> # Poll job status
# Modal routes
GET /play/session/<id>/travel-modal # Get travel modal
POST /play/session/<id>/travel # Execute travel
GET /play/session/<id>/npc/<npc_id>/chat # Get NPC chat modal
POST /play/session/<id>/npc/<npc_id>/talk # Send message to NPC
CSS Theme
/* Dark fantasy theme matching existing */
--play-bg-primary: #1a1a2a;
--play-bg-secondary: #2a2a3a;
--play-border: #4a4a5a;
/* Action tiers */
--action-free: #3b82f6; /* Blue */
--action-premium: #8b5cf6; /* Purple */
--action-elite: #f59e0b; /* Gold */
/* Resource bars */
--hp-bar-fill: #ef4444;
--mp-bar-fill: #3b82f6;
Action Button Organization
Free Tier (Blue):
- Ask Locals for Information (town/tavern)
- Explore the Area (wilderness/dungeon)
- Search for Supplies (any) - 2 turn cooldown
- Rest and Recover (town/tavern/safe) - 3 turn cooldown
Premium Tier (Purple): 5. Investigate Suspicious Activity (any) 6. Follow a Lead (any) 7. Make Camp (wilderness) - 5 turn cooldown
Elite Tier (Gold): 8. Consult Ancient Texts (library/town) - 3 turn cooldown 9. Commune with Nature (wilderness) - 4 turn cooldown 10. Seek Audience with Authorities (town) - 5 turn cooldown
HTMX Patterns
Action Submission
<button hx-post="/play/session/{id}/action"
hx-vals='{"action_type":"button","prompt_id":"ask_locals"}'
hx-target="#narrative-content"
hx-indicator="#loading"
hx-disabled-elt="this">
Job Polling (1s interval)
<div hx-get="/play/session/{id}/job/{job_id}"
hx-trigger="load delay:1s"
hx-swap="innerHTML">
Cascade Refresh (after action completes)
<!-- Hidden triggers in dm_response.html -->
<div hx-get="/play/session/{id}/history" hx-target="#accordion-history" hx-trigger="load" hidden></div>
<div hx-get="/play/session/{id}/npcs" hx-target="#accordion-npcs" hx-trigger="load" hidden></div>
Responsive Design
- Desktop (>1024px): 3-column grid
- Tablet (768-1024px): 2-column, left sidebar as slide-out drawer
- Mobile (<768px): Single column, right sidebar as bottom sheet
Implementation Approach: Visual First
Build complete UI with mock/sample data first, then wire up real API calls. This allows rapid iteration on layout and styling before integrating backend.
Phase 1: Complete Visual Layout with Mock Data
- Create
game_views.pywith main route using hardcoded mock data - Create
play.htmlbase template with 3-column grid - Create
play.csswith all styles (theme, grid, components) - Register blueprint
- Build all visual components with sample content:
- Left: Character panel with mock stats/actions
- Middle: Narrative panel with sample DM text
- Right: All 4 accordions with mock entries
Phase 2: Interactive Components (No API)
- Accordion toggle functionality (JavaScript)
- Modal open/close (travel + NPC chat)
- Action button states (hover, disabled, loading simulation)
- Collapsible ambient details
- Responsive breakpoints
Phase 3: Wire Up API Integration ✅ COMPLETE (Nov 24, 2025)
- ✅ Replace mock data with real API calls in Flask view
- ✅ Implement job polling for actions
- ✅ Wire up travel modal to
/api/v1/travel - ✅ Wire up NPC chat to
/api/v1/npcs/{id}/talk - ✅ Add HTMX refresh triggers for accordions
- ✅ Wire up equipment modal with real character data
Phase 4: Polish
- Error handling states
- Loading indicators
- Empty state messages
- Accessibility (ARIA labels, keyboard nav)
Critical Reference Files
public_web/templates/dev/story_session.html- HTMX patterns, job pollingpublic_web/app/views/dev.py- Flask view patterns, API client usagepublic_web/static/css/main.css- Theme variables, base stylesapi/app/data/action_prompts.yaml- All 10 action definitionsapi/app/api/sessions.py- Session API response formats
API Endpoints Used
All endpoints already exist:
GET /api/v1/sessions/{id}- Session state (updated to includecharacter_id)POST /api/v1/sessions/{id}/action- Submit actionGET /api/v1/sessions/{id}/history- Conversation historyGET /api/v1/jobs/{id}/status- Poll job statusGET /api/v1/characters/{id}- Character dataGET /api/v1/npcs/at-location/{id}- NPCs at locationPOST /api/v1/npcs/{id}/talk- Talk to NPCGET /api/v1/travel/available- Available destinationsPOST /api/v1/travel- Travel to location
Implementation Notes (Phase 3)
Session Creation from Characters Page
Added the ability for players to create game sessions directly from /characters:
Files Modified:
-
public_web/app/views/character_views.py- Updated
list_characters()to fetch user sessions viaGET /api/v1/sessionsand map them to characters - Added new route
POST /characters/<character_id>/play(create_session) that creates a session and redirects to play screen
- Updated
-
public_web/templates/character/list.html- Added sessions section showing active sessions per character (up to 3 displayed)
- Added "Continue Playing" button (resumes latest session)
- Added "New Session" button (creates new session)
- Added "Start Adventure" button for characters without sessions
- Added CSS for session badges (turn number, status indicator)
Play Screen API Integration
Files Modified:
public_web/app/views/game_views.py- Removed all mock data constants
- Added helper functions:
_get_user_tier(client)- Gets user subscription tier_build_location_from_game_state(game_state)- Builds location dict from session_build_character_from_api(char_data)- Transforms API character response with robust defaults
- Updated all routes to use real API calls:
play_session- Main play screencharacter_panel- Character stats refreshnarrative_panel- Narrative content refreshhistory_accordion,quests_accordion,npcs_accordion,map_accordion- Sidebar refreshestake_action- Submit actions to API, return job polling partialpoll_job- Poll job status, handle NPC dialogue vs story responsesequipment_modal,travel_modal,npc_chat_modal- Modal data loadingdo_travel,talk_to_npc- Execute travel and NPC dialogue
New Template:
public_web/templates/game/partials/npc_dialogue_response.html- Displays NPC dialogue from job polling results
API Changes
Files Modified:
api/app/api/sessions.py- Updated
get_session_state()to includecharacter_idandstatusin response - This was required because the play screen needs to know which character to load
- Updated
CSS Fixes
Files Modified:
public_web/static/css/play.css- Increased
max-widthfrom 1800px to 2400px for wider screens - Changed middle column from
1frtominmax(500px, 1fr)to ensure minimum width - Fixed NPC tags overflow:
- Added
flex-wrap: wrapto.npc-tags - Added
overflow: hiddenandmax-height: 3.5em - Added
white-space: nowrapto.npc-tag
- Added
- Increased
Bug Fixes
-
Character data showing "Unknown" - Fixed
_build_character_from_api()to always return complete dict with sensible defaults even when API data is empty or incomplete -
API not returning character_id - Updated
api/app/api/sessions.pyto includecharacter_idin session state response -
NPC tags overflow - Fixed CSS to wrap tags and hide overflow