Add a web (browser) front-end and an example web app#90
Merged
Conversation
Implements WebUserInterface, a third BaseUserInterface front-end alongside the console and pygame ones, using only the Python standard library. The synchronous game loop is unchanged: each input primitive publishes the current "screen" and blocks until the browser submits a response, coordinated through a thread-safe rendezvous; a small stdlib http.server serves the page (GET /), the current screen (GET /state), and accepts the player's response (POST /input). - UIType.WEB + a lazy factory branch (so other modes don't start HTTP machinery). - FishE accepts an interfaceType (default unchanged) so a front-end can be chosen without editing the module constant. - examples/web_app.py runs the whole game in the browser. The entire game — save manager, fishing, shop, bank, tavern, NPC dialogue — works through the web UI with no new dependencies. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dmccoystephenson
left a comment
Member
Author
There was a problem hiding this comment.
Self-review:
- Scope: PASS — WebUserInterface + UIType.WEB + lazy factory branch + FishE interfaceType param + example app + README + tests.
- Dependencies: PASS — Python standard library only (http.server, queue, threading); pygame/console modes unaffected (lazy import).
- Abstraction/DRY: PASS — implements the BaseUserInterface primitives; inherits showInteractiveDialogue and promptForNumber, so dialogue/numeric input work without web-specific code.
- Tests: PASS — 198; rendezvous round-trips for every primitive + invalid-option handling + a real ephemeral-port HTTP smoke test; manual end-to-end of the example app verified.
- Safety: default front-end unchanged; no schema/persistence/save-file paths touched.
- CI: PASS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a third front-end behind the existing
BaseUserInterfacecontract — a browser-based web interface — plus an example app that runs the whole game in the browser. No new dependencies (Python standard library only).src/ui/webUserInterface.py—WebUserInterface(BaseUserInterface). The synchronous game loop is unchanged: each input primitive (showOptions,showDialogue,promptForText,timedKeyPress) publishes the current "screen" and blocks until the browser responds, via a thread-safe rendezvous (queue.Queue+ a versioned screen snapshot). A daemon-threadhttp.serverserves the page (GET /), the screen state (GET /state), and accepts responses (POST /input).showInteractiveDialogue/promptForNumberare inherited from the base, so NPC dialogue and numeric prompts work for free.UIType.WEB+ a lazy factory branch (so console/pygame modes don't start the HTTP machinery).FishE(interfaceType=...)— optional, default unchanged — lets a caller pick a front-end without editing the module constant.examples/web_app.py—python3 examples/web_app.py, openhttp://127.0.0.1:8000.Test plan
python3 -m compileall -q srccleanSDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy python3 -m pytest— 198 passedtests/ui/test_webUserInterface.py: implements the interface;showOptions/promptForText/promptForNumber/showDialogue/timedKeyPressround-trip via the rendezvous; invalid options ignored; and a real ephemeral-port HTTP smoke test (serves/,/state, accepts/input).🤖 Generated with Claude Code