diff --git a/src/lostcity/engine/World.ts b/src/lostcity/engine/World.ts index 5b5c8ebe7..3932bc539 100644 --- a/src/lostcity/engine/World.ts +++ b/src/lostcity/engine/World.ts @@ -425,6 +425,14 @@ class World { this.broadcastMes(msg.error.replaceAll('data/src/scripts/', '')); this.broadcastMes('Check the console for more information.'); } + } else if (msg.type === 'dev_progress') { + if (msg.broadcast) { + console.log(msg.broadcast); + + this.broadcastMes(msg.broadcast); + } else if (msg.text) { + console.log(msg.text); + } } }); diff --git a/src/lostcity/network/225/incoming/handler/ClientCheatHandler.ts b/src/lostcity/network/225/incoming/handler/ClientCheatHandler.ts index 44ad6a8d4..c12bf9532 100644 --- a/src/lostcity/network/225/incoming/handler/ClientCheatHandler.ts +++ b/src/lostcity/network/225/incoming/handler/ClientCheatHandler.ts @@ -45,10 +45,6 @@ export default class ClientCheatHandler extends MessageHandler { // developer commands if (cmd === 'reload' && !Environment.STANDALONE_BUNDLE && !Environment.NODE_PRODUCTION) { World.reload(); - - // todo: we're probably reloading twice now, just to get count? - const count = ScriptProvider.load('data/pack'); - player.messageGame(`Reloaded ${count} scripts.`); } else if (cmd === 'rebuild' && !Environment.STANDALONE_BUNDLE && !Environment.NODE_PRODUCTION) { player.messageGame('Rebuilding scripts...'); diff --git a/src/lostcity/pack/interface/PackShared.ts b/src/lostcity/pack/interface/PackShared.ts index 34dc89ede..1263fb0c6 100644 --- a/src/lostcity/pack/interface/PackShared.ts +++ b/src/lostcity/pack/interface/PackShared.ts @@ -192,7 +192,7 @@ export function packInterface(server: boolean) { comName = line.substring(1, line.length - 1); comId = InterfacePack.getByName(`${ifName}:${comName}`); if (comId === -1 || typeof component[comId] === 'undefined') { - throw new Error(`Missing component ID ${ifName}:${comName} in data/src/pack/interface.pack`); + throw new Error(`Missing component ID ${ifName}:${comName} in data/src/pack/interface.order`); } component[comId].root = ifName; diff --git a/src/lostcity/pack/packall.ts b/src/lostcity/pack/packall.ts index 6ee7f169c..f7f30cb1a 100644 --- a/src/lostcity/pack/packall.ts +++ b/src/lostcity/pack/packall.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import child_process from 'child_process'; +import { parentPort } from 'worker_threads'; import { packServerInterface } from '#lostcity/pack/interface/PackServer.js'; import { packServerMap } from '#lostcity/pack/map/PackServer.js'; @@ -25,6 +26,13 @@ export async function packServer() { throw new Error('The RuneScript compiler is missing and the build process cannot continue.'); } + if (parentPort) { + parentPort.postMessage({ + type: 'dev_progress', + broadcast: 'Packing server cache (1/2)' + }); + } + revalidatePack(); packConfigs(); packServerInterface(); @@ -34,16 +42,37 @@ export async function packServer() { generateServerSymbols(); + if (parentPort) { + parentPort.postMessage({ + type: 'dev_progress', + text: 'Compiling server scripts' + }); + } + try { child_process.execSync(`"${Environment.BUILD_JAVA_PATH}" -jar RuneScriptCompiler.jar`, { stdio: 'inherit' }); } catch (err) { throw new Error('Failed to compile scripts.'); } + if (parentPort) { + parentPort.postMessage({ + type: 'dev_progress', + text: 'Packed server cache (1/2)' + }); + } + fs.writeFileSync('data/pack/server/lastbuild.pack', ''); } export async function packClient() { + if (parentPort) { + parentPort.postMessage({ + type: 'dev_progress', + broadcast: 'Packing client cache (2/2)' + }); + } + await packClientTitle(); packConfigs(); packClientInterface(); @@ -56,6 +85,13 @@ export async function packClient() { packClientMap(); packClientMusic(); + if (parentPort) { + parentPort.postMessage({ + type: 'dev_progress', + text: 'Packed client cache (2/2)' + }); + } + fs.writeFileSync('data/pack/client/crc', CrcBuffer.data); fs.writeFileSync('data/pack/client/lastbuild.pack', ''); } diff --git a/src/lostcity/util/PackFile.ts b/src/lostcity/util/PackFile.ts index 4065ca45b..47600eb8e 100644 --- a/src/lostcity/util/PackFile.ts +++ b/src/lostcity/util/PackFile.ts @@ -9,6 +9,8 @@ type PackFileValidator = (packfile: PackFile, ...args: any[]) => void; export class PackFile { type: string; + validator: PackFileValidator | null = null; + validatorArgs: any[] = []; pack: Map = new Map(); names: Set = new Set(); max: number = 0; @@ -20,11 +22,16 @@ export class PackFile { // eslint-disable-next-line @typescript-eslint/no-explicit-any constructor(type: string, validator: PackFileValidator | null = null, ...validatorArgs: any[]) { this.type = type; + this.validator = validator; + this.validatorArgs = validatorArgs; + this.reload(); + } - if (validator !== null) { - validator(this, ...validatorArgs); + reload() { + if (this.validator !== null) { + this.validator(this, ...this.validatorArgs); } else { - this.load(`${Environment.BUILD_SRC_DIR}/pack/${type}.pack`); + this.load(`${Environment.BUILD_SRC_DIR}/pack/${this.type}.pack`); } } @@ -254,60 +261,60 @@ function regenScriptPack(pack: PackFile) { pack.save(); } -export let AnimPack = new PackFile('anim', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.frame'); -export let BasePack = new PackFile('base', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.base'); -export let CategoryPack = new PackFile('category', validateCategoryPack); -export let DbRowPack = new PackFile('dbrow', validateConfigPack, '.dbrow', true, false, false, true); -export let DbTablePack = new PackFile('dbtable', validateConfigPack, '.dbtable', true, false, false, true); -export let EnumPack = new PackFile('enum', validateConfigPack, '.enum', true, false, false, true); -export let FloPack = new PackFile('flo', validateConfigPack, '.flo'); -export let HuntPack = new PackFile('hunt', validateConfigPack, '.hunt', true, false, false, true); -export let IdkPack = new PackFile('idk', validateConfigPack, '.idk'); -export let InterfacePack = new PackFile('interface', validateInterfacePack); -export let InvPack = new PackFile('inv', validateConfigPack, '.inv', true); -export let LocPack = new PackFile('loc', validateConfigPack, '.loc'); -export let MesAnimPack = new PackFile('mesanim', validateConfigPack, '.mesanim', true, false, false, true); -export let ModelPack = new PackFile('model', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.ob2'); -export let NpcPack = new PackFile('npc', validateConfigPack, '.npc'); -export let ObjPack = new PackFile('obj', validateConfigPack, '.obj'); -export let ParamPack = new PackFile('param', validateConfigPack, '.param', true, false, false, true); -export let ScriptPack = new PackFile('script', regenScriptPack); -export let SeqPack = new PackFile('seq', validateConfigPack, '.seq'); -export let SoundPack = new PackFile('sound', validateFilesPack, `${Environment.BUILD_SRC_DIR}/sounds`, '.synth'); -export let SpotAnimPack = new PackFile('spotanim', validateConfigPack, '.spotanim'); -export let StructPack = new PackFile('struct', validateConfigPack, '.struct', true, false, false, true); -export let TexturePack = new PackFile('texture', validateImagePack, `${Environment.BUILD_SRC_DIR}/textures`, '.png'); -export let VarpPack = new PackFile('varp', validateConfigPack, '.varp', true); -export let VarnPack = new PackFile('varn', validateConfigPack, '.varn', true, false, false, true); -export let VarsPack = new PackFile('vars', validateConfigPack, '.vars', true, false, false, true); +export const AnimPack = new PackFile('anim', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.frame'); +export const BasePack = new PackFile('base', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.base'); +export const CategoryPack = new PackFile('category', validateCategoryPack); +export const DbRowPack = new PackFile('dbrow', validateConfigPack, '.dbrow', true, false, false, true); +export const DbTablePack = new PackFile('dbtable', validateConfigPack, '.dbtable', true, false, false, true); +export const EnumPack = new PackFile('enum', validateConfigPack, '.enum', true, false, false, true); +export const FloPack = new PackFile('flo', validateConfigPack, '.flo'); +export const HuntPack = new PackFile('hunt', validateConfigPack, '.hunt', true, false, false, true); +export const IdkPack = new PackFile('idk', validateConfigPack, '.idk'); +export const InterfacePack = new PackFile('interface', validateInterfacePack); +export const InvPack = new PackFile('inv', validateConfigPack, '.inv', true); +export const LocPack = new PackFile('loc', validateConfigPack, '.loc'); +export const MesAnimPack = new PackFile('mesanim', validateConfigPack, '.mesanim', true, false, false, true); +export const ModelPack = new PackFile('model', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.ob2'); +export const NpcPack = new PackFile('npc', validateConfigPack, '.npc'); +export const ObjPack = new PackFile('obj', validateConfigPack, '.obj'); +export const ParamPack = new PackFile('param', validateConfigPack, '.param', true, false, false, true); +export const ScriptPack = new PackFile('script', regenScriptPack); +export const SeqPack = new PackFile('seq', validateConfigPack, '.seq'); +export const SoundPack = new PackFile('sound', validateFilesPack, `${Environment.BUILD_SRC_DIR}/sounds`, '.synth'); +export const SpotAnimPack = new PackFile('spotanim', validateConfigPack, '.spotanim'); +export const StructPack = new PackFile('struct', validateConfigPack, '.struct', true, false, false, true); +export const TexturePack = new PackFile('texture', validateImagePack, `${Environment.BUILD_SRC_DIR}/textures`, '.png'); +export const VarpPack = new PackFile('varp', validateConfigPack, '.varp', true); +export const VarnPack = new PackFile('varn', validateConfigPack, '.varn', true, false, false, true); +export const VarsPack = new PackFile('vars', validateConfigPack, '.vars', true, false, false, true); export function revalidatePack() { - AnimPack = new PackFile('anim', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.frame'); - BasePack = new PackFile('base', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.base'); - CategoryPack = new PackFile('category', validateCategoryPack); - DbRowPack = new PackFile('dbrow', validateConfigPack, '.dbrow', true, false, false, true); - DbTablePack = new PackFile('dbtable', validateConfigPack, '.dbtable', true, false, false, true); - EnumPack = new PackFile('enum', validateConfigPack, '.enum', true, false, false, true); - FloPack = new PackFile('flo', validateConfigPack, '.flo'); - HuntPack = new PackFile('hunt', validateConfigPack, '.hunt', true, false, false, true); - IdkPack = new PackFile('idk', validateConfigPack, '.idk'); - InterfacePack = new PackFile('interface', validateInterfacePack); - InvPack = new PackFile('inv', validateConfigPack, '.inv', true); - LocPack = new PackFile('loc', validateConfigPack, '.loc'); - MesAnimPack = new PackFile('mesanim', validateConfigPack, '.mesanim', true, false, false, true); - ModelPack = new PackFile('model', validateFilesPack, `${Environment.BUILD_SRC_DIR}/models`, '.ob2'); - NpcPack = new PackFile('npc', validateConfigPack, '.npc'); - ObjPack = new PackFile('obj', validateConfigPack, '.obj'); - ParamPack = new PackFile('param', validateConfigPack, '.param', true, false, false, true); - ScriptPack = new PackFile('script', regenScriptPack); - SeqPack = new PackFile('seq', validateConfigPack, '.seq'); - SoundPack = new PackFile('sound', validateFilesPack, `${Environment.BUILD_SRC_DIR}/sounds`, '.synth'); - SpotAnimPack = new PackFile('spotanim', validateConfigPack, '.spotanim'); - StructPack = new PackFile('struct', validateConfigPack, '.struct', true, false, false, true); - TexturePack = new PackFile('texture', validateImagePack, `${Environment.BUILD_SRC_DIR}/textures`, '.png'); - VarpPack = new PackFile('varp', validateConfigPack, '.varp', true); - VarnPack = new PackFile('varn', validateConfigPack, '.varn', true, false, false, true); - VarsPack = new PackFile('vars', validateConfigPack, '.vars', true, false, false, true); + AnimPack.reload(); + BasePack.reload(); + CategoryPack.reload(); + DbRowPack.reload(); + DbTablePack.reload(); + EnumPack.reload(); + FloPack.reload(); + HuntPack.reload(); + IdkPack.reload(); + InterfacePack.reload(); + InvPack.reload(); + LocPack.reload(); + MesAnimPack.reload(); + ModelPack.reload(); + NpcPack.reload(); + ObjPack.reload(); + ParamPack.reload(); + ScriptPack.reload(); + SeqPack.reload(); + SoundPack.reload(); + SpotAnimPack.reload(); + StructPack.reload(); + TexturePack.reload(); + VarpPack.reload(); + VarnPack.reload(); + VarsPack.reload(); } export function crawlConfigNames(ext: string, includeBrackets = false) {