0718e3f252
- Start the app on a shelf of every installed book instead of the last book's home. Cards show the cover, translated metadata, available languages, restored patterns and either "Continue reading" or a way in. - Keep each book's saved route: the shelf is never written to flutter_screen, so choosing a book resumes its own leaf. - Lay the shelf out responsively: dense single-column cards on phones, a two-column grid from 720 logical pixels, a centred 860 px column on tablets and a chevron that exists in the bundled handwriting font. - Keep Settings reachable from the shelf and let the home page's story library button open the shelf instead of a dialog. - Add tool/shelf_screenshots_test.dart, which renders the shelf at phone and tablet metrics, checks that every card and Settings stay reachable without overflow, and writes artifacts/library/shelf-*.png. - Commit the pending Midnight Invitation package (campaign, notebook, narration and artwork), cast drama and ambience tooling, region selection, phone/tablet integration coverage and related docs. flutter analyze is clean and all 74 widget/domain tests pass.
111 lines
6.1 KiB
Python
111 lines
6.1 KiB
Python
#!/usr/bin/env python3
|
||
"""Compile the editable diary manuscript into stable story pages and cast scripts.
|
||
|
||
Puzzle grids, clues, IDs, progress keys and artwork associations are preserved.
|
||
After running, render narration and run the story package checks before building.
|
||
"""
|
||
import json
|
||
import re
|
||
from pathlib import Path
|
||
|
||
ROOT = Path(__file__).resolve().parents[1]
|
||
PACKAGE = ROOT / 'assets/stories/midnight-invitation'
|
||
read = lambda p: json.loads(p.read_text())
|
||
write = lambda p, data: p.write_text(json.dumps(data, ensure_ascii=False, indent=2) + '\n')
|
||
parts = re.split(r'^## (\S+) \| (.+)\n\n', (PACKAGE/'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)}
|
||
campaign = read(PACKAGE/'campaign.json')
|
||
notebook = read(PACKAGE/'notebook.json')
|
||
assert set(entries) == {p['id'] for p in notebook['pages'] if p['type'] != 'puzzle'}
|
||
chapters = ['I · The road that would not end', 'II · The guest beneath the floor', 'III · Return to sender']
|
||
campaign['premise'] = 'The private diary of Elias Ward, a Blackthorn postman. On Halloween he carried a letter in his own handwriting to a house with twelve missing guests and a thirteenth place waiting for him. A complete Gothic mystery in three chapters.'
|
||
for i, level in enumerate(campaign['levels']):
|
||
prefix = 'midnight.' + level['id']
|
||
level['title'], level['before'] = entries[prefix+'.entry']
|
||
level['memoryTitle'], level['after'] = entries[prefix+'.memory']
|
||
level['chapter'] = chapters[i//4]
|
||
for page in notebook['pages']:
|
||
if page['id'] in entries:
|
||
page['title'], text = entries[page['id']]
|
||
if page.get('textSource') not in ('before','after'):
|
||
page['text'] = text
|
||
page['speaker'] = 'Elias Ward · private delivery diary'
|
||
else:
|
||
page['title'] = campaign['levels'][page['campaignIndex']]['title']
|
||
if 'caption' in page:
|
||
if page['id'] == 'midnight.opening':
|
||
page['caption'] = 'Blackthorn. An account written after the Halloween delivery.'
|
||
else:
|
||
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)
|
||
roles = {
|
||
'midnight.opening':['Ada'],
|
||
'midnight.feather.memory':['Iris','Elias','Iris','Iris'],
|
||
'midnight.key.entry':['The borrowed voice','Iris'],
|
||
'midnight.needle.memory':['Iris','Iris','The echo'],
|
||
}
|
||
effects = {
|
||
'midnight.feather.memory':{'At the door I knocked twice.':'door-knock', 'A chair scraped over the floor on the other side.':'chair-shift'},
|
||
'midnight.candle.entry':{'I spread the paper beneath the lamp.':'paper'},
|
||
'midnight.ending':{'A few minutes ago, the drawer knocked twice.':'door-knock'},
|
||
}
|
||
records=[]
|
||
for page_id,(title,text) in entries.items():
|
||
quotes=list(re.finditer('“[^”]+”',text))
|
||
speakers=roles.get(page_id,['Iris']*len(quotes))
|
||
assert len(quotes)==len(speakers),(page_id,len(quotes),speakers)
|
||
spans=[(m.start(),m.end(),speaker) for m,speaker in zip(quotes,speakers)]
|
||
cuts={0,len(text)}
|
||
cuts.update(m.end() for m in re.finditer('\n\n',text))
|
||
for a,b,_ in spans: cuts.update((a,b))
|
||
actions={}
|
||
for phrase,name in effects.get(page_id,{}).items():
|
||
assert phrase in text
|
||
end=text.index(phrase)+len(phrase)
|
||
cuts.add(end);actions[end]=name
|
||
if page_id=='midnight.feather.memory':
|
||
end=text.index('Silence.')+len('Silence.');cuts.add(end);actions[end]=1500
|
||
segments=[]
|
||
bounds=sorted(cuts)
|
||
for start,end in zip(bounds,bounds[1:]):
|
||
part=text[start:end]
|
||
if not part.strip():
|
||
segments[-1]['text']+=part
|
||
segments[-1]['pauseMs']=max(segments[-1]['pauseMs'],700)
|
||
continue
|
||
speaker=next((s for a,b,s in spans if a<=start<b),'Elias')
|
||
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']
|
||
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)
|
||
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})
|
||
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')
|
||
story['description']='A postman’s Halloween diary: twelve missing guests, a stolen voice, and a letter that must never be delivered.'
|
||
story['paperAsset']='assets/stories/midnight-invitation/artwork/diary-page-v1.png'
|
||
write(ROOT/'assets/library.json',library)
|
||
print(f'Compiled {len(entries)} diary entries, {sum(len(t.split()) for _,t in entries.values())} words; puzzle identity preserved.')
|