@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.
Files changed (107) hide show
  1. package/README.md +5 -6
  2. package/bin/tora.mjs +255 -29
  3. package/crates/packer/trusted/native-3d-meta.json +3 -3
  4. package/crates/packer/trusted/native-3d.js +180 -180
  5. package/crates/packer/trusted/native-meta.json +3 -3
  6. package/crates/packer/trusted/native.js +5 -5
  7. package/crates/packer/trusted/release-manifest.json +17 -17
  8. package/crates/packer/trusted/review-runtime-meta.json +3 -3
  9. package/crates/packer/trusted/review-runtime.js +182 -182
  10. package/docs/MIGRATION_0_3.md +39 -0
  11. package/docs/NATIVE_AGENT_TOOLS.md +12 -363
  12. package/docs/TORA_AGENT_SETUP.md +24 -106
  13. package/docs/TORA_CREATION_API.md +63 -365
  14. package/docs/reference/CORE_AUTHORING.md +8 -2
  15. package/docs/reference/PLAYABLE_STARTERS.md +1 -1
  16. package/docs/reference/packs/3d.md +2 -0
  17. package/package.json +6 -6
  18. package/packages/creative-project/project-v21.schema.json +108 -1
  19. package/scripts/lean/editor/entry.js +11 -6
  20. package/scripts/lean/editor/project-launcher.js +116 -0
  21. package/scripts/lean/editor/quick-edit-panel.js +479 -0
  22. package/scripts/lean/editor/review-editor.css +246 -68
  23. package/scripts/lean/editor/review-editor.js +1731 -1099
  24. package/scripts/lean/editor-state.mjs +6 -0
  25. package/scripts/lean/editor.mjs +6 -3
  26. package/scripts/lean/matrix.mjs +5 -0
  27. package/scripts/lean/native/agent-tools.mjs +35 -58
  28. package/scripts/lean/native/api.mjs +148 -134
  29. package/scripts/lean/native/audio-assets.mjs +30 -0
  30. package/scripts/lean/native/browser-pool.mjs +34 -0
  31. package/scripts/lean/native/build-cache.mjs +36 -5
  32. package/scripts/lean/native/contracts.mjs +8 -6
  33. package/scripts/lean/native/creative-qa.mjs +66 -12
  34. package/scripts/lean/native/demos.mjs +11 -20
  35. package/scripts/lean/native/document.mjs +14 -2
  36. package/scripts/lean/native/local-bundle.mjs +4 -2
  37. package/scripts/lean/native/mcp-server.mjs +16 -35
  38. package/scripts/lean/native/modules/harvest-restore.mjs +3 -284
  39. package/scripts/lean/native/modules/sort-puzzle.mjs +51 -0
  40. package/scripts/lean/native/modules/star-salvage.mjs +3 -368
  41. package/scripts/lean/native/project-bundle.mjs +3 -2
  42. package/scripts/lean/native/project-index.mjs +0 -2
  43. package/scripts/lean/native/qa-adapters.mjs +10 -0
  44. package/scripts/lean/native/quick-edit.mjs +328 -0
  45. package/scripts/lean/native/review.mjs +203 -572
  46. package/scripts/lean/native/schema-vocabulary.mjs +10 -0
  47. package/scripts/lean/native/schema.mjs +1 -1
  48. package/scripts/lean/native/scope.mjs +45 -0
  49. package/scripts/lean/native/service.mjs +242 -70
  50. package/scripts/lean/native/starters.mjs +135 -8
  51. package/scripts/lean/native/variant-adapters.mjs +8 -0
  52. package/scripts/lean/native/variants-core.mjs +186 -0
  53. package/scripts/lean/native/variants.mjs +63 -0
  54. package/scripts/lean/native/win-cues.mjs +1 -1
  55. package/skills/tora-playables/SKILL.md +1 -1
  56. package/scripts/lean/editor/review-intake.js +0 -837
  57. package/scripts/lean/model-client.mjs +0 -119
  58. package/scripts/lean/native/author-expansion-proofs.mjs +0 -143
  59. package/scripts/lean/native/author-fps.mjs +0 -545
  60. package/scripts/lean/native/author-games.mjs +0 -160
  61. package/scripts/lean/native/author-harvest.mjs +0 -74
  62. package/scripts/lean/native/author-primitive-proofs.mjs +0 -875
  63. package/scripts/lean/native/author-salvage.mjs +0 -71
  64. package/scripts/lean/native/chat-compose.mjs +0 -287
  65. package/scripts/lean/native/check-harvest-outcome-audio.mjs +0 -190
  66. package/scripts/lean/native/check-salvage.mjs +0 -200
  67. package/scripts/lean/native/compatibility.mjs +0 -34
  68. package/scripts/lean/native/concept.mjs +0 -633
  69. package/scripts/lean/native/draw-stroke.mjs +0 -26
  70. package/scripts/lean/native/erase-mask.mjs +0 -18
  71. package/scripts/lean/native/glb-loader.mjs +0 -468
  72. package/scripts/lean/native/harvest-recipe.mjs +0 -21
  73. package/scripts/lean/native/instance-steering.mjs +0 -24
  74. package/scripts/lean/native/intake-creator-agent.mjs +0 -98
  75. package/scripts/lean/native/intake-creator-tools.mjs +0 -218
  76. package/scripts/lean/native/interaction-gestures.mjs +0 -45
  77. package/scripts/lean/native/match-board.mjs +0 -138
  78. package/scripts/lean/native/modules/index.mjs +0 -54
  79. package/scripts/lean/native/modules/tap-collect.mjs +0 -54
  80. package/scripts/lean/native/path-network.mjs +0 -132
  81. package/scripts/lean/native/physics-2d.mjs +0 -154
  82. package/scripts/lean/native/physics-3d.mjs +0 -259
  83. package/scripts/lean/native/prepare-audio-collections.mjs +0 -112
  84. package/scripts/lean/native/prepare-fps-assets.mjs +0 -330
  85. package/scripts/lean/native/prepare-game-audio.mjs +0 -372
  86. package/scripts/lean/native/prepare-golf-3d-assets.py +0 -177
  87. package/scripts/lean/native/prepare-golf-assets.py +0 -211
  88. package/scripts/lean/native/prepare-harvest-audio.mjs +0 -83
  89. package/scripts/lean/native/prepare-harvest-images.mjs +0 -31
  90. package/scripts/lean/native/prepare-primitive-images.py +0 -25
  91. package/scripts/lean/native/prepare-space-salvage-images.mjs +0 -89
  92. package/scripts/lean/native/prepare-traffic-assets.py +0 -329
  93. package/scripts/lean/native/presentation.mjs +0 -335
  94. package/scripts/lean/native/review-agent-tools.mjs +0 -561
  95. package/scripts/lean/native/review-connection.mjs +0 -303
  96. package/scripts/lean/native/review-fields.mjs +0 -24
  97. package/scripts/lean/native/review-intake.mjs +0 -385
  98. package/scripts/lean/native/review-intents.mjs +0 -217
  99. package/scripts/lean/native/review-provider.mjs +0 -580
  100. package/scripts/lean/native/review-receipts.mjs +0 -76
  101. package/scripts/lean/native/review-resolver.mjs +0 -429
  102. package/scripts/lean/native/review-targets.mjs +0 -35
  103. package/scripts/lean/native/runtime.mjs +0 -1809
  104. package/scripts/lean/native/salvage-recipe.mjs +0 -20
  105. package/scripts/lean/native/stage-3d.mjs +0 -1121
  106. package/scripts/lean/native/verify.mjs +0 -4
  107. package/scripts/lean/scene-document.mjs +0 -48
@@ -1,633 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { Buffer } from "node:buffer";
3
- import { createRequire } from "node:module";
4
- import { URL } from "node:url";
5
- import { canonical } from "../../../packages/creative-project/src/canonical.mjs";
6
- import { parseAuthoringJson } from "../../../packages/creative-project/src/strict-json.mjs";
7
- import { isStoreDestination } from "../../../packages/adapters/src/index.mjs";
8
- import {ASSET_PROVENANCE_SCHEMA,validateAssetPolicy} from "./asset-policy.mjs";
9
- import {harvestRecipe,harvestRecipeId,harvestRecipeVariants} from "./harvest-recipe.mjs";
10
- import {salvageRecipeId,salvageRecipeVariants} from "./salvage-recipe.mjs";
11
- import {starSalvageModule} from "./modules/star-salvage.mjs";
12
- import {isAudioMime} from "./media-validate.mjs";
13
- const requireModule = createRequire(new URL("../../../packages/creative-project/package.json", import.meta.url));
14
- const { Ajv2020 } = requireModule("ajv/dist/2020.js");
15
- const text = (max = 240) => ({ type: "string", minLength: 1, maxLength: max, pattern: "^[^\\u0000-\\u001f]*$" });
16
- const id = { type: "string", maxLength: 64, pattern: "^[a-z][a-z0-9-]*$" };
17
- const color = { type: "string", pattern: "^#[0-9a-fA-F]{6}$" };
18
- const object = (properties, required = Object.keys(properties)) => ({ type: "object", additionalProperties: false, properties, required });
19
- const phases = ["first-seconds", "agency", "escalation", "payoff", "cta"];
20
- const artwork = object({ id, mime: { enum: ["image/png", "image/jpeg"] }, data: { type: "string", minLength: 4, maxLength: 4000000 }, rights: text(2048), provenance:ASSET_PROVENANCE_SCHEMA },["id","mime","data","rights"]);
21
- const audioAsset = object({ id, mime: { enum: ["audio/wav", "audio/mpeg"] }, data: { type: "string", minLength: 4, maxLength: 4000000 }, rights: text(2048),provenance:ASSET_PROVENANCE_SCHEMA },["id","mime","data","rights"]);
22
- const restoration = object({
23
- binding: object({ event: { const: "validMatch" }, choice: { const: "repairArea" }, persistent: { const: true } }),
24
- areas: { type: "array", minItems: 2, maxItems: 3, items: object({ id, label: text(80), before: artwork, after: artwork }) },
25
- tiles: object({ sun: artwork, leaf: artwork, drop: artwork }),
26
- audio: object({ ambient: audioAsset, impact: audioAsset, payoff: audioAsset, reject: audioAsset, complete: audioAsset }, ["ambient", "impact", "payoff", "reject"])
27
- }, ["binding", "areas"]);
28
- const licensedAsset = object({
29
- id,
30
- mime: {enum:["image/png","image/jpeg","audio/wav","audio/mpeg"]},
31
- data: {type:"string",minLength:4,maxLength:4000000},
32
- rights:text(2048),
33
- provenance:{anyOf:[ASSET_PROVENANCE_SCHEMA,object({
34
- origin:{const:"studio-original"},
35
- studio:text(120),
36
- sourceFile:text(180),
37
- sourceHash:{type:"string",pattern:"^sha256:[a-f0-9]{64}$"},
38
- intakeId:text(36),
39
- styleFamily:text(80)
40
- })]}
41
- });
42
- const harvest = object({
43
- assets:{type:"array",minItems:5,maxItems:48,items:licensedAsset},
44
- tiles:object({carrot:id,corn:id,tomato:id,eggplant:id,pumpkin:id}),
45
- world:{type:"array",minItems:1,maxItems:64,items:object({
46
- id,assetId:id,x:{type:"number",minimum:-400,maximum:700},y:{type:"number",minimum:-400,maximum:700},
47
- width:{type:"number",minimum:1,maximum:700},height:{type:"number",minimum:1,maximum:700},
48
- unlockAt:{type:"integer",minimum:0,maximum:3},hideAt:{type:"integer",minimum:1,maximum:3}
49
- },["id","assetId","x","y","width","height","unlockAt"])},
50
- audio:object({ambient:id,match:id,repair:id,complete:id,loss:id,reject:id},["ambient","match","complete","reject"]),
51
- seed:{type:"integer",minimum:1,maximum:2147483647},
52
- rewardRecipe:object({id:{const:harvestRecipeId},variant:{enum:harvestRecipeVariants}}),
53
- firstHintSeconds:{type:"number",minimum:0.5,maximum:6}
54
- }, ["assets","tiles","world","audio","seed"]);
55
- const salvage = object({
56
- assets:{type:"array",minItems:4,maxItems:48,items:licensedAsset},
57
- sprites:object({ship:id,core:id,hazard:id,backdrop:id}),
58
- coreVariants:{type:"array",minItems:1,maxItems:4,uniqueItems:true,items:id},
59
- hazardVariants:{type:"array",minItems:1,maxItems:4,uniqueItems:true,items:id},
60
- bay:{type:"array",minItems:4,maxItems:4,items:object({id,assetId:id,unlockAt:{type:"integer",minimum:0,maximum:3}})},
61
- audio:object({ambient:id,catch:id,repair:id,complete:id,loss:id,reject:id},["ambient","catch","complete","reject"]),
62
- seed:{type:"integer",minimum:1,maximum:2147483647},
63
- rewardRecipe:object({id:{const:salvageRecipeId},variant:{enum:salvageRecipeVariants}}),
64
- firstHintSeconds:{type:"number",minimum:0.5,maximum:6}
65
- },["assets","sprites","bay","audio","seed"]);
66
- const strategicSources = ["product.gameplayTruth", "product.differentiator", "audience.motivation", "experience.fantasy", "experience.interactionRationale", "hypothesis.statement", "hypothesis.risk", "experience.storeContinuity"];
67
- const requirements = { type: "array", minItems: 8, maxItems: 8, items: object({ source: { enum: strategicSources }, claim: text(400), effect: { enum: ["match-rule", "catch-rule", "world-transformation", "repair-choice", "recovery", "continuity"] } }) };
68
- const CREATIVE_CONCEPT_SCHEMA = {
69
- $schema: "https://json-schema.org/draft/2020-12/schema",
70
- title: "Tora creative concept 1",
71
- ...object({
72
- format: { enum: ["tora-creative-concept-1", "tora-creative-concept-2"] },
73
- id,
74
- product: object({ name: text(80), storeUrl: text(512), gameplayTruth: text(400), differentiator: text(300) }),
75
- audience: object({ segment: text(200), motivation: text(300) }),
76
- experience: object({
77
- fantasy: text(240),
78
- mechanic: { enum: ["tap-collect", "drag-catch", "match-restore", "harvest-restore", "star-salvage"] },
79
- interactionRationale: text(400),
80
- instruction: text(120),
81
- goal: { type: "integer", minimum: 1, maximum: 12 },
82
- arc: { type: "array", minItems: 5, maxItems: 5, items: object({ phase: { enum: phases }, seconds: { type: "number", minimum: 1, maximum: 15 }, description: text(240) }) },
83
- ctaLabel: text(60),
84
- storeContinuity: text(300)
85
- }),
86
- hypothesis: object({ statement: text(400), risk: text(400) }),
87
- presentation: object({ title: text(60), subtitle: text(120), rewardCopy: text(120), palette: object({ background: color, primary: color, accent: color, text: color }) }),
88
- restoration,
89
- harvest,
90
- salvage,
91
- requirements
92
- }, ["format", "id", "product", "audience", "experience", "hypothesis", "presentation"])
93
- };
94
- const valid = new Ajv2020({ strict: true, allErrors: false }).compile(CREATIVE_CONCEPT_SCHEMA);
95
- function check(value, code) {
96
- if (!value) throw Error(code);
97
- }
98
- function freeze(value) {
99
- if (value && typeof value === "object") {
100
- Object.values(value).forEach(freeze);
101
- Object.freeze(value);
102
- }
103
- return value;
104
- }
105
- function validateCreativeConcept(input) {
106
- let value = input;
107
- if (typeof input !== "string") {
108
- let encoded;
109
- try {
110
- encoded = JSON.stringify(input);
111
- } catch {
112
- throw Error("E_CONCEPT_JSON");
113
- }
114
- check(typeof encoded === "string", "E_CONCEPT_JSON");
115
- check(Buffer.byteLength(encoded, "utf8") <= 4194304, "E_CONCEPT_SIZE");
116
- }
117
- if (typeof input === "string") {
118
- check(Buffer.byteLength(input, "utf8") <= 4194304, "E_CONCEPT_SIZE");
119
- try {
120
- value = parseAuthoringJson(input);
121
- } catch {
122
- throw Error("E_CONCEPT_JSON");
123
- }
124
- }
125
- if (value?.experience?.mechanic === "match-restore") {
126
- check(value.restoration && Array.isArray(value.restoration.areas), "E_CONCEPT_RESTORATION_REQUIRED");
127
- check(value.restoration.areas.length >= 2 && value.restoration.areas.every((area) => area?.before?.data && area?.after?.data), "E_CONCEPT_RESTORATION_ARTWORK");
128
- check(value.restoration.binding?.event === "validMatch" && value.restoration.binding?.choice === "repairArea" && value.restoration.binding?.persistent === true, "E_CONCEPT_RESTORATION_BINDING");
129
- }
130
- check(valid(value), "E_CONCEPT_SCHEMA");
131
- if(value.experience.mechanic === "harvest-restore")check(value.format === "tora-creative-concept-2" && value.harvest,"E_CONCEPT_HARVEST_REQUIRED");
132
- if(value.experience.mechanic === "star-salvage")check(value.format === "tora-creative-concept-2" && value.salvage,"E_CONCEPT_SALVAGE_REQUIRED");
133
- if (value.format === "tora-creative-concept-2") {
134
- check(["match-restore","harvest-restore","star-salvage"].includes(value.experience.mechanic), "E_CONCEPT_MODULE_REQUIRED");
135
- const harvesting = value.experience.mechanic === "harvest-restore", salvaging = value.experience.mechanic === "star-salvage", moduleGoal = harvesting || salvaging;
136
- if(harvesting)check(value.harvest,"E_CONCEPT_HARVEST_REQUIRED");
137
- else if(salvaging)check(value.salvage,"E_CONCEPT_SALVAGE_REQUIRED");
138
- else check(value.restoration.tiles, "E_CONCEPT_TILE_ARTWORK");
139
- const rule = salvaging ? "catch-rule" : "match-rule";
140
- const effects = [rule, "world-transformation", moduleGoal?"world-transformation":"repair-choice", "world-transformation", rule, "world-transformation", "recovery", "continuity"];
141
- check(value.requirements?.length === strategicSources.length && strategicSources.every((source, index) => value.requirements.some((requirement) => requirement.source === source && requirement.effect === effects[index])), "E_CONCEPT_REQUIREMENT_COVERAGE");
142
- check(value.requirements.every((requirement) => requirement.claim === requirement.source.split(".").reduce((record, key) => record[key], value)), "E_CONCEPT_REQUIREMENT_STALE");
143
- if(moduleGoal)check(value.experience.goal===3,salvaging?"E_CONCEPT_SALVAGE_GOAL":"E_CONCEPT_HARVEST_GOAL");
144
- else check(value.experience.goal === 2 && value.restoration.areas.length === 2, "E_CONCEPT_REPAIR_GOAL");
145
- }
146
- check(isStoreDestination(value.product.storeUrl), "E_CONCEPT_STORE");
147
- check(value.experience.arc.every((step, index) => step.phase === phases[index]), "E_CONCEPT_ARC");
148
- const seconds = value.experience.arc.reduce((sum, step) => sum + step.seconds, 0);
149
- check(seconds >= 15 && seconds <= 30, "E_CONCEPT_DURATION");
150
- return freeze(globalThis.structuredClone(value));
151
- }
152
- function conceptHash(input) {
153
- const concept = validateCreativeConcept(input);
154
- return "sha256:" + createHash("sha256").update("tora-concept/1\n" + canonical(concept)).digest("hex");
155
- }
156
- function builder(concept) {
157
- const operations = [];
158
- const add = (recordId, kind, x, y, width, height, parameters = {}, extra = {}) => operations.push({ kind: "createComponent", component: { id: recordId, label: recordId, contract: "native." + kind + ".v1", transform: [1, 0, 0, 1, x, y], parameters: { width, height, ...parameters }, ...extra } });
159
- const behavior = (recordId, componentId, kind, parameters) => operations.push({ kind: "putBehavior", behavior: { id: recordId, componentId, kind, parameters } });
160
- const binding = (recordId, event, actions, condition) => operations.push({ kind: "putBinding", binding: { id: recordId, event, actions, ...condition ? { condition } : {} } });
161
- const palette = concept.presentation.palette;
162
- operations.push({ kind: "putVariable", variable: { id: "score", label: "Score", type: "number", initial: 0 } });
163
- operations.push({ kind: "createScene", scene: { id: "scene.success", label: "Success", role: "end-card" } });
164
- add("background", "rectangle", 0, 0, 390, 700, { fill: palette.background, radius: 0 });
165
- add("title", "text", 20, 64, 350, 60, { text: concept.presentation.title, fontSize: 30, color: palette.text });
166
- add("subtitle", "text", 20, 130, 350, 50, { text: concept.presentation.subtitle, fontSize: 16, color: palette.text });
167
- add("instruction", "text", 20, 180, 350, 50, { text: concept.experience.instruction, fontSize: 16, color: palette.text });
168
- add("score.label", "text", 45, 590, 300, 50, { text: "{{score}} / " + concept.experience.goal, fontSize: 24, color: palette.accent });
169
- behavior("feedback.sound", "target", "audio", { loop: false, volume: 0.09, frequency: 760, seconds: 0.16 });
170
- behavior("feedback.particles", "target", "emitter", { count: 24, color: palette.accent, speed: 140 });
171
- behavior("feedback.pulse", "target", "animation", { property: "scale", from: 0.9, to: 1, seconds: 0.2, loop: false });
172
- add("success.background", "rectangle", 0, 0, 390, 700, { fill: palette.background, radius: 0 }, { sceneId: "scene.success" });
173
- add("success.stars", "path", 132, 92, 126, 36, { fill: palette.accent, stroke: palette.primary, strokeWidth: 2, commands: [["M",20,6],["L",24,15],["L",34,16],["L",27,22],["L",29,32],["L",20,27],["L",11,32],["L",13,22],["L",6,16],["L",16,15],["Z"],["M",63,2],["L",68,12],["L",79,13],["L",71,20],["L",73,31],["L",63,26],["L",53,31],["L",55,20],["L",47,13],["L",58,12],["Z"],["M",106,6],["L",110,15],["L",120,16],["L",113,22],["L",115,32],["L",106,27],["L",97,32],["L",99,22],["L",92,16],["L",102,15],["Z"]] }, { sceneId: "scene.success" });
174
- add("success.title", "text", 25, 160, 340, 100, { text: concept.presentation.rewardCopy, fontSize: 30, color: palette.text }, { sceneId: "scene.success" });
175
- add("success.score", "text", 45, 285, 300, 50, { text: "{{score}} / " + concept.experience.goal, fontSize: 24, color: palette.accent }, { sceneId: "scene.success" });
176
- add("success.cta", "button", 45, 410, 300, 82, { presentation: "shiny-cta", fill: palette.accent, stroke: palette.background, strokeWidth: 3, radius: 16 }, { sceneId: "scene.success" });
177
- add("success.cta.label", "text", 0, 0, 300, 82, { text: concept.experience.ctaLabel, fontSize: 20, color: palette.background }, { sceneId: "scene.success", parentId: "success.cta" });
178
- behavior("success.stars.bob", "success.stars", "animation", { property: "y", from: 89, to: 95, seconds: 1.0, loop: true, easing: "ease-in-out" });
179
- behavior("success.cta.pulse", "success.cta", "animation", { property: "y", from: 407, to: 413, seconds: 0.95, loop: true, easing: "ease-in-out" });
180
- behavior("success.confetti", "success.background", "emitter", { shape: "confetti", coverage: "screen", count: 56, color: palette.accent, color2: "#4ecdc4", color3: "#ff6b6b", speed: 120, lifetime: 2.6, gravity: 70 });
181
- binding("success.enter", { kind: "sceneEnter", sceneId: "scene.success" }, [{ kind: "emit", behaviorId: "success.confetti" }, { kind: "animate", behaviorId: "success.stars.bob" }, { kind: "animate", behaviorId: "success.cta.pulse" }]);
182
- binding("success.store", { kind: "click", componentId: "success.cta" }, [{ kind: "store" }]);
183
- binding("goal", { kind: "variableChange", variableId: "score" }, [{ kind: "changeScene", sceneId: "scene.success" }], { variableId: "score", op: "gte", value: concept.experience.goal });
184
- operations.push({ kind: "setStore", url: concept.product.storeUrl });
185
- return { operations, add, behavior, binding, palette };
186
- }
187
- function tapCollect(concept) {
188
- const b = builder(concept);
189
- b.add("target", "button", 115, 285, 160, 160, { fill: b.palette.primary, radius: 80, pressedFill: b.palette.accent });
190
- b.add("target.label", "text", 0, 0, 160, 160, { text: "+", fontSize: 72, color: b.palette.text }, { parentId: "target" });
191
- b.binding("target.feedback", { kind: "click", componentId: "target" }, [{ kind: "add", variableId: "score", value: 1 }, { kind: "emit", behaviorId: "feedback.particles" }, { kind: "playAudio", behaviorId: "feedback.sound" }, { kind: "animate", behaviorId: "feedback.pulse" }]);
192
- return b.operations;
193
- }
194
- function dragCatch(concept) {
195
- const b = builder(concept);
196
- b.add("controller", "group", 0, 0, 0, 0);
197
- b.add("target", "rectangle", 130, 510, 130, 70, { fill: b.palette.primary, radius: 18 });
198
- b.behavior("target.drag", "target", "drag", { axis: "x" });
199
- b.behavior("target.collider", "target", "collider", { shape: "box" });
200
- b.add("falling", "ellipse", 0, 0, 48, 48, { fill: b.palette.accent }, { prototype: true });
201
- b.behavior("falling.motion", "falling", "motion", { vx: 0, vy: 180, gravity: 20 });
202
- b.behavior("falling.collider", "falling", "collider", { shape: "circle" });
203
- b.behavior("spawn.timer", "controller", "timer", { seconds: 0.8, repeat: true });
204
- b.binding("spawn", { kind: "timer", behaviorId: "spawn.timer" }, [{ kind: "spawn", prototypeId: "falling", x: 40, y: -50 }]);
205
- b.binding("catch", { kind: "contactBegin", componentId: "falling", otherId: "target" }, [{ kind: "add", variableId: "score", value: 1 }, { kind: "despawn" }, { kind: "emit", behaviorId: "feedback.particles" }, { kind: "playAudio", behaviorId: "feedback.sound" }, { kind: "animate", behaviorId: "feedback.pulse" }]);
206
- return b.operations;
207
- }
208
- function matchRestore(concept) {
209
- if(concept.format === "tora-creative-concept-2")check(concept.restoration.audio?.ambient&&concept.restoration.audio?.impact&&concept.restoration.audio?.payoff&&concept.restoration.audio?.reject&&concept.restoration.audio?.complete,"E_CONCEPT_AUDIO_REQUIRED");
210
- const operations = [], assets = [], assetPolicy = [], palette = concept.presentation.palette;
211
- const arc = Object.fromEntries(concept.experience.arc.map((step) => [step.phase, step]));
212
- const add = (recordId, kind, x, y, width, height, parameters = {}, extra = {}) => operations.push({ kind: "createComponent", component: { id: recordId, label: recordId, contract: "native." + kind + ".v1", transform: [1, 0, 0, 1, x, y], parameters: { width, height, ...parameters }, ...extra } });
213
- const behavior = (recordId, componentId, kind, parameters) => operations.push({ kind: "putBehavior", behavior: { id: recordId, componentId, kind, parameters } });
214
- const binding = (recordId, event, actions, condition) => operations.push({ kind: "putBinding", binding: { id: recordId, event, actions, ...condition ? { condition } : {} } });
215
- const variable = (recordId, type, initial) => operations.push({ kind: "putVariable", variable: { id: recordId, label: recordId, type, initial } });
216
- const set = (variableId, value) => ({ kind: "set", variableId, value });
217
- const property = (componentId, key, value) => ({ kind: "setComponent", componentId, key, value });
218
- const is = (variableId, value) => ({ variableId, op: "eq", value });
219
- const phase = (value) => set("phase", value);
220
- const asset = (input) => {
221
- let receipt;
222
- if(concept.format === "tora-creative-concept-2") {
223
- const styleFamily=concept.restoration.areas[0].before.provenance?.styleFamily;
224
- receipt=validateAssetPolicy(input,{role:isAudioMime(input.mime)?'audio':'visual',styleFamily});
225
- assetPolicy.push({id:input.id,...receipt});
226
- }
227
- check(/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(input.data), "E_CONCEPT_RESTORATION_ARTWORK");
228
- const bytes = Buffer.from(input.data, "base64");
229
- check(bytes.length > 0 && bytes.length <= 7e5, "E_CONCEPT_RESTORATION_ARTWORK");
230
- const rights=input.rights+(receipt?.attribution?"\n"+receipt.attribution:"");
231
- check(rights.length<=2048,"E_CONCEPT_ASSET_RIGHTS");
232
- const prior = assets.find((existing) => existing.id === input.id);
233
- if (prior) {
234
- check(prior.data === input.data && prior.mime === input.mime && prior.rights === rights, "E_CONCEPT_RESTORATION_ARTWORK");
235
- return;
236
- }
237
- assets.push({id:input.id,mime:input.mime,data:input.data,rights});
238
- operations.push({ kind: "registerAsset", asset: { id: input.id, hash: "sha256:" + createHash("sha256").update(bytes).digest("hex"), mime: input.mime, bytes: bytes.length, rights, provenance: receipt ? JSON.stringify(receipt) : "Concept artwork; decoded media verified by the native composition entry point." } });
239
- };
240
- const areaCount = concept.restoration.areas.length;
241
- const areaWidth = (366 - (areaCount - 1) * 12) / areaCount;
242
- check(new Set(concept.restoration.areas.map((area) => area.id)).size === areaCount, "E_CONCEPT_RESTORATION_ARTWORK");
243
- for (const area of concept.restoration.areas) {
244
- check(area.before.data !== area.after.data, "E_CONCEPT_RESTORATION_ARTWORK");
245
- asset(area.before);
246
- asset(area.after);
247
- variable("repaired." + area.id, "boolean", false);
248
- }
249
- for (const art of [...Object.values(concept.restoration.tiles ?? {}), ...Object.values(concept.restoration.audio ?? {})]) asset(art);
250
- variable("phase", "string", "first-seconds");
251
- variable("repairs", "number", 0);
252
- variable("message", "string", concept.experience.instruction);
253
- add("background", "rectangle", 0, 0, 700, 700, { fill: palette.background });
254
- const responsiveLayouts = {
255
- "world.layout": { x: 0, y: -15, scaleX: 1, scaleY: 1 },
256
- "puzzle.layout": { x: 350, y: -330, scaleX: 1, scaleY: 1 },
257
- "instruction.layout": { x: 344, y: -345, scaleX: .8, scaleY: 1 },
258
- "cta.layout": { x: 385, y: -260, scaleX: .8, scaleY: .9 }
259
- };
260
- for (const [componentId, parameters] of Object.entries(responsiveLayouts)) {
261
- add(componentId, "group", 0, 0, 0, 0);
262
- behavior(componentId + ".landscape", componentId, "responsive-layout", parameters);
263
- }
264
- add("title", "text", 56, 20, 278, 45, { text: concept.presentation.title, fontSize: 29, color: palette.text });
265
- add("subtitle", "text", 15, 65, 360, 35, { text: concept.presentation.subtitle, fontSize: 16, color: palette.accent });
266
- for (const [index, area] of concept.restoration.areas.entries()) {
267
- add("world." + area.id, "image", 12 + index * (areaWidth + 12), 110, areaWidth, 245, { fit: "cover" }, { parentId: "world.layout", order: 0, assetSlots: [{ slotId: "source", assetId: area.before.id }] });
268
- add("world.label.background." + area.id, "rectangle", 12 + index * (areaWidth + 12), 327, areaWidth, 28, { fill: "#123a32dd" }, { parentId: "world.layout", order: 1 });
269
- add("world.label." + area.id, "text", 12 + index * (areaWidth + 12), 327, areaWidth, 35, { text: area.label, fontSize: 17, color: palette.text }, { parentId: "world.layout", order: 2 });
270
- }
271
- add("instruction", "text", 15, 365, 360, 44, { text: "{{message}}", fontSize: 17, color: palette.text }, { parentId: "instruction.layout" });
272
- const boardIds = ["board.controller", "board.escalation"];
273
- const fills = { sun: "#f6c453", leaf: "#5ba879", drop: "#62a8d8" };
274
- const symbols = { sun: "\u25CF", leaf: "\u25B2", drop: "\u25A0" };
275
- const cells = [["sun", "leaf", "sun"], ["leaf", "sun", "drop"], ["drop", "drop", "leaf"]];
276
- for (const [stage, boardId] of boardIds.entries()) {
277
- add(boardId, "group", 0, 0, 0, 0, { visible: stage === 0 }, { parentId: "puzzle.layout" });
278
- for (let row = 0; row < 3; row++) for (let column = 0; column < 3; column++) {
279
- const recordId = stage === 0 ? `tile.${row}.${column}` : `tile.second.${row}.${column}`;
280
- const group = stage === 0 ? cells[row][column] : cells[2 - row][2 - column];
281
- add(recordId, "button", 70 + column * 86, 420 + row * 86, 78, 78, { fill: fills[group], radius: 16, stroke: palette.text, strokeWidth: 1 }, { parentId: boardId });
282
- const art = concept.restoration.tiles?.[group];
283
- if (art) add(recordId + ".art", "image", 5, 5, 68, 68, { fit: "contain" }, { parentId: recordId, assetSlots: [{ slotId: "source", assetId: art.id }] });
284
- else add(recordId + ".symbol", "text", 0, 0, 78, 78, { text: symbols[group], fontSize: 38, color: palette.background }, { parentId: recordId });
285
- behavior(recordId + ".match", recordId, "match-tile", { row, column, group });
286
- }
287
- }
288
- add("match.lock", "rectangle", 60, 410, 270, 270, { fill: "#ffffff00", visible: false }, { parentId: "puzzle.layout" });
289
- const hintIds = ["tile.0.1", "tile.1.1", "tile.second.1.1", "tile.second.2.1"];
290
- for (const recordId of hintIds) behavior("hint." + recordId, recordId, "animation", { property: "opacity", from: 0.45, to: 1, seconds: 0.65, loop: true, easing: "ease-in-out" });
291
- const stopHints = hintIds.map((recordId) => ({ kind: "stopAnimation", behaviorId: "hint." + recordId }));
292
- const hideBoards = boardIds.map((recordId) => property(recordId, "visible", false));
293
- add("director", "group", 0, 0, 0, 0);
294
- const audioTarget = (kind) => {
295
- const art = concept.restoration.audio?.[kind];
296
- if (!art) return "director";
297
- const recordId = "sound." + kind;
298
- add(recordId, "group", 0, 0, 0, 0, {}, { assetSlots: [{ slotId: "source", assetId: art.id }] });
299
- return recordId;
300
- };
301
- behavior("feedback.contact", audioTarget("impact"), "audio", { loop: false, volume: 0.2, frequency: 520, seconds: 0.12, bus: "sfx", role: "match" });
302
- behavior("feedback.reward", audioTarget("payoff"), "audio", { loop: false, volume: 0.28, frequency: 880, seconds: 0.4, bus: "sfx", role: "reward" });
303
- behavior("feedback.reject", audioTarget("reject"), "audio", { loop: false, volume: 0.12, frequency: 220, seconds: 0.09, bus: "sfx", role: "reject" });
304
- if (concept.restoration.audio) {
305
- behavior("feedback.music", audioTarget("ambient"), "audio", { loop: true, volume: 0.12, frequency: 330, seconds: 2, bus: "music", role: "ambient" });
306
- binding("feedback.music.start", { kind: "click", componentId: "board.controller" }, [{ kind: "playAudio", behaviorId: "feedback.music" }]);
307
- }
308
- behavior("feedback.complete", audioTarget("complete"), "audio", { loop: false, volume: 0.35, frequency: 1040, seconds: 0.65, bus: "sfx", role: "win" });
309
- behavior("feedback.celebration", "director", "emitter", { shape: "confetti", coverage: "screen", count: 48, color: palette.accent, color2: "#4ecdc4", color3: "#fff3b0", speed: 120, lifetime: 1.05, gravity: 85 });
310
- for (const [index, area] of concept.restoration.areas.entries()) {
311
- behavior("feedback.sparkles." + area.id, "world." + area.id, "emitter", { shape: "confetti", coverage: "local", count: 16, color: palette.accent, color2: "#4ecdc4", color3: "#fff3b0", speed: 100, lifetime: 0.85, gravity: 70 });
312
- behavior("celebrate." + area.id, "world." + area.id, "animation", { property: "scale", from: 0.96, to: 1, seconds: 0.7, loop: false, easing: "back-out" });
313
- behavior("reveal." + area.id, "world." + area.id, "animation", { property: "opacity", from: 0.25, to: 1, seconds: 0.8, loop: false, easing: "ease-out" });
314
- const choice = "repair." + area.id;
315
- add(choice, "button", 12 + index * (areaWidth + 12), 455, areaWidth, 95, { visible: false, fill: palette.primary, radius: 18, pressedFill: palette.accent }, { parentId: "cta.layout" });
316
- add(choice + ".label", "text", 8, 8, areaWidth - 16, 79, { text: "Restore " + area.label, fontSize: 19, color: palette.text }, { parentId: choice });
317
- binding(choice + ".select", { kind: "click", componentId: choice }, [
318
- set("repaired." + area.id, true),
319
- { kind: "setAsset", componentId: "world." + area.id, assetId: area.after.id },
320
- { kind: "animate", behaviorId: "reveal." + area.id },
321
- { kind: "playAudio", behaviorId: "feedback.reward" },
322
- { kind: "emit", behaviorId: "feedback.sparkles." + area.id },
323
- ...concept.restoration.areas.map((candidate) => property("repair." + candidate.id, "visible", false)),
324
- { kind: "add", variableId: "repairs", value: 1 }
325
- ], { all: [is("phase", "repair"), is("repaired." + area.id, false)] });
326
- binding(choice + ".offer", { kind: "variableChange", variableId: "phase" }, [property(choice, "visible", true)], { all: [is("phase", "repair"), is("repaired." + area.id, false)] });
327
- }
328
- const hideChoices = concept.restoration.areas.map((area) => property("repair." + area.id, "visible", false));
329
- variable("contact.elapsed", "number", 0);
330
- for (const [index, boardId] of boardIds.entries()) {
331
- binding(index === 0 ? "board.matched" : "board.second.matched", { kind: "validMatch", componentId: boardId }, [
332
- phase("contact"),
333
- set("contact.elapsed", 0),
334
- set("message", "A match! Choose what grows next"),
335
- property("match.lock", "visible", true),
336
- ...stopHints,
337
- { kind: "playAudio", behaviorId: "feedback.contact" }
338
- ], { any: [is("phase", "first-seconds"), is("phase", "agency"), is("phase", "escalation")] });
339
- binding(index === 0 ? "board.rejected" : "board.second.rejected", { kind: "invalidMatch", componentId: boardId }, [
340
- set("message", "Try another swap \u2014 line up three matching tiles"),
341
- { kind: "playAudio", behaviorId: "feedback.reject" }
342
- ]);
343
- }
344
- binding("contact.tick", { kind: "timer", behaviorId: "director.payoff" }, [{ kind: "add", variableId: "contact.elapsed", value: 0.1 }], is("phase", "contact"));
345
- binding("contact.finish", { kind: "variableChange", variableId: "contact.elapsed" }, [
346
- phase("repair"),
347
- set("message", arc.escalation.description),
348
- ...hideBoards,
349
- property("match.lock", "visible", false)
350
- ], { all: [is("phase", "contact"), { variableId: "contact.elapsed", op: "gte", value: 0.35 }] });
351
- binding("progress.first", { kind: "variableChange", variableId: "repairs" }, [
352
- phase("escalation"),
353
- set("message", "One more repair \u2014 match three again"),
354
- property("board.controller", "visible", false),
355
- { kind: "resetMatch", componentId: "board.escalation" },
356
- property("board.escalation", "visible", true),
357
- { kind: "animate", behaviorId: "hint.tile.second.1.1" },
358
- { kind: "animate", behaviorId: "hint.tile.second.2.1" }
359
- ], { all: [
360
- { variableId: "repairs", op: "gte", value: 1 },
361
- { variableId: "repairs", op: "lt", value: areaCount }
362
- ] });
363
- binding("progress.complete", { kind: "variableChange", variableId: "repairs" }, [
364
- phase("payoff"),
365
- set("message", concept.presentation.rewardCopy),
366
- property("continue", "visible", true),
367
- { kind: "playAudio", behaviorId: "feedback.complete" },
368
- { kind: "emit", behaviorId: "feedback.celebration" },
369
- ...concept.restoration.areas.map((area) => ({ kind: "animate", behaviorId: "celebrate." + area.id }))
370
- ], is("repairs", areaCount));
371
- add("continue", "button", 90, 540, 210, 52, { visible: false, fill: palette.primary, radius: 14 }, { parentId: "cta.layout" });
372
- add("continue.label", "text", 0, 0, 210, 52, { text: "Continue", fontSize: 18, color: palette.text }, { parentId: "continue" });
373
- binding("continue.action", { kind: "click", componentId: "continue" }, [phase("cta")], is("phase", "payoff"));
374
- add("cta", "button", 35, 505, 320, 68, { visible: false, presentation: "shiny-cta", fill: palette.accent, stroke: palette.background, strokeWidth: 3, radius: 18 }, { parentId: "cta.layout" });
375
- add("cta.label", "text", 0, 0, 320, 68, { text: concept.experience.ctaLabel, fontSize: 19, color: palette.background }, { parentId: "cta" });
376
- behavior("cta.pulse", "cta", "animation", { property: "y", from: 502, to: 508, seconds: 0.95, loop: true, easing: "ease-in-out" });
377
- binding("cta.store", { kind: "click", componentId: "cta" }, [{ kind: "store" }], is("phase", "cta"));
378
- binding("cta.enter", { kind: "variableChange", variableId: "phase" }, [
379
- ...hideBoards,
380
- ...stopHints,
381
- property("match.lock", "visible", false),
382
- ...hideChoices,
383
- property("continue", "visible", false),
384
- property("cta", "visible", true),
385
- { kind: "animate", behaviorId: "cta.pulse" },
386
- set("message", arc.cta.description)
387
- ], is("phase", "cta"));
388
- behavior("director.opening", "director", "timer", { seconds: arc["first-seconds"].seconds, repeat: false });
389
- binding("director.agency", { kind: "timer", behaviorId: "director.opening" }, [phase("agency"), set("message", concept.experience.instruction)], is("phase", "first-seconds"));
390
- behavior("director.hint", "director", "timer", { seconds: arc["first-seconds"].seconds + arc.agency.seconds, repeat: false });
391
- binding("director.hint.show", { kind: "timer", behaviorId: "director.hint" }, [set("message", "Try the top middle tile and the tile below it"), { kind: "animate", behaviorId: "hint.tile.0.1" }, { kind: "animate", behaviorId: "hint.tile.1.1" }], { any: [is("phase", "first-seconds"), is("phase", "agency")] });
392
- const deadline = arc["first-seconds"].seconds + arc.agency.seconds + arc.escalation.seconds;
393
- behavior("director.deadline", "director", "timer", { seconds: deadline, repeat: false });
394
- binding("director.deadline.cta", { kind: "timer", behaviorId: "director.deadline" }, [phase("cta")], { variableId: "phase", op: "ne", value: "payoff" });
395
- // Measure payoff exposure independently of the time taken to solve the puzzles.
396
- variable("payoff.elapsed", "number", 0);
397
- behavior("director.payoff", "director", "timer", { seconds: 0.1, repeat: true });
398
- binding("director.payoff.tick", { kind: "timer", behaviorId: "director.payoff" }, [{ kind: "add", variableId: "payoff.elapsed", value: 0.1 }], is("phase", "payoff"));
399
- binding("director.payoff.finish", { kind: "variableChange", variableId: "payoff.elapsed" }, [phase("cta")], { all: [is("phase", "payoff"), { variableId: "payoff.elapsed", op: "gte", value: arc.payoff.seconds }] });
400
- operations.push({ kind: "setStore", url: concept.product.storeUrl });
401
- const effects = {
402
- "match-rule": ["board.controller", "board.matched"],
403
- "world-transformation": concept.restoration.areas.map((area) => "world." + area.id),
404
- "repair-choice": concept.restoration.areas.map((area) => "repair." + area.id),
405
- recovery: ["board.rejected", "director.hint.show"],
406
- continuity: ["cta", "cta.store"]
407
- };
408
- return { operations, assets, assetPolicy, requirements: (concept.requirements ?? []).map((requirement) => ({ ...requirement, records: effects[requirement.effect] })) };
409
- }
410
- function harvestRestore(concept, studioAssets) {
411
- const operations = [];
412
- const assets = [];
413
- const assetPolicy = [];
414
- const plan = concept.harvest;
415
- const {treatment,receipt:recipe} = harvestRecipe(plan);
416
- const palette = concept.presentation.palette;
417
- const arc = Object.fromEntries(concept.experience.arc.map(step => [step.phase, step]));
418
- const add = (id, kind, x, y, width, height, parameters = {}, extra = {}) => {
419
- operations.push({kind: 'createComponent', component: {
420
- id, label: id, order: operations.length, contract: 'native.' + kind + '.v1',
421
- transform: [1, 0, 0, 1, x, y], parameters: {width, height, ...parameters}, ...extra,
422
- }});
423
- };
424
- const behavior = (id, componentId, kind, parameters) => operations.push({kind: 'putBehavior', behavior: {id, componentId, kind, parameters}});
425
- const bind = (id, event, actions, condition) => operations.push({kind: 'putBinding', binding: {id, event, actions, ...(condition ? {condition} : {})}});
426
- const property = (componentId, key, value) => ({kind: 'setComponent', componentId, key, value});
427
- const set = (variableId, value) => ({kind: 'set', variableId, value});
428
- const is = (variableId, value) => ({variableId, op: 'eq', value});
429
- const variable = (id, type, initial) => operations.push({kind: 'putVariable', variable: {id, label: id, type, initial}});
430
- const assetById = new Map(plan.assets.map(asset => [asset.id, asset]));
431
- check(assetById.size === plan.assets.length, 'E_CONCEPT_ASSET_DUPLICATE');
432
- const styleFamily = plan.assets.find(asset => asset.mime.startsWith('image/'))?.provenance.styleFamily;
433
- for (const source of plan.assets) {
434
- let receipt;
435
- if (source.provenance.origin === 'studio-original') {
436
- const original = studioAssets?.get(source.id);
437
- check(original && canonical(original) === canonical(source), 'E_ASSET_POLICY_STUDIO_SOURCE');
438
- check(source.provenance.styleFamily === styleFamily || isAudioMime(source.mime), 'E_ASSET_POLICY_STYLE');
439
- receipt = source.provenance;
440
- } else {
441
- receipt = validateAssetPolicy(source, {role: isAudioMime(source.mime) ? 'audio' : 'visual', styleFamily});
442
- }
443
- assetPolicy.push({id: source.id, ...receipt});
444
- const bytes = Buffer.from(source.data, 'base64');
445
- check(bytes.length <= 700000, 'E_CONCEPT_ASSET_SIZE');
446
- const rights = source.rights + (receipt.attribution ? '\n' + receipt.attribution : '');
447
- check(rights.length <= 2048, 'E_CONCEPT_ASSET_RIGHTS');
448
- assets.push({id: source.id, mime: source.mime, data: source.data, rights});
449
- operations.push({kind: 'registerAsset', asset: {
450
- id: source.id, hash: 'sha256:' + createHash('sha256').update(bytes).digest('hex'),
451
- mime: source.mime, bytes: bytes.length, rights, provenance: JSON.stringify(receipt),
452
- }});
453
- }
454
- const imageReference = assetId => check(assetById.get(assetId)?.mime.startsWith('image/'), 'E_CONCEPT_VISUAL_REFERENCE');
455
- Object.values(plan.tiles).forEach(imageReference);
456
- check(new Set(Object.values(plan.tiles)).size === 5, 'E_CONCEPT_TILE_PALETTE');
457
- Object.values(plan.audio).forEach(assetId => check(isAudioMime(assetById.get(assetId)?.mime), 'E_CONCEPT_AUDIO_REFERENCE'));
458
- check(new Set(plan.world.map(object => object.id)).size === plan.world.length, 'E_CONCEPT_WORLD_ID');
459
- for (const object of plan.world) {
460
- imageReference(object.assetId);
461
- check(object.hideAt === undefined || object.hideAt > object.unlockAt, 'E_CONCEPT_WORLD_STATE');
462
- }
463
- const worldObjects=plan.world.map(object=>{
464
- const left=Math.max(0,object.x),top=Math.max(0,object.y),right=Math.min(390,object.x+object.width),bottom=Math.min(332,object.y+object.height);
465
- check(right>left&&bottom>top,'E_CONCEPT_WORLD_STATE');
466
- return {...object,x:left,y:top,width:right-left,height:bottom-top};
467
- });
468
- for (const stage of [0, 1, 2, 3]) check(plan.world.some(object => object.unlockAt === stage), 'E_CONCEPT_WORLD_TRANSFORMATION');
469
- variable('harvest.moves', 'number', 0);
470
- variable('harvest.phase', 'string', 'first-seconds');
471
- variable('harvest.message', 'string', concept.experience.instruction);
472
- variable('harvest.payoff', 'number', 0);
473
- variable('harvest.idle', 'number', 0);
474
- add('harvest.background', 'rectangle', 0, 0, 700, 700, {fill: palette.background});
475
- const layouts = {
476
- 'harvest.puzzle.layout': {x: 341.25, y: -270, scaleX: .95, scaleY: .95},
477
- 'harvest.world.layout': {x: 0, y: 0, scaleX: .92, scaleY: .92},
478
- 'harvest.instruction.layout': {x: 341.25, y: -270, scaleX: .95, scaleY: .95},
479
- 'harvest.cta.layout': {x: 341.25, y: -270, scaleX: .95, scaleY: .95},
480
- };
481
- for (const [id, alternate] of Object.entries(layouts)) {
482
- add(id, 'group', 0, 0, 0, 0);
483
- behavior(id + '.responsive', id, 'responsive-layout', alternate);
484
- }
485
- const pixelText={fontFamily:'pixel',fontWeight:'700',pixelPanel:true,panelFill:palette.primary,panelStroke:palette.accent,color:palette.accent};
486
- add('harvest.brand', 'text', 60, 4, 178, 32, {text: concept.presentation.title, fontSize: 24, align: 'center', wrap:false, ...pixelText});
487
- add('harvest.progress', 'text', 248, 4, 82, 32, {text: '{{harvest.moves}} / 3', fontSize: 20, align: 'center', wrap:false, ...pixelText});
488
- add('harvest.world.frame','group',0,0,390,332,{clip:true},{parentId:'harvest.world.layout'});
489
- const worldBounds = new Map();
490
- for (let stage = 0; stage <= 3; stage++) {
491
- const objects = worldObjects.filter(object => object.unlockAt === stage);
492
- const left = Math.min(...objects.map(object => object.x));
493
- const top = Math.min(...objects.map(object => object.y));
494
- const right = Math.max(...objects.map(object => object.x + object.width));
495
- const bottom = Math.max(...objects.map(object => object.y + object.height));
496
- const bounds = {x:(left+right)/2,y:(top+bottom)/2,width:right-left,height:bottom-top};
497
- worldBounds.set(stage,bounds);
498
- const id = 'harvest.world.stage.' + stage;
499
- add(id, 'group', bounds.x, 40+bounds.y, bounds.width, bounds.height, {visible: stage === 0}, {parentId: 'harvest.world.frame'});
500
- if (stage) behavior(id + '.reveal', id, 'animation', {property: 'scale', from: stage===3?treatment.revealFrom:.2, to: 1,
501
- seconds: stage===3?treatment.revealSeconds:.5, loop: false, easing: stage===3?treatment.easing:'back-out'});
502
- }
503
- for (const object of worldObjects) {
504
- const bounds = worldBounds.get(object.unlockAt);
505
- add('harvest.world.' + object.id, 'image', object.x-bounds.x, object.y-bounds.y, object.width, object.height, {fit: 'contain', smoothing: false}, {
506
- parentId: 'harvest.world.stage.' + object.unlockAt,
507
- assetSlots: [{slotId: 'source', assetId: object.assetId}],
508
- });
509
- }
510
- add('harvest.instruction', 'text', 77, 303, 236, 28, {text: '{{harvest.message}}', fontSize: 18, minFontSize: 8, wrap:false, ...pixelText}, {parentId: 'harvest.instruction.layout'});
511
- add('harvest.board.shell', 'rectangle', 25, 335, 340, 334, {fill: palette.primary, radius: 0, stroke: palette.accent, strokeWidth: 3, pixelFrame: true}, {parentId: 'harvest.puzzle.layout'});
512
- add('harvest.board', 'group', 35, 345, 320, 320, {clip:true}, {parentId: 'harvest.puzzle.layout'});
513
- const groups = ['carrot', 'corn', 'tomato', 'eggplant', 'pumpkin'];
514
- const initial = [[0,1,0,3,4],[2,0,2,4,1],[1,2,3,0,4],[4,3,1,2,0],[3,4,2,1,3]];
515
- for (let row = 0; row < 5; row++) for (let column = 0; column < 5; column++) {
516
- const group = groups[initial[row][column]];
517
- const id = 'harvest.tile.' + row + '.' + column;
518
- add(id, 'button', column * 64+2, row * 64+2, 58, 58, {
519
- fill: '#d6b27c', pressedFill: '#ffe6ab', hoverFill: '#e8ca96', radius: 0,
520
- stroke: '#6b4a3c', strokeWidth: 2,
521
- }, {parentId: 'harvest.board'});
522
- add(id + '.crop', 'image', 8, 8, 42, 42, {fit: 'contain', smoothing: false}, {
523
- parentId: id, assetSlots: [{slotId: 'source', assetId: plan.tiles[group]}],
524
- });
525
- behavior(id + '.cell', id, 'match-tile', {row, column, group});
526
- }
527
- behavior('harvest.rules', 'harvest.board', 'match-board', {rows: 5, columns: 5, seed: plan.seed});
528
- add('harvest.board.lock', 'rectangle', 25, 335, 340, 334, {fill: palette.primary, visible: false, radius: 0, stroke: palette.accent, strokeWidth: 3, pixelFrame: true}, {parentId: 'harvest.puzzle.layout'});
529
- add('harvest.reward.stars', 'path', 132, 356, 126, 34, {
530
- visible: false, fill: '#ffd05a', stroke: palette.primary, strokeWidth: 2,
531
- commands: [['M',20,6],['L',24,14],['L',33,15],['L',26,21],['L',28,30],['L',20,25],['L',12,30],['L',14,21],['L',7,15],['L',16,14],['Z'],['M',63,2],['L',68,12],['L',79,13],['L',71,20],['L',73,31],['L',63,25],['L',53,31],['L',55,20],['L',47,13],['L',58,12],['Z'],['M',106,6],['L',110,14],['L',119,15],['L',112,21],['L',114,30],['L',106,25],['L',98,30],['L',100,21],['L',93,15],['L',102,14],['Z']],
532
- }, {parentId: 'harvest.puzzle.layout'});
533
- add('harvest.reward.title', 'text', 45, 400, 300, 52, {text: 'FARM RESTORED!', fontFamily: 'pixel', fontSize: 26, color: palette.accent, visible: false}, {parentId: 'harvest.puzzle.layout'});
534
- add('harvest.reward.detail', 'text', 45, 460, 300, 32, {text: 'WELL DONE!', fontFamily: 'pixel', fontSize: 18, color: palette.accent, visible: false}, {parentId: 'harvest.puzzle.layout'});
535
- add('harvest.flight', 'image', 170, 480, 44, 44, {visible: false, fit: 'contain', smoothing: false}, {
536
- parentId: 'harvest.world.layout', assetSlots: [{slotId: 'source', assetId: plan.tiles.carrot}],
537
- });
538
- for(const stage of [1,2,3]) {
539
- const bounds=worldBounds.get(stage);
540
- behavior('harvest.flight.x.'+stage, 'harvest.flight', 'animation', {property:'x',from:170,to:bounds.x-22,fromCurrent:true,seconds:.7,loop:false,easing:'ease-in-out'});
541
- behavior('harvest.flight.y.'+stage, 'harvest.flight', 'animation', {property:'y',from:480,to:40+bounds.y-22,fromCurrent:true,seconds:.7,loop:false,easing:'ease-out'});
542
- }
543
- behavior('harvest.flight.fade', 'harvest.flight', 'animation', {property: 'opacity', from: 1, to: 0, delay: .5, seconds: .25, loop: false, easing: 'ease-out'});
544
- behavior('harvest.celebration', 'harvest.world.stage.3', 'emitter', {
545
- shape: 'pixel-confetti', coverage: 'screen',
546
- count: treatment.particles * 2,
547
- color: '#ffd05a', color2: '#34714a', color3: '#ffe6ab',
548
- speed: treatment.speed, lifetime: treatment.lifetime + .18, gravity: 110,
549
- });
550
- for (const [cue, assetId] of Object.entries(plan.audio)) {
551
- const target = 'harvest.audio.' + cue;
552
- add(target, 'group', 0, 0, 0, 0, {}, {assetSlots: [{slotId: 'source', assetId}]});
553
- const volume={ambient:.09,match:.24,repair:.32,complete:treatment.gain,loss:.32,reject:.13}[cue];
554
- behavior(target + '.play', target, 'audio', {loop: cue === 'ambient', volume, frequency: 660, seconds: .2, bus: cue === 'ambient' ? 'music' : ['complete','loss'].includes(cue)?'stinger':'sfx', ...(cue === 'match' ? {pitchVariableId: 'harvest.moves', pitchStep: 1.5} : {})});
555
- }
556
- const sound = cue => ({kind: 'playAudio', behaviorId: 'harvest.audio.' + cue + '.play'});
557
- bind('harvest.music.start', {kind: 'click', componentId: 'harvest.board'}, [sound('ambient'),set('harvest.idle',0),set('harvest.message',concept.experience.instruction)]);
558
- bind('harvest.clear', {kind: 'matchClear', componentId: 'harvest.board'}, [
559
- set('harvest.idle',0),property('harvest.instruction','visible',false),sound('match'), {kind: 'copyMatchAsset', componentId: 'harvest.flight', boardId: 'harvest.board'},
560
- property('harvest.flight', 'visible', true), property('harvest.flight', 'opacity', 1),
561
- {kind: 'animate', behaviorId: 'harvest.flight.fade'},
562
- ],{all:[{variableId:'harvest.phase',op:'ne',value:'cta'},{variableId:'harvest.phase',op:'ne',value:'payoff'}]});
563
- for(const stage of [1,2,3]) bind('harvest.flight.destination.'+stage,{kind:'matchClear',componentId:'harvest.board'},[
564
- {kind:'animate',behaviorId:'harvest.flight.x.'+stage},{kind:'animate',behaviorId:'harvest.flight.y.'+stage},
565
- ],{all:[is('harvest.moves',stage-1),{variableId:'harvest.phase',op:'ne',value:'cta'},{variableId:'harvest.phase',op:'ne',value:'payoff'}]});
566
- bind('harvest.matched', {kind: 'validMatch', componentId: 'harvest.board'}, [{kind: 'add', variableId: 'harvest.moves', value: 1}], {all:[{variableId:'harvest.moves',op:'lt',value:3},{variableId:'harvest.phase',op:'ne',value:'cta'},{variableId:'harvest.phase',op:'ne',value:'payoff'}]});
567
- bind('harvest.reject', {kind: 'invalidMatch', componentId: 'harvest.board'}, [set('harvest.message', 'Try another swap'), property('harvest.instruction', 'visible', true), sound('reject')],{variableId:'harvest.phase',op:'ne',value:'cta'});
568
- const milestones = ['Orchard growing!', 'Crops blooming!', concept.presentation.rewardCopy];
569
- for (const stage of [1, 2, 3]) {
570
- const worldId = 'harvest.world.stage.' + stage;
571
- bind('harvest.restore.' + stage, {kind: 'variableChange', variableId: 'harvest.moves'}, [
572
- property(worldId, 'visible', true), {kind: 'animate', behaviorId: worldId + '.reveal'},
573
- ...plan.world.filter(object => object.hideAt === stage).map(object => property('harvest.world.' + object.id, 'visible', false)),
574
- set('harvest.message', milestones[stage - 1]), set('harvest.phase', stage === 3 ? 'payoff' : stage === 1 ? 'agency' : 'escalation'),
575
- sound(stage === 3 ? 'complete' : plan.audio.repair ? 'repair' : 'match'),
576
- {kind: 'floatingText', text: stage === 3 ? 'RESTORED!' : '+1', componentId: worldId, color: '#fff0bd', fontSize: 20, risePx: 36, seconds: .75},
577
- ...(stage === 3 ? [
578
- {kind: 'cameraShake', intensity: 6, seconds: .22}, {kind: 'screenFlash', color: '#fff0bd', opacity: .2, seconds: .22},
579
- property('harvest.instruction', 'visible', false), property('harvest.board.lock', 'visible', true),
580
- property('harvest.reward.stars', 'visible', true), property('harvest.reward.title', 'visible', true),
581
- property('harvest.reward.detail', 'visible', true), {kind: 'emit', behaviorId: 'harvest.celebration'},
582
- ] : [{kind: 'cameraShake', intensity: 3, seconds: .12}]),
583
- ], is('harvest.moves', stage));
584
- }
585
- add('harvest.cta', 'button', 45, 528, 300, 70, {
586
- visible: false, presentation: 'pixel-cta', fill: '#f1bb46', pressedFill: '#cf892f',
587
- hoverFill: '#ffd069', radius: 0, stroke: palette.primary, strokeWidth: 3, pixelFrame: true,
588
- }, {parentId: 'harvest.cta.layout'});
589
- add('harvest.cta.label', 'text', 0, 0, 300, 70, {text: concept.experience.ctaLabel, fontFamily: 'pixel', fontSize: 22, color: palette.primary}, {parentId: 'harvest.cta'});
590
- behavior('harvest.cta.pulse', 'harvest.cta', 'animation', {property: 'y', from: 525, to: 531, seconds: 1.9, loop: true, easing: 'ease-in-out'});
591
- bind('harvest.cta.click', {kind: 'click', componentId: 'harvest.cta'}, [{kind: 'store'}], is('harvest.phase', 'cta'));
592
- bind('harvest.cta.show', {kind: 'variableChange', variableId: 'harvest.phase'}, [
593
- property('harvest.instruction', 'visible', false), property('harvest.board.lock','visible',true),
594
- property('harvest.cta', 'visible', true), {kind: 'animate', behaviorId: 'harvest.cta.pulse'},
595
- ], is('harvest.phase', 'cta'));
596
- behavior('harvest.clock', 'harvest.background', 'timer', {seconds: .1, repeat: true});
597
- bind('harvest.payoff.tick', {kind: 'timer', behaviorId: 'harvest.clock'}, [{kind: 'add', variableId: 'harvest.payoff', value: .1}], is('harvest.phase', 'payoff'));
598
- bind('harvest.payoff.finish', {kind: 'variableChange', variableId: 'harvest.payoff'}, [
599
- set('harvest.message', arc.cta.description), set('harvest.phase', 'cta'),
600
- ], {all: [is('harvest.phase', 'payoff'), {variableId: 'harvest.payoff', op: 'gte', value: arc.payoff.seconds + .1}]});
601
- bind('harvest.idle.tick', {kind: 'timer', behaviorId: 'harvest.clock'}, [{kind:'add',variableId:'harvest.idle',value:.1}], {any:[is('harvest.phase','first-seconds'),is('harvest.phase','agency'),is('harvest.phase','escalation')]});
602
- const normalHint={variableId:'harvest.idle',op:'gte',value:arc['first-seconds'].seconds};
603
- const hintCondition=plan.firstHintSeconds===undefined?normalHint:{any:[
604
- {all:[is('harvest.moves',0),{...normalHint,value:plan.firstHintSeconds}]},
605
- {all:[{variableId:'harvest.moves',op:'gt',value:0},normalHint]},
606
- ]};
607
- bind('harvest.hint.show', {kind:'variableChange',variableId:'harvest.idle'}, [{kind:'hintMatch',componentId:'harvest.board'},set('harvest.idle',0)], hintCondition);
608
- behavior('harvest.deadline', 'harvest.background', 'timer', {seconds: arc['first-seconds'].seconds + arc.agency.seconds + arc.escalation.seconds, repeat: false});
609
- bind('harvest.deadline.cta', {kind: 'timer', behaviorId: 'harvest.deadline'}, [
610
- set('harvest.message', 'Try again'), property('harvest.instruction', 'visible', false), set('harvest.phase', 'cta'),
611
- property('harvest.reward.title', 'text', 'TIME IS UP!'), property('harvest.reward.title', 'visible', true),
612
- property('harvest.reward.detail', 'text', 'MATCH 3 CROPS'), property('harvest.reward.detail', 'visible', true),
613
- ...(plan.audio.loss?[sound('loss')]:[]),
614
- ], {all: [{variableId: 'harvest.phase', op: 'ne', value: 'payoff'}, {variableId: 'harvest.phase', op: 'ne', value: 'cta'}]});
615
- operations.push({kind: 'setStore', url: concept.product.storeUrl});
616
- check(operations.length <= 256, 'E_CONCEPT_OPERATION_LIMIT');
617
- const effects = {
618
- 'match-rule': ['harvest.board', 'harvest.rules', 'harvest.matched'],
619
- 'world-transformation': ['harvest.restore.1', 'harvest.restore.2', 'harvest.restore.3'],
620
- recovery: ['harvest.reject', 'harvest.hint.show'], continuity: ['harvest.cta', 'harvest.cta.click'],
621
- };
622
- return {operations, assets, assetPolicy, recipe, requirements: concept.requirements.map(requirement => ({...requirement, records: effects[requirement.effect]}))};
623
- }
624
- function composeNativeConcept(input, {studioAssets} = {}) {
625
- const concept = validateCreativeConcept(input), result = concept.experience.mechanic === "harvest-restore" ? harvestRestore(concept, studioAssets) : concept.experience.mechanic === "star-salvage" ? starSalvageModule.compose(concept, studioAssets) : concept.experience.mechanic === "match-restore" ? matchRestore(concept) : { operations: concept.experience.mechanic === "tap-collect" ? tapCollect(concept) : dragCatch(concept), assets: [] };
626
- return freeze({ format: "tora-native-composition-1", conceptHash: conceptHash(concept), conceptAccepted: false, creativeStatus: concept.format === "tora-creative-concept-2" ? "REQUIRES_VISUAL_REVIEW" : "PROTOTYPE", unmetRequirements: concept.format === "tora-creative-concept-2" ? [] : ["Explicit strategic requirements and creative review are pending."], operations: result.operations, assets: result.assets, assetPolicy: result.assetPolicy ?? [], requirements: result.requirements ?? [], ...(result.recipe ? {recipe:result.recipe} : {}) });
627
- }
628
- export {
629
- CREATIVE_CONCEPT_SCHEMA,
630
- composeNativeConcept,
631
- conceptHash,
632
- validateCreativeConcept
633
- };