From bfe731d286c6fdef34659659dd0145e1016dd8e0 Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 17 Feb 2021 00:22:18 -0500 Subject: [PATCH] Add pet spinner --- error.log | 0 .../furniture/FurnitureConverter.ts | 4 +-- src/converters/pet/PetConverter.ts | 34 ++++++++++++++----- 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 error.log diff --git a/error.log b/error.log new file mode 100644 index 0000000..e69de29 diff --git a/src/converters/furniture/FurnitureConverter.ts b/src/converters/furniture/FurnitureConverter.ts index e0b6751..84d0a20 100644 --- a/src/converters/furniture/FurnitureConverter.ts +++ b/src/converters/furniture/FurnitureConverter.ts @@ -74,7 +74,7 @@ export class FurnitureConverter extends SWFConverter const name = habboAssetSWF.getDocumentClass(); const path = outputFolder + '/' + name + '.nitro'; const nitroBundle = new NitroBundle(); - + nitroBundle.addFile((name + '.json'), Buffer.from(JSON.stringify(assetData))); if(spriteBundle && (spriteBundle.spritesheet !== undefined)) @@ -88,7 +88,7 @@ export class FurnitureConverter extends SWFConverter } const buffer = await nitroBundle.toBufferAsync(); - + await writeFile(path, buffer); } diff --git a/src/converters/pet/PetConverter.ts b/src/converters/pet/PetConverter.ts index e1e4499..c637317 100644 --- a/src/converters/pet/PetConverter.ts +++ b/src/converters/pet/PetConverter.ts @@ -1,4 +1,5 @@ import { writeFile } from 'fs/promises'; +import * as ora from 'ora'; import { singleton } from 'tsyringe'; import { BundleProvider } from '../../common/bundle/BundleProvider'; import { SpriteBundle } from '../../common/bundle/SpriteBundle'; @@ -26,13 +27,26 @@ export class PetConverter extends SWFConverter public async convertAsync(): Promise { + const now = Date.now(); + + const spinner = ora('Preparing Pets').start(); + const outputFolder = new File(this._config.getValue('output.folder.pet')); - if(!outputFolder.isDirectory()) outputFolder.mkdirs(); + if(!outputFolder.isDirectory()) + { + spinner.text = `Creating Folder: ${ outputFolder.path }`; + + spinner.render(); + + outputFolder.mkdirs(); + } await this._petDownloader.download(async (habboAssetSwf: HabboAssetSWF) => { - console.log('Parsing Pet: ' + habboAssetSwf.getDocumentClass()); + spinner.text = 'Parsing Pet: ' + habboAssetSwf.getDocumentClass(); + + spinner.render(); try { @@ -47,6 +61,8 @@ export class PetConverter extends SWFConverter console.error(error); } }); + + spinner.succeed(`Pets Finished in ${ Date.now() - now }ms`); } private async fromHabboAsset(habboAssetSWF: HabboAssetSWF, outputFolder: string, type: string, spriteBundle: SpriteBundle): Promise @@ -56,26 +72,26 @@ export class PetConverter extends SWFConverter const assetData = await this.mapXML2JSON(habboAssetSWF, 'pet'); if(!assetData) return; - + if(spriteBundle && (spriteBundle.spritesheet !== undefined)) assetData.spritesheet = spriteBundle.spritesheet; - + const name = habboAssetSWF.getDocumentClass(); const path = outputFolder + '/' + name + '.nitro'; const nitroBundle = new NitroBundle(); - + nitroBundle.addFile((name + '.json'), Buffer.from(JSON.stringify(assetData))); - + if(spriteBundle.imageData !== undefined) { nitroBundle.addFile(spriteBundle.imageData.name, spriteBundle.imageData.buffer); } - + const buffer = await nitroBundle.toBufferAsync(); - + await writeFile(path, buffer); } - catch(err) + catch (err) { this._logger.logErrorAsync(err); }