Expand Lumen stories and add island postcards
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// Freeze the boards so future generator changes cannot change saved puzzles.
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:lumen/domain/puzzle.dart';
|
||||
|
||||
void main() {
|
||||
final lines = <String>[
|
||||
'// Generated by tool/author_postcard_puzzles.dart. Stable v1 save identities.',
|
||||
'const postcardPatterns = <(String, List<int>)>[',
|
||||
];
|
||||
final seen = <String>{};
|
||||
for (var i = 0; i < 42; i++) {
|
||||
final difficulty = i < 6 || i % 3 == 0
|
||||
? Difficulty.easy
|
||||
: i % 3 == 1 || i < 18
|
||||
? Difficulty.medium
|
||||
: Difficulty.hard;
|
||||
var seed = 830000 + i * 1000;
|
||||
Puzzle p;
|
||||
do {
|
||||
p = Puzzle.generate(BigInt.from(seed++), difficulty);
|
||||
} while (!seen.add(p.solution.join()));
|
||||
if (p.countSolutions() != 1 ||
|
||||
!LogicSolver(
|
||||
p.solution.length,
|
||||
p.constraints,
|
||||
).analyze(p.initial).solved) {
|
||||
throw StateError('Invalid postcard board $i');
|
||||
}
|
||||
lines.add(
|
||||
" ('${p.solution.join()}', ${[for (var j = 0; j < 25; j++)
|
||||
if (p.given[j]) j]}),",
|
||||
);
|
||||
}
|
||||
lines.add('];');
|
||||
File('lib/domain/postcard_patterns.dart')
|
||||
.writeAsStringSync('${lines.join('\n')}\n');
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile Mara's spoken manuscript while preserving puzzles and save identities."""
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
ASSETS = ROOT / 'assets'
|
||||
SOURCE = ASSETS / 'narration'
|
||||
|
||||
def read(path): return json.loads(path.read_text())
|
||||
def write(path, data): path.write_text(json.dumps(data, ensure_ascii=False, indent=2) + '\n')
|
||||
|
||||
parts = re.split(r'^## (\S+) \| (.+)\n\n', (SOURCE / 'STORY.md').read_text(), flags=re.M)
|
||||
entries = {parts[i]: (parts[i+1], parts[i+2].strip()) for i in range(1, len(parts), 3)}
|
||||
old = read(SOURCE / 'scripts.json')
|
||||
assert set(entries) == {r['pageId'] for r in old}, 'Preserve all 28 reading IDs'
|
||||
cast = read(SOURCE / 'cast.json')
|
||||
performance = read(SOURCE / 'performance.json')
|
||||
assert set(entries) == set(performance['scenes'])
|
||||
campaign = read(ASSETS / 'campaign.json')
|
||||
notebook = read(ASSETS / 'notebook.json')
|
||||
pages = {p['id']: p for p in notebook['pages']}
|
||||
records = []
|
||||
for previous in old:
|
||||
page_id = previous['pageId']
|
||||
title, prose = entries[page_id]
|
||||
split = prose.split('\n\n<!-- Narrator -->\n\n')
|
||||
assert len(split) in (1, 2)
|
||||
lead = 'Mara' if page_id in ('cottage.dedication', 'cottage.window', 'cottage.match.memory',
|
||||
'cottage.folded.note', 'cottage.lantern.sketch') else 'Narrator'
|
||||
text = '\n\n'.join(split)
|
||||
blocks = [(split[0] + ('\n\n' if len(split)==2 else ''), lead)]
|
||||
if len(split)==2: blocks.append((split[1], 'Narrator'))
|
||||
segments = []
|
||||
for block, default in blocks:
|
||||
quotes = list(re.finditer('“[^”]+”', block)) if default == 'Narrator' else []
|
||||
cuts = {0, len(block)}
|
||||
cuts.update(m.end() for m in re.finditer('\n\n', block))
|
||||
for m in quotes: cuts.update((m.start(), m.end()))
|
||||
bounds = sorted(cuts)
|
||||
for start, end in zip(bounds, bounds[1:]):
|
||||
part = block[start:end]
|
||||
if not part.strip():
|
||||
segments[-1]['text'] += part
|
||||
segments[-1]['pauseMs'] = 650
|
||||
continue
|
||||
role = 'Mara' if any(m.start() <= start < m.end() for m in quotes) else default
|
||||
segment = {'speaker': role, 'text': part,
|
||||
'direction': performance['scenes'][page_id][role],
|
||||
'pauseMs': 650 if part.endswith('\n\n') else 200}
|
||||
previous_segment = segments[-1] if segments else None
|
||||
if (previous_segment and previous_segment['speaker']==role
|
||||
and previous_segment['direction']==segment['direction']
|
||||
and len((previous_segment['text']+part).split())<=90):
|
||||
previous_segment['text'] += part
|
||||
previous_segment['pauseMs'] = segment['pauseMs']
|
||||
else: segments.append(segment)
|
||||
assert ''.join(s['text'] for s in segments) == text
|
||||
record = {'pageId': page_id, 'resource': previous['resource'], 'text': text,
|
||||
'speaker': lead, 'production': 'mara-qwen-v1', 'segments': segments}
|
||||
if len(split)==2:
|
||||
record.update(baseText=split[0], continuation=split[1], continuationSpeaker='Narrator')
|
||||
records.append(record)
|
||||
if page_id.startswith('campaign.'):
|
||||
_, index, phase = page_id.split('.')
|
||||
campaign['levels'][int(index)][phase] = text
|
||||
else:
|
||||
page = pages[page_id]
|
||||
page['speaker'] = lead
|
||||
page.pop('continuation', None)
|
||||
if len(split)==2: page['continuation'] = split[1]
|
||||
if page.get('textSource') in ('before','after'):
|
||||
campaign['levels'][page['campaignIndex']][page['textSource']] = text
|
||||
elif page.get('textSource') != 'recording':
|
||||
page['text'] = text
|
||||
if page_id=='cottage.window': campaign['levels'][0]['before'] = text
|
||||
if page_id=='cottage.match.memory': campaign['levels'][0]['after'] = text
|
||||
for level in campaign['levels']:
|
||||
level.pop('beforeContinuation', None)
|
||||
level.pop('afterContinuation', None)
|
||||
write(ASSETS / 'campaign.json', campaign)
|
||||
write(ASSETS / 'notebook.json', notebook)
|
||||
write(SOURCE / 'scripts.json', records)
|
||||
print(f'Compiled {len(records)} readings, {sum(len(r["text"].split()) for r in records)} words, '
|
||||
f'{sum(len(r["segments"]) for r in records)} directed takes.')
|
||||
@@ -39,19 +39,9 @@ for page in notebook['pages']:
|
||||
page['caption'] = chapters[page['campaignIndex']//4]
|
||||
write(PACKAGE/'campaign.json',campaign)
|
||||
write(PACKAGE/'notebook.json',notebook)
|
||||
cast = {
|
||||
'Elias': {'voice':'bm_george','speed':.93,'language':'en-gb',
|
||||
'direction':'A postman recording a night he barely survived. Personal and restrained; fear through careful observation, not theatrical shouting.'},
|
||||
'Iris': {'voice':'bf_emma','speed':.91,'language':'en-gb',
|
||||
'direction':'A tired guardian speaking quietly so the house will not hear. Clear, urgent warnings; fragile relief near the end.'},
|
||||
'Ada': {'voice':'bf_isabella','speed':.94,'language':'en-gb',
|
||||
'direction':'The postmistress. A practical voice with a serious warning.'},
|
||||
'The borrowed voice': {'voice':'bf_isabella','speed':.87,'language':'en-gb',
|
||||
'direction':'An imitation of Ada through a closed door. Do not exaggerate; its familiarity is the threat.'},
|
||||
'The echo': {'voice':'bm_george','speed':.87,'language':'en-gb',
|
||||
'direction':'An imitation of Elias behind a door, slightly slower and distant.'},
|
||||
}
|
||||
write(PACKAGE/'narration/cast.json',cast)
|
||||
cast = read(PACKAGE/'narration/cast.json')
|
||||
performance = read(PACKAGE/'narration/performance.json')
|
||||
assert set(performance['scenes']) == set(entries), 'Every scene needs performance direction'
|
||||
roles = {
|
||||
'midnight.opening':['Ada'],
|
||||
'midnight.feather.memory':['Iris','Elias','Iris','Iris'],
|
||||
@@ -91,16 +81,38 @@ for page_id,(title,text) in entries.items():
|
||||
segment={'speaker':speaker,'text':part,'pauseMs':700 if part.endswith('\n\n') else 220}
|
||||
if speaker in ('The borrowed voice','The echo') or (page_id=='midnight.feather.memory' and speaker=='Iris'):
|
||||
segment['perspective']='behind-door'
|
||||
if speaker=='Iris': segment['direction']=cast['Iris']['direction']
|
||||
scene = performance['scenes'][page_id]
|
||||
segment['direction'] = scene.get(speaker, scene['Elias'])
|
||||
action=actions.get(end)
|
||||
if isinstance(action,str): segment.update(afterEffect=action,pauseMs=1350)
|
||||
elif action: segment['pauseMs']=action
|
||||
if part.strip() in ('I kept walking.','It did not strike.','The mouth closed.'):
|
||||
segment['pauseMs']=1200
|
||||
segments.append(segment)
|
||||
# Keep short paragraphs together for connected acting and voice continuity.
|
||||
# Explicit silences and Foley boundaries always remain separate takes.
|
||||
joined=[]
|
||||
for segment in segments:
|
||||
previous=joined[-1] if joined else None
|
||||
if (previous and previous['speaker']==segment['speaker']
|
||||
and previous['direction']==segment['direction']
|
||||
and previous.get('perspective')==segment.get('perspective')
|
||||
and previous['pauseMs']<=700 and not previous.get('afterEffect')
|
||||
and len((previous['text']+segment['text']).split())<=90):
|
||||
previous['text']+=segment['text']
|
||||
previous['pauseMs']=segment['pauseMs']
|
||||
if segment.get('afterEffect'): previous['afterEffect']=segment['afterEffect']
|
||||
else:
|
||||
joined.append(segment.copy())
|
||||
segments=joined
|
||||
if page_id=='midnight.chair.memory':
|
||||
for segment in segments:
|
||||
if segment['speaker']=='Iris':
|
||||
segment['direction'] = ('Her mother is about to leave forever. Let the name falter with grief; quiet and audible, no sobbing sounds.'
|
||||
if '...' in segment['text'] else 'Gather courage and finish her mother\'s name clearly. Tender, grieving, determined; no sobbing sounds.')
|
||||
assert ''.join(s['text'] for s in segments)==text
|
||||
records.append({'pageId':page_id,'resource':page_id.replace('.','_'),'text':text,
|
||||
'speaker':'Elias','production':'diary-drama-v2','segments':segments})
|
||||
'speaker':'Elias','production':'diary-qwen-v3','segments':segments})
|
||||
write(PACKAGE/'narration/scripts.json',records)
|
||||
library=read(ROOT/'assets/library.json')
|
||||
story=next(s for s in library['stories'] if s['id']=='midnight-invitation')
|
||||
|
||||
Reference in New Issue
Block a user