mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-02-26 16:17:05 +08:00
资源分离完成
This commit is contained in:
parent
1bdfb9be7d
commit
7a196b5922
@ -1,6 +1,7 @@
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { uniqueSymbol } from './utils.js';
|
import { uniqueSymbol } from './utils.js';
|
||||||
import { extname, resolve } from 'path';
|
import { basename, extname, resolve } from 'path';
|
||||||
|
import { dirname } from 'path';
|
||||||
|
|
||||||
type ResorceType =
|
type ResorceType =
|
||||||
| 'bgms'
|
| 'bgms'
|
||||||
@ -96,21 +97,26 @@ async function doSplit(compress: boolean) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let currSize = 0;
|
let currSize = 0;
|
||||||
|
const length = Object.fromEntries(
|
||||||
|
priority.map(v => [v, dirInfo[v].length])
|
||||||
|
);
|
||||||
|
const soruceIndex: Record<string, number> = {};
|
||||||
const split = async (index: number): Promise<void> => {
|
const split = async (index: number): Promise<void> => {
|
||||||
size -= currSize;
|
size -= currSize;
|
||||||
currSize = 0;
|
currSize = 0;
|
||||||
|
|
||||||
const cut: string[] = [];
|
const cut: string[] = [];
|
||||||
|
|
||||||
(() => {
|
|
||||||
const mapped: ResorceType[] = [];
|
const mapped: ResorceType[] = [];
|
||||||
while (1) {
|
while (1) {
|
||||||
const toCut = priority.find(
|
const toCut = priority.find(
|
||||||
v => dirInfo[v].length > 0 && !mapped.includes(v)
|
v => dirInfo[v].length > 0 && !mapped.includes(v)
|
||||||
);
|
);
|
||||||
if (!toCut) return;
|
if (!toCut) break;
|
||||||
|
|
||||||
mapped.push(toCut);
|
mapped.push(toCut);
|
||||||
|
const l = dirInfo[toCut].length;
|
||||||
|
const data: string[] = [];
|
||||||
|
|
||||||
let pass = 0;
|
let pass = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -123,12 +129,18 @@ async function doSplit(compress: boolean) {
|
|||||||
pass++;
|
pass++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cut.push(`${toCut}/${stat.name}`);
|
data.push(`${toCut}/${stat.name}`);
|
||||||
stats.splice(pass, 1);
|
stats.splice(pass, 1);
|
||||||
currSize += stat.size;
|
currSize += stat.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (l === length[toCut] && dirInfo[toCut].length === 0) {
|
||||||
|
soruceIndex[`${toCut}.*`] = index;
|
||||||
|
} else {
|
||||||
|
data.map(v => (soruceIndex[v] = index));
|
||||||
|
}
|
||||||
|
cut.push(...data);
|
||||||
}
|
}
|
||||||
})();
|
|
||||||
|
|
||||||
const dir = `./dist-resource/${index}`;
|
const dir = `./dist-resource/${index}`;
|
||||||
await fs.ensureDir(dir);
|
await fs.ensureDir(dir);
|
||||||
@ -138,7 +150,11 @@ async function doSplit(compress: boolean) {
|
|||||||
cut.map(v =>
|
cut.map(v =>
|
||||||
fs.move(
|
fs.move(
|
||||||
resolve('./dist/project', v),
|
resolve('./dist/project', v),
|
||||||
resolve(dir, `${v}-${SYMBOL}`)
|
resolve(
|
||||||
|
dir,
|
||||||
|
dirname(v),
|
||||||
|
`${basename(v).split('.')[0]}-${SYMBOL}${extname(v)}`
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -148,4 +164,25 @@ async function doSplit(compress: boolean) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await split(0);
|
await split(0);
|
||||||
|
|
||||||
|
await rewriteMain(soruceIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function rewriteMain(sourceIndex: Record<string, number>) {
|
||||||
|
const main = await fs.readFile('./dist/main.js', 'utf-8');
|
||||||
|
const res = main
|
||||||
|
.replace(/this\.USE_RESOURCE\s*\=\s*false/, 'this.USE_RESOURCE = true')
|
||||||
|
.replace(
|
||||||
|
/this\.RESOURCE_URL\s*\=\s*'.*'/,
|
||||||
|
"this.RESOURCE_URL = '/games/HumanBreakRes/'"
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
/this\.RESOURCE_SYMBOL\s*\=\s*'.*'/,
|
||||||
|
`this.RESOURCE_SYMBOL = '${SYMBOL}'`
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
/this\.RESOURCE_INDEX\s*\=\s*\{.*\}/,
|
||||||
|
`this.RESOURCE_INDEX = ${JSON.stringify(sourceIndex, void 0, 8)}`
|
||||||
|
);
|
||||||
|
await fs.writeFile('./dist/main.js', res, 'utf-8');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user