Repository navigation
1.16 part 9/18: Games: the Red night light in every game's stylesheet - #180
epheterson wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Reviewer's GuideImplementationAdd the generator that scans game stylesheets, converts literal colours into Red-theme twins, and supports rewriting or checking generated blocks.
UIAdd Red-theme colour overrides and generated rule twins across the game stylesheets, alongside the listed layout and sizing adjustments.
TestsAdd a drift check and converter assertions for generated Red rules, plus browser coverage that Mahjong tile glyphs remain readable in Red.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
b9589c2 to
7d5a2e5
Compare
1d0a378 to
9151986
Compare
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="scripts/games_red.py" line_range="207" />
<code_context>
+ if want != have:
+ stale.append(fn)
+ if "--check" not in argv:
+ with open(path, "w", encoding="utf-8") as f:
+ f.write(want)
+ if stale:
</code_context>
<issue_to_address>
**Generator overwrites external files**
When a contributor-controlled `.css` symlink in `GAMES` points outside the tree and a maintainer runs the documented rewrite mode, the rewrite's `open(path, "w")` follows the symlink and writes generated stylesheet contents to its target, corrupting the maintainer's external file.
Reject symlinks and verify each resolved stylesheet path remains inside `GAMES` before reading or writing it.
</issue_to_address>
### Comment 2
<location path="zimi/builtin/games/world.css" line_range="35" />
<code_context>
+ .bg-main:not(.is-rail):has(> :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board)) > :not(.wl-wrap, .ff-board, .po-board) { grid-column: 2; max-width: 100%; }
</code_context>
<issue_to_address>
**Boards appear in controls column**
When a game with a direct-child `.bg-board` or `.wk-board` is shown in landscape at a height of 520px or less, `> :not(.wl-wrap, .ff-board, .po-board)` also matches those board children, so its later `grid-column: 2` overrides their `grid-column: 1` placement and leaves the board in the controls column.
Exclude `.bg-board` and `.wk-board` from the controls selector, or target the controls explicitly.
</issue_to_address>
### Comment 3
<location path="scripts/games_red.py" line_range="23-24" />
<code_context>
+BEGIN = "/* Red, generated by scripts/games_red.py from the rules above: do not edit. */"
+END = "/* end Red */"
+RED = ":root.gs.night-red"
+HEX = re.compile(r"#([0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b")
+RGB = re.compile(r"rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)")
+SKIP_AT = ("@keyframes", "@-webkit-keyframes", "@font-face", "@page", "@property", "@import", "@charset")
+
</code_context>
<issue_to_address>
**Some colours stay unchanged in Red mode**
When a game stylesheet uses valid CSS colour syntax outside the regex patterns, such as `#RGBA` or percentage/space-separated `rgb()` or `rgba()`, `HEX` and `RGB`/`has_colour` do not recognize those forms, so the colour is not converted and its original hue remains visible in Red mode.
Extend the colour matching and conversion to cover the valid CSS colour syntaxes used by game stylesheets.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: scripts/games_red.py:207, zimi/builtin/games/world.css:35, scripts/games_red.py:24
| if want != have: | ||
| stale.append(fn) | ||
| if "--check" not in argv: | ||
| with open(path, "w", encoding="utf-8") as f: |
There was a problem hiding this comment.
🟡 Medium · Generator overwrites external files
When a contributor-controlled .css symlink in GAMES points outside the tree and a maintainer runs the documented rewrite mode, the rewrite's open(path, "w") follows the symlink and writes generated stylesheet contents to its target, corrupting the maintainer's external file.
Reject symlinks and verify each resolved stylesheet path remains inside GAMES before reading or writing it.
Prompt for AI agents
In `scripts/games_red.py` at line 207:
**Generator overwrites external files**
When a contributor-controlled `.css` symlink in `GAMES` points outside the tree and a maintainer runs the documented rewrite mode, the rewrite's `open(path, "w")` follows the symlink and writes generated stylesheet contents to its target, corrupting the maintainer's external file.
Reject symlinks and verify each resolved stylesheet path remains inside `GAMES` before reading or writing it.| .bg-main:not(.is-rail):has(> :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board)) { --side: calc(100vw - 2 * var(--gutter) - var(--sp-4)); --board: min(100svh - var(--bar-h) - 44px, var(--side) - 300px, 560px); | ||
| display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 1fr repeat(6, auto) 1fr; column-gap: var(--sp-4); row-gap: var(--sp-2); align-content: center; justify-content: center; justify-items: center; align-items: center; } | ||
| .bg-main:not(.is-rail):has(> :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board)) > :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board) { --hs: var(--board); --fs: var(--board); --ps: var(--board); --bs: var(--board); grid-column: 1; grid-row: 1 / span 8; } | ||
| .bg-main:not(.is-rail):has(> :is(.wl-wrap, .ff-board, .po-board, .bg-board, .wk-board)) > :not(.wl-wrap, .ff-board, .po-board) { grid-column: 2; max-width: 100%; } |
There was a problem hiding this comment.
🟡 Medium · Boards appear in controls column
When a game with a direct-child .bg-board or .wk-board is shown in landscape at a height of 520px or less, > :not(.wl-wrap, .ff-board, .po-board) also matches those board children, so its later grid-column: 2 overrides their grid-column: 1 placement and leaves the board in the controls column.
Exclude .bg-board and .wk-board from the controls selector, or target the controls explicitly.
Prompt for AI agents
In `zimi/builtin/games/world.css` at line 35:
**Boards appear in controls column**
When a game with a direct-child `.bg-board` or `.wk-board` is shown in landscape at a height of 520px or less, `> :not(.wl-wrap, .ff-board, .po-board)` also matches those board children, so its later `grid-column: 2` overrides their `grid-column: 1` placement and leaves the board in the controls column.
Exclude `.bg-board` and `.wk-board` from the controls selector, or target the controls explicitly.| HEX = re.compile(r"#([0-9a-fA-F]{8}|[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b") | ||
| RGB = re.compile(r"rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+)\s*)?\)") |
There was a problem hiding this comment.
🟡 Medium · Some colours stay unchanged in Red mode
When a game stylesheet uses valid CSS colour syntax outside the regex patterns, such as #RGBA or percentage/space-separated rgb() or rgba(), HEX and RGB/has_colour do not recognize those forms, so the colour is not converted and its original hue remains visible in Red mode.
Extend the colour matching and conversion to cover the valid CSS colour syntaxes used by game stylesheets.
Prompt for AI agents
In `scripts/games_red.py` at lines 23-24:
**Some colours stay unchanged in Red mode**
When a game stylesheet uses valid CSS colour syntax outside the regex patterns, such as `#RGBA` or percentage/space-separated `rgb()` or `rgba()`, `HEX` and `RGB`/`has_colour` do not recognize those forms, so the colour is not converted and its original hue remains visible in Red mode.
Extend the colour matching and conversion to cover the valid CSS colour syntaxes used by game stylesheets.7d5a2e5 to
87f5336
Compare
9151986 to
fd2590f
Compare
87f5336 to
173a003
Compare
fd2590f to
445cb99
Compare
173a003 to
74fbfb9
Compare
445cb99 to
729e9a3
Compare
|
Reviewed here; included in the release PR #189. |
Part 9 of 18 of Zimi 1.16.0: Games: the Red night light in every game's stylesheet. Base:
line/1.16.0-08-games-new(part 8); the diff shows only this part's files. The PR carries thenot-a-releaselabel and the version stays 1.15.7, so merging it cuts no release. Merge in order (1 to 17, then 18) with a merge commit, not a squash.What this is
The Games shell (part 6) already has a Red night theme for its own tokens. The older games write colours straight into their stylesheets, so in Red they stayed light. This part adds a generator that gives every games stylesheet a Red twin of each rule that holds a colour literal, plus a drift test and one browser test.
What changes
scripts/games_red.py: for eachzimi/builtin/games/*.cssit finds every declaration holding a hex,rgb()orrgba()colour and appends a twin under:root.gs.night-red. Each colour is mapped by luminance onto black-to-red (white becomes#ff2010, black stays black, alpha is kept).scripts/games_red.pydetails: rules insideprefers-color-scheme: darkare unwrapped (Red is dark), light-only rules,@keyframes,@font-faceand similar at-rules are skipped, and the twins keep source order so later overrides still win.python3 scripts/games_red.pyrewrites the blocks,--checkexits 1 if one is stale./* Red, generated by scripts/games_red.py ... */and/* end Red */, appended at the end of the file./* Red (games.css): ... */, that sets the file's own custom properties (for example the 2048 tile ramp, the Mahjong face and edge) under:root.gs.night-red. The generator skips custom properties on:rooton purpose.tests/test_games_red_generated.py: fails if any stylesheet's block differs from what the script would write, and checks the colour mapping.tests/test_games_mahjong_red_browser.py: in Red, every ink in a tile of both Mahjong games is near black on the red face.fiveletters.css(how-to-play example rows, a larger tap box for keys on a coarse pointer, a help button),minicrossword.css(the same key tap box),cribbage.css(peg-board tick labels 6px to 11px),backgammon.css(point numbers 10px to 12px),hex.css(the board's height budget 205px to 292px),wikirace.css(trail scrollbar rule removed),kart.css(a portrait media block).world.css: a landscape block for the square-board games (Walls, Fourfold, Polyominoes, Checkers, Reversi, Go): board on the left, status and controls stacked beside it.How to review
scripts/games_red.pyfirst:blocks(the brace and string scanner),red_selector(which selectors are skipped) andgenerated(comments are stripped before scanning, so a colour inside a comment never produces a twin).zimi/builtin/games/mahjong.cssorworld.css, and check that each twin keeps its property list and only the colours change.var()gets no twin and relies on the token values ingames.css. Nothing here runs on the server path.--checkproves it) and the 31 one-line token overrides after a quick look that each uses:root.gs.night-red.fiveletters.cssstyle markup that lands in part 10 (fiveletters.js,fiveletters.html), so they are unused until then. Theworld.csslandscape block and the key tap boxes belong to the phone and landscape pass (part 10) by subject; they are here because they sit in the same stylesheets the generator rewrote.Tests
tests/test_games_red_generated.py(quick, no browser): every stylesheet's generated block is current, andconvertmaps white, black, alpha colours andvar()values as stated.tests/test_games_mahjong_red_browser.py: the glyph inks ofmahjong.htmlandmahjong4.htmltiles are near black in Red at a 390px touch viewport.Summary by Sourcery
Extend the Games stylesheets with synchronized Red night-theme coverage while improving mobile and landscape presentation across selected games.
New Features:
Bug Fixes:
Enhancements:
Tests: