@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
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import {chromium} from 'playwright';
|
|
2
|
-
import {readFile,writeFile,mkdir} from 'node:fs/promises';
|
|
3
|
-
import {resolve} from 'node:path';
|
|
4
|
-
import {createHash} from 'node:crypto';
|
|
5
|
-
import {Buffer} from 'node:buffer';
|
|
6
|
-
import process from 'node:process';
|
|
7
|
-
import {analyzeWav} from './audio-analysis.mjs';
|
|
8
|
-
|
|
9
|
-
const root=resolve(import.meta.dirname,'../../..');
|
|
10
|
-
const hash=bytes=>'sha256:'+createHash('sha256').update(bytes).digest('hex');
|
|
11
|
-
const licenseUrl='https://creativecommons.org/publicdomain/zero/1.0/';
|
|
12
|
-
const kenney={
|
|
13
|
-
interface:'kenney-interface-sounds',
|
|
14
|
-
jingles:'kenney-music-jingles',
|
|
15
|
-
};
|
|
16
|
-
const familyDefinitions=[
|
|
17
|
-
{
|
|
18
|
-
id:'casual-warm',label:'Casual Warm',styleTags:['casual','warm','acoustic'],
|
|
19
|
-
ambientSource:{
|
|
20
|
-
id:'tarush-singhal-happy-ukelele',author:'Tarush Singhal',license:'CC0-1.0',
|
|
21
|
-
sourceUrl:'https://opengameart.org/content/happy-ukelele-island-surfing-theme',styleFamily:'casual-warm',
|
|
22
|
-
licenseFile:'assets/free-audio/cozy-warm/source/source-page.html',
|
|
23
|
-
archive:{url:'https://opengameart.org/sites/default/files/ukele.mp3',file:'assets/free-audio/cozy-warm/source/ukele.mp3'},
|
|
24
|
-
},
|
|
25
|
-
cues:[
|
|
26
|
-
{role:'ambient',sourceId:'tarush-singhal-happy-ukelele',input:'assets/free-audio/cozy-warm/source/ukele.mp3',duration:16,valence:'positive',energy:'low',loopable:true,tags:['ukulele','island','music','loop']},
|
|
27
|
-
{role:'tap',sourceId:kenney.interface,input:'assets/kenney-harvest/source/interface-sounds/Audio/select_001.ogg',valence:'neutral',energy:'low',tags:['interface','select','short-cue']},
|
|
28
|
-
{role:'match',sourceId:kenney.interface,input:'assets/kenney-harvest/source/interface-sounds/Audio/confirmation_002.ogg',valence:'positive',energy:'medium',tags:['interface','confirmation','short-cue']},
|
|
29
|
-
{role:'reject',sourceId:kenney.interface,input:'assets/kenney-harvest/source/interface-sounds/Audio/error_003.ogg',valence:'negative',energy:'medium',tags:['interface','error','short-cue']},
|
|
30
|
-
{role:'reward',sourceId:kenney.jingles,input:'assets/kenney-harvest/source/music-jingles/OGG/jingles_SAX/jingles_SAX09.ogg',valence:'positive',energy:'medium',tags:['sax','jingle','reward']},
|
|
31
|
-
{role:'win',sourceId:kenney.jingles,input:'assets/kenney-harvest/source/music-jingles/OGG/jingles_SAX/jingles_SAX03.ogg',valence:'positive',energy:'high',tags:['sax','jingle','fanfare','success']},
|
|
32
|
-
{role:'loss',sourceId:kenney.jingles,input:'assets/kenney-harvest/source/music-jingles/OGG/jingles_SAX/jingles_SAX00.ogg',valence:'negative',energy:'medium',tags:['sax','jingle','failure','timeout']},
|
|
33
|
-
],
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
id:'arcade-pop',label:'Arcade Pop',styleTags:['arcade','pop-punk','chiptune'],
|
|
37
|
-
ambientSource:{
|
|
38
|
-
id:'3xblast-pop-punk-chiptune',author:'3xBlast',license:'CC0-1.0',
|
|
39
|
-
sourceUrl:'https://opengameart.org/content/7-pop-punk-chiptune-tracks',styleFamily:'arcade-pop',
|
|
40
|
-
licenseFile:'assets/free-audio/arcade-pop/source/INFO.txt',
|
|
41
|
-
archive:{url:'https://opengameart.org/sites/default/files/3xblast_-_7_pop-punk_chiptune_tracks_0.zip',file:'assets/free-audio/arcade-pop/source/pop-punk-chiptune.zip'},
|
|
42
|
-
},
|
|
43
|
-
cues:[
|
|
44
|
-
{role:'ambient',sourceId:'3xblast-pop-punk-chiptune',input:'assets/free-audio/arcade-pop/source/3xBlast - A Band of Jellyfish (Looped).ogg',duration:16,valence:'positive',energy:'high',loopable:true,tags:['chiptune','pop-punk','music','loop']},
|
|
45
|
-
{role:'tap',sourceId:kenney.interface,input:'assets/kenney-harvest/source/interface-sounds/Audio/click_001.ogg',valence:'neutral',energy:'medium',tags:['interface','click','short-cue']},
|
|
46
|
-
{role:'match',sourceId:kenney.interface,input:'assets/kenney-harvest/source/interface-sounds/Audio/confirmation_004.ogg',valence:'positive',energy:'high',tags:['interface','confirmation','short-cue']},
|
|
47
|
-
{role:'reject',sourceId:kenney.interface,input:'assets/kenney-harvest/source/interface-sounds/Audio/error_008.ogg',valence:'negative',energy:'high',tags:['interface','error','short-cue']},
|
|
48
|
-
{role:'reward',sourceId:kenney.jingles,input:'assets/kenney-harvest/source/music-jingles/OGG/jingles_PIZZA/jingles_PIZZA09.ogg',valence:'positive',energy:'high',tags:['chiptune','jingle','reward']},
|
|
49
|
-
{role:'win',sourceId:kenney.jingles,input:'assets/kenney-harvest/source/music-jingles/OGG/jingles_PIZZA/jingles_PIZZA03.ogg',valence:'positive',energy:'high',tags:['chiptune','jingle','fanfare','success']},
|
|
50
|
-
{role:'loss',sourceId:kenney.jingles,input:'assets/kenney-harvest/source/music-jingles/OGG/jingles_PIZZA/jingles_PIZZA00.ogg',valence:'negative',energy:'medium',tags:['chiptune','jingle','failure','timeout']},
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
];
|
|
54
|
-
const catalogFile=resolve(root,'assets/free-assets/catalog.json');
|
|
55
|
-
const catalog=JSON.parse(await readFile(catalogFile,'utf8'));
|
|
56
|
-
const browser=await chromium.launch();
|
|
57
|
-
const receipts=[];
|
|
58
|
-
try{
|
|
59
|
-
const page=await browser.newPage();
|
|
60
|
-
for(const family of familyDefinitions){
|
|
61
|
-
const outputFolder=resolve(root,'assets/free-audio',family.id,'audio');
|
|
62
|
-
await mkdir(outputFolder,{recursive:true});
|
|
63
|
-
const files=[];
|
|
64
|
-
for(const cue of family.cues){
|
|
65
|
-
const input=await readFile(resolve(root,cue.input));
|
|
66
|
-
const converted=await page.evaluate(async({base64,duration})=>{
|
|
67
|
-
const bytes=Uint8Array.from(globalThis.atob(base64),character=>character.charCodeAt(0));
|
|
68
|
-
const decoder=new globalThis.OfflineAudioContext(1,1,16000);
|
|
69
|
-
const decoded=await decoder.decodeAudioData(bytes.buffer);
|
|
70
|
-
const seconds=Math.min(decoded.duration,duration??decoded.duration);
|
|
71
|
-
const context=new globalThis.OfflineAudioContext(1,Math.ceil(seconds*16000),16000);
|
|
72
|
-
const source=context.createBufferSource();source.buffer=decoded;source.connect(context.destination);source.start();
|
|
73
|
-
const pcm=(await context.startRendering()).getChannelData(0);
|
|
74
|
-
let sourcePeak=0;for(const sample of pcm)sourcePeak=Math.max(sourcePeak,Math.abs(sample));
|
|
75
|
-
const gain=Math.min(1,0.891250938/sourcePeak),fade=duration?320:0;
|
|
76
|
-
const output=new Uint8Array(44+pcm.length*2),view=new DataView(output.buffer);
|
|
77
|
-
const text=(at,value)=>{for(let index=0;index<value.length;index++)output[at+index]=value.charCodeAt(index);};
|
|
78
|
-
text(0,'RIFF');view.setUint32(4,output.length-8,true);text(8,'WAVEfmt ');view.setUint32(16,16,true);view.setUint16(20,1,true);view.setUint16(22,1,true);view.setUint32(24,16000,true);view.setUint32(28,32000,true);view.setUint16(32,2,true);view.setUint16(34,16,true);text(36,'data');view.setUint32(40,pcm.length*2,true);
|
|
79
|
-
for(let index=0;index<pcm.length;index++){
|
|
80
|
-
const envelope=fade?Math.min(1,index/fade,(pcm.length-1-index)/fade):1;
|
|
81
|
-
const sample=Math.max(-1,Math.min(1,pcm[index]*gain*envelope));
|
|
82
|
-
view.setInt16(44+index*2,Math.round(sample*(sample<0?32768:32767)),true);
|
|
83
|
-
}
|
|
84
|
-
let encoded='';for(let index=0;index<output.length;index+=8192)encoded+=String.fromCharCode(...output.subarray(index,index+8192));
|
|
85
|
-
return {base64:globalThis.btoa(encoded),sourceDuration:decoded.duration,sourcePeak,gain};
|
|
86
|
-
},{base64:input.toString('base64'),duration:cue.duration});
|
|
87
|
-
const bytes=Buffer.from(converted.base64,'base64'),audioMeta=analyzeWav(bytes);
|
|
88
|
-
const id=`${family.id}-${cue.role}`,path=`${family.id}/${cue.role}.wav`,file=`assets/free-audio/${family.id}/audio/${cue.role}.wav`;
|
|
89
|
-
await writeFile(resolve(root,file),bytes);
|
|
90
|
-
const args=['decodeAudioData','mono','16000 Hz','16-bit PCM',...(cue.duration?[`first ${cue.duration} seconds`,'20ms source boundary fades']:['full source duration']),...(converted.gain<1?[`gain ${converted.gain} for -1 dBFS ceiling`]:[])];
|
|
91
|
-
const record={
|
|
92
|
-
id,path,file,mime:'audio/wav',sha256:hash(bytes),
|
|
93
|
-
audioMeta:{role:cue.role,valence:cue.valence,energy:cue.energy,styleTags:[...new Set([...family.styleTags,...cue.tags])],loopable:cue.loopable??false,auditionStatus:'analyzed',...audioMeta},
|
|
94
|
-
processing:{kind:'audio-transcode',sourceFile:cue.input,sourceSha256:hash(input),tool:'Web Audio OfflineAudioContext',arguments:args},
|
|
95
|
-
};
|
|
96
|
-
files.push(record);receipts.push({family:family.id,id,role:cue.role,sourceId:cue.sourceId,sourceFile:cue.input,sourceSha256:hash(input),outputFile:file,outputSha256:hash(bytes),sourceDuration:converted.sourceDuration,sourcePeak:converted.sourcePeak,gain:converted.gain,audioMeta:record.audioMeta});
|
|
97
|
-
}
|
|
98
|
-
const newSource=family.ambientSource,{archive,...sourceFields}=newSource;
|
|
99
|
-
const ambientRecord={...sourceFields,licenseUrl,licenseSha256:hash(await readFile(resolve(root,newSource.licenseFile))),archive:{url:archive.url,sha256:hash(await readFile(resolve(root,archive.file)))},files:files.filter(file=>file.audioMeta.role==='ambient')};
|
|
100
|
-
catalog.sources=catalog.sources.filter(source=>source.id!==newSource.id);catalog.sources.push(ambientRecord);
|
|
101
|
-
for(const sourceId of [kenney.interface,kenney.jingles]){
|
|
102
|
-
const source=catalog.sources.find(row=>row.id===sourceId);if(!source)throw Error(`Missing catalog source ${sourceId}`);
|
|
103
|
-
const owned=new Set(files.filter(file=>file.audioMeta.role!=='ambient').map(file=>file.path));
|
|
104
|
-
source.files=source.files.filter(file=>!owned.has(file.path));source.files.push(...files.filter(file=>file.processing.sourceFile.includes(sourceId===kenney.interface?'interface-sounds':'music-jingles')));
|
|
105
|
-
}
|
|
106
|
-
const receiptFile=resolve(root,'assets/free-audio',family.id,'audio-conversion.json');
|
|
107
|
-
await writeFile(receiptFile,JSON.stringify({format:'tora-audio-conversion-1',method:'CC0 source decode, mono PCM conversion, boundary fades and optional -1 dBFS ceiling only',browser:browser.version(),script:'scripts/lean/native/prepare-audio-collections.mjs',family:family.id,cues:receipts.filter(receipt=>receipt.family===family.id)},null,2)+'\n');
|
|
108
|
-
}
|
|
109
|
-
catalog.audioCollections=familyDefinitions.map(family=>({id:family.id,label:family.label,auditionStatus:'analyzed',cues:Object.fromEntries(family.cues.map(cue=>[cue.role,`${family.id}-${cue.role}`]))}));
|
|
110
|
-
await writeFile(catalogFile,JSON.stringify(catalog,null,2)+'\n');
|
|
111
|
-
process.stdout.write(JSON.stringify(receipts.map(({family,id,audioMeta})=>({family,id,durationSec:audioMeta.durationSec,peakDbfs:audioMeta.peakDbfs,clipping:audioMeta.clipping})),null,2)+'\n');
|
|
112
|
-
}finally{await browser.close();}
|
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
import {execFileSync} from 'node:child_process';
|
|
2
|
-
import {createHash} from 'node:crypto';
|
|
3
|
-
import {mkdir,readFile,writeFile} from 'node:fs/promises';
|
|
4
|
-
import {resolve} from 'node:path';
|
|
5
|
-
import {Buffer} from 'node:buffer';
|
|
6
|
-
import process from 'node:process';
|
|
7
|
-
import {analyzeAudio} from './audio-analysis.mjs';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Prepare compressed, 100% unique CC0 MP3 audio packs for Tiny Harvest, Traffic Tycoon, and Mini Golf.
|
|
11
|
-
* - Zero shared music or SFX across the 3 showcase playables.
|
|
12
|
-
* - Zero sax honks or oscillator synthesis; authentic CC0 third-party recordings only.
|
|
13
|
-
* - Longer (~1.9–2.3s) rising celebratory win fanfares for all 3 games.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const root=resolve(import.meta.dirname,'../../..');
|
|
17
|
-
const hash=bytes=>'sha256:'+createHash('sha256').update(bytes).digest('hex');
|
|
18
|
-
const RATE=22050;
|
|
19
|
-
|
|
20
|
-
function decodeToPcmFloat(filePath){
|
|
21
|
-
const raw=execFileSync('gst-launch-1.0',['-q','filesrc',`location=${resolve(root,filePath)}`,'!','decodebin','!','audioconvert','!','audioresample','!',`audio/x-raw,channels=1,rate=${RATE},format=S16LE`,'!','fdsink','fd=1'],{maxBuffer:40*1024*1024,stdio:['ignore','pipe','pipe']});
|
|
22
|
-
const samples=new Float64Array(raw.length/2);
|
|
23
|
-
for(let i=0;i<samples.length;i++)samples[i]=raw.readInt16LE(i*2)/32768;
|
|
24
|
-
return samples;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function trimSilence(samples,threshold=0.004,padSamples=Math.round(RATE*0.012)){
|
|
28
|
-
let first=0,last=samples.length-1;
|
|
29
|
-
while(first<samples.length&&Math.abs(samples[first])<threshold)first++;
|
|
30
|
-
while(last>first&&Math.abs(samples[last])<threshold)last--;
|
|
31
|
-
first=Math.max(0,first-padSamples);
|
|
32
|
-
last=Math.min(samples.length-1,last+padSamples);
|
|
33
|
-
return samples.subarray(first,last+1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function crossfadeJoin(clips,overlapSec=0.045){
|
|
37
|
-
if(clips.length===1)return Float64Array.from(clips[0]);
|
|
38
|
-
const overlap=Math.max(1,Math.round(RATE*overlapSec));
|
|
39
|
-
let total=clips[0].length;
|
|
40
|
-
for(let i=1;i<clips.length;i++)total+=clips[i].length-Math.min(overlap,clips[i-1].length,clips[i].length);
|
|
41
|
-
const out=new Float64Array(total);
|
|
42
|
-
out.set(clips[0],0);
|
|
43
|
-
let cursor=clips[0].length;
|
|
44
|
-
for(let i=1;i<clips.length;i++){
|
|
45
|
-
const prevLen=clips[i-1].length,next=clips[i],ov=Math.min(overlap,prevLen,next.length);
|
|
46
|
-
const start=cursor-ov;
|
|
47
|
-
for(let j=0;j<ov;j++){
|
|
48
|
-
const t=j/ov,fadeOut=Math.cos(t*Math.PI*0.5),fadeIn=Math.sin(t*Math.PI*0.5);
|
|
49
|
-
out[start+j]=out[start+j]*fadeOut+next[j]*fadeIn;
|
|
50
|
-
}
|
|
51
|
-
out.set(next.subarray(ov),cursor);
|
|
52
|
-
cursor=start+next.length;
|
|
53
|
-
}
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function masterPcm(samples,{startSec=0,maxDurationSec,fadeInSec,fadeOutSec,fadeSec=0.015,ceiling=0.87,loopFadeSec=0,softDrive=1}={}){
|
|
58
|
-
let data=startSec>0?samples.subarray(Math.min(samples.length,Math.round(startSec*RATE))):samples;
|
|
59
|
-
if(maxDurationSec&&data.length>Math.ceil(maxDurationSec*RATE)){
|
|
60
|
-
data=data.subarray(0,Math.ceil(maxDurationSec*RATE));
|
|
61
|
-
}
|
|
62
|
-
let peak=0;
|
|
63
|
-
for(let i=0;i<data.length;i++)peak=Math.max(peak,Math.abs(data[i]));
|
|
64
|
-
const gain=peak>0?Math.min(4.0,ceiling/peak):1;
|
|
65
|
-
const fadeIn=Math.round(RATE*(loopFadeSec||fadeInSec||fadeSec));
|
|
66
|
-
const fadeOut=Math.round(RATE*(loopFadeSec||fadeOutSec||fadeSec));
|
|
67
|
-
const pcm16=Buffer.alloc(data.length*2);
|
|
68
|
-
for(let i=0;i<data.length;i++){
|
|
69
|
-
let env=1;
|
|
70
|
-
if(fadeIn>0&&i<fadeIn)env*=i/fadeIn;
|
|
71
|
-
if(fadeOut>0&&i>=data.length-fadeOut)env*=(data.length-1-i)/fadeOut;
|
|
72
|
-
let v=data[i]*gain*env;
|
|
73
|
-
if(softDrive>1)v=Math.tanh(v*softDrive)/Math.tanh(softDrive)*ceiling;
|
|
74
|
-
v=Math.max(-0.95,Math.min(0.95,v));
|
|
75
|
-
pcm16.writeInt16LE(Math.round(v*(v<0?32768:32767)),i*2);
|
|
76
|
-
}
|
|
77
|
-
return pcm16;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function encodeMp3(pcm16,bitrateKbps){
|
|
81
|
-
const wav=Buffer.alloc(44+pcm16.length);
|
|
82
|
-
wav.write('RIFF',0,'ascii');wav.writeUInt32LE(36+pcm16.length,4);wav.write('WAVEfmt ',8,'ascii');
|
|
83
|
-
wav.writeUInt32LE(16,16);wav.writeUInt16LE(1,20);wav.writeUInt16LE(1,22);
|
|
84
|
-
wav.writeUInt32LE(RATE,24);wav.writeUInt32LE(RATE*2,28);wav.writeUInt16LE(2,32);wav.writeUInt16LE(16,34);
|
|
85
|
-
wav.write('data',36,'ascii');wav.writeUInt32LE(pcm16.length,40);pcm16.copy(wav,44);
|
|
86
|
-
return execFileSync('gst-launch-1.0',['-q','fdsrc','fd=0','!','wavparse','!','audioconvert','!','lamemp3enc','target=bitrate','cbr=true',`bitrate=${bitrateKbps}`,'!','fdsink','fd=1'],{input:wav,maxBuffer:20*1024*1024,stdio:['pipe','pipe','pipe']});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
async function ensureTrafficMusicSource(){
|
|
90
|
-
const outRel='assets/tora-traffic/source/now-this-is-a-waterpark.ogg';
|
|
91
|
-
const outAbs=resolve(root,outRel);
|
|
92
|
-
await mkdir(resolve(root,'assets/tora-traffic/source'),{recursive:true});
|
|
93
|
-
const ogg=execFileSync('unzip',['-p',resolve(root,'assets/free-audio/arcade-pop/source/pop-punk-chiptune.zip'),'3xBlast - Now This Is A Waterpark! (Looped).ogg'],{maxBuffer:20*1024*1024});
|
|
94
|
-
await writeFile(outAbs,ogg);
|
|
95
|
-
return outRel;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const trafficMusicSource=await ensureTrafficMusicSource();
|
|
99
|
-
|
|
100
|
-
// 1. Tiny Harvest (cozy farm chiptune + longer 2.0s rising NES victory fanfare)
|
|
101
|
-
const harvestCues=[
|
|
102
|
-
{
|
|
103
|
-
id:'audio-ambient',role:'ambient',outFile:'assets/kenney-harvest/audio/ambient.mp3',catalogPath:'audio/ambient.mp3',
|
|
104
|
-
sourceId:'zane-little-flowerbed-fields',inputs:['assets/kenney-harvest/source/flowerbed-fields/flowerbed_fields.ogg'],
|
|
105
|
-
maxDurationSec:16,loopFadeSec:0.03,bitrate:32,valence:'neutral',energy:'low',loopable:true,tags:['chiptune','cozy','music','loop'],
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
id:'audio-match',role:'match',outFile:'assets/kenney-harvest/audio/match.mp3',catalogPath:'audio/match.mp3',
|
|
109
|
-
sourceId:'kenney-interface-sounds',inputs:['assets/kenney-harvest/source/interface-sounds/Audio/confirmation_001.ogg'],
|
|
110
|
-
bitrate:48,valence:'positive',energy:'medium',loopable:false,tags:['interface','match','short-cue'],
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
id:'audio-reject',role:'reject',outFile:'assets/kenney-harvest/audio/reject.mp3',catalogPath:'audio/reject.mp3',
|
|
114
|
-
sourceId:'kenney-interface-sounds',inputs:['assets/kenney-harvest/source/interface-sounds/Audio/error_004.ogg'],
|
|
115
|
-
bitrate:48,valence:'negative',energy:'medium',loopable:false,tags:['interface','reject','short-cue'],
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
id:'audio-victory',role:'complete',catalogRole:'victory',outFile:'assets/kenney-harvest/audio/victory.mp3',catalogPath:'audio/victory.mp3',
|
|
119
|
-
sourceId:'mintodog-cozy-puzzle-jingle',
|
|
120
|
-
author:'MintoDog',license:'CC0-1.0',sourceUrl:'https://opengameart.org/content/cozy-puzzle-jingle-result',
|
|
121
|
-
inputs:['assets/free-audio/victory-cc0/cozy-puzzle-jingle-result/preview_cozy_puzzle_jingle_result.ogg'],
|
|
122
|
-
maxDurationSec:3.75,fadeInSec:0.01,fadeOutSec:0.22,bitrate:48,valence:'positive',energy:'high',loopable:false,tags:['cozy','harp','fanfare','victory','win'],
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
id:'audio-complete',role:'loss',catalogRole:'loss',outFile:'assets/kenney-harvest/audio/complete.mp3',catalogPath:'audio/complete.mp3',
|
|
126
|
-
sourceId:'kenney-music-jingles',inputs:['assets/kenney-harvest/source/music-jingles/OGG/jingles_NES/jingles_NES00.ogg'],
|
|
127
|
-
bitrate:48,valence:'negative',energy:'medium',loopable:false,tags:['nes','timeout','failure'],
|
|
128
|
-
},
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
// 2. Traffic Tycoon (sunny upbeat 3xBlast groove + tactile road-snap + bright chime + joyful Fupi grand-piano victory fanfare)
|
|
132
|
-
const trafficCues=[
|
|
133
|
-
{
|
|
134
|
-
id:'traffic.audio.ambient',role:'ambient',outFile:'assets/tora-traffic/audio/ambient.mp3',
|
|
135
|
-
author:'3xBlast',license:'CC0-1.0',sourceUrl:'https://opengameart.org/content/7-pop-punk-chiptune-tracks',sourceId:'3xblast-pop-punk-chiptune',
|
|
136
|
-
inputs:[trafficMusicSource],maxDurationSec:16,loopFadeSec:0.03,bitrate:32,
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
id:'traffic.audio.tap',role:'tap',outFile:'assets/tora-traffic/audio/tap.mp3',
|
|
140
|
-
author:'Kenney',license:'CC0-1.0',sourceUrl:'https://kenney.nl/assets/interface-sounds',sourceId:'kenney-interface-sounds',
|
|
141
|
-
inputs:['assets/kenney-harvest/source/interface-sounds/Audio/drop_002.ogg'],bitrate:48,
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
id:'traffic.audio.reward',role:'reward',outFile:'assets/tora-traffic/audio/reward.mp3',
|
|
145
|
-
author:'Kenney',license:'CC0-1.0',sourceUrl:'https://kenney.nl/assets/interface-sounds',sourceId:'kenney-interface-sounds',
|
|
146
|
-
inputs:['assets/kenney-harvest/source/interface-sounds/Audio/maximize_006.ogg'],bitrate:48,
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
id:'traffic.audio.win',role:'win',outFile:'assets/tora-traffic/audio/win.mp3',
|
|
150
|
-
author:'Fupi',license:'CC0-1.0',sourceUrl:'https://opengameart.org/content/win-jingle',sourceId:'fupi-win-jingle',
|
|
151
|
-
inputs:['assets/free-audio/victory-cc0/win-jingle/WinGrandPiano.ogg'],
|
|
152
|
-
maxDurationSec:3.0,fadeInSec:0.008,fadeOutSec:0.14,bitrate:48,
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
id:'traffic.audio.loss',role:'loss',outFile:'assets/tora-traffic/audio/loss.mp3',
|
|
156
|
-
author:'Kenney',license:'CC0-1.0',sourceUrl:'https://kenney.nl/assets/music-jingles',sourceId:'kenney-music-jingles',
|
|
157
|
-
inputs:['assets/kenney-harvest/source/music-jingles/OGG/jingles_PIZZA/jingles_PIZZA11.ogg'],bitrate:48,
|
|
158
|
-
},
|
|
159
|
-
];
|
|
160
|
-
|
|
161
|
-
// 3. Mini Golf (sunny island ukulele theme + crisp golf strike/bank/cup SFX + sparkling Listener bells/chimes orchestral victory fanfare)
|
|
162
|
-
const golfCues=[
|
|
163
|
-
{
|
|
164
|
-
id:'golf.audio.ambient',role:'ambient',outFile:'assets/tora-golf/audio/ambient.mp3',
|
|
165
|
-
author:'Tarush Singhal',license:'CC0-1.0',sourceUrl:'https://opengameart.org/content/happy-ukelele-island-surfing-theme',sourceId:'tarush-singhal-happy-ukelele',
|
|
166
|
-
inputs:['assets/free-audio/cozy-warm/source/ukele.mp3'],maxDurationSec:16,loopFadeSec:0.03,bitrate:32,
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
id:'golf.audio.strike',role:'tap',outFile:'assets/tora-golf/audio/strike.mp3',
|
|
170
|
-
author:'Kenney',license:'CC0-1.0',sourceUrl:'https://kenney.nl/assets/interface-sounds',sourceId:'kenney-interface-sounds',
|
|
171
|
-
inputs:['fixtures/mini-golf/audio/strike.ogg'],bitrate:48,
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
id:'golf.audio.bank',role:'bank',outFile:'assets/tora-golf/audio/bank.mp3',
|
|
175
|
-
author:'Kenney',license:'CC0-1.0',sourceUrl:'https://kenney.nl/assets/interface-sounds',sourceId:'kenney-interface-sounds',
|
|
176
|
-
inputs:['fixtures/mini-golf/audio/bank.ogg'],bitrate:48,
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
id:'golf.audio.cup',role:'reward',outFile:'assets/tora-golf/audio/cup.mp3',
|
|
180
|
-
author:'Kenney',license:'CC0-1.0',sourceUrl:'https://kenney.nl/assets/interface-sounds',sourceId:'kenney-interface-sounds',
|
|
181
|
-
inputs:['fixtures/mini-golf/audio/cup.ogg'],bitrate:48,
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
id:'golf.audio.win',role:'win',outFile:'assets/tora-golf/audio/win.mp3',
|
|
185
|
-
author:'Listener',license:'CC0-1.0',sourceUrl:'https://opengameart.org/content/win-sound-effect',sourceId:'listener-win-sound-effect',
|
|
186
|
-
inputs:['assets/free-audio/victory-cc0/win-sound-effect/Win sound.wav'],
|
|
187
|
-
trimClip:true,maxDurationSec:3.0,fadeInSec:0.008,fadeOutSec:0.18,ceiling:0.9,softDrive:1.8,bitrate:48,
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
id:'golf.audio.loss',role:'loss',outFile:'assets/tora-golf/audio/loss.mp3',
|
|
191
|
-
author:'Kenney',license:'CC0-1.0',sourceUrl:'https://kenney.nl/assets/music-jingles',sourceId:'kenney-music-jingles',
|
|
192
|
-
inputs:['assets/kenney-harvest/source/music-jingles/OGG/jingles_STEEL/jingles_STEEL14.ogg'],bitrate:48,
|
|
193
|
-
},
|
|
194
|
-
];
|
|
195
|
-
|
|
196
|
-
async function renderCue(cue){
|
|
197
|
-
const clips=cue.inputs.map(input=>{
|
|
198
|
-
const pcm=decodeToPcmFloat(input);
|
|
199
|
-
return (cue.inputs.length>1||cue.trimClip)?trimSilence(pcm):pcm;
|
|
200
|
-
});
|
|
201
|
-
const joined=crossfadeJoin(clips,cue.overlapSec??0.04);
|
|
202
|
-
const shortTransient=cue.inputs.length===1&&!cue.maxDurationSec&&!cue.trimClip&&joined.length<RATE*0.08;
|
|
203
|
-
const pcm16=masterPcm(joined,{
|
|
204
|
-
startSec:cue.startSec??0,
|
|
205
|
-
maxDurationSec:cue.maxDurationSec,
|
|
206
|
-
loopFadeSec:cue.loopFadeSec??0,
|
|
207
|
-
fadeInSec:cue.fadeInSec,
|
|
208
|
-
fadeOutSec:cue.fadeOutSec,
|
|
209
|
-
ceiling:cue.ceiling??0.87,
|
|
210
|
-
softDrive:cue.softDrive??1,
|
|
211
|
-
fadeSec:shortTransient?0:(cue.inputs.length===1&&!cue.maxDurationSec?0.004:0.015),
|
|
212
|
-
});
|
|
213
|
-
const mp3=encodeMp3(pcm16,cue.bitrate);
|
|
214
|
-
await mkdir(resolve(root,cue.outFile,'..'),{recursive:true});
|
|
215
|
-
await writeFile(resolve(root,cue.outFile),mp3);
|
|
216
|
-
const analysis=analyzeAudio(mp3,'audio/mpeg');
|
|
217
|
-
const sourceHashes=await Promise.all(cue.inputs.map(async f=>hash(await readFile(resolve(root,f)))));
|
|
218
|
-
return {
|
|
219
|
-
...cue,
|
|
220
|
-
bytes:mp3.length,
|
|
221
|
-
sha256:hash(mp3),
|
|
222
|
-
sourceHashes,
|
|
223
|
-
analysis,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const harvestOut=await Promise.all(harvestCues.map(renderCue));
|
|
228
|
-
const trafficOut=await Promise.all(trafficCues.map(renderCue));
|
|
229
|
-
const golfOut=await Promise.all(golfCues.map(renderCue));
|
|
230
|
-
|
|
231
|
-
// Verify zero shared inputs or SHA-256 hashes across all 3 games!
|
|
232
|
-
const allGroups={harvest:harvestOut,traffic:trafficOut,golf:golfOut};
|
|
233
|
-
const seenInputs=new Map(),seenHashes=new Map();
|
|
234
|
-
for(const [game,list]of Object.entries(allGroups)){
|
|
235
|
-
for(const item of list){
|
|
236
|
-
for(const inp of item.inputs){
|
|
237
|
-
if(seenInputs.has(inp)&&seenInputs.get(inp)!==game)throw Error(`Duplicate audio source ${inp} across ${seenInputs.get(inp)} and ${game}`);
|
|
238
|
-
seenInputs.set(inp,game);
|
|
239
|
-
}
|
|
240
|
-
if(seenHashes.has(item.sha256))throw Error(`Duplicate MP3 hash ${item.sha256} for ${item.id}`);
|
|
241
|
-
seenHashes.set(item.sha256,`${game}:${item.id}`);
|
|
242
|
-
if(item.analysis.clipping)throw Error(`Clipping detected in ${game}:${item.id}`);
|
|
243
|
-
if(['win','complete'].includes(item.role)){
|
|
244
|
-
if(item.analysis.trimmedDurationSec<1.6)throw Error(`Win fanfare ${game}:${item.id} too short: ${item.analysis.trimmedDurationSec}s`);
|
|
245
|
-
if(item.analysis.pitchContour==='falling')throw Error(`Win fanfare ${game}:${item.id} has falling contour!`);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Update assets/free-assets/catalog.json (preserving ALL 20 legacy audio/wav entries untouched!)
|
|
251
|
-
const catalogFile=resolve(root,'assets/free-assets/catalog.json');
|
|
252
|
-
const catalog=JSON.parse(await readFile(catalogFile,'utf8'));
|
|
253
|
-
const mintoLicenseFile='assets/free-audio/victory-cc0/cozy-puzzle-jingle-result/source-page.html';
|
|
254
|
-
const mintoArchiveFile='assets/free-audio/victory-cc0/cozy-puzzle-jingle-result/preview_cozy_puzzle_jingle_result.ogg';
|
|
255
|
-
const mintoSourceMeta={
|
|
256
|
-
id:'mintodog-cozy-puzzle-jingle',
|
|
257
|
-
author:'MintoDog',
|
|
258
|
-
license:'CC0-1.0',
|
|
259
|
-
sourceUrl:'https://opengameart.org/content/cozy-puzzle-jingle-result',
|
|
260
|
-
styleFamily:'cozy-acoustic-audio',
|
|
261
|
-
licenseFile:mintoLicenseFile,
|
|
262
|
-
licenseUrl:'https://creativecommons.org/publicdomain/zero/1.0/',
|
|
263
|
-
licenseSha256:hash(await readFile(resolve(root,mintoLicenseFile))),
|
|
264
|
-
archive:{
|
|
265
|
-
url:'https://opengameart.org/sites/default/files/preview_cozy_puzzle_jingle_result.ogg',
|
|
266
|
-
sha256:hash(await readFile(resolve(root,mintoArchiveFile))),
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
const existingMinto=catalog.sources.find(s=>s.id==='mintodog-cozy-puzzle-jingle');
|
|
270
|
-
if(existingMinto){
|
|
271
|
-
Object.assign(existingMinto,mintoSourceMeta);
|
|
272
|
-
delete existingMinto.title;
|
|
273
|
-
delete existingMinto.attributionRequired;
|
|
274
|
-
delete existingMinto.role;
|
|
275
|
-
}else{
|
|
276
|
-
catalog.sources.push({...mintoSourceMeta,files:[]});
|
|
277
|
-
}
|
|
278
|
-
for(const item of harvestOut){
|
|
279
|
-
const source=catalog.sources.find(s=>s.id===item.sourceId);
|
|
280
|
-
if(!source)throw Error(`Missing catalog source ${item.sourceId}`);
|
|
281
|
-
const metaFields={...item.analysis};
|
|
282
|
-
delete metaFields.startHz;delete metaFields.endHz;delete metaFields.pitchContour;
|
|
283
|
-
// Remove any stale victory.mp3 from kenney-music-jingles when moving victory.mp3 to MintoDog
|
|
284
|
-
if(item.catalogPath==='audio/victory.mp3'){
|
|
285
|
-
for(const s of catalog.sources)if(s.id!==item.sourceId)s.files=s.files.filter(f=>f.path!=='audio/victory.mp3');
|
|
286
|
-
}
|
|
287
|
-
const record={
|
|
288
|
-
path:item.catalogPath,
|
|
289
|
-
file:item.outFile,
|
|
290
|
-
mime:'audio/mpeg',
|
|
291
|
-
sha256:item.sha256,
|
|
292
|
-
audioMeta:{
|
|
293
|
-
role:item.catalogRole??item.role,
|
|
294
|
-
valence:item.valence,
|
|
295
|
-
energy:item.energy,
|
|
296
|
-
styleTags:item.tags,
|
|
297
|
-
loopable:item.loopable,
|
|
298
|
-
auditionStatus:'analyzed',
|
|
299
|
-
...metaFields,
|
|
300
|
-
},
|
|
301
|
-
processing:{
|
|
302
|
-
kind:'audio-transcode',
|
|
303
|
-
sourceFile:item.inputs[0],
|
|
304
|
-
sourceSha256:item.sourceHashes[0],
|
|
305
|
-
tool:'GStreamer lamemp3enc',
|
|
306
|
-
arguments:['mono',`${RATE} Hz`,'MP3',`${item.bitrate} kbps`,...(item.inputs.length>1?['phrase-join',...item.inputs]:[]),...(item.maxDurationSec?[`first ${item.maxDurationSec}s`,item.loopFadeSec?'30ms loop fade':'fade out']:['full duration'])],
|
|
307
|
-
},
|
|
308
|
-
};
|
|
309
|
-
source.files=source.files.filter(f=>f.path!==item.catalogPath);
|
|
310
|
-
source.files.push(record);
|
|
311
|
-
}
|
|
312
|
-
await writeFile(catalogFile,JSON.stringify(catalog,null,2)+'\n');
|
|
313
|
-
|
|
314
|
-
// Update assets/kenney-harvest/plan.json to use the compressed MP3 audio + longer rising victory fanfare
|
|
315
|
-
const harvestPlanFile=resolve(root,'assets/kenney-harvest/plan.json');
|
|
316
|
-
const harvestPlan=JSON.parse(await readFile(harvestPlanFile,'utf8'));
|
|
317
|
-
harvestPlan.assets=harvestPlan.assets.filter(a=>!a.id.startsWith('audio-'));
|
|
318
|
-
harvestPlan.audio={};
|
|
319
|
-
for(const item of harvestOut){
|
|
320
|
-
const source=catalog.sources.find(s=>s.id===item.sourceId);
|
|
321
|
-
harvestPlan.assets.push({
|
|
322
|
-
id:item.id,
|
|
323
|
-
file:item.catalogPath,
|
|
324
|
-
mime:'audio/mpeg',
|
|
325
|
-
rights:`${source.author}, CC0-1.0. ${source.sourceUrl}`,
|
|
326
|
-
provenance:{
|
|
327
|
-
origin:'third-party-free',
|
|
328
|
-
sourceId:source.id,
|
|
329
|
-
sourceFile:item.catalogPath,
|
|
330
|
-
sourceHash:item.sha256,
|
|
331
|
-
author:source.author,
|
|
332
|
-
license:source.license,
|
|
333
|
-
sourceUrl:source.sourceUrl,
|
|
334
|
-
styleFamily:source.styleFamily,
|
|
335
|
-
},
|
|
336
|
-
});
|
|
337
|
-
harvestPlan.audio[item.role]=item.id;
|
|
338
|
-
}
|
|
339
|
-
await writeFile(harvestPlanFile,JSON.stringify(harvestPlan,null,2)+'\n');
|
|
340
|
-
|
|
341
|
-
// Write dedicated audio plans for Traffic Tycoon and Mini Golf
|
|
342
|
-
function writeGameAudioPlan(dest,list){
|
|
343
|
-
const payload={
|
|
344
|
-
format:'tora-game-audio-plan-1',
|
|
345
|
-
files:list.map(item=>({
|
|
346
|
-
id:item.id,
|
|
347
|
-
role:item.role,
|
|
348
|
-
file:item.outFile,
|
|
349
|
-
mime:'audio/mpeg',
|
|
350
|
-
bytes:item.bytes,
|
|
351
|
-
sha256:item.sha256,
|
|
352
|
-
durationSec:item.analysis.durationSec,
|
|
353
|
-
trimmedDurationSec:item.analysis.trimmedDurationSec,
|
|
354
|
-
pitchContour:item.analysis.pitchContour,
|
|
355
|
-
rights:`${item.author}; ${item.license}; ${item.sourceUrl}; attribution required: no`,
|
|
356
|
-
provenance:{
|
|
357
|
-
sourceId:item.sourceId,
|
|
358
|
-
sourceFiles:item.inputs,
|
|
359
|
-
sourceHashes:item.sourceHashes,
|
|
360
|
-
license:item.license,
|
|
361
|
-
tool:'GStreamer lamemp3enc',
|
|
362
|
-
bitrateKbps:item.bitrate,
|
|
363
|
-
},
|
|
364
|
-
})),
|
|
365
|
-
};
|
|
366
|
-
return writeFile(resolve(root,dest),JSON.stringify(payload,null,2)+'\n');
|
|
367
|
-
}
|
|
368
|
-
await writeGameAudioPlan('assets/tora-traffic/audio-plan.json',trafficOut);
|
|
369
|
-
await writeGameAudioPlan('assets/tora-golf/audio-plan.json',golfOut);
|
|
370
|
-
|
|
371
|
-
const summary=Object.fromEntries(Object.entries(allGroups).map(([game,list])=>[game,list.map(x=>({id:x.id,role:x.role,bytes:x.bytes,dur:Number(x.analysis.durationSec.toFixed(2)),trim:Number(x.analysis.trimmedDurationSec.toFixed(2)),contour:x.analysis.pitchContour,peak:Number(x.analysis.peakDbfs.toFixed(1))}))]));
|
|
372
|
-
process.stdout.write(JSON.stringify(summary,null,2)+'\n');
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
"""Convert immutable CC0 Kenney minigolf-kit OBJ models into strict TORA3DM1 binary meshes + compact end-card PNGs."""
|
|
3
|
-
import hashlib
|
|
4
|
-
import json
|
|
5
|
-
import struct
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
from PIL import Image
|
|
8
|
-
|
|
9
|
-
ROOT = Path(__file__).resolve().parents[3]
|
|
10
|
-
MODELS_DIR = ROOT / "fixtures" / "mini-golf" / "models"
|
|
11
|
-
TEX_SRC = MODELS_DIR / "Textures" / "colormap.png"
|
|
12
|
-
ICON_DIR = ROOT / "assets" / "tora-golf" / "imported"
|
|
13
|
-
OUT_DIR = ROOT / "assets" / "tora-golf" / "3d"
|
|
14
|
-
PLAN_PATH = ROOT / "assets" / "tora-golf" / "plan.json"
|
|
15
|
-
OUT_DIR.mkdir(parents=True, exist_ok=True)
|
|
16
|
-
|
|
17
|
-
MESH_NAMES = [
|
|
18
|
-
"open",
|
|
19
|
-
"obstacle-block",
|
|
20
|
-
"structure-gate",
|
|
21
|
-
"castle",
|
|
22
|
-
"flag-red",
|
|
23
|
-
"ball-blue",
|
|
24
|
-
"support",
|
|
25
|
-
]
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def sha256_bytes(data: bytes) -> str:
|
|
29
|
-
return "sha256:" + hashlib.sha256(data).hexdigest()
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def parse_obj_to_tora3dm1(obj_path: Path) -> tuple[bytes, int, int]:
|
|
33
|
-
positions: list[tuple[float, float, float]] = []
|
|
34
|
-
normals: list[tuple[float, float, float]] = []
|
|
35
|
-
uvs: list[tuple[float, float]] = []
|
|
36
|
-
vert_map: dict[tuple[int, int, int], int] = {}
|
|
37
|
-
vertices: list[tuple[float, float, float, float, float, float, float, float]] = []
|
|
38
|
-
indices: list[int] = []
|
|
39
|
-
|
|
40
|
-
def resolve_idx(raw: str, count: int) -> int:
|
|
41
|
-
if not raw:
|
|
42
|
-
return -1
|
|
43
|
-
idx = int(raw)
|
|
44
|
-
return idx - 1 if idx > 0 else count + idx
|
|
45
|
-
|
|
46
|
-
for line in obj_path.read_text(encoding="utf-8").splitlines():
|
|
47
|
-
line = line.strip()
|
|
48
|
-
if not line or line.startswith("#"):
|
|
49
|
-
continue
|
|
50
|
-
parts = line.split()
|
|
51
|
-
tag = parts[0]
|
|
52
|
-
if tag == "v" and len(parts) >= 4:
|
|
53
|
-
positions.append((float(parts[1]), float(parts[2]), float(parts[3])))
|
|
54
|
-
elif tag == "vn" and len(parts) >= 4:
|
|
55
|
-
normals.append((float(parts[1]), float(parts[2]), float(parts[3])))
|
|
56
|
-
elif tag == "vt" and len(parts) >= 3:
|
|
57
|
-
uvs.append((float(parts[1]), float(parts[2])))
|
|
58
|
-
elif tag == "f" and len(parts) >= 4:
|
|
59
|
-
face_verts = []
|
|
60
|
-
for tok in parts[1:]:
|
|
61
|
-
segs = tok.split("/")
|
|
62
|
-
vi = resolve_idx(segs[0], len(positions))
|
|
63
|
-
ti = resolve_idx(segs[1], len(uvs)) if len(segs) > 1 and segs[1] else -1
|
|
64
|
-
ni = resolve_idx(segs[2], len(normals)) if len(segs) > 2 and segs[2] else -1
|
|
65
|
-
key = (vi, ti, ni)
|
|
66
|
-
if key not in vert_map:
|
|
67
|
-
px, py, pz = positions[vi]
|
|
68
|
-
nx, ny, nz = normals[ni] if 0 <= ni < len(normals) else (0.0, 1.0, 0.0)
|
|
69
|
-
u, v = uvs[ti] if 0 <= ti < len(uvs) else (0.0, 0.0)
|
|
70
|
-
vert_map[key] = len(vertices)
|
|
71
|
-
vertices.append((px, py, pz, nx, ny, nz, u, v))
|
|
72
|
-
face_verts.append(vert_map[key])
|
|
73
|
-
for k in range(1, len(face_verts) - 1):
|
|
74
|
-
indices.extend((face_verts[0], face_verts[k], face_verts[k + 1]))
|
|
75
|
-
|
|
76
|
-
assert 1 <= len(vertices) <= 65535, f"Vertex count out of bounds: {len(vertices)}"
|
|
77
|
-
assert 3 <= len(indices) <= 196605 and len(indices) % 3 == 0, f"Index count out of bounds: {len(indices)}"
|
|
78
|
-
|
|
79
|
-
buf = bytearray()
|
|
80
|
-
buf.extend(b"TORA3DM1")
|
|
81
|
-
buf.extend(struct.pack("<II", len(vertices), len(indices)))
|
|
82
|
-
for v in vertices:
|
|
83
|
-
buf.extend(struct.pack("<8f", *v))
|
|
84
|
-
for idx in indices:
|
|
85
|
-
buf.extend(struct.pack("<H", idx))
|
|
86
|
-
return bytes(buf), len(vertices), len(indices)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def save_quantized_png(src: Path, dest: Path, max_size: int = 160) -> bytes:
|
|
90
|
-
im = Image.open(src).convert("RGBA")
|
|
91
|
-
if max(im.size) > max_size:
|
|
92
|
-
im.thumbnail((max_size, max_size), Image.Resampling.LANCZOS)
|
|
93
|
-
q = im.quantize(colors=256, method=Image.Quantize.FASTOCTREE, dither=Image.Dither.NONE)
|
|
94
|
-
q.save(dest, format="PNG", optimize=True)
|
|
95
|
-
return dest.read_bytes()
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
files = []
|
|
99
|
-
|
|
100
|
-
# 1. Shared Kenney minigolf-kit colormap texture (verbatim CC0 PNG)
|
|
101
|
-
tex_dest = OUT_DIR / "colormap.png"
|
|
102
|
-
tex_bytes = TEX_SRC.read_bytes()
|
|
103
|
-
tex_dest.write_bytes(tex_bytes)
|
|
104
|
-
files.append({
|
|
105
|
-
"id": "golf.colormap",
|
|
106
|
-
"mime": "image/png",
|
|
107
|
-
"file": str(tex_dest.relative_to(ROOT)),
|
|
108
|
-
"bytes": len(tex_bytes),
|
|
109
|
-
"sha256": sha256_bytes(tex_bytes),
|
|
110
|
-
"processing": {
|
|
111
|
-
"kind": "png-verbatim-copy",
|
|
112
|
-
"sourceFile": str(TEX_SRC.relative_to(ROOT)),
|
|
113
|
-
"sourceSha256": sha256_bytes(tex_bytes),
|
|
114
|
-
},
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
# 2. Seven Kenney minigolf-kit 3D meshes -> TORA3DM1 binary assets
|
|
118
|
-
for name in MESH_NAMES:
|
|
119
|
-
src = MODELS_DIR / f"{name}.obj"
|
|
120
|
-
mesh_bytes, vcount, icount = parse_obj_to_tora3dm1(src)
|
|
121
|
-
dest = OUT_DIR / f"{name}.t3d"
|
|
122
|
-
dest.write_bytes(mesh_bytes)
|
|
123
|
-
files.append({
|
|
124
|
-
"id": f"mesh.{name}",
|
|
125
|
-
"mime": "model/tora-mesh",
|
|
126
|
-
"file": str(dest.relative_to(ROOT)),
|
|
127
|
-
"bytes": len(mesh_bytes),
|
|
128
|
-
"vertexCount": vcount,
|
|
129
|
-
"indexCount": icount,
|
|
130
|
-
"sha256": sha256_bytes(mesh_bytes),
|
|
131
|
-
"processing": {
|
|
132
|
-
"kind": "obj-to-tora3dm1",
|
|
133
|
-
"sourceFile": str(src.relative_to(ROOT)),
|
|
134
|
-
"sourceSha256": sha256_bytes(src.read_bytes()),
|
|
135
|
-
},
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
# 3. Crisp high-contrast hero badges for Win & Timeout end cards (rendered from Kenney minigolf-kit)
|
|
139
|
-
for icon_id, filename, max_sz in [
|
|
140
|
-
("golf.flag", "golf.flag.png", 160),
|
|
141
|
-
("golf.club", "golf.club.png", 160),
|
|
142
|
-
("golf.castle", "golf.castle.png", 192),
|
|
143
|
-
("golf.windmill", "golf.windmill.png", 192),
|
|
144
|
-
]:
|
|
145
|
-
src = ICON_DIR / filename
|
|
146
|
-
dest = OUT_DIR / filename
|
|
147
|
-
data = save_quantized_png(src, dest, max_size=max_sz)
|
|
148
|
-
files.append({
|
|
149
|
-
"id": icon_id,
|
|
150
|
-
"mime": "image/png",
|
|
151
|
-
"file": str(dest.relative_to(ROOT)),
|
|
152
|
-
"bytes": len(data),
|
|
153
|
-
"sha256": sha256_bytes(data),
|
|
154
|
-
"processing": {
|
|
155
|
-
"kind": "png8-quantize",
|
|
156
|
-
"sourceFile": str(src.relative_to(ROOT)),
|
|
157
|
-
"sourceSha256": sha256_bytes(src.read_bytes()),
|
|
158
|
-
},
|
|
159
|
-
})
|
|
160
|
-
|
|
161
|
-
plan = {
|
|
162
|
-
"format": "tora-native-3d-asset-plan-1",
|
|
163
|
-
"source": {
|
|
164
|
-
"id": "kenney-minigolf-kit",
|
|
165
|
-
"author": "Kenney",
|
|
166
|
-
"sourceUrl": "https://kenney.nl/assets/minigolf-kit",
|
|
167
|
-
"license": "CC0-1.0",
|
|
168
|
-
"licenseUrl": "https://creativecommons.org/publicdomain/zero/1.0/",
|
|
169
|
-
"attributionRequired": False,
|
|
170
|
-
},
|
|
171
|
-
"visualDirection": "Exact sunlit 3D Three.js WebGL2 Mini Golf Challenge diorama using Kenney CC0 minigolf-kit 3D geometry, continuous fairway with circular cup cutout, animated pennant, bank rails, moving gate, and uphill ramp.",
|
|
172
|
-
"files": files,
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
PLAN_PATH.write_text(json.dumps(plan, indent=2) + "\n")
|
|
176
|
-
total_bytes = sum(f["bytes"] for f in files)
|
|
177
|
-
print(f"Prepared {len(files)} 3D Mini Golf assets ({total_bytes} bytes total) -> {PLAN_PATH.relative_to(ROOT)}")
|