Update things

This commit is contained in:
Bill 2022-07-27 12:46:23 -04:00
parent 3deddc713f
commit 4863141073
7 changed files with 65 additions and 53 deletions

2
.gitignore vendored
View File

@ -54,4 +54,4 @@ Thumbs.db
/assets
# Nitro
/src/configuration.json
configuration.json

View File

@ -35,7 +35,7 @@ You may set any of the urls to a local path on your system or a remote url. A lo
## Running the converter
**Make sure you run `yarn install` before first use.**
**Make sure you run `yarn install && yarn build` before first use.**
To run the converter open a new terminal / console window in the main converter directory.
@ -43,6 +43,7 @@ The converter has a few different start commands:
| key | value |
| ---------------------- | ---------------------------------------------------------- |
| yarn build | Will run `tsc` and build .js from .ts |
| yarn start | Will download and convert assets as set in the config |
| yarn start:bundle | Will bundle decompressed `.nitro` assets (json / png) |
| yarn start:extract | Will extract `.nitro` assets which can be used for editing |

View File

@ -17,7 +17,7 @@
"scripts": {
"build": "tsc",
"start:dev": "ts-node-dev --respawn --transpile-only src/Main.ts",
"start": "yarn build && node ./dist/Main.js",
"start": "node ./dist/Main.js",
"start:bundle": "yarn start --bundle",
"start:extract": "yarn start --extract",
"start:convert-swf": "yarn start --convert-swf"

View File

@ -1,5 +1,6 @@
import 'reflect-metadata';
import { container } from 'tsyringe';
import { FileUtilities } from './common';
import { Configuration } from './common/config/Configuration';
import { IConverter } from './common/converters/IConverter';
import { ConverterUtilities } from './converters/ConverterUtilities';
@ -12,44 +13,54 @@ import { ProductDataConverter } from './converters/ProductDataConverter';
(async () =>
{
const config = container.resolve(Configuration);
await config.init();
const converters = [
FurnitureDataConverter,
FigureDataConverter,
ProductDataConverter,
ExternalTextsConverter,
EffectMapConverter,
FigureMapConverter
];
const bundle = (process.argv.indexOf('--bundle') >= 0);
const extract = (process.argv.indexOf('--extract') >= 0);
const convertSwf = (process.argv.indexOf('--convert-swf') >= 0);
const skip = (bundle || extract || convertSwf);
if(skip)
try
{
const extractor = container.resolve(ConverterUtilities);
const configurationContent = await FileUtilities.readFileAsString('./configuration.json');
const config = container.resolve(Configuration);
bundle && await extractor.bundleExtractedFromFolder();
extract && await extractor.extractNitroFromFolder();
convertSwf && await extractor.convertSwfFromFolder();
await config.init(JSON.parse(configurationContent));
const converters = [
FurnitureDataConverter,
FigureDataConverter,
ProductDataConverter,
ExternalTextsConverter,
EffectMapConverter,
FigureMapConverter
];
const bundle = (process.argv.indexOf('--bundle') >= 0);
const extract = (process.argv.indexOf('--extract') >= 0);
const convertSwf = (process.argv.indexOf('--convert-swf') >= 0);
const skip = (bundle || extract || convertSwf);
if (skip)
{
const extractor = container.resolve(ConverterUtilities);
bundle && await extractor.bundleExtractedFromFolder();
extract && await extractor.extractNitroFromFolder();
convertSwf && await extractor.convertSwfFromFolder();
process.exit();
}
for (const converterClass of converters)
{
const converter = (container.resolve<any>(converterClass) as IConverter);
await converter.convertAsync();
}
const utilities = container.resolve(ConverterUtilities);
await utilities.downloadSwfTypes();
process.exit();
}
for(const converterClass of converters)
catch (e)
{
const converter = (container.resolve<any>(converterClass) as IConverter);
await converter.convertAsync();
console.error(e);
}
const utilities = container.resolve(ConverterUtilities);
await utilities.downloadSwfTypes();
process.exit();
})();

View File

@ -1,5 +1,4 @@
import { singleton } from 'tsyringe';
import * as configuration from '../../configuration.json';
import { FileUtilities } from '../utils';
@singleton()
@ -12,7 +11,7 @@ export class Configuration
this._config = new Map<string, string>();
}
public async init(): Promise<void>
public async init(configuration: Object): Promise<void>
{
this.parseConfiguration(configuration);
@ -41,20 +40,20 @@ export class Configuration
private parseConfiguration(content: Object): boolean
{
if(!content) return false;
if (!content) return false;
try
{
const regex = new RegExp(/\${(.*?)}/g);
for(const key of Object.keys(configuration))
for (const key of Object.keys(content))
{
if(this._config.get(key))
if (this._config.get(key))
{
if(!configuration[key].length) continue;
if (!content[key].length) continue;
}
this._config.set(key, this.interpolate(configuration[key], regex));
this._config.set(key, this.interpolate(content[key], regex));
}
return true;
@ -71,18 +70,18 @@ export class Configuration
private parseExternalVariables(content: string): boolean
{
if(!content || (content === '')) return false;
if (!content || (content === '')) return false;
try
{
const regex = new RegExp(/\${(.*?)}/g);
const lines: string[] = content.split('\n');
for(const line of lines)
for (const line of lines)
{
const [ key, value ] = line.split('=');
const [key, value] = line.split('=');
if(key.startsWith('landing.view')) continue;
if (key.startsWith('landing.view')) continue;
this._config.set(key, this.interpolate((value || ''), regex));
}
@ -101,18 +100,18 @@ export class Configuration
public interpolate(value: string, regex: RegExp = null): string
{
if(!value || (typeof value === 'object')) return value;
if(!regex) regex = new RegExp(/\${(.*?)}/g);
if (!value || (typeof value === 'object')) return value;
if (!regex) regex = new RegExp(/\${(.*?)}/g);
const pieces = value.match(regex);
if(pieces && pieces.length)
if (pieces && pieces.length)
{
for(const piece of pieces)
for (const piece of pieces)
{
const existing = this._config.get(this.removeInterpolateKey(piece));
if(existing) (value = value.replace(piece, existing));
if (existing) (value = value.replace(piece, existing));
}
}
@ -126,7 +125,7 @@ export class Configuration
public getValue(key: string, value: string = ''): string
{
if(this._config.has(key)) return this._config.get(key);
if (this._config.has(key)) return this._config.get(key);
return value;
}

View File

@ -22,6 +22,7 @@
],
"exclude": [
"node_modules",
"dist"
"dist",
"src/configuration.json"
]
}