@tora-editor/tora 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -6
- package/bin/tora.mjs +255 -29
- package/crates/packer/trusted/native-3d-meta.json +3 -3
- package/crates/packer/trusted/native-3d.js +180 -180
- package/crates/packer/trusted/native-meta.json +3 -3
- package/crates/packer/trusted/native.js +5 -5
- package/crates/packer/trusted/release-manifest.json +17 -17
- package/crates/packer/trusted/review-runtime-meta.json +3 -3
- package/crates/packer/trusted/review-runtime.js +182 -182
- package/docs/MIGRATION_0_3.md +39 -0
- package/docs/NATIVE_AGENT_TOOLS.md +12 -363
- package/docs/TORA_AGENT_SETUP.md +24 -106
- package/docs/TORA_CREATION_API.md +63 -365
- package/docs/reference/CORE_AUTHORING.md +8 -2
- package/docs/reference/PLAYABLE_STARTERS.md +1 -1
- package/docs/reference/packs/3d.md +2 -0
- package/package.json +6 -6
- package/packages/creative-project/project-v21.schema.json +108 -1
- package/scripts/lean/editor/entry.js +11 -6
- package/scripts/lean/editor/project-launcher.js +116 -0
- package/scripts/lean/editor/quick-edit-panel.js +479 -0
- package/scripts/lean/editor/review-editor.css +246 -68
- package/scripts/lean/editor/review-editor.js +1731 -1099
- package/scripts/lean/editor-state.mjs +6 -0
- package/scripts/lean/editor.mjs +6 -3
- package/scripts/lean/matrix.mjs +5 -0
- package/scripts/lean/native/agent-tools.mjs +35 -58
- package/scripts/lean/native/api.mjs +148 -134
- package/scripts/lean/native/audio-assets.mjs +30 -0
- package/scripts/lean/native/browser-pool.mjs +34 -0
- package/scripts/lean/native/build-cache.mjs +36 -5
- package/scripts/lean/native/contracts.mjs +8 -6
- package/scripts/lean/native/creative-qa.mjs +66 -12
- package/scripts/lean/native/demos.mjs +11 -20
- package/scripts/lean/native/document.mjs +14 -2
- package/scripts/lean/native/local-bundle.mjs +4 -2
- package/scripts/lean/native/mcp-server.mjs +16 -35
- package/scripts/lean/native/modules/harvest-restore.mjs +3 -284
- package/scripts/lean/native/modules/sort-puzzle.mjs +51 -0
- package/scripts/lean/native/modules/star-salvage.mjs +3 -368
- package/scripts/lean/native/project-bundle.mjs +3 -2
- package/scripts/lean/native/project-index.mjs +0 -2
- package/scripts/lean/native/qa-adapters.mjs +10 -0
- package/scripts/lean/native/quick-edit.mjs +328 -0
- package/scripts/lean/native/review.mjs +203 -572
- package/scripts/lean/native/schema-vocabulary.mjs +10 -0
- package/scripts/lean/native/schema.mjs +1 -1
- package/scripts/lean/native/scope.mjs +45 -0
- package/scripts/lean/native/service.mjs +242 -70
- package/scripts/lean/native/starters.mjs +135 -8
- package/scripts/lean/native/variant-adapters.mjs +8 -0
- package/scripts/lean/native/variants-core.mjs +186 -0
- package/scripts/lean/native/variants.mjs +63 -0
- package/scripts/lean/native/win-cues.mjs +1 -1
- package/skills/tora-playables/SKILL.md +1 -1
- package/scripts/lean/editor/review-intake.js +0 -837
- package/scripts/lean/model-client.mjs +0 -119
- package/scripts/lean/native/author-expansion-proofs.mjs +0 -143
- package/scripts/lean/native/author-fps.mjs +0 -545
- package/scripts/lean/native/author-games.mjs +0 -160
- package/scripts/lean/native/author-harvest.mjs +0 -74
- package/scripts/lean/native/author-primitive-proofs.mjs +0 -875
- package/scripts/lean/native/author-salvage.mjs +0 -71
- package/scripts/lean/native/chat-compose.mjs +0 -287
- package/scripts/lean/native/check-harvest-outcome-audio.mjs +0 -190
- package/scripts/lean/native/check-salvage.mjs +0 -200
- package/scripts/lean/native/compatibility.mjs +0 -34
- package/scripts/lean/native/concept.mjs +0 -633
- package/scripts/lean/native/draw-stroke.mjs +0 -26
- package/scripts/lean/native/erase-mask.mjs +0 -18
- package/scripts/lean/native/glb-loader.mjs +0 -468
- package/scripts/lean/native/harvest-recipe.mjs +0 -21
- package/scripts/lean/native/instance-steering.mjs +0 -24
- package/scripts/lean/native/intake-creator-agent.mjs +0 -98
- package/scripts/lean/native/intake-creator-tools.mjs +0 -218
- package/scripts/lean/native/interaction-gestures.mjs +0 -45
- package/scripts/lean/native/match-board.mjs +0 -138
- package/scripts/lean/native/modules/index.mjs +0 -54
- package/scripts/lean/native/modules/tap-collect.mjs +0 -54
- package/scripts/lean/native/path-network.mjs +0 -132
- package/scripts/lean/native/physics-2d.mjs +0 -154
- package/scripts/lean/native/physics-3d.mjs +0 -259
- package/scripts/lean/native/prepare-audio-collections.mjs +0 -112
- package/scripts/lean/native/prepare-fps-assets.mjs +0 -330
- package/scripts/lean/native/prepare-game-audio.mjs +0 -372
- package/scripts/lean/native/prepare-golf-3d-assets.py +0 -177
- package/scripts/lean/native/prepare-golf-assets.py +0 -211
- package/scripts/lean/native/prepare-harvest-audio.mjs +0 -83
- package/scripts/lean/native/prepare-harvest-images.mjs +0 -31
- package/scripts/lean/native/prepare-primitive-images.py +0 -25
- package/scripts/lean/native/prepare-space-salvage-images.mjs +0 -89
- package/scripts/lean/native/prepare-traffic-assets.py +0 -329
- package/scripts/lean/native/presentation.mjs +0 -335
- package/scripts/lean/native/review-agent-tools.mjs +0 -561
- package/scripts/lean/native/review-connection.mjs +0 -303
- package/scripts/lean/native/review-fields.mjs +0 -24
- package/scripts/lean/native/review-intake.mjs +0 -385
- package/scripts/lean/native/review-intents.mjs +0 -217
- package/scripts/lean/native/review-provider.mjs +0 -580
- package/scripts/lean/native/review-receipts.mjs +0 -76
- package/scripts/lean/native/review-resolver.mjs +0 -429
- package/scripts/lean/native/review-targets.mjs +0 -35
- package/scripts/lean/native/runtime.mjs +0 -1809
- package/scripts/lean/native/salvage-recipe.mjs +0 -20
- package/scripts/lean/native/stage-3d.mjs +0 -1121
- package/scripts/lean/native/verify.mjs +0 -4
- package/scripts/lean/scene-document.mjs +0 -48
|
@@ -14,8 +14,6 @@ import {packageVersion} from './native-bin.mjs';
|
|
|
14
14
|
import {fetchCc0Properties,pivotMode,stageCc0ItemSchema} from './cc0-inputs.mjs';
|
|
15
15
|
import {availablePacks,capabilities,capabilitiesForPacks,capabilitySummary,compactCapabilities} from './contracts.mjs';
|
|
16
16
|
import {NativeReview} from './review.mjs';
|
|
17
|
-
import {reviewRoutingFlags} from './review-resolver.mjs';
|
|
18
|
-
import {ReviewIntake} from './review-intake.mjs';
|
|
19
17
|
import {targets} from './network-targets.mjs';
|
|
20
18
|
import {AssetCatalog} from './asset-catalog.mjs';
|
|
21
19
|
import {RemoteCc0Fetcher} from './remote-cc0-fetcher.mjs';
|
|
@@ -35,29 +33,24 @@ export const tools=[];
|
|
|
35
33
|
function define(name,description,properties={},required=[],readOnly=false){tools.push({name:'tora_'+name,description,inputSchema:{type:'object',properties,required,additionalProperties:false},annotations:{readOnlyHint:readOnly,destructiveHint:!readOnly,openWorldHint:false}});}
|
|
36
34
|
define('brief','Read current production instructions and core authoring documentation. Load domain guides with packs or legacy full references with full:true. Pass alreadyRead:[{name,sha256}] on re-reads to omit unchanged docs.',{packs:strings,full:boolean,alreadyRead:{type:'array',items:{type:'object',properties:{name:string,sha256:string},required:['name','sha256'],additionalProperties:false}}},[],true);
|
|
37
35
|
define('capabilities','Discover supported contracts. Use packs for domains, names for exact descriptors, summary for the pack index, format:"compact" for concise schema with units, or omit all for the full registry.',{names:strings,packs:strings,summary:boolean,format:{type:'string',enum:['full','compact']}},[],true);
|
|
38
|
-
define('compose','Compose an editable playable from a structured creative concept and prepared artwork. Read tora_brief and discover creative-concept capabilities first. Returns creative review status and requirement trace.',{id:string,name:string,concept:{type:'object'}},['id','concept']);
|
|
39
36
|
define('starters','List tested editable playable starters and their visual asset roles. Use for simple requests that match a starter.',{},[],true);
|
|
40
37
|
define('compose_starter','Create a new editable playable draft with a complete win, timeout and Store CTA. Pick a starter using tora_starters, use its bundled CC0 assets or verified source IDs, and set deliver:true to write the draft, editable bundle, and QA evidence together.',starterInputProperties,['id','starter']);
|
|
41
38
|
define('create','Create an empty editable native project. Read tora_brief first.',{id:string,name:string,androidUrl:string},['id','name']);
|
|
42
|
-
define('inspect','Inspect current state and revision identity. Use tree:true for a compact scene outline, narrow with ids/search, or full:true for the complete project.',{id:string,revisionId:string,ids:strings,fields:strings,search:string,full:boolean,tree:boolean,sceneId:string},['id'],true);
|
|
39
|
+
define('inspect','Inspect current state and revision identity. Use tree:true for a compact scene outline, narrow with ids/search, or full:true for the complete project. includeBudget adds the selected target/variant budget; includeReview adds compact pending review requests.',{id:string,revisionId:string,ids:strings,fields:strings,search:string,full:boolean,tree:boolean,sceneId:string,includeBudget:boolean,includeReview:boolean,target:string,variantId:string},['id'],true);
|
|
43
40
|
define('edit','Preview and commit native operations against expected revision. Supply operations or commitPreviewDigest (not both). Scope lists intended changed IDs; scopeCreates:true auto-allows brand-new records whose pre-existing targets are in scope.',{id:string,expected,operations:{type:'array',items:{type:'object'}},scope:strings,previewOnly:boolean,previewDigest:string,commitPreviewDigest:string,scopeCreates:boolean},['id','expected','scope']);
|
|
44
41
|
define('list_assets','Search verified local and cached CC0 assets with dimensions, 3D facts, and style families. Set includeRemote:true to also search allowlisted Kenney, Quaternius, and OpenGameArt CC0 packs.',{query:string,kind:{type:'string',enum:['sprite','audio','mesh']},styleFamily:string,includeRemote:boolean,limit:integer},[],true);
|
|
45
42
|
define('fetch_cc0_pack','Fetch, license-verify, optimize, and cache one allowlisted Kenney, Quaternius, or OpenGameArt CC0 pack into the active workspace cache. Supports 2D, audio, and bounded 3D model preparation.',fetchCc0Properties,['sourceUrl']);
|
|
46
43
|
define('stage_cc0_assets','Stage up to 32 verified local or cached remote CC0 assets into a project in one atomic revision with server-enforced provenance and single visual style family.',{id:string,expected,items:{type:'array',items:stageCc0ItemSchema}},['id','expected','items']);
|
|
47
44
|
define('prep_assets','Prepare directory-based OBJ/glTF/GLB models with local dependencies, or prepare PNG/JPEG assets mechanically (crop, trim transparent padding, aspect-safe resize, or grid slice) into .tora/prepared-assets with hash-bound provenance receipts for tora_upload_assets.',{items:{type:'array',items:prepItemSchema}},['items']);
|
|
48
|
-
define('upload_asset','Upload images, audio and 3D models. Local GLB, OBJ and glTF file paths support 32 MiB. Use prep_assets for multi-file models. Supply base64 data, a workspace filePath, or sourceHash from a retained original. Auto is default; lossless/none and preserveResolution are optional.',{id:string,expected,filePath:string,asset:assetSchema},['id','expected','asset']);
|
|
49
45
|
define('upload_assets','Batch upload and optimize up to 32 PNG/JPEG/WAV/MP3/mesh assets in one atomic revision. Prefer workspace filePath (avoids the 12 MiB MCP frame limit) or supply base64 data / retained sourceHash.',{id:string,expected,items:{type:'array',items:{type:'object',properties:{filePath:string,asset:assetSchema},required:['asset'],additionalProperties:false}}},['id','expected','items']);
|
|
50
46
|
define('render','Write an HTML scene preview to output. Open it in a browser for visual inspection; this tool does not capture screenshots.',{id:string,revisionId:string,sceneId:string,output:string},['id','output']);
|
|
51
|
-
define('qa','Run deterministic static, acoustic, four-viewport layout, primary-interaction, and motion filmstrip QA on a native revision. Pass recordVideo:true for an opt-in WebM clip or fitTargetBudget:true to verify a target-fitted export variant. A pass is engineering verification, not creative, device, or network acceptance.',{id:string,revisionId:string,output:string,target:{type:'string',enum:[...targets]},motionFilmstrip:boolean,recordVideo:boolean,fitTargetBudget:boolean},['id']);
|
|
52
|
-
define('export','Write standalone HTML, any of seven ad-network HTML/ZIP artifacts, a batch of targets to outputDir, or an editable project bundle. Set fitTargetBudget:true to opt in to deterministic export-time budget fitting without mutating stored revisions. Network exports must pass Creative QA on the exact delivered artifact; project format exports the current working head. Passing QA is not visual, device, or network approval.',{id:string,revisionId:string,output:string,format:{type:'string',enum:['project']},target:{type:'string',enum:[...targets]},targets:{type:'array',items:{type:'string',enum:[...targets]}},outputDir:string,fitTargetBudget:boolean},['id']);
|
|
47
|
+
define('qa','Run deterministic static, acoustic, four-viewport layout, primary-interaction, and motion filmstrip QA on a native revision. Pass recordVideo:true for an opt-in WebM clip or fitTargetBudget:true to verify a target-fitted export variant. A pass is engineering verification, not creative, device, or network acceptance.',{id:string,revisionId:string,output:string,target:{type:'string',enum:[...targets]},motionFilmstrip:boolean,recordVideo:boolean,fitTargetBudget:boolean,variantId:string,confirmReviewed:string},['id']);
|
|
48
|
+
define('export','Write standalone HTML, any of seven ad-network HTML/ZIP artifacts, a batch of targets to outputDir, a pinned variant matrix, or an editable project bundle. Set fitTargetBudget:true to opt in to deterministic export-time budget fitting without mutating stored revisions. Network exports must pass Creative QA and Rust artifact inspection on the exact delivered artifact; project format exports the current working head. Passing QA is not visual, device, or network approval.',{id:string,revisionId:string,output:string,format:{type:'string',enum:['project']},target:{type:'string',enum:[...targets]},targets:{type:'array',items:{type:'string',enum:[...targets]}},variants:strings,variantId:string,outputDir:string,fitTargetBudget:boolean,confirmReviewed:string},['id']);
|
|
49
|
+
define('variants','List, materialize/diff, upsert, delete, or create preset creative variants. Locale variants require complete visible component, variable, and runtime-action translations.',{id:string,revisionId:string,action:{type:'string',enum:['list','diff','upsert','delete','preset']},variantId:string,variant:{type:'object'},expectedVariantRevision:integer,preset:string,label:string,language:string,texts:{type:'object'},actionTexts:{type:'object'},variables:{type:'object'},storeUrl:string,direction:{type:'string',enum:['auto','ltr','rtl']},text:string},['id','action']);
|
|
53
50
|
define('history','Save, undo or redo against expected revision.',{id:string,expected,action:{type:'string',enum:['save','undo','redo']}},['id','expected','action']);
|
|
54
|
-
define('review_claim','Claim
|
|
55
|
-
define('review_propose','Submit
|
|
56
|
-
define('review_resolve','Run an enabled deterministic review intent through the shared native candidate service. Does not promote the candidate.',{id:string,requestId:string},['id','requestId']);
|
|
51
|
+
define('review_claim','Claim a scoped editor review request. Returns its exact baseline, native record scopes, notes, frames, and any existing candidate.',{id:string,requestId:string},['id','requestId']);
|
|
52
|
+
define('review_propose','Submit native operations for every note in a review request. The stored request supplies authorization. Creates are checked against the computed diff and shared reference rules; candidates require standalone-browser QA and are never committed automatically.',{id:string,requestId:string,proposalId:string,operations:{type:'array',items:{type:'object'}},addressedNoteIds:strings,summary:string},['id','requestId','proposalId','operations','addressedNoteIds','summary']);
|
|
57
53
|
define('review_needs_scope','Explain why a claimed note needs a different or broader edit before attempting it.',{id:string,requestId:string,reason:string},['id','requestId','reason']);
|
|
58
|
-
define('intake_read','Read a local studio intake and list source asset IDs and the brief.',{id:string},['id'],true);
|
|
59
|
-
define('intake_claim','Claim a submitted studio intake. Use the Harvest Restore or Star Salvage concept contract selected by the intake and reference the retained asset IDs.',{id:string},['id']);
|
|
60
|
-
define('intake_build','Build the initial Harvest Restore or Star Salvage playable from an intake with its v2 concept. Omit harvest.assets or salvage.assets, which are resolved from the intake.',{id:string,concept:{type:'object'}},['id']);
|
|
61
54
|
|
|
62
55
|
function valid(value,schema){
|
|
63
56
|
if(schema.type==='object'){if(!value||typeof value!=='object'||Array.isArray(value))return false;if(schema.required?.some(k=>!Object.hasOwn(value,k)))return false;if(schema.additionalProperties===false&&Object.keys(value).some(k=>!Object.hasOwn(schema.properties,k)))return false;return Object.entries(schema.properties??{}).every(([k,s])=>!Object.hasOwn(value,k)||valid(value[k],s));}
|
|
@@ -81,8 +74,7 @@ export function createMcpServer({
|
|
|
81
74
|
const store=new ProjectStore(resolvedStoreRoot,{workspaceRoot:ws});
|
|
82
75
|
const service=new NativeService(store,new EditorState(store),{browserProvider});
|
|
83
76
|
const agent=new NativeAgentTools(service);
|
|
84
|
-
const review=new NativeReview(service
|
|
85
|
-
const intakes=new ReviewIntake(service);
|
|
77
|
+
const review=new NativeReview(service);
|
|
86
78
|
const assetCatalog=catalog??new AssetCatalog({root:PACKAGE_ROOT});
|
|
87
79
|
const cc0Fetcher=remoteFetcher??new RemoteCc0Fetcher({workspaceRoot:ws,catalog:assetCatalog});
|
|
88
80
|
|
|
@@ -126,7 +118,7 @@ export function createMcpServer({
|
|
|
126
118
|
if(known.get(doc.name)===sha256)return {name:doc.name,path:doc.path,sha256,omitted:true};
|
|
127
119
|
return doc;
|
|
128
120
|
});
|
|
129
|
-
briefRead=true;return {documents,digests,availablePacks:availablePacks.map(({id,description})=>({id,description})),store:store.root,workspace:ws,instructions:'Apply these briefs. Establish one coherent visual style and an asset plan before implementation. Use
|
|
121
|
+
briefRead=true;return {documents,digests,availablePacks:availablePacks.map(({id,description})=>({id,description})),store:store.root,workspace:ws,instructions:'Apply these briefs. Establish one coherent visual style and an asset plan before implementation. Use retained project assets or free third-party libraries with verified commercial-use license evidence, author, source URL, and source hashes. Keep visual assets within one style family; audio may use a separate compatible pack. Asset creation and image generation are outside this authoring workflow. Inspect packaged screenshots and footage; tests do not establish visual quality. Use connected browser tools to inspect actual exported output.'};
|
|
130
122
|
}
|
|
131
123
|
if(name==='tora_capabilities'){
|
|
132
124
|
if(args.summary)return capabilitySummary();
|
|
@@ -157,6 +149,10 @@ export function createMcpServer({
|
|
|
157
149
|
if(name==='tora_starters')return listStarters();
|
|
158
150
|
if(!['tora_inspect'].includes(name)&&!briefRead)throw Error('E_MCP_READ_BRIEF_FIRST');
|
|
159
151
|
if(name==='tora_compose_starter')return composeStarter(args,{service,catalog:assetCatalog,remoteFetcher:cc0Fetcher,workspaceRoot:ws});
|
|
152
|
+
if(name==='tora_variants'){
|
|
153
|
+
try{return await agent.run({...args,command:'variants'});}
|
|
154
|
+
catch(err){if(err.message==='E_AGENT_ARGUMENT')throw Error('E_MCP_ARGUMENT',{cause:err});throw err;}
|
|
155
|
+
}
|
|
160
156
|
if(name==='tora_fetch_cc0_pack'){
|
|
161
157
|
const receipt=await cc0Fetcher.fetchPackWithFallback(args);
|
|
162
158
|
return {
|
|
@@ -177,23 +173,8 @@ export function createMcpServer({
|
|
|
177
173
|
return prepAssets({workspaceRoot:ws,items:args.items,catalog:assetCatalog,remoteFetcher:cc0Fetcher});
|
|
178
174
|
}
|
|
179
175
|
if(name==='tora_review_claim')return review.claim(args.id,args.requestId);
|
|
180
|
-
if(name==='tora_review_propose')return review.propose(
|
|
181
|
-
if(name==='tora_review_resolve'){
|
|
182
|
-
const result=await review.resolveDeterministic(args.id,args.requestId);
|
|
183
|
-
if(!result)throw Error('E_REVIEW_INTENT_UNSUPPORTED');
|
|
184
|
-
return result;
|
|
185
|
-
}
|
|
176
|
+
if(name==='tora_review_propose'){const {id,...proposal}=args;return review.propose(id,proposal);}
|
|
186
177
|
if(name==='tora_review_needs_scope')return review.needsScope(args.id,args.requestId,args.reason);
|
|
187
|
-
if(name==='tora_intake_read')return intakes.read(args.id);
|
|
188
|
-
if(name==='tora_intake_claim')return intakes.claim(args.id);
|
|
189
|
-
if(name==='tora_intake_build')return intakes.build(args.id,args.concept?{concept:args.concept}:{});
|
|
190
|
-
if(name==='tora_upload_asset'){
|
|
191
|
-
const current=await service.read(args.id);if(current.revisionId!==args.expected.revisionId||current.contentHash!==args.expected.contentHash)throw Error('E_NATIVE_STALE');
|
|
192
|
-
const asset={...args.asset};
|
|
193
|
-
if([args.filePath,asset.data,asset.sourceHash,asset.useOriginal].filter(Boolean).length!==1)throw Error('E_MCP_ARGUMENT');
|
|
194
|
-
const r=await service.upload(args.id,{expected:args.expected,asset},{workspaceRoot:ws,filePaths:[args.filePath]});
|
|
195
|
-
return {status:'UPLOADED',asset:r.asset,expected:{revisionId:r.revisionId,contentHash:r.contentHash}};
|
|
196
|
-
}
|
|
197
178
|
if(name==='tora_upload_assets'){
|
|
198
179
|
if(!Array.isArray(args.items)||args.items.length<1||args.items.length>32)throw Error('E_MCP_ARGUMENT');
|
|
199
180
|
for(const item of args.items){
|
|
@@ -207,7 +188,8 @@ export function createMcpServer({
|
|
|
207
188
|
if(name==='tora_export'){
|
|
208
189
|
const isBatch=args.targets!==undefined;
|
|
209
190
|
if(isBatch&&(args.output||args.target||args.format||!args.outputDir))throw Error('E_MCP_ARGUMENT');
|
|
210
|
-
if(!isBatch&&(!args.output||args.outputDir))throw Error('E_MCP_ARGUMENT');
|
|
191
|
+
if(!isBatch&&(!args.output||args.outputDir||args.variants!==undefined))throw Error('E_MCP_ARGUMENT');
|
|
192
|
+
if(isBatch&&args.variants!==undefined&&(!args.variants.length||args.variantId))throw Error('E_MCP_ARGUMENT');
|
|
211
193
|
}
|
|
212
194
|
const input={...args,command:name.slice(5)};
|
|
213
195
|
for(const key of ['output','outputDir']){
|
|
@@ -230,9 +212,8 @@ export function createMcpServer({
|
|
|
230
212
|
const result=await call(request.params?.name,request.params?.arguments??{});
|
|
231
213
|
const content=[];
|
|
232
214
|
if(request.params.name==='tora_review_claim'){
|
|
233
|
-
const {
|
|
215
|
+
const {frames,...details}=result;
|
|
234
216
|
content.push({type:'text',text:JSON.stringify(details)});
|
|
235
|
-
if(frame)content.push({type:'image',mimeType:'image/jpeg',data:frame});
|
|
236
217
|
for(const {noteId,data} of frames??[]){
|
|
237
218
|
content.push({type:'text',text:'Frozen frame for note '+noteId},{type:'image',mimeType:'image/jpeg',data});
|
|
238
219
|
}
|
|
@@ -1,255 +1,3 @@
|
|
|
1
|
-
import {isDeepStrictEqual} from 'node:util';
|
|
2
|
-
import {component} from '../document.mjs';
|
|
3
|
-
import {assertValue,fieldLimits,layout,record,standardText} from '../review-fields.mjs';
|
|
4
|
-
import {isAudioMime} from '../media-validate.mjs';
|
|
5
|
-
|
|
6
|
-
const moments=[
|
|
7
|
-
{id:'opening',label:'Opening'},
|
|
8
|
-
{id:'first-harvest',label:'First harvest'},
|
|
9
|
-
{id:'end-card',label:'End card'},
|
|
10
|
-
{id:'timeout',label:'Timeout'},
|
|
11
|
-
];
|
|
12
|
-
const targetDefinitions=[
|
|
13
|
-
{id:'opening',label:'Opening instruction',moment:'opening',componentIds:['harvest.instruction'],
|
|
14
|
-
fields:[['instruction','Instruction'],['hint-delay','Time before opening hint (s)']]},
|
|
15
|
-
{id:'first-harvest',label:'First orchard restoration',moment:'first-harvest',componentIds:['harvest.world.stage.1','harvest.instruction'],
|
|
16
|
-
fields:[['reveal-duration','Reveal duration (s)'],['message','Reward message']]},
|
|
17
|
-
{id:'cta',label:'Install button',moment:'end-card',componentIds:['harvest.cta'],
|
|
18
|
-
fields:[['text','Button wording'],['payoff-hold','Time to enjoy the farm before showing the button (s)']]},
|
|
19
|
-
{id:'ending',label:'Final payoff',moment:'end-card',componentIds:['harvest.reward.title','harvest.reward.detail'],
|
|
20
|
-
fields:[['payoff-hold','Hold before install button (s)']]},
|
|
21
|
-
];
|
|
22
|
-
const message=binding=>binding?.actions.find(action=>action.kind==='set'&&action.variableId==='harvest.message');
|
|
23
|
-
const payoff=binding=>binding?.condition?.all?.find(part=>part.variableId==='harvest.payoff'&&part.op==='gte');
|
|
24
|
-
const timeoutCaptionId='harvest.timeout.caption';
|
|
25
|
-
const timeoutLayoutId='harvest.timeout.layout';
|
|
26
|
-
const timeoutBindingId='harvest.timeout.caption.show';
|
|
27
|
-
const endingCues={match:'short clear confirmation cue',repair:'short restoration cue',complete:'current completion cue'};
|
|
28
|
-
const openingHint=condition=>condition?.any?.[0]?.all?.find(part=>part.variableId==='harvest.idle')??condition;
|
|
29
|
-
|
|
30
|
-
function condition(binding,variableId,op,value){
|
|
31
|
-
const parts=[binding.condition,...binding.condition?.all??[],...binding.condition?.any??[]].filter(Boolean);
|
|
32
|
-
return parts.some(part=>part.variableId===variableId&&part.op===op&&part.value===value)||
|
|
33
|
-
binding.condition?.all?.some(group=>group.all?.some(part=>part.variableId===variableId&&part.op===op&&part.value===value));
|
|
34
|
-
}
|
|
35
|
-
function setsPhase(binding,value){
|
|
36
|
-
return binding?.actions.some(action=>action.kind==='set'&&action.variableId==='harvest.phase'&&action.value===value);
|
|
37
|
-
}
|
|
38
|
-
function audioCue(index,binding){
|
|
39
|
-
const actions=binding?.actions.filter(action=>action.kind==='playAudio')??[];
|
|
40
|
-
if(actions.length!==1)return {unresolved:actions.length?'multiple-cues':'missing-cue'};
|
|
41
|
-
const behavior=index.behavior(actions[0].behaviorId),component=behavior&&index.component(behavior.componentId);
|
|
42
|
-
const assetId=component?.assetSlots[0]?.assetId,asset=assetId&&index.asset(assetId);
|
|
43
|
-
if(behavior?.kind!=='audio'||!component||!isAudioMime(asset?.mime))return {unresolved:'invalid-cue'};
|
|
44
|
-
return {behaviorId:behavior.id,componentId:component.id,assetId,assetHash:asset.hash};
|
|
45
|
-
}
|
|
46
|
-
function outcome(index,{bindingId,eventKind,eventReference,phase}){
|
|
47
|
-
const binding=index.binding(bindingId),event=binding&&index.event(binding.eventId);
|
|
48
|
-
if(!binding||event?.kind!==eventKind||event[eventReference.key]!==eventReference.value||!setsPhase(binding,phase))return {unresolved:'invalid-binding'};
|
|
49
|
-
const duplicate=index.bindingsForEvent(event.id).filter(other=>other.id!==binding.id&&
|
|
50
|
-
isDeepStrictEqual(other.condition,binding.condition)&&setsPhase(other,phase));
|
|
51
|
-
if(duplicate.length)return {unresolved:'ambiguous-binding'};
|
|
52
|
-
return {bindingId,eventId:event.id,cue:audioCue(index,binding)};
|
|
53
|
-
}
|
|
54
|
-
export function resolveHarvestRoles(index){
|
|
55
|
-
const unresolved=[];
|
|
56
|
-
const board=index.behavior('harvest.rules');
|
|
57
|
-
if(board?.kind!=='match-board'||board.componentId!=='harvest.board')return {status:'unsupported',module:null,unresolved:['module']};
|
|
58
|
-
const win=outcome(index,{bindingId:'harvest.restore.3',eventKind:'variableChange',eventReference:{key:'variableId',value:'harvest.moves'},phase:'payoff'});
|
|
59
|
-
if(!condition(index.binding('harvest.restore.3')??{},'harvest.moves','eq',3))win.unresolved??='invalid-condition';
|
|
60
|
-
const loss=outcome(index,{bindingId:'harvest.deadline.cta',eventKind:'timer',eventReference:{key:'behaviorId',value:'harvest.deadline'},phase:'cta'});
|
|
61
|
-
const cta=index.component('harvest.cta'),ctaLabel=index.component('harvest.cta.label'),ctaBinding=index.binding('harvest.cta.click');
|
|
62
|
-
const ctaEvent=ctaBinding&&index.event(ctaBinding.eventId);
|
|
63
|
-
const primaryCta=cta?.contract==='native.button.v1'&&ctaLabel?.parentId===cta.id&&ctaLabel.contract==='native.text.v1'&&
|
|
64
|
-
ctaEvent?.kind==='click'&&ctaEvent.componentId===cta.id&&ctaBinding.actions.some(action=>action.kind==='store')
|
|
65
|
-
?{componentId:cta.id,labelId:ctaLabel.id,bindingId:ctaBinding.id}:{unresolved:'invalid-cta'};
|
|
66
|
-
const panel=index.component('harvest.board.lock');
|
|
67
|
-
const outcomePanel=panel?{componentId:panel.id}:{unresolved:'missing-panel'};
|
|
68
|
-
const roles={winEvent:win,timeoutEvent:loss,primaryCta,outcomePanel,rewardCue:win.cue??{unresolved:win.unresolved??'invalid-cue'}};
|
|
69
|
-
for(const [role,value] of Object.entries(roles))if(value.unresolved)unresolved.push(role+':'+value.unresolved);
|
|
70
|
-
if(index.component(timeoutCaptionId))roles.timeoutCaption={componentId:timeoutCaptionId};
|
|
71
|
-
if(win.bindingId&&win.bindingId===loss.bindingId)unresolved.push('outcomes:shared-binding');
|
|
72
|
-
return {status:unresolved.length?'unresolved':'resolved',module:'harvest-restore',version:1,roles,unresolved};
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function endingFields(project,resolution){
|
|
76
|
-
const puzzle=layout(project,'harvest.puzzle.layout');
|
|
77
|
-
const panel=record(project,'components','harvest.board.lock');
|
|
78
|
-
const cta=record(project,'components','harvest.cta');
|
|
79
|
-
const winAudio=record(project,'components',resolution.roles?.rewardCue?.componentId);
|
|
80
|
-
if(!puzzle||!panel||!cta||!layout(project,'harvest.cta.layout')||!layout(project,'harvest.instruction.layout')||!record(project,'eventBindings','harvest.cta.show'))return [];
|
|
81
|
-
const descriptions={};
|
|
82
|
-
for(const [role,description] of Object.entries(endingCues)){
|
|
83
|
-
const assetId=record(project,'components','harvest.audio.'+role)?.assetSlots[0]?.assetId;
|
|
84
|
-
if(assetId&&project.assets.some(asset=>asset.id===assetId&&isAudioMime(asset.mime)))descriptions[assetId]=description;
|
|
85
|
-
}
|
|
86
|
-
const windowWidth=Math.max(project.base.width,project.base.height);
|
|
87
|
-
const rightEdge=puzzle.parameters.x+puzzle.parameters.scaleX*(panel.transform[4]+panel.parameters.width);
|
|
88
|
-
return [
|
|
89
|
-
{id:'landscape-inset',label:'Right margin around the landscape end card (px)',value:windowWidth-rightEdge,...fieldLimits['landscape-inset'],viewportWidth:windowWidth,panelRight:rightEdge},
|
|
90
|
-
{id:'timeout-caption',label:'Centered text on the timeout end card',value:record(project,'components',timeoutCaptionId)?.parameters?.text??'',...standardText},
|
|
91
|
-
...(winAudio?[{id:'win-cue',label:'Sound played when the last harvest completes',value:winAudio.assetSlots[0]?.assetId,
|
|
92
|
-
choices:Object.keys(descriptions),descriptions}]:[]),
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
function values(project){
|
|
96
|
-
const binding=id=>record(project,'eventBindings',id);
|
|
97
|
-
return {
|
|
98
|
-
instruction:record(project,'variables','harvest.message')?.initial,
|
|
99
|
-
'hint-delay':openingHint(binding('harvest.hint.show')?.condition)?.value,
|
|
100
|
-
'reveal-duration':record(project,'gameplay','harvest.world.stage.1.reveal')?.parameters.seconds,
|
|
101
|
-
message:message(binding('harvest.restore.1'))?.value,
|
|
102
|
-
text:record(project,'components','harvest.cta.label')?.parameters.text,
|
|
103
|
-
'payoff-hold':payoff(binding('harvest.payoff.finish'))?.value,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
function sharedCropTargets(project){
|
|
107
|
-
const crops=new Map();
|
|
108
|
-
for(const behavior of project.gameplay){
|
|
109
|
-
if(behavior.kind!=='match-tile')continue;
|
|
110
|
-
const component=record(project,'components',behavior.componentId);
|
|
111
|
-
if(component?.parentId!=='harvest.board')continue;
|
|
112
|
-
const artwork=project.components.find(item=>item.parentId===component.id&&item.contract==='native.image.v1');
|
|
113
|
-
if(!artwork?.assetSlots[0])continue;
|
|
114
|
-
const group=behavior.parameters.group;
|
|
115
|
-
const crop=crops.get(group)??{cells:[],assets:new Set()};
|
|
116
|
-
crop.cells.push(component.id);crop.assets.add(artwork.assetSlots[0].assetId);crops.set(group,crop);
|
|
117
|
-
}
|
|
118
|
-
const usedForOtherCrops=new Set([...crops.values()].flatMap(crop=>[...crop.assets]));
|
|
119
|
-
return [...crops].flatMap(([group,crop])=>{
|
|
120
|
-
if(crop.assets.size!==1)return [];
|
|
121
|
-
const [assetId]=crop.assets;
|
|
122
|
-
if([...crops.values()].filter(item=>item.assets.has(assetId)).length!==1)return [];
|
|
123
|
-
const uses=project.components.filter(item=>item.assetSlots.some(slot=>slot.assetId===assetId));
|
|
124
|
-
if(uses.some(item=>item.assetSlots.length!==1||item.assetSlots[0].slotId!=='source'))return [];
|
|
125
|
-
const imageChoices=project.assets.filter(asset=>asset.mime.startsWith('image/')&&!usedForOtherCrops.has(asset.id)).map(asset=>asset.id);
|
|
126
|
-
if(!imageChoices.length)return [];
|
|
127
|
-
return [{id:'crop-'+group,label:group[0].toUpperCase()+group.slice(1)+' artwork',cropGroup:group,moment:'opening',
|
|
128
|
-
componentIds:crop.cells,uses:uses.map(item=>item.id),imageChoices,
|
|
129
|
-
fields:[{id:'shared-art',label:'Replace all '+uses.length+' uses of this source asset',confirm:true,value:assetId}]}];
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function reviewTargets(project,resolution){
|
|
133
|
-
const current=values(project);
|
|
134
|
-
if(!record(project,'gameplay','harvest.rules')||!message(record(project,'eventBindings','harvest.music.start'))||
|
|
135
|
-
Object.values(current).some(value=>value===undefined)||targetDefinitions.some(target=>target.componentIds.some(id=>!record(project,'components',id))))
|
|
136
|
-
return {module:'harvest-restore',moments:[],targets:[]};
|
|
137
|
-
const targets=targetDefinitions.map(target=>({...target,fields:target.fields.map(([id,label])=>({id,label,value:current[id],...fieldLimits[id]}))}));
|
|
138
|
-
const ending=endingFields(project,resolution);
|
|
139
|
-
targets.find(target=>target.id==='ending').fields.push(...ending);
|
|
140
|
-
if(ending.length)targets.push({id:'timeout-card',label:'Timeout end card',moment:'timeout',
|
|
141
|
-
componentIds:['harvest.board.lock',timeoutCaptionId],fields:[
|
|
142
|
-
...ending.filter(field=>field.id!=='win-cue'),
|
|
143
|
-
...(record(project,'components',timeoutCaptionId)?[{id:'caption-alignment',label:'Caption alignment within the panel',choices:['center']}]:[]),
|
|
144
|
-
]});
|
|
145
|
-
return {module:'harvest-restore',moments,targets:[...targets,...sharedCropTargets(project)],
|
|
146
|
-
momentRules:{phaseVariable:'harvest.phase',progressVariable:'harvest.moves',goal:3,progressMoment:'first-harvest'},
|
|
147
|
-
picker:{cropGroups:true}};
|
|
148
|
-
}
|
|
149
|
-
function reviewOperations(project,targetId,fields,changes,baseline,resolution){
|
|
150
|
-
if(!changes||typeof changes!=='object'||Array.isArray(changes))throw Error('E_REVIEW_ARGUMENT');
|
|
151
|
-
const keys=Object.keys(changes);
|
|
152
|
-
if(!keys.length||keys.some(key=>!fields.includes(key)))throw Error('E_REVIEW_SCOPE');
|
|
153
|
-
const operations=[],expected=globalThis.structuredClone(project);
|
|
154
|
-
function update(collection,id,kind,key,change){
|
|
155
|
-
const next=record(expected,collection,id);change(next);operations.push({kind,[key]:globalThis.structuredClone(next)});
|
|
156
|
-
}
|
|
157
|
-
const binding=(id,change)=>update('eventBindings',id,'putBinding','binding',change);
|
|
158
|
-
for(const field of keys){
|
|
159
|
-
const value=changes[field];
|
|
160
|
-
if(field==='shared-art'){
|
|
161
|
-
const target=sharedCropTargets(baseline).find(item=>item.id===targetId);
|
|
162
|
-
if(!target?.imageChoices.includes(value))throw Error('E_REVIEW_ASSET_CHOICE');
|
|
163
|
-
for(const id of target.uses){
|
|
164
|
-
record(expected,'components',id).assetSlots=[{slotId:'source',assetId:value}];
|
|
165
|
-
operations.push({kind:'replaceAsset',id,assetId:value});
|
|
166
|
-
}
|
|
167
|
-
continue;
|
|
168
|
-
}
|
|
169
|
-
if(field==='win-cue'){
|
|
170
|
-
const cue=endingFields(baseline,resolution).find(item=>item.id===field);
|
|
171
|
-
if(!cue?.choices.includes(value))throw Error('E_REVIEW_ASSET_CHOICE');
|
|
172
|
-
const id=resolution.roles?.rewardCue?.componentId;
|
|
173
|
-
if(!id)throw Error('E_REVIEW_ROLE_UNRESOLVED');
|
|
174
|
-
record(expected,'components',id).assetSlots=[{slotId:'source',assetId:value}];
|
|
175
|
-
operations.push({kind:'replaceAsset',id,assetId:value});continue;
|
|
176
|
-
}
|
|
177
|
-
assertValue(field,value);
|
|
178
|
-
switch(field){
|
|
179
|
-
case 'landscape-inset':{
|
|
180
|
-
const panel=record(expected,'components','harvest.board.lock'),stageWidth=Math.max(expected.base.width,expected.base.height);
|
|
181
|
-
const puzzle=layout(expected,'harvest.puzzle.layout');
|
|
182
|
-
const insetDelta=stageWidth-value-puzzle.parameters.x-puzzle.parameters.scaleX*(panel.transform[4]+panel.parameters.width);
|
|
183
|
-
for(const id of ['harvest.puzzle.layout','harvest.cta.layout','harvest.instruction.layout'])update('gameplay',id+'.responsive','putBehavior','behavior',entry=>{entry.parameters.x+=insetDelta;});
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
case 'timeout-caption':{
|
|
187
|
-
const existing=record(expected,'components',timeoutCaptionId);
|
|
188
|
-
if(existing){existing.parameters.text=value;operations.push({kind:'setParameter',id:timeoutCaptionId,key:'text',value});break;}
|
|
189
|
-
const title=record(expected,'components','harvest.reward.title'),panel=record(expected,'components','harvest.board.lock');
|
|
190
|
-
const button=record(expected,'components','harvest.cta'),puzzleLayout=layout(expected,'harvest.puzzle.layout').parameters;
|
|
191
|
-
const buttonLayout=layout(expected,'harvest.cta.layout').parameters;
|
|
192
|
-
const landscapeButtonTop=buttonLayout.y+buttonLayout.scaleY*button.transform[5];
|
|
193
|
-
const landscapeOffset=((landscapeButtonTop-puzzleLayout.y)/puzzleLayout.scaleY-button.transform[5])/2;
|
|
194
|
-
const group=component({id:timeoutLayoutId,label:'Timeout caption layout',contract:'native.group.v1',parentId:title.parentId,sceneId:title.sceneId,order:title.order});
|
|
195
|
-
const responsive={id:timeoutLayoutId+'.responsive',componentId:timeoutLayoutId,kind:'responsive-layout',parameters:{x:0,y:landscapeOffset,scaleX:1,scaleY:1}};
|
|
196
|
-
const caption=component({...title,id:timeoutCaptionId,label:'Timeout caption',parentId:group.id,
|
|
197
|
-
transform:[1,0,0,1,title.transform[4],(panel.transform[5]+button.transform[5]-title.parameters.height)/2],
|
|
198
|
-
parameters:{...title.parameters,text:value,visible:false,fontSize:22}});
|
|
199
|
-
const show={id:timeoutBindingId,eventId:record(expected,'eventBindings','harvest.cta.show').eventId,
|
|
200
|
-
condition:{all:[{variableId:'harvest.phase',op:'eq',value:'cta'},{variableId:'harvest.moves',op:'lt',value:3}]},
|
|
201
|
-
actions:[
|
|
202
|
-
{kind:'setComponent',componentId:'harvest.reward.title',key:'visible',value:false},
|
|
203
|
-
{kind:'setComponent',componentId:'harvest.reward.detail',key:'visible',value:false},
|
|
204
|
-
{kind:'setComponent',componentId:timeoutCaptionId,key:'visible',value:true},
|
|
205
|
-
]};
|
|
206
|
-
expected.components.push(group,caption);expected.gameplay.push(responsive);expected.eventBindings.push(show);
|
|
207
|
-
operations.push({kind:'createComponent',component:group},{kind:'createComponent',component:caption},{kind:'putBehavior',behavior:responsive},{kind:'putBinding',binding:show});
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
case 'caption-alignment':{
|
|
211
|
-
const caption=record(expected,'components',timeoutCaptionId),panel=record(expected,'components','harvest.board.lock');
|
|
212
|
-
const button=record(expected,'components','harvest.cta'),group=caption&&record(expected,'components',caption.parentId);
|
|
213
|
-
const alternate=group&&layout(expected,group.id),panelLayout=panel&&layout(expected,panel.parentId),buttonLayout=button&&layout(expected,button.parentId);
|
|
214
|
-
const isTranslation=object=>object.transform.slice(0,4).join(',')==='1,0,0,1';
|
|
215
|
-
if(targetId!=='timeout-card'||!caption||!panel||!group||!button||!panelLayout||!buttonLayout||
|
|
216
|
-
group.parentId!==panel.parentId||panel.parentId!=='harvest.puzzle.layout'||button.parentId!=='harvest.cta.layout'||
|
|
217
|
-
![caption,panel,group,button].every(isTranslation)||alternate?.parameters.x!==group.transform[4]||
|
|
218
|
-
alternate.parameters.scaleX!==1||alternate.parameters.scaleY!==1)throw Error('E_REVIEW_ROLE_UNRESOLVED');
|
|
219
|
-
const x=panel.transform[4]+(panel.parameters.width-caption.parameters.width)/2-group.transform[4];
|
|
220
|
-
const y=(panel.transform[5]+button.transform[5]-caption.parameters.height)/2-group.transform[5];
|
|
221
|
-
const landscapeButtonTop=buttonLayout.parameters.y+buttonLayout.parameters.scaleY*button.transform[5];
|
|
222
|
-
const landscapeButtonY=(landscapeButtonTop-panelLayout.parameters.y)/panelLayout.parameters.scaleY;
|
|
223
|
-
const landscapeOffset=(panel.transform[5]+landscapeButtonY-caption.parameters.height)/2-y;
|
|
224
|
-
const transform=[...caption.transform];transform[4]=x;transform[5]=y;
|
|
225
|
-
if(Math.abs(x-caption.transform[4])>.001||Math.abs(y-caption.transform[5])>.001)operations.push({kind:'setTransform',id:caption.id,transform});
|
|
226
|
-
if(caption.parameters.align!=='center')operations.push({kind:'setParameter',id:caption.id,key:'align',value:'center'});
|
|
227
|
-
if(Math.abs(landscapeOffset-alternate.parameters.y)>.001)update('gameplay',alternate.id,'putBehavior','behavior',entry=>{entry.parameters.y=landscapeOffset;});
|
|
228
|
-
caption.transform=transform;caption.parameters.align='center';break;
|
|
229
|
-
}
|
|
230
|
-
case 'text':{
|
|
231
|
-
const label=record(expected,'components',resolution.roles?.primaryCta?.labelId);
|
|
232
|
-
if(!label)throw Error('E_REVIEW_ROLE_UNRESOLVED');
|
|
233
|
-
label.parameters.text=value;operations.push({kind:'setParameter',id:label.id,key:'text',value});break;
|
|
234
|
-
}
|
|
235
|
-
case 'instruction':
|
|
236
|
-
update('variables','harvest.message','putVariable','variable',entry=>{entry.initial=value;});
|
|
237
|
-
binding('harvest.music.start',entry=>{message(entry).value=value;});break;
|
|
238
|
-
case 'hint-delay':
|
|
239
|
-
binding('harvest.hint.show',entry=>{
|
|
240
|
-
if(entry.condition.any){openingHint(entry.condition).value=value;return;}
|
|
241
|
-
const previous=entry.condition;
|
|
242
|
-
entry.condition={any:[{all:[{variableId:'harvest.moves',op:'eq',value:0},{...previous,value}]},{all:[{variableId:'harvest.moves',op:'gt',value:0},previous]}]};
|
|
243
|
-
});break;
|
|
244
|
-
case 'reveal-duration':update('gameplay','harvest.world.stage.1.reveal','putBehavior','behavior',entry=>{entry.parameters.seconds=value;});break;
|
|
245
|
-
case 'message':binding('harvest.restore.1',entry=>{message(entry).value=value;});break;
|
|
246
|
-
case 'payoff-hold':binding('harvest.payoff.finish',entry=>{payoff(entry).value=value;});break;
|
|
247
|
-
default:throw Error('E_REVIEW_SCOPE');
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
return {operations,expected};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
1
|
async function playToEndCard(page,project){
|
|
254
2
|
const boardBehavior=(project.gameplay??[]).find(behavior=>behavior.kind==='match-board');
|
|
255
3
|
if(!boardBehavior)return {available:false};
|
|
@@ -293,37 +41,8 @@ async function playToEndCard(page,project){
|
|
|
293
41
|
return {available:finalPhase==='cta',mode:'real-play'};
|
|
294
42
|
}
|
|
295
43
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
matches:index=>Boolean(index.behavior('harvest.rules')),
|
|
300
|
-
resolveRoles:resolveHarvestRoles,reviewTargets,reviewOperations,
|
|
301
|
-
canTransferOutcomeCue:(index,resolution)=>resolution.status==='resolved'&&resolution.roles.timeoutEvent.cue?.unresolved==='missing-cue'&&!index.asset('harvest.audio.victory.source'),
|
|
302
|
-
timingFields:()=>({
|
|
303
|
-
'hint-delay':{target:'opening',targets:['opening'],moment:'opening',label:'opening hint delay'},
|
|
304
|
-
'reveal-duration':{target:'first-harvest',targets:['first-harvest'],moment:'first-harvest',label:'reveal duration'},
|
|
305
|
-
'payoff-hold':{target:'ending',targets:['ending','cta'],moment:'end-card',label:'payoff hold'},
|
|
306
|
-
}),
|
|
307
|
-
intake:{
|
|
308
|
-
validateMedia(assets,concept){
|
|
309
|
-
const images=new Set(assets.filter(asset=>asset.mime.startsWith('image/')).map(asset=>asset.hash));
|
|
310
|
-
if(images.size<5||!assets.some(asset=>isAudioMime(asset.mime)))throw Error('E_INTAKE_HARVEST_MEDIA');
|
|
311
|
-
if(concept){
|
|
312
|
-
const tiles=Object.values(concept.harvest.tiles).map(id=>assets.find(asset=>asset.id===id));
|
|
313
|
-
if(tiles.length!==5||tiles.some(asset=>!asset?.mime.startsWith('image/'))||new Set(tiles.map(asset=>asset.hash)).size!==5)throw Error('E_INTAKE_HARVEST_MEDIA');
|
|
314
|
-
}
|
|
315
|
-
},
|
|
316
|
-
validateConcept(concept){
|
|
317
|
-
const audio=concept?.harvest?.audio;
|
|
318
|
-
const supportedAudio=JSON.stringify(Object.keys(audio??{}).sort())===JSON.stringify(['ambient','complete','loss','match','reject'])||
|
|
319
|
-
JSON.stringify(Object.keys(audio??{}).sort())===JSON.stringify(['ambient','complete','match','reject','repair']);
|
|
320
|
-
if(concept?.experience?.mechanic!=='harvest-restore'||!concept.harvest||
|
|
321
|
-
JSON.stringify(Object.keys(concept.harvest).sort())!==JSON.stringify(['audio','firstHintSeconds','seed','tiles','world'])||
|
|
322
|
-
JSON.stringify(Object.keys(concept.harvest.tiles??{}).sort())!==JSON.stringify(['carrot','corn','eggplant','pumpkin','tomato'])||
|
|
323
|
-
!supportedAudio||!Array.isArray(concept.harvest.world)||concept.harvest.world.length>64)throw Error('E_INTAKE_ARGUMENT');
|
|
324
|
-
return [...Object.values(concept.harvest.tiles),...Object.values(audio),...concept.harvest.world.map(object=>object?.assetId)];
|
|
325
|
-
},
|
|
326
|
-
hydrateConcept(concept,assets){return {...concept,harvest:{...concept.harvest,assets}};},
|
|
327
|
-
},
|
|
44
|
+
|
|
45
|
+
export const harvestQaAdapter=Object.freeze({
|
|
46
|
+
id:'harvest-restore',matches:index=>Boolean(index.behavior('harvest.rules')),
|
|
328
47
|
qa:{phaseVariable:'harvest.phase',progressVariable:'harvest.moves',goalValue:3,deadlineBehaviorId:'harvest.deadline',playToEndCard},
|
|
329
48
|
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const crops=['carrot','corn','tomato'];
|
|
2
|
+
const cropId=crop=>'sort.crop.'+crop;
|
|
3
|
+
const zoneId=crop=>'sort.crate.'+crop;
|
|
4
|
+
|
|
5
|
+
async function dragPoints(page,from,to){
|
|
6
|
+
return page.evaluate(({from,to})=>{
|
|
7
|
+
const runtime=globalThis.toraRuntime,canvas=globalThis.document.querySelector('canvas');
|
|
8
|
+
if(!runtime||!canvas)return null;
|
|
9
|
+
const audit=runtime.auditSceneLayout({ids:[from,to],interactiveIds:[from,to],minTouchPx:1}),rect=canvas.getBoundingClientRect(),stage=audit.viewport,scale=stage.scale;
|
|
10
|
+
const point=id=>{const row=audit.interactive.find(item=>item.id===id);if(!row)return null;const b=row.bounds;return {x:rect.left+(rect.width-stage.width*scale)/2+(b.left+b.right)/2*scale,y:rect.top+(rect.height-stage.height*scale)/2+(b.top+b.bottom)/2*scale};};
|
|
11
|
+
return {from:point(from),to:point(to)};
|
|
12
|
+
},{from,to});
|
|
13
|
+
}
|
|
14
|
+
async function realDrag(page,from,to){
|
|
15
|
+
const points=await dragPoints(page,from,to);if(!points?.from||!points?.to)throw Error('E_SORT_QA_TARGET');
|
|
16
|
+
await page.mouse.move(points.from.x,points.from.y);await page.mouse.down();await page.mouse.move(points.to.x,points.to.y,{steps:8});await page.mouse.up();
|
|
17
|
+
}
|
|
18
|
+
async function playToEndCard(page){
|
|
19
|
+
for(const [index,crop] of crops.entries()){
|
|
20
|
+
const phase=await page.evaluate(()=>globalThis.toraRuntime?.state?.()?.variables?.['sort.phase']);
|
|
21
|
+
if(phase==='payoff')break;
|
|
22
|
+
await realDrag(page,cropId(crop),zoneId(crop));
|
|
23
|
+
await page.waitForFunction(value=>globalThis.toraRuntime?.state?.()?.variables?.['sort.sorted']>=value,index+1,{timeout:2500});
|
|
24
|
+
}
|
|
25
|
+
try{await page.waitForFunction(()=>globalThis.toraRuntime?.state?.()?.scene==='scene.win',undefined,{timeout:6000});}catch{return {available:false};}
|
|
26
|
+
return {available:true,mode:'real-play'};
|
|
27
|
+
}
|
|
28
|
+
async function prepareTimeout(page){
|
|
29
|
+
await realDrag(page,cropId('carrot'),zoneId('corn'));
|
|
30
|
+
const sorted=await page.evaluate(()=>globalThis.toraRuntime?.state?.()?.variables?.['sort.sorted']);
|
|
31
|
+
if(sorted!==0)throw Error('E_SORT_TIMEOUT_INPUT');
|
|
32
|
+
}
|
|
33
|
+
function validateTimeout(state){
|
|
34
|
+
return state?.scene==='scene.timeout'&&state.variables?.['sort.phase']==='cta'&&state.variables['sort.sorted']<3;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
export function variantPreset(id){
|
|
39
|
+
const overlay={id,label:id,preset:id};
|
|
40
|
+
if(id==='shorter-hook')return {...overlay,texts:{'sort.instruction':{text:'SORT THE CROPS'}}};
|
|
41
|
+
if(id==='easier-win')return {...overlay,variables:{'sort.time':30},behaviors:{'sort.deadline':{seconds:30},'sort.time.meter':{max:30}}};
|
|
42
|
+
if(id==='high-contrast-cta')return {...overlay,colors:Object.fromEntries(['sort.cta','sort.timeout.cta'].map(componentId=>[componentId,{fill:'#ffd23f',hoverFill:'#ffe784',pressedFill:'#d99a2b',stroke:'#3c2933'}]))};
|
|
43
|
+
if(id==='custom')return overlay;
|
|
44
|
+
throw Error('E_VARIANT_PRESET');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
export const sortPuzzleCompatibility=Object.freeze({
|
|
49
|
+
id:'sort-puzzle',matches:index=>Boolean(index.behavior('sort.rules')),variantPreset,
|
|
50
|
+
qa:{phaseVariable:'sort.phase',progressVariable:'sort.sorted',goalValue:3,deadlineBehaviorId:'sort.deadline',playToEndCard,prepareTimeout,validateTimeout},
|
|
51
|
+
});
|