218 lines
8.9 KiB
JavaScript
218 lines
8.9 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Config = void 0;
|
|
const node_xlsx_1 = __importDefault(require("node-xlsx"));
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const path_1 = __importDefault(require("path"));
|
|
const Utils_1 = require("./Utils");
|
|
const ROOM_COUNT = 7;
|
|
class Config {
|
|
constructor(projectDir, xlsxPath, xxtea) {
|
|
this.assetsDir = path_1.default.join(projectDir, 'assets');
|
|
const buildJson = fs_1.default.readFileSync(path_1.default.join(projectDir, 'build', 'build.json'));
|
|
const buildData = JSON.parse(buildJson.toString());
|
|
this.uuidMap = buildData.uuid;
|
|
const gameConfigPath = path_1.default.join(this.assetsDir, 'resources', 'conf', 'allConf.json');
|
|
const gameConfigContent = fs_1.default.readFileSync(gameConfigPath);
|
|
this.gameConfig = JSON.parse(gameConfigContent.toString());
|
|
this.packageMap = {};
|
|
for (let db in buildData.pac) {
|
|
const url = buildData.pac[db];
|
|
const name = url.substring(url.lastIndexOf('\\') + 1, url.lastIndexOf('.'));
|
|
this.packageMap[name] = this.packageMap[name] || [];
|
|
this.packageMap[name].push(db);
|
|
}
|
|
this.subpackageContentData = {};
|
|
const data = node_xlsx_1.default.parse(xlsxPath);
|
|
for (const item of data) {
|
|
switch (item.name) {
|
|
case 'Subpackage':
|
|
this.subpackageInfoData = this.decodeSubpackageInfoData(item.data);
|
|
break;
|
|
default:
|
|
this.subpackageContentData[item.name] = this.initializeSubpackageData(item.data);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
dataArrayToObjectArray(data) {
|
|
const title = data.shift();
|
|
const objArray = [];
|
|
for (const dataItem of data) {
|
|
const dataObj = {};
|
|
for (let i = 0, length = title.length; i < length; i++) {
|
|
const key = title[i];
|
|
if (!key)
|
|
break;
|
|
dataObj[key] = dataItem[i];
|
|
}
|
|
objArray.push(dataObj);
|
|
}
|
|
return objArray;
|
|
}
|
|
decodeSubpackageInfoData(data) {
|
|
const subpackageInfoData = {};
|
|
data.splice(1, 1);
|
|
const objArray = this.dataArrayToObjectArray(data);
|
|
for (const obj of objArray) {
|
|
obj.name && (subpackageInfoData[obj.key] = { key: obj.key, name: obj.name, des: obj.des });
|
|
}
|
|
return subpackageInfoData;
|
|
}
|
|
initializeSubpackageData(data) {
|
|
const files = [];
|
|
data.splice(1, 1);
|
|
const objArray = this.dataArrayToObjectArray(data);
|
|
for (const obj of objArray) {
|
|
const path = obj.path;
|
|
const type = parseInt(obj.type);
|
|
files.push({ path, type });
|
|
}
|
|
return files;
|
|
}
|
|
getUUIDsInPath(filePath, uuids) {
|
|
uuids = uuids || [];
|
|
this.uuidMap.forEach(value => {
|
|
const db = value.db.substring(12);
|
|
if (!db.startsWith(filePath))
|
|
return;
|
|
if (uuids.findIndex(item => item.uuid === value.uuid) >= 0)
|
|
return;
|
|
uuids.push(value);
|
|
});
|
|
return uuids;
|
|
}
|
|
getUUIDsByRegExp(regExp, uuids) {
|
|
uuids = uuids || [];
|
|
this.uuidMap.forEach(value => {
|
|
const db = value.db.substring(12);
|
|
if (!regExp.test(db))
|
|
return;
|
|
if (uuids.findIndex(item => item.uuid === value.uuid) >= 0)
|
|
return;
|
|
uuids.push(value);
|
|
});
|
|
return uuids;
|
|
}
|
|
updatePackageAssets(uuids) {
|
|
for (const fileName in this.packageMap) {
|
|
const packageDBs = this.packageMap[fileName];
|
|
let match = true;
|
|
const removedUUIDs = [];
|
|
for (const packageDB of packageDBs) {
|
|
const index = uuids.findIndex(value => value.db === packageDB);
|
|
match = index >= 0;
|
|
if (match) {
|
|
removedUUIDs.push(...uuids.splice(index, 1));
|
|
}
|
|
else {
|
|
uuids.push(...removedUUIDs);
|
|
match = false;
|
|
break;
|
|
}
|
|
}
|
|
match && uuids.push({ db: null, uuid: fileName });
|
|
}
|
|
return uuids;
|
|
}
|
|
decodeRoomFishData() {
|
|
const filesRoomData = {};
|
|
const fishAttribute = this.dataArrayToObjectArray(this.gameConfig['FishAttribute']);
|
|
for (const fish of fishAttribute) {
|
|
const fishName = fish.name;
|
|
if (!fishName)
|
|
continue;
|
|
this.updateRoomFishData(filesRoomData, `resources/anim/clip/fish/${fishName}`, fish);
|
|
this.updateRoomFishData(filesRoomData, `res/anim/texture/fish/${fishName}`, fish);
|
|
;
|
|
this.updateRoomFishData(filesRoomData, `resources/spine/fish/play/${fishName}`, fish);
|
|
this.updateRoomFishData(filesRoomData, `res/spine/fish/play/${fishName}`, fish);
|
|
}
|
|
return filesRoomData;
|
|
}
|
|
updateRoomFishData(container, key, fish) {
|
|
const exitsData = container[key] || {};
|
|
for (let i = 1; i <= ROOM_COUNT; i++) {
|
|
exitsData[i] = exitsData[i] || (fish[`room${i}`] === 1);
|
|
}
|
|
container[key] = exitsData;
|
|
}
|
|
initExcelSubpackage(config) {
|
|
const fileRoomData = this.decodeRoomFishData();
|
|
Utils_1.Utils.log(`fileRoomData: ${JSON.stringify(fileRoomData)}`, Utils_1.Utils.LogLevel.Particular);
|
|
for (const key in this.subpackageContentData) {
|
|
Utils_1.Utils.log(`-------------------------------------------Decode package [${key}] config---------------------------------------------------`, Utils_1.Utils.LogLevel.Particular);
|
|
const uuids = [];
|
|
const files = this.subpackageContentData[key];
|
|
const roomTypes = [];
|
|
const excludeRoomTypes = [];
|
|
for (const file of files) {
|
|
switch (file.type) {
|
|
case 1:
|
|
{
|
|
Utils_1.Utils.log(`Add path: ${file.path}`, Utils_1.Utils.LogLevel.Particular);
|
|
this.getUUIDsInPath(file.path, uuids);
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
Utils_1.Utils.log(`Add path: ${file.path}`, Utils_1.Utils.LogLevel.Particular);
|
|
const regexp = new RegExp(file.path, 'i');
|
|
this.getUUIDsByRegExp(regexp, uuids);
|
|
}
|
|
break;
|
|
case 3:
|
|
{
|
|
const roomType = parseInt(file.path);
|
|
roomTypes.indexOf(roomType) >= 0 || roomTypes.push(roomType);
|
|
}
|
|
break;
|
|
case 4:
|
|
{
|
|
const roomType = parseInt(file.path);
|
|
excludeRoomTypes.indexOf(roomType) >= 0 || excludeRoomTypes.push(roomType);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (roomTypes.length || excludeRoomTypes.length) {
|
|
for (const filePath in fileRoomData) {
|
|
let isSubFile = true;
|
|
const data = fileRoomData[filePath];
|
|
for (let i = 0; i < roomTypes.length && isSubFile; i++) {
|
|
const roomType = roomTypes[i];
|
|
if (!data[roomType])
|
|
isSubFile = false;
|
|
}
|
|
for (let i = 0; i < excludeRoomTypes.length && isSubFile; i++) {
|
|
const roomType = excludeRoomTypes[i];
|
|
if (data[roomType])
|
|
isSubFile = false;
|
|
}
|
|
if (isSubFile) {
|
|
Utils_1.Utils.log(`Add path: ${filePath}`, Utils_1.Utils.LogLevel.Particular);
|
|
this.getUUIDsInPath(filePath, uuids);
|
|
}
|
|
}
|
|
}
|
|
this.updatePackageAssets(uuids);
|
|
const base = this.subpackageInfoData[key];
|
|
console.log(`Package ${key} files: \n${uuids.join(', ')}`);
|
|
config.push({ key: base.key, name: base.name, des: base.des, uuids: uuids.map(value => value.uuid) });
|
|
}
|
|
}
|
|
initSubpackageConfig() {
|
|
const config = [];
|
|
this.initExcelSubpackage(config);
|
|
return config;
|
|
}
|
|
getSubpackageConfig() {
|
|
this.subpackageConfigs = this.subpackageConfigs || this.initSubpackageConfig();
|
|
return this.subpackageConfigs;
|
|
}
|
|
}
|
|
exports.Config = Config;
|