@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
|
@@ -17,28 +17,54 @@ const cars = ['blue', 'red', 'yellow', 'green'];
|
|
|
17
17
|
const carSources = Object.fromEntries(cars.map(color => [
|
|
18
18
|
color, `assets/kenney-racing/source/racing-pack/extracted/PNG/Cars/car_${color}_1.png`,
|
|
19
19
|
]));
|
|
20
|
+
const targets3d = ['target1', 'target2', 'target3', 'target4'];
|
|
21
|
+
const target3dSources = {
|
|
22
|
+
target1: 'Models/GLB format/burger.glb',
|
|
23
|
+
target2: 'Models/GLB format/frying-pan.glb',
|
|
24
|
+
target3: 'Models/GLB format/pot.glb',
|
|
25
|
+
target4: 'Models/GLB format/plate.glb',
|
|
26
|
+
};
|
|
20
27
|
|
|
21
28
|
const definitions = {
|
|
22
29
|
'stack-and-serve': {
|
|
23
30
|
name: 'Stack & Serve',
|
|
31
|
+
genre: '3D Cooking',
|
|
32
|
+
tagline: 'Stack five 3D burger ingredients to complete an order with a celebratory end card.',
|
|
24
33
|
mechanic: 'Stack five 3D ingredients to finish an order.',
|
|
25
34
|
palette: {background: '#382322', surface: '#fff2d7', ink: '#321b1a', accent: '#ffc15e'},
|
|
26
35
|
winTitle: 'Order up!',
|
|
27
36
|
timeoutTitle: 'So close',
|
|
28
37
|
art: Object.fromEntries(['burger', 'plate', 'frying-pan', 'pot'].map(model => [model, `Models/GLB format/${model}.glb`])),
|
|
29
38
|
artPack: 'kenney-food-kit',
|
|
39
|
+
artMime: 'model/gltf-binary',
|
|
30
40
|
audio: {music: 'arcade-pop/ambient.wav', step: 'arcade-pop/reward.wav', win: 'arcade-pop/win.wav', loss: 'arcade-pop/loss.wav'},
|
|
31
41
|
},
|
|
32
42
|
'tap-targets': {
|
|
33
43
|
name: 'Pit Stop Dash',
|
|
44
|
+
genre: '2D Racing',
|
|
45
|
+
tagline: 'Tap cars arriving in pit boxes with crisp arcade feedback and a Store CTA.',
|
|
34
46
|
mechanic: 'Tap each car as it arrives at a pit box to finish the round.',
|
|
35
47
|
palette: {background: '#132635', surface: '#dbeaf2', ink: '#10232c', accent: '#ffc750'},
|
|
36
48
|
winTitle: 'Grid ready!',
|
|
37
49
|
timeoutTitle: 'Race awaits',
|
|
38
50
|
art: carSources,
|
|
39
51
|
artPack: 'kenney-racing-pack',
|
|
52
|
+
artMime: 'image/',
|
|
40
53
|
audio: {music: 'arcade-pop/ambient.wav', step: 'arcade-pop/reward.wav', win: 'audio/victory.wav', loss: 'arcade-pop/loss.wav'},
|
|
41
54
|
},
|
|
55
|
+
'tap-targets-3d': {
|
|
56
|
+
name: 'Bistro Rush',
|
|
57
|
+
genre: '3D Tap & Collect',
|
|
58
|
+
tagline: 'Tap four 3D dishes directly on the counter using projected 3D touch rings across portrait and landscape.',
|
|
59
|
+
mechanic: 'Tap all four 3D kitchen items on the counter to finish service.',
|
|
60
|
+
palette: {background: '#17323a', surface: '#fff5e1', ink: '#1f1a17', accent: '#ffb84d'},
|
|
61
|
+
winTitle: 'Table served!',
|
|
62
|
+
timeoutTitle: 'Orders waiting',
|
|
63
|
+
art: target3dSources,
|
|
64
|
+
artPack: 'kenney-food-kit',
|
|
65
|
+
artMime: 'model/gltf-binary',
|
|
66
|
+
audio: {music: 'arcade-pop/ambient.wav', step: 'arcade-pop/reward.wav', win: 'arcade-pop/win.wav', loss: 'arcade-pop/loss.wav'},
|
|
67
|
+
},
|
|
42
68
|
};
|
|
43
69
|
|
|
44
70
|
const starterNames = Object.keys(definitions);
|
|
@@ -54,7 +80,7 @@ export const starterInputProperties = {
|
|
|
54
80
|
durationSeconds: {type: 'integer', minimum: 10, maximum: 60},
|
|
55
81
|
winHoldSeconds: {type: 'number', minimum: 0.25, maximum: 3},
|
|
56
82
|
palette: strings(['background','surface','ink','accent']),
|
|
57
|
-
art: strings([...Object.keys(definitions['stack-and-serve'].art), ...cars]),
|
|
83
|
+
art: strings([...Object.keys(definitions['stack-and-serve'].art), ...cars, ...targets3d]),
|
|
58
84
|
audio: strings(['music','step','win','loss']),
|
|
59
85
|
};
|
|
60
86
|
|
|
@@ -62,6 +88,7 @@ export function listStarters(){
|
|
|
62
88
|
return {
|
|
63
89
|
starters: Object.entries(definitions).map(([id, definition]) => ({
|
|
64
90
|
id, name: definition.name, mechanic: definition.mechanic,
|
|
91
|
+
genre: definition.genre, tagline: definition.tagline,
|
|
65
92
|
visualPack: definition.artPack, artRoles: Object.keys(definition.art),
|
|
66
93
|
})),
|
|
67
94
|
defaults: {durationSeconds: 25, winHoldSeconds: 0.9, ctaLabel: 'Play now'},
|
|
@@ -150,9 +177,11 @@ function backdrop(make,scene,palette){
|
|
|
150
177
|
make.component(id,scene,'rectangle',0,0,390,700,{fill:palette.background},{parentId});
|
|
151
178
|
}
|
|
152
179
|
|
|
153
|
-
function progress(make,count,palette){
|
|
154
|
-
|
|
155
|
-
|
|
180
|
+
function progress(make,count,palette,landscapePos=[475,106]){
|
|
181
|
+
const totalWidth = Math.max(23, (count - 1) * 28 + 23);
|
|
182
|
+
const portraitX = Math.round((390 - totalWidth) / 2);
|
|
183
|
+
make.component('starter.progress',gameplay,'group',portraitX,62,totalWidth,20,{}, {order:15});
|
|
184
|
+
make.landscape('starter.progress',landscapePos[0],landscapePos[1]);
|
|
156
185
|
for(let i=0;i<count;i++){
|
|
157
186
|
make.component(`starter.pip.${i}`,gameplay,'rectangle',i*28,2,23,10,{
|
|
158
187
|
fill:palette.surface+'32',radius:5,
|
|
@@ -344,14 +373,112 @@ function tapTargets(make,{palette,winHoldSeconds,ctaLabel,winTitle,timeoutTitle}
|
|
|
344
373
|
return targets.length;
|
|
345
374
|
}
|
|
346
375
|
|
|
376
|
+
function bistroStage(make,scene,palette,{fullBleed=false,plan}={}){
|
|
377
|
+
const stage = scene+'.counter';
|
|
378
|
+
const parentId = fullBleed
|
|
379
|
+
? make.placed(stage,scene,0,0,390,700,[0,0,700/390,390/700],1)
|
|
380
|
+
: make.placed(stage,scene,0,128,390,402,[34,13,.9],1);
|
|
381
|
+
make.component(stage,scene,'stage3d',0,0,390,fullBleed?700:402,{
|
|
382
|
+
skyColor:palette.background,hemiSkyColor:'#fff3dc',hemiGroundColor:'#355259',
|
|
383
|
+
hemiIntensity:1.35,sunColor:'#fff0cf',sunIntensity:3.0,sunX:-4,sunY:9,sunZ:5,
|
|
384
|
+
shadowsEnabled:true,shadowMapSize:'1024',toneMapping:'aces',renderMaxDim:600,
|
|
385
|
+
cameraX:0,cameraY:fullBleed?5.35:4.5,cameraZ:fullBleed?5.25:5.2,cameraFov:fullBleed?36:35,
|
|
386
|
+
landscapeCameraX:0,landscapeCameraY:fullBleed?5.5:4.3,landscapeCameraZ:fullBleed?3.9:4.9,landscapeCameraFov:fullBleed?36:34,
|
|
387
|
+
lookAtX:0,lookAtY:fullBleed?.04:.06,lookAtZ:fullBleed?.08:0,introLift:fullBleed?.001:0,
|
|
388
|
+
},{parentId});
|
|
389
|
+
const prop = (id,parameters) =>
|
|
390
|
+
make.component(id,scene,'mesh3d',0,0,0,0,{
|
|
391
|
+
primitive:'box',castShadow:false,receiveShadow:true,...parameters,
|
|
392
|
+
},{parentId:stage});
|
|
393
|
+
prop(stage+'.top',{x:0,y:-.14,z:0,sx:2.58,sy:.24,sz:2.54,color:'#734b36'});
|
|
394
|
+
prop(stage+'.trim',{x:0,y:-.28,z:0,sx:2.72,sy:.08,sz:2.68,color:'#d9b892'});
|
|
395
|
+
prop(stage+'.runner',{x:0,y:-.015,z:0,sx:2.26,sy:.02,sz:2.2,color:'#244852'});
|
|
396
|
+
const item = (id,role,parameters) =>
|
|
397
|
+
make.component(id,scene,'mesh3d',0,0,0,0,{
|
|
398
|
+
primitive:'model',materialMode:'lambert',pivotMode:'bottom-center',normalizeSize:.54,
|
|
399
|
+
castShadow:true,receiveShadow:true,...parameters,
|
|
400
|
+
},{parentId:stage,assetSlots:[{slotId:'source',assetId:`starter.asset.${role}`}]});
|
|
401
|
+
plan?.(item,stage);
|
|
402
|
+
return stage;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const bistroSpots = [
|
|
406
|
+
{role:'target1',x:-.68,y:.02,z:.71,ry:.35,phase:0},
|
|
407
|
+
{role:'target2',x:.68,y:.02,z:.71,ry:-.55,phase:1.5},
|
|
408
|
+
{role:'target3',x:-.68,y:.02,z:-.71,ry:.45,phase:3.0},
|
|
409
|
+
{role:'target4',x:.68,y:.02,z:-.71,ry:-.3,phase:4.5},
|
|
410
|
+
];
|
|
411
|
+
|
|
412
|
+
function tapTargets3d(make,{palette,winHoldSeconds,ctaLabel,winTitle,timeoutTitle}){
|
|
413
|
+
bistroStage(make,gameplay,palette,{fullBleed:true,plan:item=>{
|
|
414
|
+
for(const spot of bistroSpots){
|
|
415
|
+
const meshId = `starter.item.${spot.role}`;
|
|
416
|
+
item(meshId,spot.role,{x:spot.x,y:spot.y,z:spot.z,ry:spot.ry});
|
|
417
|
+
make.behavior(meshId+'.bob',meshId,'oscillate-3d',{axis:'y',amplitude:.02,angularSpeed:1.75,phase:spot.phase});
|
|
418
|
+
make.behavior(meshId+'.burst',meshId,'emitter',{
|
|
419
|
+
origin:'contact-3d',coverage:'local',shape:'confetti',color:palette.accent,color2:palette.surface,color3:'#ff7a59',
|
|
420
|
+
count:14,speed:130,lifetime:.48,gravity:240,spread:260,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}});
|
|
424
|
+
for(const spot of bistroSpots){
|
|
425
|
+
const meshId = `starter.item.${spot.role}`;
|
|
426
|
+
const btnId = `starter.target.${spot.role}`;
|
|
427
|
+
make.component(btnId,gameplay,'button',0,0,64,64,{
|
|
428
|
+
radius:48,fill:'#00000000',hoverFill:palette.accent+'22',pressedFill:palette.surface+'44',
|
|
429
|
+
stroke:palette.accent,strokeWidth:0,
|
|
430
|
+
},{order:12});
|
|
431
|
+
make.behavior(btnId+'.anchor',btnId,'ui-anchor-3d',{
|
|
432
|
+
targetId:meshId,anchor:'center',fitToProjectedBounds:true,paddingPx:6,minSizePx:54,maxSizePx:92,
|
|
433
|
+
squareBounds:true,showHighlight:true,highlightStyle:'pulse-ring',highlightColor:palette.accent,
|
|
434
|
+
syncVisibility:true,offscreen:'hide',
|
|
435
|
+
});
|
|
436
|
+
make.behavior(btnId+'.press',btnId,'press-feedback',{scaleDown:.9,springBackSeconds:.15,liftShadow:false});
|
|
437
|
+
make.bind(btnId+'.collect',{kind:'click',componentId:btnId},[
|
|
438
|
+
set(meshId,'visible',false),
|
|
439
|
+
set(btnId,'enabled',false),
|
|
440
|
+
{kind:'emit',behaviorId:meshId+'.burst'},
|
|
441
|
+
play('step'),
|
|
442
|
+
{kind:'add',variableId:steps,value:1},
|
|
443
|
+
]);
|
|
444
|
+
}
|
|
445
|
+
make.behavior('starter.guide','starter.target.target1','tutorial-hand',{
|
|
446
|
+
targetId:'starter.item.target1',mode:'tap',idleDelaySeconds:.85,hideOnFirstInput:true,
|
|
447
|
+
});
|
|
448
|
+
const instruction = 'starter.hint';
|
|
449
|
+
make.component(instruction,gameplay,'group',65,596,260,54,{}, {order:22});
|
|
450
|
+
make.landscape(instruction,220,330);
|
|
451
|
+
make.label(instruction+'.text',gameplay,0,0,260,54,'Tap every dish',28,palette.surface,instruction);
|
|
452
|
+
for(let index=0;index<bistroSpots.length;index++){
|
|
453
|
+
make.bind(`starter.step.${index+1}`,{kind:'variableChange',variableId:steps},[
|
|
454
|
+
...(index===0?[play('music'),set(instruction,'visible',false)]:[]),
|
|
455
|
+
set(`starter.pip.${index}`,'fill',palette.accent),
|
|
456
|
+
...(index===bistroSpots.length-1?[{kind:'changeScene',sceneId:win,delaySeconds:winHoldSeconds}]:[]),
|
|
457
|
+
],{all:[eq(steps,index+1)]});
|
|
458
|
+
}
|
|
459
|
+
outcome(make,win,winTitle,ctaLabel,palette,()=>bistroStage(make,win,palette,{
|
|
460
|
+
plan:item=>bistroSpots.forEach(spot=>{
|
|
461
|
+
const id = `${win}.hero.${spot.role}`;
|
|
462
|
+
item(id,spot.role,{x:spot.x,y:spot.y,z:spot.z,ry:spot.ry});
|
|
463
|
+
make.behavior(id+'.bob',id,'oscillate-3d',{axis:'y',amplitude:.028,angularSpeed:1.6,phase:spot.phase});
|
|
464
|
+
}),
|
|
465
|
+
}));
|
|
466
|
+
outcome(make,timeout,timeoutTitle,ctaLabel,palette,()=>bistroStage(make,timeout,palette,{
|
|
467
|
+
plan:item=>bistroSpots.forEach(spot=>{
|
|
468
|
+
item(`${timeout}.hero.${spot.role}`,spot.role,{x:spot.x,y:spot.y,z:spot.z,ry:spot.ry});
|
|
469
|
+
}),
|
|
470
|
+
}));
|
|
471
|
+
return bistroSpots.length;
|
|
472
|
+
}
|
|
473
|
+
|
|
347
474
|
function composition(input, settings){
|
|
348
475
|
const make = builder();
|
|
349
476
|
const {palette,durationSeconds} = settings;
|
|
350
477
|
backdrop(make,gameplay,palette);
|
|
351
478
|
make.variable(steps);
|
|
352
479
|
audioRig(make);
|
|
353
|
-
const count = (input.starter==='stack-and-serve'?stackAndServe:tapTargets)(make,settings);
|
|
354
|
-
progress(make,count,palette);
|
|
480
|
+
const count = (input.starter==='stack-and-serve'?stackAndServe:input.starter==='tap-targets-3d'?tapTargets3d:tapTargets)(make,settings);
|
|
481
|
+
progress(make,count,palette,input.starter==='tap-targets-3d'?[296,22]:[475,106]);
|
|
355
482
|
const deadline = 'starter.deadline';
|
|
356
483
|
make.behavior(deadline,gameplay+'.backdrop','timer',{seconds:durationSeconds,repeat:false});
|
|
357
484
|
make.bind(deadline+'.transition',timer(deadline),[
|
|
@@ -370,9 +497,9 @@ async function starterSources(input, definition, catalog, remoteFetcher){
|
|
|
370
497
|
const sourceId = requested ?? entry?.id;
|
|
371
498
|
check(sourceId,'E_STARTER_ASSET_UNAVAILABLE',{role,path});
|
|
372
499
|
const source = await resolveCc0SourceItem(sourceId,{catalog,remoteFetcher});
|
|
373
|
-
const expectedType = isArt?
|
|
500
|
+
const expectedType = isArt?definition.artMime:'audio/';
|
|
374
501
|
check(source.mime.startsWith(expectedType),'E_STARTER_ASSET_TYPE',{role,expectedType});
|
|
375
|
-
if(role==='burger'){
|
|
502
|
+
if(input.starter==='stack-and-serve'&&role==='burger'){
|
|
376
503
|
const {subNodes=[]} = inspectMedia(source.bytes,source.mime);
|
|
377
504
|
check(['bun-bottom',...layers].every(layer=>subNodes.includes(layer)),'E_STARTER_BURGER_NODES',{role});
|
|
378
505
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import {createProjectIndex} from './project-index.mjs';
|
|
2
|
+
import {sortPuzzleCompatibility} from './modules/sort-puzzle.mjs';
|
|
3
|
+
|
|
4
|
+
export const variantAdapters=Object.freeze([sortPuzzleCompatibility]);
|
|
5
|
+
export function variantAdapterForProject(project){
|
|
6
|
+
const index=createProjectIndex(project);
|
|
7
|
+
return variantAdapters.find(adapter=>adapter.matches(index))??null;
|
|
8
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import {check,exact,identifier,validateDocument} from './document.mjs';
|
|
2
|
+
import {contracts,behaviors,validateValue} from './contracts.mjs';
|
|
3
|
+
import {measurePixelText} from './pixel-text.mjs';
|
|
4
|
+
|
|
5
|
+
export const VARIANTS_FORMAT='tora-variants-1';
|
|
6
|
+
export const LANGUAGE_PATTERN=/^[a-z]{2,3}(?:-[A-Z][a-z]{3})?(?:-(?:[A-Z]{2}|[0-9]{3}))?$/;
|
|
7
|
+
const RTL_LANGUAGE_PATTERN=/^(ar|fa|he|iw|ps|sd|ug|ur|yi)(?:-|$)/;
|
|
8
|
+
export const emptyVariantStore=()=>({format:VARIANTS_FORMAT,revision:0,variants:[]});
|
|
9
|
+
const overlayKeys=['id','label','preset','language','storeUrl','variables','texts','actionTexts','colors','behaviors','assets'];
|
|
10
|
+
const textKeys=['text','color','fontSize','fontFamily','direction'];
|
|
11
|
+
const colorKeys=['fill','stroke','hoverFill','pressedFill','skyColor','tintColor'];
|
|
12
|
+
const presets=['shorter-hook','easier-win','high-contrast-cta','locale','custom'];
|
|
13
|
+
const plain=value=>value&&typeof value==='object'&&!Array.isArray(value);
|
|
14
|
+
const localizableAction=(action,visibleVariables)=>action?.kind==='floatingText'||action?.kind==='setComponent'&&action.key==='text'&&typeof action.value==='string'||action?.kind==='set'&&visibleVariables.has(action.variableId)&&typeof action.value==='string';
|
|
15
|
+
|
|
16
|
+
export function visibleStringVariables(project){
|
|
17
|
+
const ids=new Set();for(const component of project?.components??[])if(component.contract==='native.text.v1')for(const match of component.parameters.text.matchAll(/\{\{([a-z0-9_.-]+)\}\}/g))ids.add(match[1]);
|
|
18
|
+
for(const binding of project?.eventBindings??[])for(const action of binding.actions)if(action.kind==='setComponent'&&action.key==='text'&&typeof action.value==='string')for(const match of action.value.matchAll(/\{\{([a-z0-9_.-]+)\}\}/g))ids.add(match[1]);
|
|
19
|
+
return ids;
|
|
20
|
+
}
|
|
21
|
+
const diagnostic=(code,variantId,recordId,reason)=>({code,variantId,...(recordId?{recordId}:{}),reason});
|
|
22
|
+
|
|
23
|
+
export function extractLocalizableStrings(project){
|
|
24
|
+
const texts=Object.fromEntries(project.components.filter(component=>component.contract==='native.text.v1').map(component=>[component.id,component.parameters.text]));
|
|
25
|
+
const actionTexts={},visibleVariables=visibleStringVariables(project);
|
|
26
|
+
for(const binding of project.eventBindings)binding.actions.forEach((action,index)=>{if(localizableAction(action,visibleVariables))actionTexts[`${binding.id}:${index}`]=action.kind==='floatingText'?action.text:action.value;});
|
|
27
|
+
return {texts,actionTexts};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function validateOverrideRecord(record,allowed,variantId,kind,diagnostics){
|
|
31
|
+
if(!plain(record)){diagnostics.push(diagnostic('E_NATIVE_VARIANT',variantId,undefined,`${kind}_must_be_object`));return false;}
|
|
32
|
+
let valid=true;
|
|
33
|
+
for(const [key,value] of Object.entries(record)){
|
|
34
|
+
if(!allowed.includes(key)){diagnostics.push(diagnostic('E_NATIVE_VARIANT',variantId,key,`unknown_${kind}_field`));valid=false;continue;}
|
|
35
|
+
if(typeof value==='string'&&[...value].some(char=>{const code=char.codePointAt(0);return code<32||code===127;})&&!(kind==='text'&&key==='text')){diagnostics.push(diagnostic('E_NATIVE_VARIANT',variantId,key,'control_character'));valid=false;}
|
|
36
|
+
}
|
|
37
|
+
return valid;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function validateVariantStore(store,baseProject,{failOnOrphans=false,failOnIncomplete=true}={}){
|
|
41
|
+
const diagnostics=[],orphans=[],incomplete=[];
|
|
42
|
+
if(!plain(store)||!exact(store,['format','revision','variants'])||store.format!==VARIANTS_FORMAT||!Number.isSafeInteger(store.revision)||store.revision<0||!Array.isArray(store.variants)||store.variants.length>128){
|
|
43
|
+
return {valid:false,orphans,incomplete,diagnostics:[diagnostic('E_NATIVE_VARIANT_STORE',undefined,undefined,'invalid_store')]};
|
|
44
|
+
}
|
|
45
|
+
const ids=new Set(),components=new Map((baseProject?.components??[]).map(component=>[component.id,component])),variables=new Map((baseProject?.variables??[]).map(variable=>[variable.id,variable])),behaviorMap=new Map((baseProject?.gameplay??[]).map(behavior=>[behavior.id,behavior])),bindings=new Map((baseProject?.eventBindings??[]).map(binding=>[binding.id,binding])),assets=new Map((baseProject?.assets??[]).map(asset=>[asset.id,asset])),visibleVariables=visibleStringVariables(baseProject??{});
|
|
46
|
+
for(const variant of store.variants){
|
|
47
|
+
const id=variant?.id;
|
|
48
|
+
if(!plain(variant)||!exact(variant,overlayKeys)||typeof id!=='string'||id==='base'||!/^[a-z][a-z0-9-]{1,47}$/.test(id)||ids.has(id)||typeof variant.label!=='string'||!variant.label.trim()||variant.label.length>60){
|
|
49
|
+
diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_identity'));continue;
|
|
50
|
+
}
|
|
51
|
+
ids.add(id);
|
|
52
|
+
if(variant.preset!==undefined&&!presets.includes(variant.preset))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_preset'));
|
|
53
|
+
if(variant.language!==undefined&&(typeof variant.language!=='string'||variant.language.length>16||!LANGUAGE_PATTERN.test(variant.language)))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_language'));
|
|
54
|
+
if(variant.storeUrl!==undefined&&(typeof variant.storeUrl!=='string'||!/^https:\/\/(play\.google\.com\/store\/apps\/details\?id=[a-zA-Z0-9._-]+|apps\.apple\.com\/[a-zA-Z0-9/._?=&-]+)$/.test(variant.storeUrl)))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_store_url'));
|
|
55
|
+
if(variant.variables!==undefined){
|
|
56
|
+
if(!plain(variant.variables))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_variables'));
|
|
57
|
+
else for(const [recordId,value] of Object.entries(variant.variables)){
|
|
58
|
+
const variable=variables.get(recordId);
|
|
59
|
+
if(!variable){orphans.push(diagnostic('E_NATIVE_VARIANT_ORPHAN',id,recordId,'missing_variable'));continue;}
|
|
60
|
+
if(typeof value!==variable.type||variable.type==='number'&&!Number.isFinite(value)||typeof value==='string'&&value.length>512)diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,recordId,'invalid_variable_value'));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if(variant.texts!==undefined){
|
|
64
|
+
if(!plain(variant.texts))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_texts'));
|
|
65
|
+
else for(const [recordId,override] of Object.entries(variant.texts)){
|
|
66
|
+
const component=components.get(recordId);
|
|
67
|
+
if(component?.contract!=='native.text.v1'){orphans.push(diagnostic('E_NATIVE_VARIANT_ORPHAN',id,recordId,'missing_text_component'));continue;}
|
|
68
|
+
if(!validateOverrideRecord(override,textKeys,id,'text',diagnostics))continue;
|
|
69
|
+
for(const [key,value] of Object.entries(override))if(!validateValue(contracts['native.text.v1'].properties[key],value))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,recordId,`invalid_${key}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if(variant.actionTexts!==undefined){
|
|
73
|
+
if(!plain(variant.actionTexts))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_action_texts'));
|
|
74
|
+
else for(const [recordId,value] of Object.entries(variant.actionTexts)){
|
|
75
|
+
const separator=recordId.lastIndexOf(':'),binding=bindings.get(recordId.slice(0,separator)),actionIndex=Number(recordId.slice(separator+1)),action=binding?.actions[actionIndex];
|
|
76
|
+
if(separator<1||!Number.isInteger(actionIndex)||!localizableAction(action,visibleVariables)){orphans.push(diagnostic('E_NATIVE_VARIANT_ORPHAN',id,recordId,'missing_text_action'));continue;}
|
|
77
|
+
if(typeof value!=='string'||value.length>512)diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,recordId,'invalid_action_text'));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if(variant.colors!==undefined){
|
|
81
|
+
if(!plain(variant.colors))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_colors'));
|
|
82
|
+
else for(const [recordId,override] of Object.entries(variant.colors)){
|
|
83
|
+
const component=components.get(recordId);
|
|
84
|
+
if(!component){orphans.push(diagnostic('E_NATIVE_VARIANT_ORPHAN',id,recordId,'missing_color_component'));continue;}
|
|
85
|
+
if(!validateOverrideRecord(override,colorKeys,id,'color',diagnostics))continue;
|
|
86
|
+
for(const [key,value] of Object.entries(override))if(!component.contract||!contracts[component.contract].properties[key]||!validateValue(contracts[component.contract].properties[key],value))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,recordId,`invalid_${key}`));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if(variant.behaviors!==undefined){
|
|
90
|
+
if(!plain(variant.behaviors))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_behaviors'));
|
|
91
|
+
else for(const [recordId,override] of Object.entries(variant.behaviors)){
|
|
92
|
+
const behavior=behaviorMap.get(recordId);
|
|
93
|
+
if(!behavior){orphans.push(diagnostic('E_NATIVE_VARIANT_ORPHAN',id,recordId,'missing_behavior'));continue;}
|
|
94
|
+
if(!plain(override)){diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,recordId,'invalid_behavior_override'));continue;}
|
|
95
|
+
for(const [key,value] of Object.entries(override))if(!Object.hasOwn(behaviors[behavior.kind],key)||!validateValue(behaviors[behavior.kind][key],value))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,recordId,`invalid_${key}`));
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if(variant.assets!==undefined){
|
|
99
|
+
if(!plain(variant.assets))diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,undefined,'invalid_assets'));
|
|
100
|
+
else for(const [recordId,override] of Object.entries(variant.assets)){
|
|
101
|
+
const component=components.get(recordId),asset=plain(override)?assets.get(override.assetId):undefined;
|
|
102
|
+
if(!component){orphans.push(diagnostic('E_NATIVE_VARIANT_ORPHAN',id,recordId,'missing_asset_component'));continue;}
|
|
103
|
+
if(!asset){orphans.push(diagnostic('E_NATIVE_VARIANT_ORPHAN',id,recordId,'missing_asset'));continue;}
|
|
104
|
+
if(!exact(override,['slotId','assetId'])||!identifier(override.assetId)||override.slotId!==undefined&&typeof override.slotId!=='string')diagnostics.push(diagnostic('E_NATIVE_VARIANT',id,recordId,'invalid_asset_override'));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if(variant.preset==='locale'&&variant.language){
|
|
108
|
+
const extracted=extractLocalizableStrings(baseProject);
|
|
109
|
+
for(const recordId of Object.keys(extracted.texts))if(typeof variant.texts?.[recordId]?.text!=='string')incomplete.push(diagnostic('E_NATIVE_VARIANT_INCOMPLETE',id,recordId,'missing_text_translation'));
|
|
110
|
+
for(const recordId of Object.keys(extracted.actionTexts))if(typeof variant.actionTexts?.[recordId]!=='string')incomplete.push(diagnostic('E_NATIVE_VARIANT_INCOMPLETE',id,recordId,'missing_action_translation'));
|
|
111
|
+
for(const variableId of visibleVariables)if(variables.get(variableId)?.type==='string'&&typeof variant.variables?.[variableId]!=='string')incomplete.push(diagnostic('E_NATIVE_VARIANT_INCOMPLETE',id,variableId,'missing_variable_translation'));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if(failOnIncomplete)diagnostics.push(...incomplete);
|
|
115
|
+
if(failOnOrphans)diagnostics.push(...orphans);
|
|
116
|
+
return {valid:diagnostics.length===0,orphans,incomplete,diagnostics};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function assertVariantStore(store,baseProject,options){
|
|
120
|
+
const report=validateVariantStore(store,baseProject,options);
|
|
121
|
+
check(report.valid,'E_NATIVE_VARIANT',report);
|
|
122
|
+
return store;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function materializeVariant(baseProject,variant){
|
|
126
|
+
validateDocument(baseProject);
|
|
127
|
+
assertVariantStore({format:VARIANTS_FORMAT,revision:0,variants:[variant]},baseProject,{failOnOrphans:true,failOnIncomplete:true});
|
|
128
|
+
const project=globalThis.structuredClone(baseProject),components=new Map(project.components.map(component=>[component.id,component]));
|
|
129
|
+
if(variant.language)project.creativeBrief.language=variant.language;
|
|
130
|
+
if(variant.storeUrl!==undefined)project.base.storeUrl=variant.storeUrl;
|
|
131
|
+
for(const [id,value] of Object.entries(variant.variables??{}))project.variables.find(variable=>variable.id===id).initial=value;
|
|
132
|
+
for(const [id,override] of Object.entries(variant.texts??{}))Object.assign(components.get(id).parameters,globalThis.structuredClone(override));
|
|
133
|
+
for(const [key,text] of Object.entries(variant.actionTexts??{})){
|
|
134
|
+
const separator=key.lastIndexOf(':'),binding=project.eventBindings.find(item=>item.id===key.slice(0,separator)),action=binding.actions[Number(key.slice(separator+1))];
|
|
135
|
+
if(action.kind==='floatingText')action.text=text;else action.value=text;
|
|
136
|
+
}
|
|
137
|
+
for(const [id,override] of Object.entries(variant.colors??{}))Object.assign(components.get(id).parameters,globalThis.structuredClone(override));
|
|
138
|
+
for(const [id,override] of Object.entries(variant.behaviors??{}))Object.assign(project.gameplay.find(behavior=>behavior.id===id).parameters,globalThis.structuredClone(override));
|
|
139
|
+
for(const [id,override] of Object.entries(variant.assets??{})){
|
|
140
|
+
const component=components.get(id),slotId=override.slotId??'source',slot=component.assetSlots.find(item=>item.slotId===slotId);
|
|
141
|
+
if(slot)slot.assetId=override.assetId;else component.assetSlots.push({slotId,assetId:override.assetId});
|
|
142
|
+
}
|
|
143
|
+
const variableValues=new Map();
|
|
144
|
+
for(const variable of project.variables)variableValues.set(variable.id,[String(variable.initial??'')]);
|
|
145
|
+
for(const binding of project.eventBindings)for(const action of binding.actions)if(action.kind==='set'&&typeof action.value==='string'&&variableValues.has(action.variableId))variableValues.get(action.variableId).push(action.value);
|
|
146
|
+
const expandedTexts=raw=>{
|
|
147
|
+
const text=String(raw??''),refs=[...text.matchAll(/\{\{([a-z0-9_.-]+)\}\}/g)].map(match=>match[1]);
|
|
148
|
+
const staticOnly=text.replace(/\{\{[a-z0-9_.-]+\}\}/g,'');
|
|
149
|
+
return [staticOnly,...refs.flatMap(ref=>variableValues.get(ref)??[])];
|
|
150
|
+
};
|
|
151
|
+
const pixelComponents=project.components.filter(component=>component.contract==='native.text.v1'&&component.parameters.fontFamily==='pixel');
|
|
152
|
+
let anyPixelFallback=false;
|
|
153
|
+
for(const component of pixelComponents){
|
|
154
|
+
const dynamic=project.eventBindings.flatMap(binding=>binding.actions).filter(action=>action.kind==='setComponent'&&action.componentId===component.id&&action.key==='text'&&typeof action.value==='string').map(action=>action.value);
|
|
155
|
+
if([component.parameters.text,...dynamic].flatMap(expandedTexts).some(text=>measurePixelText(text,component.parameters).unsupportedChars.length>0)){component.parameters.fontFamily='sans-serif';anyPixelFallback=true;}
|
|
156
|
+
}
|
|
157
|
+
if(anyPixelFallback&&(variant.preset==='locale'||Boolean(variant.language)))for(const component of pixelComponents)component.parameters.fontFamily='sans-serif';
|
|
158
|
+
return validateDocument(project);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function createLocaleVariant(baseProject,{id,label,language,texts={},actionTexts={},variables={},storeUrl,direction}={}){
|
|
162
|
+
const resolvedDirection=direction??(typeof language==='string'&&RTL_LANGUAGE_PATTERN.test(language)?'rtl':undefined);
|
|
163
|
+
const overrides={};for(const [componentId,text] of Object.entries(texts))overrides[componentId]={text,...(resolvedDirection?{direction:resolvedDirection}:{})};
|
|
164
|
+
return {id,label:label??id,preset:'locale',language,...(storeUrl!==undefined?{storeUrl}:{}),variables:{...variables},texts:overrides,actionTexts:{...actionTexts}};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function createPresetOverlay(baseProject,{id,label,preset='custom',...options}={}){
|
|
168
|
+
if(preset==='locale')return createLocaleVariant(baseProject,{id,label,...options});
|
|
169
|
+
const variant={id,label:label??id,preset};
|
|
170
|
+
if(preset==='high-contrast-cta'){
|
|
171
|
+
const eventsById=new Map((baseProject.events??[]).map(event=>[event.id,event]));
|
|
172
|
+
const storeButtons=new Set((baseProject.eventBindings??[]).filter(binding=>binding.actions.some(action=>action.kind==='store')).map(binding=>eventsById.get(binding.eventId)).filter(event=>event?.kind==='click').map(event=>event.componentId));
|
|
173
|
+
const targets=baseProject.components.filter(component=>component.contract==='native.button.v1'&&(storeButtons.size?storeButtons.has(component.id):true));
|
|
174
|
+
if(targets.length)variant.colors=Object.fromEntries(targets.map(component=>[component.id,{fill:'#ffc857',hoverFill:'#ffdf88',pressedFill:'#e6a93d',stroke:'#193b46'}]));
|
|
175
|
+
}
|
|
176
|
+
if(preset==='shorter-hook'){
|
|
177
|
+
const hintTexts=baseProject.components.filter(component=>component.contract==='native.text.v1'&&/hint|instruction|prompt/i.test(component.id));
|
|
178
|
+
if(hintTexts.length)variant.texts=Object.fromEntries(hintTexts.map(component=>[component.id,{text:options.text??'PLAY NOW'}]));
|
|
179
|
+
}
|
|
180
|
+
if(preset==='easier-win'){
|
|
181
|
+
const deadlines=baseProject.gameplay.filter(behavior=>behavior.kind==='timer'&&!behavior.parameters.repeat);
|
|
182
|
+
if(deadlines.length)variant.behaviors=Object.fromEntries(deadlines.map(behavior=>[behavior.id,{seconds:Math.min(120,behavior.parameters.seconds*1.5)}]));
|
|
183
|
+
}
|
|
184
|
+
const extras=Object.fromEntries(Object.entries(options).filter(([key,value])=>value!==undefined&&overlayKeys.includes(key)&&!['id','label','preset'].includes(key)));
|
|
185
|
+
return {...variant,...extras};
|
|
186
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {createHash} from 'node:crypto';
|
|
2
|
+
import {readFile,mkdir,rename,rm,writeFile} from 'node:fs/promises';
|
|
3
|
+
import {resolve} from 'node:path';
|
|
4
|
+
import {canonical} from '../../../packages/creative-project/src/canonical.mjs';
|
|
5
|
+
import {parseAuthoringJson} from '../../../packages/creative-project/src/strict-json.mjs';
|
|
6
|
+
import {check} from './document.mjs';
|
|
7
|
+
import {withProjectFileLock} from '../editor-state.mjs';
|
|
8
|
+
import {assertStorePath} from './store-path.mjs';
|
|
9
|
+
import {
|
|
10
|
+
VARIANTS_FORMAT,
|
|
11
|
+
LANGUAGE_PATTERN,
|
|
12
|
+
emptyVariantStore,
|
|
13
|
+
visibleStringVariables,
|
|
14
|
+
extractLocalizableStrings,
|
|
15
|
+
validateVariantStore,
|
|
16
|
+
assertVariantStore,
|
|
17
|
+
materializeVariant,
|
|
18
|
+
createLocaleVariant,
|
|
19
|
+
createPresetOverlay,
|
|
20
|
+
} from './variants-core.mjs';
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
VARIANTS_FORMAT,
|
|
24
|
+
LANGUAGE_PATTERN,
|
|
25
|
+
emptyVariantStore,
|
|
26
|
+
visibleStringVariables,
|
|
27
|
+
extractLocalizableStrings,
|
|
28
|
+
validateVariantStore,
|
|
29
|
+
assertVariantStore,
|
|
30
|
+
materializeVariant,
|
|
31
|
+
createLocaleVariant,
|
|
32
|
+
createPresetOverlay,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const variantStoreHash=store=>'sha256:'+createHash('sha256').update(canonical(store)).digest('hex');
|
|
36
|
+
export const variantsPath=projectRoot=>resolve(projectRoot,'variants.json');
|
|
37
|
+
|
|
38
|
+
export async function readVariants(projectRoot,baseProject){
|
|
39
|
+
await assertStorePath(projectRoot);
|
|
40
|
+
const path=variantsPath(projectRoot);
|
|
41
|
+
await assertStorePath(path);
|
|
42
|
+
let store;
|
|
43
|
+
try{store=parseAuthoringJson(await readFile(path,'utf8'));}catch(error){if(error.code==='ENOENT')return emptyVariantStore();throw error;}
|
|
44
|
+
assertVariantStore(store,baseProject,{failOnOrphans:false,failOnIncomplete:false});
|
|
45
|
+
return store;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function updateVariants(projectRoot,baseProject,expectedRevision,update){
|
|
49
|
+
await assertStorePath(projectRoot);
|
|
50
|
+
const path=variantsPath(projectRoot);
|
|
51
|
+
await assertStorePath(path);
|
|
52
|
+
return withProjectFileLock(path+'.lock',async()=>{
|
|
53
|
+
const current=await readVariants(projectRoot,baseProject);
|
|
54
|
+
check(expectedRevision===undefined||current.revision===expectedRevision,'E_NATIVE_STALE');
|
|
55
|
+
const variants=update(globalThis.structuredClone(current))??current;
|
|
56
|
+
const next={format:VARIANTS_FORMAT,revision:current.revision+1,variants:variants.variants??variants};
|
|
57
|
+
assertVariantStore(next,baseProject,{failOnOrphans:false,failOnIncomplete:true});
|
|
58
|
+
await mkdir(projectRoot,{recursive:true});
|
|
59
|
+
const temporary=path+'.'+createHash('sha256').update(JSON.stringify(next)+Math.random()).digest('hex').slice(0,16)+'.tmp';
|
|
60
|
+
try{await writeFile(temporary,JSON.stringify(next),{flag:'wx'});await rename(temporary,path);}finally{await rm(temporary,{force:true});}
|
|
61
|
+
return next;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -7,7 +7,7 @@ import {lowerAssets} from './assets.mjs';
|
|
|
7
7
|
import {loadCatalog} from './catalog-cache.mjs';
|
|
8
8
|
import {check,exact} from './document.mjs';
|
|
9
9
|
import {isAudioMime} from './media-validate.mjs';
|
|
10
|
-
import {stageAudio} from './
|
|
10
|
+
import {stageAudio} from './audio-assets.mjs';
|
|
11
11
|
|
|
12
12
|
export const winCueCatalog = Object.freeze({
|
|
13
13
|
'arcade-rise': Object.freeze({catalogId:'kenney-music-jingles/audio/victory.wav',label:'Arcade rise'}),
|
|
@@ -25,7 +25,7 @@ Prove one representative scene at the intended phone size before expanding the a
|
|
|
25
25
|
|
|
26
26
|
## Author and inspect safely
|
|
27
27
|
|
|
28
|
-
Create a new project or inspect the requested existing project. Use `tora_inspect({ id, tree: true })` for a compact scene outline before targeted `ids` reads (`full: true` only when you truly need the complete JSON document); preserve unrelated objects and scenes. Use `tora_list_assets` and `tora_fetch_cc0_pack` to discover/cache verified CC0 2D, 3D, and audio packs and `tora_stage_cc0_assets` to stage them with server-enforced provenance, retained 3D masters, and single-visual-style-family validation. Remote 3D sources are restricted to Kenney, Quaternius, and CC0-filtered OpenGameArt; external-only Quaternius downloads require manual workspace import. When sprite sheets or padded sprites need faithful mechanical preparation (`crop`, `trim`, `resize`/`maxSide`, or `sliceGrid`), or GLB/glTF/OBJ models need dependency-aware `prep-3d`, run `tora_prep_assets` and upload the emitted `.tora/prepared-assets/...` paths via `tora_upload_assets` (which verifies the hash-bound prep manifest and preserves provenance, dependency lineage, and `styleFamily`). For raw studio assets, use `tora_upload_assets` with workspace `filePath` items (up to 32 files in one atomic revision, avoiding the 12 MiB MCP frame limit),
|
|
28
|
+
Create a new project or inspect the requested existing project. Use `tora_inspect({ id, tree: true })` for a compact scene outline before targeted `ids` reads (`full: true` only when you truly need the complete JSON document); preserve unrelated objects and scenes. Use `tora_list_assets` and `tora_fetch_cc0_pack` to discover/cache verified CC0 2D, 3D, and audio packs and `tora_stage_cc0_assets` to stage them with server-enforced provenance, retained 3D masters, and single-visual-style-family validation. Remote 3D sources are restricted to Kenney, Quaternius, and CC0-filtered OpenGameArt; external-only Quaternius downloads require manual workspace import. When sprite sheets or padded sprites need faithful mechanical preparation (`crop`, `trim`, `resize`/`maxSide`, or `sliceGrid`), or GLB/glTF/OBJ models need dependency-aware `prep-3d`, run `tora_prep_assets` and upload the emitted `.tora/prepared-assets/...` paths via `tora_upload_assets` (which verifies the hash-bound prep manifest and preserves provenance, dependency lineage, and `styleFamily`). For raw studio assets, use `tora_upload_assets` with workspace `filePath` items (up to 32 files in one atomic revision, avoiding the 12 MiB MCP frame limit), including a one-item batch for a single file. Raw PNG/JPEG/WAV/MP3 uploads up to 8 MB and GLB/glTF/OBJ uploads up to 32 MiB are optimized automatically while original masters are retained; use `optimize:"lossless"|"none"`, `preserveResolution`, workspace `filePath`, or an original `sourceHash` when needed. Connect delivered images and models through supported asset slots; inspect mesh `subNodes`/`animations`, use `animate-3d` for bounded clips, and opt in to `fitTargetBudget` on export/QA when a network cap requires deterministic re-optimization from retained masters.
|
|
29
29
|
|
|
30
30
|
Submit edits through `tora_edit`, with the inspected `expected` revision and intended changed record IDs in `scope`. Use `scopeCreates: true` to auto-allow brand-new records without duplicating every new ID in `scope` — any pre-existing component, behavior, event, binding, or variable referenced by a new record (or `$project.base`) still requires explicit inclusion in `scope`. A `PREVIEW` response is not a committed change: inspect the effects and either adjust scope and commit the cached preview directly via `commitPreviewDigest` (without re-emitting `operations[]`) when those effects belong to the requested task, or revise your operations. On a stale revision, inspect again before rebuilding the edit. Never blindly replay edits or bypass validation. For HTTP authoring, use the documented preview/commit sequence and revision checks.
|
|
31
31
|
|