@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
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import {behaviors,contracts,validateValue} from './contracts.mjs';
|
|
2
|
+
import {validateDocument} from './document.mjs';
|
|
3
|
+
import {measurePixelText} from './pixel-text.mjs';
|
|
4
|
+
|
|
5
|
+
const COLOR_KEYS=new Set(['fill','stroke','hoverFill','pressedFill','skyColor','tintColor','color','panelFill','panelStroke']);
|
|
6
|
+
const STORE_URL_RE=/^https:\/\/(play\.google\.com\/store\/apps\/details\?id=[a-zA-Z0-9._-]+|apps\.apple\.com\/[a-zA-Z0-9/._?=&-]+)$/;
|
|
7
|
+
|
|
8
|
+
function check(condition,code){
|
|
9
|
+
if(!condition)throw Error(code);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function humanizeId(raw){
|
|
13
|
+
const tail=String(raw??'').split('.').filter(part=>part&&!['starter','scene','harvest','salvage','sort','ui','hud','label','text','btn','button','bg','group','placement'].includes(part.toLowerCase()));
|
|
14
|
+
const source=(tail.length?tail.slice(-2):String(raw??'item').split('.').slice(-2)).join(' ');
|
|
15
|
+
const spaced=source.replace(/[-_]+/g,' ').replace(/([a-z])([A-Z])/g,'$1 $2').replace(/\s+/g,' ').trim();
|
|
16
|
+
return spaced?spaced[0].toUpperCase()+spaced.slice(1):'Element';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function sceneMoment(scene){
|
|
20
|
+
if(!scene)return 'opening';
|
|
21
|
+
if(scene.role==='end-card')return /fail|loss|timeout/i.test(scene.id)?'timeout':'end-card';
|
|
22
|
+
return 'opening';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function sceneFriendlyLabel(scene){
|
|
26
|
+
if(!scene)return 'Gameplay';
|
|
27
|
+
if(scene.role==='end-card'){
|
|
28
|
+
return /fail|loss|timeout/i.test(scene.id)?'Time\'s Up Screen':'Win Screen';
|
|
29
|
+
}
|
|
30
|
+
const label=typeof scene.label==='string'&&scene.label.trim()?scene.label.trim():'';
|
|
31
|
+
return label&&!/^scene\./i.test(label)?label:'Gameplay';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function storeButtonComponentIds(project){
|
|
35
|
+
const eventsById=new Map((project.events??[]).map(event=>[event.id,event]));
|
|
36
|
+
const ids=new Set();
|
|
37
|
+
for(const binding of project.eventBindings??[]){
|
|
38
|
+
if(!binding.actions?.some(action=>action.kind==='store'))continue;
|
|
39
|
+
const event=eventsById.get(binding.eventId);
|
|
40
|
+
if(event?.kind==='click'&&event.componentId)ids.add(event.componentId);
|
|
41
|
+
}
|
|
42
|
+
return ids;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function shiftHexColor(hex,delta){
|
|
46
|
+
if(typeof hex!=='string'||!/^#[0-9a-f]{6}$/i.test(hex))return hex;
|
|
47
|
+
const clamp=v=>Math.max(0,Math.min(255,Math.round(v)));
|
|
48
|
+
const r=clamp(parseInt(hex.slice(1,3),16)+delta);
|
|
49
|
+
const g=clamp(parseInt(hex.slice(3,5),16)+delta);
|
|
50
|
+
const b=clamp(parseInt(hex.slice(5,7),16)+delta);
|
|
51
|
+
return '#'+[r,g,b].map(v=>v.toString(16).padStart(2,'0')).join('');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function textRoleLabel(component,scene,storeButtons){
|
|
55
|
+
const moment=sceneMoment(scene);
|
|
56
|
+
const suffix=moment==='timeout'?' (Time\'s up)':moment==='end-card'?' (Win)':'';
|
|
57
|
+
if(component.parentId&&storeButtons.has(component.parentId))return 'Install button'+suffix;
|
|
58
|
+
const id=component.id||'';
|
|
59
|
+
if(/cta/i.test(id))return 'Install button'+suffix;
|
|
60
|
+
if(/hint|instruction|prompt/i.test(id))return 'Opening prompt';
|
|
61
|
+
if(/title|headline|heading/i.test(id))return (moment==='timeout'?'Time\'s up headline':moment==='end-card'?'Win headline':'Title');
|
|
62
|
+
if(/reward|message|caption|subtitle|sub/i.test(id))return (moment==='timeout'?'Time\'s up message':moment==='end-card'?'Win message':'Subtitle');
|
|
63
|
+
if(component.label&&component.label!==component.id&&!/^[a-z0-9_.-]+\.[a-z0-9_.-]+$/i.test(component.label))return component.label;
|
|
64
|
+
return humanizeId(id);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function summarizeQuickEdit(project){
|
|
68
|
+
const scenesById=new Map((project.scenes??[]).map(scene=>[scene.id,scene]));
|
|
69
|
+
const storeButtons=storeButtonComponentIds(project);
|
|
70
|
+
const assetsById=new Map((project.assets??[]).map(asset=>[asset.id,asset]));
|
|
71
|
+
const scenes=(project.scenes??[]).map(scene=>({
|
|
72
|
+
id:scene.id,
|
|
73
|
+
label:sceneFriendlyLabel(scene),
|
|
74
|
+
role:scene.role,
|
|
75
|
+
moment:sceneMoment(scene),
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
const texts=[];
|
|
79
|
+
const colors=[];
|
|
80
|
+
const seenColorKeys=new Set();
|
|
81
|
+
|
|
82
|
+
const pushColor=entry=>{
|
|
83
|
+
const key=`${entry.componentId}:${entry.key}`;
|
|
84
|
+
if(seenColorKeys.has(key))return;
|
|
85
|
+
seenColorKeys.add(key);
|
|
86
|
+
colors.push(entry);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
for(const component of project.components??[]){
|
|
90
|
+
const scene=scenesById.get(component.sceneId);
|
|
91
|
+
const moment=sceneMoment(scene);
|
|
92
|
+
if(component.contract==='native.text.v1'){
|
|
93
|
+
const text=String(component.parameters?.text??'');
|
|
94
|
+
const isCta=Boolean(component.parentId&&storeButtons.has(component.parentId))||/cta/i.test(component.id);
|
|
95
|
+
texts.push({
|
|
96
|
+
id:component.id,
|
|
97
|
+
sceneId:component.sceneId,
|
|
98
|
+
sceneLabel:sceneFriendlyLabel(scene),
|
|
99
|
+
moment,
|
|
100
|
+
parentId:component.parentId??null,
|
|
101
|
+
componentIds:component.parentId&&storeButtons.has(component.parentId)?[component.parentId,component.id]:[component.id],
|
|
102
|
+
roleLabel:textRoleLabel(component,scene,storeButtons),
|
|
103
|
+
isCta,
|
|
104
|
+
text,
|
|
105
|
+
color:component.parameters?.color??'#ffffff',
|
|
106
|
+
fontSize:component.parameters?.fontSize??24,
|
|
107
|
+
fontFamily:component.parameters?.fontFamily??'sans-serif',
|
|
108
|
+
isPixelFont:component.parameters?.fontFamily==='pixel',
|
|
109
|
+
hasPlaceholder:/\{\{[^}]+\}\}/.test(text),
|
|
110
|
+
maxLength:isCta?24:120,
|
|
111
|
+
});
|
|
112
|
+
}else if(component.contract==='native.button.v1'){
|
|
113
|
+
const isCta=storeButtons.has(component.id);
|
|
114
|
+
const suffix=moment==='timeout'?' (Time\'s up)':moment==='end-card'?' (Win)':'';
|
|
115
|
+
if(typeof component.parameters?.fill==='string'){
|
|
116
|
+
pushColor({
|
|
117
|
+
componentId:component.id,
|
|
118
|
+
sceneId:component.sceneId,
|
|
119
|
+
sceneLabel:sceneFriendlyLabel(scene),
|
|
120
|
+
moment,
|
|
121
|
+
key:'fill',
|
|
122
|
+
value:component.parameters.fill,
|
|
123
|
+
roleLabel:isCta?`Install button color${suffix}`:`${humanizeId(component.id)} button color`,
|
|
124
|
+
isCta,
|
|
125
|
+
syncButtonStates:true,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}else if(component.contract==='native.stage3d.v1'){
|
|
129
|
+
if(typeof component.parameters?.skyColor==='string'){
|
|
130
|
+
pushColor({
|
|
131
|
+
componentId:component.id,
|
|
132
|
+
sceneId:component.sceneId,
|
|
133
|
+
sceneLabel:sceneFriendlyLabel(scene),
|
|
134
|
+
moment,
|
|
135
|
+
key:'skyColor',
|
|
136
|
+
value:component.parameters.skyColor,
|
|
137
|
+
roleLabel:`3D Sky color (${sceneFriendlyLabel(scene)})`,
|
|
138
|
+
isCta:false,
|
|
139
|
+
syncButtonStates:false,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}else if(component.contract==='native.rectangle.v1'){
|
|
143
|
+
const w=Number(component.parameters?.width??0),h=Number(component.parameters?.height??0);
|
|
144
|
+
const isBackdrop=(w>=300&&h>=400)||/(?:backdrop|background|^bg$|\.bg$)/i.test(component.id);
|
|
145
|
+
if(isBackdrop&&typeof component.parameters?.fill==='string'){
|
|
146
|
+
pushColor({
|
|
147
|
+
componentId:component.id,
|
|
148
|
+
sceneId:component.sceneId,
|
|
149
|
+
sceneLabel:sceneFriendlyLabel(scene),
|
|
150
|
+
moment,
|
|
151
|
+
key:'fill',
|
|
152
|
+
value:component.parameters.fill,
|
|
153
|
+
roleLabel:`Background color (${sceneFriendlyLabel(scene)})`,
|
|
154
|
+
isCta:false,
|
|
155
|
+
syncButtonStates:false,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Sort CTA texts & colors near the top of their sections for fast UA editing.
|
|
162
|
+
texts.sort((a,b)=>Number(b.isCta)-Number(a.isCta));
|
|
163
|
+
colors.sort((a,b)=>Number(b.isCta)-Number(a.isCta));
|
|
164
|
+
|
|
165
|
+
const timings=[];
|
|
166
|
+
for(const behavior of project.gameplay??[]){
|
|
167
|
+
if(behavior.kind==='timer'&&!behavior.parameters?.repeat&&Number(behavior.parameters?.seconds)>=3){
|
|
168
|
+
const isDeadline=/deadline|timeout|round|countdown/i.test(behavior.id);
|
|
169
|
+
const secs=Number(behavior.parameters.seconds);
|
|
170
|
+
timings.push({
|
|
171
|
+
behaviorId:behavior.id,
|
|
172
|
+
componentId:behavior.componentId,
|
|
173
|
+
roleLabel:isDeadline?'Round duration (seconds)':`${humanizeId(behavior.id)} (seconds)`,
|
|
174
|
+
seconds:secs,
|
|
175
|
+
min:Math.min(5,Math.max(1,Math.floor(secs))),
|
|
176
|
+
max:120,
|
|
177
|
+
step:1,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const audioBehaviorByComponent=new Map();
|
|
183
|
+
for(const behavior of project.gameplay??[]){
|
|
184
|
+
if(behavior.kind==='audio')audioBehaviorByComponent.set(behavior.componentId,behavior);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const mediaByAsset=new Map();
|
|
188
|
+
for(const component of project.components??[]){
|
|
189
|
+
for(const slot of component.assetSlots??[]){
|
|
190
|
+
const asset=assetsById.get(slot.assetId);
|
|
191
|
+
if(!asset)continue;
|
|
192
|
+
const kind=asset.mime.startsWith('image/')?'image':asset.mime.startsWith('audio/')?'audio':'model3d';
|
|
193
|
+
const audioBehavior=audioBehaviorByComponent.get(component.id);
|
|
194
|
+
const mapKey=`${asset.id}:${slot.slotId}`;
|
|
195
|
+
let entry=mediaByAsset.get(mapKey);
|
|
196
|
+
if(!entry){
|
|
197
|
+
const roleHint=audioBehavior?.parameters?.role;
|
|
198
|
+
const roleLabel=kind==='audio'&&roleHint
|
|
199
|
+
? `${roleHint[0].toUpperCase()+roleHint.slice(1)} sound`
|
|
200
|
+
: humanizeId(asset.id);
|
|
201
|
+
entry={
|
|
202
|
+
assetId:asset.id,
|
|
203
|
+
slotId:slot.slotId,
|
|
204
|
+
kind,
|
|
205
|
+
mime:asset.mime,
|
|
206
|
+
bytes:asset.bytes,
|
|
207
|
+
roleLabel,
|
|
208
|
+
componentIds:[],
|
|
209
|
+
behaviorId:audioBehavior?.id??null,
|
|
210
|
+
volume:audioBehavior?Number(audioBehavior.parameters?.volume??0.5):null,
|
|
211
|
+
};
|
|
212
|
+
mediaByAsset.set(mapKey,entry);
|
|
213
|
+
}
|
|
214
|
+
if(!entry.componentIds.includes(component.id))entry.componentIds.push(component.id);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
storeUrl:project.base?.storeUrl??'',
|
|
220
|
+
scenes,
|
|
221
|
+
texts,
|
|
222
|
+
colors,
|
|
223
|
+
timings,
|
|
224
|
+
media:[...mediaByAsset.values()],
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function buildQuickEditOperations(project,edits){
|
|
229
|
+
check(Array.isArray(edits)&&edits.length>=1&&edits.length<=32,'E_QUICK_EDIT_ARGUMENT');
|
|
230
|
+
const componentsById=new Map((project.components??[]).map(component=>[component.id,component]));
|
|
231
|
+
const behaviorsById=new Map((project.gameplay??[]).map(behavior=>[behavior.id,behavior]));
|
|
232
|
+
const assetsById=new Map((project.assets??[]).map(asset=>[asset.id,asset]));
|
|
233
|
+
const operations=[];
|
|
234
|
+
|
|
235
|
+
for(const edit of edits){
|
|
236
|
+
check(edit&&typeof edit==='object'&&!Array.isArray(edit),'E_QUICK_EDIT_ARGUMENT');
|
|
237
|
+
if(edit.kind==='text'){
|
|
238
|
+
const component=componentsById.get(edit.componentId);
|
|
239
|
+
check(component?.contract==='native.text.v1','E_QUICK_EDIT_TARGET');
|
|
240
|
+
const props=contracts['native.text.v1'].properties;
|
|
241
|
+
if(edit.text!==undefined){
|
|
242
|
+
check(typeof edit.text==='string'&&validateValue(props.text,edit.text),'E_REVIEW_VALUE');
|
|
243
|
+
operations.push({kind:'setParameter',id:component.id,key:'text',value:edit.text});
|
|
244
|
+
if(component.parameters?.fontFamily==='pixel'&&edit.autoFallbackFont!==false){
|
|
245
|
+
const measured=measurePixelText(edit.text,component.parameters);
|
|
246
|
+
if(measured.unsupportedChars.length>0){
|
|
247
|
+
operations.push({kind:'setParameter',id:component.id,key:'fontFamily',value:'sans-serif'});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if(edit.color!==undefined){
|
|
252
|
+
check(validateValue(props.color,edit.color),'E_REVIEW_VALUE');
|
|
253
|
+
operations.push({kind:'setParameter',id:component.id,key:'color',value:edit.color});
|
|
254
|
+
}
|
|
255
|
+
if(edit.fontSize!==undefined){
|
|
256
|
+
check(validateValue(props.fontSize,edit.fontSize),'E_REVIEW_VALUE');
|
|
257
|
+
operations.push({kind:'setParameter',id:component.id,key:'fontSize',value:edit.fontSize});
|
|
258
|
+
}
|
|
259
|
+
}else if(edit.kind==='color'){
|
|
260
|
+
const component=componentsById.get(edit.componentId);
|
|
261
|
+
check(component,'E_QUICK_EDIT_TARGET');
|
|
262
|
+
check(COLOR_KEYS.has(edit.key),'E_QUICK_EDIT_ARGUMENT');
|
|
263
|
+
const spec=contracts[component.contract]?.properties?.[edit.key];
|
|
264
|
+
check(spec&&validateValue(spec,edit.value),'E_REVIEW_VALUE');
|
|
265
|
+
operations.push({kind:'setParameter',id:component.id,key:edit.key,value:edit.value});
|
|
266
|
+
if(component.contract==='native.button.v1'&&edit.key==='fill'&&edit.syncButtonStates!==false&&/^#[0-9a-f]{6}$/i.test(edit.value)){
|
|
267
|
+
operations.push({kind:'setParameter',id:component.id,key:'hoverFill',value:shiftHexColor(edit.value,18)});
|
|
268
|
+
operations.push({kind:'setParameter',id:component.id,key:'pressedFill',value:shiftHexColor(edit.value,-20)});
|
|
269
|
+
}
|
|
270
|
+
}else if(edit.kind==='timing'){
|
|
271
|
+
const behavior=behaviorsById.get(edit.behaviorId);
|
|
272
|
+
check(behavior?.kind==='timer','E_QUICK_EDIT_TARGET');
|
|
273
|
+
check(validateValue(behaviors.timer.seconds,edit.seconds),'E_REVIEW_VALUE');
|
|
274
|
+
operations.push({
|
|
275
|
+
kind:'putBehavior',
|
|
276
|
+
behavior:{...globalThis.structuredClone(behavior),parameters:{...behavior.parameters,seconds:edit.seconds}},
|
|
277
|
+
});
|
|
278
|
+
}else if(edit.kind==='audioVolume'){
|
|
279
|
+
const behavior=behaviorsById.get(edit.behaviorId);
|
|
280
|
+
check(behavior?.kind==='audio','E_QUICK_EDIT_TARGET');
|
|
281
|
+
check(validateValue(behaviors.audio.volume,edit.volume),'E_REVIEW_VALUE');
|
|
282
|
+
operations.push({
|
|
283
|
+
kind:'putBehavior',
|
|
284
|
+
behavior:{...globalThis.structuredClone(behavior),parameters:{...behavior.parameters,volume:edit.volume}},
|
|
285
|
+
});
|
|
286
|
+
}else if(edit.kind==='replaceAsset'){
|
|
287
|
+
check(assetsById.has(edit.assetId),'E_QUICK_EDIT_TARGET');
|
|
288
|
+
const ids=Array.isArray(edit.componentIds)?edit.componentIds:[edit.componentId];
|
|
289
|
+
check(ids.length>=1&&ids.length<=64,'E_QUICK_EDIT_ARGUMENT');
|
|
290
|
+
const slotId=edit.slotId??'source';
|
|
291
|
+
check(typeof slotId==='string'&&slotId.length>0&&slotId.length<=64,'E_QUICK_EDIT_ARGUMENT');
|
|
292
|
+
for(const componentId of ids){
|
|
293
|
+
check(componentsById.has(componentId),'E_QUICK_EDIT_TARGET');
|
|
294
|
+
operations.push({kind:'replaceAsset',id:componentId,slotId,assetId:edit.assetId});
|
|
295
|
+
}
|
|
296
|
+
}else if(edit.kind==='storeUrl'){
|
|
297
|
+
check(typeof edit.url==='string'&&(edit.url===''||STORE_URL_RE.test(edit.url)),'E_NATIVE_STORE');
|
|
298
|
+
operations.push({kind:'setStore',url:edit.url});
|
|
299
|
+
}else{
|
|
300
|
+
check(false,'E_QUICK_EDIT_ARGUMENT');
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
check(operations.length>0,'E_REVIEW_NO_CHANGE');
|
|
304
|
+
return operations;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function applyQuickEditInMemory(project,edits){
|
|
308
|
+
const operations=buildQuickEditOperations(project,edits);
|
|
309
|
+
const next=globalThis.structuredClone(project);
|
|
310
|
+
const components=new Map((next.components??[]).map(c=>[c.id,c]));
|
|
311
|
+
const behaviorsMap=new Map((next.gameplay??[]).map(b=>[b.id,b]));
|
|
312
|
+
for(const op of operations){
|
|
313
|
+
if(op.kind==='setParameter'){
|
|
314
|
+
components.get(op.id).parameters[op.key]=globalThis.structuredClone(op.value);
|
|
315
|
+
}else if(op.kind==='putBehavior'){
|
|
316
|
+
const index=next.gameplay.findIndex(b=>b.id===op.behavior.id);
|
|
317
|
+
if(index>=0)next.gameplay[index]=globalThis.structuredClone(op.behavior);
|
|
318
|
+
else next.gameplay.push(globalThis.structuredClone(op.behavior));
|
|
319
|
+
behaviorsMap.set(op.behavior.id,op.behavior);
|
|
320
|
+
}else if(op.kind==='replaceAsset'){
|
|
321
|
+
const c=components.get(op.id);
|
|
322
|
+
c.assetSlots=[...(c.assetSlots??[]).filter(slot=>slot.slotId!==op.slotId),{slotId:op.slotId,assetId:op.assetId}];
|
|
323
|
+
}else if(op.kind==='setStore'){
|
|
324
|
+
next.base.storeUrl=op.url;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return {project:validateDocument(next),operations};
|
|
328
|
+
}
|