Skip to content

Export a scene to Ren'Py and serve its web build at /renpy - #401

Merged
calebl merged 1 commit into
mainfrom
fm/ta-renpy-s1-export
Dec 4, 2026
Merged

calebl merged 1 commit into
mainfrom
fm/ta-renpy-s1-export

Conversation

@calebl

@calebl calebl commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator

Stage 1 of the Ren'Py proof scene: export a scene to Ren'Py and serve its web build from this server. No pictures, no model calls, no spend, and no text a model reads changes.

What it does

  • Renpy::Export (app/models/renpy/export.rb) writes a story's opening, or a playthrough's scene_chain, as a Ren'Py project (game/script.rpy).
    • One Ren'Py scene per Scene row.
    • Every line is narration from scenes.description, one sentence per click. Speech is not split out of the prose.
    • The protagonist is the narrator's side image; nobody stands in the room for them.
    • Every picture is one of Ren'Py's built-in placeholders.
    • Image names come from record ids (bg l<id>, c<id> neutral, side c<id>).
  • Renpy::Placement decides who stands where. The cast is the scene's characters_scenes minus the protagonist, plus the person talked to on a talk turn.
    • The person spoken to stands at the centre.
    • Everyone else takes right, then left, then centre, in id order.
    • With more people than the three places, the extra people are not drawn (the prose still names them). The file header records this rule.
  • Renpy::Text handles escaping and sentence splitting:
    • [ becomes [[, { becomes {{, and " and \ are backslashed.
    • A sentence ends at ., !, ? or … followed by a capital. No word is ever dropped.
  • rake renpy:export[story] and rake renpy:build[story], or PLAYTHROUGH=<id or token> for one game's turns. Renpy::Build runs the SDK steps:
    1. launcher generate_gui at 1920×1080, once per project. Without it there is no side image and only a bare text box.
    2. The project's gui_images, normal and phone. Without these the build stops at the main menu with "could not find image".
    3. lint --error-code.
    4. launcher web_build into a staging folder, which is then moved into TA_RENPY_ROOT/<name>-<script digest>/.
  • The /renpy mount (Renpy::Files, config/routes.rb):
    • It is a Rack::Files over TA_RENPY_ROOT (default storage/renpy), drawn below the hosted-mode cut, so the browser install has it and a hosted instance does not.
    • .wasm is sent as application/wasm and every file as cache-control: no-cache.
    • A folder serves its index.html, and a folder requested without its trailing slash redirects to it.
    • /renpy/ lists the builds with Ren'Py's licence link, in the wording Ren'Py's licence page suggests (Renpy::Index).
  • Settings: TA_RENPY_SDK and TA_RENPY_ROOT (config/application.rb, deploy/local/deploy.env.example).
  • Docs: steps in docs/local-deploy.md, plus a short README section.
  • AGENTS.md: one line naming the Ren'Py build tool as the second exception to the zero-build-step rule, as approved. The old sentence said "the one approved exception", so it now says "the first".

The Ren'Py SDK: how it is obtained and where it lives

It is never committed, and the app runs and serves without it; only rake renpy:build needs it.

To prove the build, I downloaded Ren'Py 8.6.2 from renpy.org to ~/.cache/renpy-sdk/ on the build machine, outside the repository:

  • renpy-8.6.2-sdk.tar.bz2 and renpy-8.6.2-web.zip;
  • both sha256 sums match https://www.renpy.org/dl/8.6.2/checksums.txt;
  • the web zip is unzipped into the SDK folder so web/ sits beside renpy.sh, because the launcher cannot install web support without a window.

docs/local-deploy.md gives the same steps for the private install, under ~/.local/share/text-adventure-web/renpy-8.6.2-sdk.

Proven on this machine

  • bin/rails 'renpy:build[The Lunar Cartographer]' on a freshly seeded database ran every step headless, with no xvfb, in about 11 seconds. The build is about 46 MB.
  • I served it through bin/rails server and played it in Chrome at /renpy/story-1-<digest>/. It showed:
    • the room placeholder;
    • Grenn's placeholder standing at the right;
    • Isbet's placeholder as the side image beside the standard text box;
    • one sentence per click, with [, { and " shown as written.
  • This settles three of the plan's open questions:
    • the side image works on the narrator;
    • web_build needs no set_project first;
    • the project does need generate_gui and gui_images.

Tests

  • test/models/renpy/export_test.rb:
    • the seeded Lunar Cartographer opening exports to a stored expected script (test/fixtures/files/renpy/the-lunar-cartographer-opening.rpy);
    • six clicks that join back into the full paragraph;
    • the side image, the build-name digest, a playthrough's chain, and escaping.
  • placement_test.rb and text_test.rb cover who stands where, and sentence splitting with escaping.
  • test/integration/renpy_files_test.rb serves a small fixture build: renpy.wasm as application/wasm, the trailing-slash redirects, a path outside the folder refused, and an empty root returning 404.
  • renpy.sh lint --error-code runs on two exports (the seeded opening and an escaping case) when TA_RENPY_SDK is set, and is skipped otherwise. With the SDK set it passes. Lint catches a parse error or an undefined image. It does not read say text, so an unescaped [, { or " passes it; I checked this. The escaping test is the guard there.
  • build_test.rb and index_test.rb cover the error messages when the SDK is missing or wrong, and the list page.

Checks

All run with OPENROUTER_API_KEY, TYPESAFE_API_KEY and TA_RENPY_SDK unset:

  • bin/rails test: 5537 runs, 0 failures, 0 errors, 1 skip (the SDK lint test);
  • bundle exec rubocop: no offences;
  • bin/rails zeitwerk:check: all good;
  • bin/brakeman --no-pager: no warnings.

No migration, and no Update::REGISTRY step is needed.

The Lunar Cartographer opening played at /renpy/ with placeholders

Renpy::Export writes a story's opening, or a playthrough's scene_chain,
as a Ren'Py project: one Ren'Py scene per Scene row, every line narration
from scenes.description one sentence per click, the cast standing where
Renpy::Placement puts them (the person spoken to centred), the protagonist
as the narrator's side image, and Ren'Py's own placeholders for every
picture. Image names come from record ids; [, {, " and \ are escaped.

rake renpy:export / renpy:build run Ren'Py 8.6.2's SDK (TA_RENPY_SDK,
outside the repository): generate_gui, gui_images, lint --error-code and
launcher web_build, into TA_RENPY_ROOT. The app mounts that folder at
/renpy (browser install only), sends .wasm as application/wasm, and lists
the builds at /renpy/ with Ren'Py's licence link. AGENTS.md names the
Ren'Py build tool as the second exception to the zero-build-step rule.

No model calls; no text a model reads changes.
@calebl
calebl merged commit 648b923 into main Dec 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant