clone

a browser grid puzzle game where you push words around to rewrite the rules of each level

Preserve physical ledger tokens through exits

Dami committed b73c92a
commit
b73c92a9820cca5f844b6556b0c895f8b8a4f943
parent
c2304c10f7241fbed4bb080270bd222a91d9b79d
author
Dami <dami.etoile@gmail.com>
3 files changed, +20 -6
Msrc/juice.js22+++++++++++++++++-----
Msrc/juice/ledger.js3++-
Mtests/juice.test.js1+
M src/juice.js +17 -5
@@ -144,7 +144,14 @@ export function createJuice({ reducedMotion = false, now = () => performance.now
144144 priorSentenceCells = new Map();145145 priorSentences = new Map();146146 for (const sentence of state.sentences || []) {147- const normalized = { ids: [...(sentence.ids || [])], axis: sentence.axis };147+ const normalized = {148+ ids: [...(sentence.ids || [])],149+ axis: sentence.axis,150+ tokens: (sentence.ids || []).map(id => {151+ const object = state.objects.find(candidate => candidate.id === id);152+ return object?.text || object?.noun || '';153+ }),154+ };148155 const key = keyForSentence(normalized);149156 priorSentences.set(key, normalized);150157 priorSentenceCells.set(key, normalized.ids.map(id => {
@@ -152,7 +159,7 @@ export function createJuice({ reducedMotion = false, now = () => performance.now
152159 return object ? cellOf(object) : null;153160 }).filter(Boolean));154161 if (!sentences.has(key)) sentences.set(key, { key, ids: [...normalized.ids], axis: normalized.axis, phase: 'active', start: at, holdUntil: at, duration: 0, frozenCells: null });155- if (!ledger.has(key)) ledger.set(key, { key, ids: [...normalized.ids], phase: 'active', start: at });162+ if (!ledger.has(key)) ledger.set(key, { key, ids: [...normalized.ids], tokens: [...normalized.tokens], phase: 'active', start: at });156163 }157164 const live = new Set();158165 for (const object of state.objects) {
@@ -233,7 +240,7 @@ export function createJuice({ reducedMotion = false, now = () => performance.now
233240 });234241 }235242 236- function consumeSentenceAdded(sentence, at, holdUntil, predicate = 'ink') {243+ function consumeSentenceAdded(sentence, at, holdUntil, predicate = 'ink', tokens = []) {237244 const key = keyForSentence(sentence);238245 const start = holdUntil;239246 sentences.set(key, {
@@ -247,7 +254,7 @@ export function createJuice({ reducedMotion = false, now = () => performance.now
247254 duration: duration(RULE_FORM_MS),248255 frozenCells: null,249256 });250- ledger.set(key, { key, ids: [...(sentence.ids || [])], phase: 'stamping', start });257+ ledger.set(key, { key, ids: [...(sentence.ids || [])], tokens: [...tokens], phase: 'stamping', start });251258 for (const id of sentence.ids || []) {252259 const entity = entityAt(id);253260 entity.bounceStart = start;
@@ -279,6 +286,7 @@ export function createJuice({ reducedMotion = false, now = () => performance.now
279286 ledger.set(key, {280287 key,281288 ids: [...(sentence.ids || ledgerEntry?.ids || [])],289+ tokens: [...(sentence.tokens || ledgerEntry?.tokens || [])],282290 phase: 'removing',283291 start: at,284292 });
@@ -376,7 +384,11 @@ export function createJuice({ reducedMotion = false, now = () => performance.now
376384 const key = keyForSentence(sentence);377385 if (!priorSentences.has(key)) {378386 const rule = (result.rulesAdded || []).find(candidate => (candidate.sourceIds || []).join('>') === key);379- consumeSentenceAdded(sentence, at, holdUntil, rule?.predicate || 'ink');387+ const tokens = sentence.ids.map(id => {388+ const object = state.objects.find(candidate => candidate.id === id);389+ return object?.text || object?.noun || '';390+ });391+ consumeSentenceAdded(sentence, at, holdUntil, rule?.predicate || 'ink', tokens);380392 }381393 else if (!sentences.has(key)) sentences.set(key, { key, ids: [...sentence.ids], axis: sentence.axis, phase: 'active', start: at, holdUntil: at, duration: 0, frozenCells: null });382394 }
M src/juice/ledger.js +2 -1
@@ -35,6 +35,7 @@ export function projectLedgerEntry(entry, at, timings = LEDGER_TIMINGS) {
3535 return {3636 key: entry.key,3737 ids,38+ tokens: [...(entry.tokens || [])],3839 phase: exitProgress >= 1 ? 'exited' : 'removing',3940 stampProgress: ids.map(() => 1),4041 strikeProgress,
@@ -47,6 +48,7 @@ export function projectLedgerEntry(entry, at, timings = LEDGER_TIMINGS) {
4748 return {4849 key: entry.key,4950 ids,51+ tokens: [...(entry.tokens || [])],5052 phase: complete ? 'active' : 'stamping',5153 stampProgress: progresses,5254 strikeProgress: 0,
@@ -54,4 +56,3 @@ export function projectLedgerEntry(entry, at, timings = LEDGER_TIMINGS) {
5456 visible: true,5557 };5658 }57-
M tests/juice.test.js +1 -0