资源加载,bgm和音效播放

This commit is contained in:
AncTe committed 2023-06-21 17:10:06 +08:00
1 parent 6f59ea51ac
commit 5aed6393a2
16 files changed
+289 -52

No files matched your search

+4
View File
@@ -56,6 +56,10 @@ const compress = type === 'dist';
await fs.remove('./dist/_server');
await fs.remove('./dist/editor.html');
await fs.remove('./dist/server.cjs');
await fs.remove('./dist/project/materials/airwall.png');
await fs.remove('./dist/project/materials/ground.png');
await fs.remove('./dist/project/materials/icons_old.png');
} catch {}
// 2. 压缩字体
+39 -1
View File
@@ -254,7 +254,7 @@ async function writeFile(req: Request, res: Response) {
if (name.endsWith('project/events.js')) doDeclaration('events', value);
if (name.endsWith('project/items.js')) doDeclaration('items', value);
if (name.endsWith('project/maps.js')) doDeclaration('maps', value);
if (name.endsWith('project/data.js')) doDeclaration('data', value);
if (name.endsWith('project/data.js')) writeDevResource(value);
} catch (e) {
console.log(e);
res.end(
@@ -315,6 +315,44 @@ async function writeMultiFiles(req: Request, res: Response) {
res.end();
}
async function writeDevResource(data: string) {
try {
const buf = Buffer.from(data, 'base64');
data = buf.toString('utf-8');
const info = JSON.parse(data.split('\n').slice(1).join(''));
const res: string[] = [];
const icons = await fs.readFile('./public/project/icons.js', 'utf-8');
const iconData = JSON.parse(icons.split('\n').slice(1).join(''));
res.push(
...info.main.animates.map((v: any) => `animates.${v}.animate`),
...info.main.bgms.map((v: any) => `bgms.${v}`),
...info.main.fonts.map((v: any) => `fonts.${v}.ttf`),
...info.main.images.map((v: any) => `images.${v}`),
...info.main.sounds.map((v: any) => `sounds.${v}`),
...info.main.tilesets.map((v: any) => `tilesets.${v}`),
...Object.keys(iconData.autotile).map(v => `autotiles.${v}.png`),
...[
'animates',
'cloud',
'enemy48',
'enemys',
'fog',
'icons',
'items',
'keyboard',
'npc48',
'npcs',
'sun',
'terrains'
].map(v => `materials.${v}.png`)
);
const text = JSON.stringify(res, void 0, 4);
await fs.writeFile('./src/data/resource-dev.json', text, 'utf-8');
} catch (e) {
console.log(e);
}
}
/**
* 声明某种类型
* @param {string} type 类型