@tora-editor/tora 0.1.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 +107 -58
- package/assets/free-audio/arcade-pop/audio/loss.wav +0 -0
- package/assets/free-audio/arcade-pop/audio/reward.wav +0 -0
- package/assets/free-audio/arcade-pop/audio/win.wav +0 -0
- package/assets/free-audio/arcade-pop/source/INFO.txt +11 -11
- package/assets/kenney-food-starter/License.txt +28 -0
- package/assets/kenney-food-starter/burger.glb +0 -0
- package/assets/kenney-food-starter/frying-pan.glb +0 -0
- package/assets/kenney-food-starter/plan.json +61 -0
- package/assets/kenney-food-starter/plate.glb +0 -0
- package/assets/kenney-food-starter/pot.glb +0 -0
- package/assets/kenney-harvest/audio/victory.wav +0 -0
- package/assets/kenney-harvest/source/music-jingles/OGG/jingles_NES/jingles_NES03.ogg +0 -0
- package/assets/kenney-harvest/source/music-jingles/OGG/jingles_PIZZA/jingles_PIZZA03.ogg +0 -0
- package/assets/kenney-harvest/source/music-jingles/license.txt +14 -0
- package/bin/tora.mjs +322 -28
- package/crates/packer/trusted/native-3d-meta.json +4 -3
- package/crates/packer/trusted/native-3d.js +181 -181
- 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 +4 -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 -95
- package/docs/TORA_CREATION_API.md +63 -348
- package/docs/reference/CORE_AUTHORING.md +10 -3
- package/docs/reference/PLAYABLE_STARTERS.md +20 -0
- package/docs/reference/packs/3d.md +11 -3
- package/network-rules/mintegral-appgrowth-single-html.json +10 -10
- package/package.json +6 -6
- package/packages/creative-project/project-v21.schema.json +372 -9
- 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 +256 -68
- package/scripts/lean/editor/review-editor.js +1834 -1086
- 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 +39 -62
- package/scripts/lean/native/api.mjs +161 -136
- package/scripts/lean/native/asset-catalog.mjs +7 -6
- package/scripts/lean/native/asset-lineage.mjs +54 -0
- package/scripts/lean/native/asset-prep.mjs +173 -40
- package/scripts/lean/native/assets.mjs +107 -11
- 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 +38 -7
- package/scripts/lean/native/cc0-inputs.mjs +24 -0
- package/scripts/lean/native/cc0-staging.mjs +28 -8
- package/scripts/lean/native/compiler.mjs +9 -3
- package/scripts/lean/native/contracts.mjs +16 -11
- package/scripts/lean/native/creative-qa.mjs +365 -128
- package/scripts/lean/native/demos.mjs +53 -18
- package/scripts/lean/native/document.mjs +50 -12
- package/scripts/lean/native/export-budget.mjs +75 -0
- package/scripts/lean/native/local-bundle.mjs +7 -3
- package/scripts/lean/native/mcp-server.mjs +42 -74
- package/scripts/lean/native/media-validate.mjs +124 -0
- 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/native-bin.mjs +3 -3
- package/scripts/lean/native/outcome-playthrough.mjs +97 -0
- package/scripts/lean/native/project-bundle.mjs +6 -5
- 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/remote-cc0-fetcher.mjs +403 -197
- package/scripts/lean/native/review.mjs +205 -571
- package/scripts/lean/native/schema-vocabulary.mjs +10 -0
- package/scripts/lean/native/schema.mjs +7 -5
- package/scripts/lean/native/scope.mjs +45 -0
- package/scripts/lean/native/service.mjs +378 -79
- package/scripts/lean/native/starters.mjs +563 -0
- 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 +96 -0
- 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 -240
- 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 -874
- 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 -191
- package/scripts/lean/native/check-salvage.mjs +0 -197
- 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/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 -165
- 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-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 -1623
- package/scripts/lean/native/salvage-recipe.mjs +0 -20
- package/scripts/lean/native/stage-3d.mjs +0 -818
- package/scripts/lean/native/verify.mjs +0 -4
- package/scripts/lean/scene-document.mjs +0 -48
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {createHash} from 'node:crypto';
|
|
2
|
+
import {Buffer} from 'node:buffer';
|
|
3
|
+
import {readFile} from 'node:fs/promises';
|
|
4
|
+
import {resolve} from 'node:path';
|
|
5
|
+
import {PACKAGE_ROOT} from '../runtime-paths.mjs';
|
|
6
|
+
import {lowerAssets} from './assets.mjs';
|
|
7
|
+
import {loadCatalog} from './catalog-cache.mjs';
|
|
8
|
+
import {check,exact} from './document.mjs';
|
|
9
|
+
import {isAudioMime} from './media-validate.mjs';
|
|
10
|
+
import {stageAudio} from './audio-assets.mjs';
|
|
11
|
+
|
|
12
|
+
export const winCueCatalog = Object.freeze({
|
|
13
|
+
'arcade-rise': Object.freeze({catalogId:'kenney-music-jingles/audio/victory.wav',label:'Arcade rise'}),
|
|
14
|
+
'arcade-fanfare': Object.freeze({catalogId:'kenney-music-jingles/arcade-pop/win.wav',label:'Arcade fanfare'}),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
async function catalogCue(key){
|
|
18
|
+
check(Object.hasOwn(winCueCatalog,key),'E_NATIVE_ARGUMENT');
|
|
19
|
+
const catalogId=winCueCatalog[key].catalogId;
|
|
20
|
+
const cue=(await loadCatalog()).audioFiles.find(item=>item.catalogId===catalogId);
|
|
21
|
+
check(cue?.source.license==='CC0-1.0','E_NATIVE_NOT_FOUND');
|
|
22
|
+
return cue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function winCuePreview(key){
|
|
26
|
+
const {file}=await catalogCue(key);
|
|
27
|
+
const bytes=await readFile(resolve(PACKAGE_ROOT,file.file));
|
|
28
|
+
check('sha256:'+createHash('sha256').update(bytes).digest('hex')===file.sha256,'E_NATIVE_HASH');
|
|
29
|
+
return {bytes,mime:file.mime};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function projectTracks(project){
|
|
33
|
+
const used=new Set(project.eventBindings.flatMap(binding=>binding.actions
|
|
34
|
+
.filter(action=>action.kind==='playAudio').map(action=>action.behaviorId)));
|
|
35
|
+
const routes=project.gameplay.filter(behavior=>behavior.kind==='audio');
|
|
36
|
+
const winRoutes=routes.filter(({id,parameters})=>used.has(id)&&!parameters.loop&&['win','victory'].includes(parameters.role));
|
|
37
|
+
if(winRoutes.length!==1)return;
|
|
38
|
+
const win=winRoutes[0];
|
|
39
|
+
if(routes.some(route=>route.id!==win.id&&route.componentId===win.componentId))return;
|
|
40
|
+
const assetFor=route=>{
|
|
41
|
+
const component=project.components.find(item=>item.id===route.componentId);
|
|
42
|
+
const assetId=component?.assetSlots.find(slot=>slot.slotId==='source')?.assetId;
|
|
43
|
+
return project.assets.find(asset=>asset.id===assetId&&isAudioMime(asset.mime));
|
|
44
|
+
};
|
|
45
|
+
const current=assetFor(win);
|
|
46
|
+
if(!current)return;
|
|
47
|
+
const music=routes.find(({id,parameters})=>used.has(id)&¶meters.bus==='music'&¶meters.loop);
|
|
48
|
+
const backing=music&&assetFor(music);
|
|
49
|
+
return {win,current,...(backing?{music,backing}:{})};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function matchesCue(asset,file){
|
|
53
|
+
if(asset.hash===file.sha256)return true;
|
|
54
|
+
if(!asset.provenance?.startsWith('{'))return false;
|
|
55
|
+
try{return JSON.parse(asset.provenance).sourceHash===file.sha256;}catch{return false;}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function projectWinCueChoices(project){
|
|
59
|
+
const tracks=projectTracks(project);
|
|
60
|
+
if(!tracks)return;
|
|
61
|
+
const choices=await Promise.all(Object.entries(winCueCatalog).map(async ([key,choice])=>{
|
|
62
|
+
const {file}=await catalogCue(key);
|
|
63
|
+
return {key,label:choice.label,current:matchesCue(tracks.current,file)};
|
|
64
|
+
}));
|
|
65
|
+
return {choices,volume:tracks.win.parameters.volume,duckMusic:tracks.win.parameters.bus==='stinger',
|
|
66
|
+
...(tracks.music?{musicVolume:tracks.music.parameters.volume}:{})};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function projectWinCueTrack(service,id,track){
|
|
70
|
+
check(track==='music'||track==='current','E_NATIVE_ARGUMENT');
|
|
71
|
+
const {project}=await service.read(id),tracks=projectTracks(project);
|
|
72
|
+
const ref=track==='music'?tracks?.backing:tracks?.current;
|
|
73
|
+
check(ref,'E_NATIVE_NOT_FOUND');
|
|
74
|
+
const [asset]=await lowerAssets(resolve(service.store.root,id),[ref]);
|
|
75
|
+
return {bytes:Buffer.from(asset.data,'base64'),mime:asset.mime};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function replaceProjectWinCue(service,id,body){
|
|
79
|
+
check(exact(body,['expected','key'])&&exact(body.expected,['revisionId','contentHash'])&&typeof body.key==='string','E_NATIVE_ARGUMENT');
|
|
80
|
+
const {project,revisionId,contentHash}=await service.read(id);
|
|
81
|
+
check(body.expected.revisionId===revisionId&&body.expected.contentHash===contentHash,'E_NATIVE_STALE');
|
|
82
|
+
const tracks=projectTracks(project);
|
|
83
|
+
check(tracks,'E_NATIVE_NOT_FOUND');
|
|
84
|
+
const cue=await catalogCue(body.key);
|
|
85
|
+
if(matchesCue(tracks.current,cue.file))return {revisionId,contentHash};
|
|
86
|
+
const existing=project.assets.find(asset=>asset.hash===cue.file.sha256&&isAudioMime(asset.mime));
|
|
87
|
+
let assetId=existing?.id??'catalog.win.'+body.key;
|
|
88
|
+
let sequence=1;
|
|
89
|
+
while(!existing&&(project.assets.some(asset=>asset.id===assetId)||project.tombstones.includes(assetId)))assetId='catalog.win.'+body.key+'.'+sequence++;
|
|
90
|
+
const imports=existing?[]:await stageAudio(service,id,[{catalogId:cue.catalogId,assetId}],{optimize:'none'});
|
|
91
|
+
const operations=[...imports,{kind:'replaceAsset',id:tracks.win.componentId,assetId}];
|
|
92
|
+
const envelope={format:'tora-transaction-1',expected:body.expected,operations};
|
|
93
|
+
const preview=await service.preview(id,envelope);
|
|
94
|
+
const committed=await service.transact(id,{...envelope,previewDigest:preview.previewDigest});
|
|
95
|
+
return {revisionId:committed.revisionId,contentHash:committed.contentHash};
|
|
96
|
+
}
|
|
@@ -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 packs and `tora_stage_cc0_assets` to stage them with server-enforced provenance and single-visual-style-family validation. When sprite sheets or padded sprites need faithful mechanical preparation (`crop`, `trim`, `resize`/`maxSide`, or `sliceGrid`), 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 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
|
|