Extract the arithmetic into wiring/engine.js, pinned by recordings of the tool - #17
Open
nicobrinkkemper wants to merge 1 commit into
Open
Extract the arithmetic into wiring/engine.js, pinned by recordings of the tool#17nicobrinkkemper wants to merge 1 commit into
nicobrinkkemper wants to merge 1 commit into
Conversation
… the tool The Collecting and Wiring generators computed everything inside DOM event handlers, with the rail search written twice (isWirable and findWiringResults). engine.js now holds the whole calculation as plain functions; script.js reads the page, calls the engine, and writes the result back. data.js and script.js are ES modules; the site still has no build step. Before extracting, test/record-goldens.mjs recorded the original tool's output for 160 collecting runs and 312 wiring lookups (test/fixtures). `npm test` replays them through the engine and passes; re-recording from the refactored page yields byte-identical fixtures. One behaviour change, covered by test/page.test.mjs: the Wiring Generator took its water/ground rule from the Collecting Generator's type selector (typeKeys) instead of its own, so with Collecting on ground and Wiring on water it searched with the ground rule. It now uses its own selector. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Author
|
I had my ai test the system and do some translations. Also found one bug. Feel free to ignore, use this code or request changes, i pr'd it for visibility |
Owner
|
Thank you for your PR - that's amazing! Thanks again! |
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.
Goal
Make it safe to change TrackConductor without breaking the numbers. This PR adds no feature. It does two things:
npm testchecks that the calculation still produces exactly those results. Any future change that alters a delay, a height or a grade fails the test, and an intended change shows up as a small diff intest/fixtures.wiring/engine.js, plain functions with no DOM.script.jskeeps the page behaviour and calls the engine. This is what makes the tests possible, and it is groundwork for the translation and UI work discussed with Nico: those can then touch the page without touching the maths.The page looks and behaves the same. The one exception is a bug fix described below.
目的: 計算結果を変えずにツールを改修できるようにすることです。機能追加はありません。(1) 元ツールの出力を472ケース記録し、
npm testで同一であることを検証します。(2) 計算部分をwiring/engine.jsにまとめ、ページ側(script.js)はそれを呼ぶだけにしました。見た目と挙動は同じです。例外は下記のバグ修正1点のみです。Bug fix (the only behaviour change)
findWiringResultsdecided the water/ground search rule from the Collecting Generator's type selector (typeKeys) rather than the Wiring Generator's own. With Collecting on "Winged, Ground" and Wiring on "Winged, Underwater", the search ran with the ground rule. The engine now derives the rule from the Wiring Generator's type.npm run test:page(Playwright, drives the real page) checks this against the recorded underwater results; it fails on the previousscript.jsand passes now.配線生成の水中/地上判定が、配線側ではなく集音側のタイプ選択を参照していました。配線側の選択を参照するように修正しています。
Details
wiring/engine.js:noteFrames,columnTimes,landingColumnDelays,scrollColumnDelays,collect(the Collecting Generator),grade/findWirings(one search instead of the two copiesisWirableandfindWiringResults),wiringTiles(the rail diagram).wiring/data.jsandwiring/script.jsare ES modules. No build step, no bundler;package.jsonexists only for the test scripts.old/is untouched.test/README.mdexplainsnpm test,npm run test:pageandnpm run record(re-record fixtures after an intentional change). Fixtures are one case per line so diffs stay readable.