diff --git a/src/ArxMap.ts b/src/ArxMap.ts index 88c43ccd..bb35710a 100644 --- a/src/ArxMap.ts +++ b/src/ArxMap.ts @@ -24,7 +24,7 @@ import { LevelLoader } from '@src/LevelLoader.js' import { Light } from '@src/Light.js' import { Lights } from '@src/Lights.js' import { Manifest } from '@src/Manifest.js' -import { MetaData } from '@src/MetaData.js' +import { generateMetadata } from '@src/MetaData.js' import { Path } from '@src/Path.js' import { Player } from '@src/Player.js' import { Polygon } from '@src/Polygon.js' @@ -57,7 +57,6 @@ type ToBeSortedLater = { } export class ArxMap { - meta = new MetaData() polygons = new Polygons() lights = new Lights() fogs: Fog[] = [] @@ -347,18 +346,7 @@ export class ArxMap { await Manifest.uninstall(settings) - const generator = await getGeneratorPackageJSON() - this.meta.generator = generator.name - this.meta.generatorVersion = generator.version - this.meta.generatorUrl = generator.homepage - this.meta.seed = settings.seed - - const project = await getProjectPackageJSON() - this.meta.name = project.name - this.meta.version = project.version - this.meta.description = project.description - this.meta.author = project.author - this.meta.url = project.homepage + const meta = await generateMetadata(settings) // ------------------------ @@ -508,7 +496,7 @@ export class ArxMap { for (const [filename, translation] of Object.entries(translations)) { await fs.promises.writeFile( filename, - `// ${this.meta.name} v.${this.meta.version} - ${generatorId} + `// ${meta.name} v.${meta.version} - ${generatorId} ${translation}`, 'utf8', @@ -547,7 +535,7 @@ export class ArxMap { // ------------------------ - await Manifest.write(settings, this, pathsOfTheFiles) + await Manifest.write(settings, pathsOfTheFiles) } adjustOffsetTo(map: ArxMap) { diff --git a/src/Manifest.ts b/src/Manifest.ts index ce67f91d..7dbd5fea 100644 --- a/src/Manifest.ts +++ b/src/Manifest.ts @@ -1,11 +1,11 @@ import fs from 'node:fs' import path from 'node:path' import { ArxMap } from '@src/ArxMap.js' -import { MetaData } from '@src/MetaData.js' +import { MetaData, generateMetadata } from '@src/MetaData.js' import { Settings } from '@src/Settings.js' import { fileExists } from './helpers.js' -export type ManifestData = ReturnType & { +export type ManifestData = MetaData & { files: string[] } @@ -21,17 +21,11 @@ export class Manifest { return await fileExists(filename) } - static async read(settings: Settings): Promise { + static async read(settings: Settings): Promise { const filename = Manifest.getPathToFilename(settings) - const emptyMetadata = new MetaData() - const emptyManifest = { - ...emptyMetadata.toData(), - files: [], - } - if (!(await Manifest.exists(settings))) { - return emptyManifest + return undefined } try { @@ -39,13 +33,15 @@ export class Manifest { return JSON.parse(rawIn) } catch (e: unknown) { console.error(`[error] Manifest: failed to read or parse "${Manifest.filename}" in "${settings.outputDir}"`) - return emptyManifest + return undefined } } - static async write(settings: Settings, map: ArxMap, files: string[], prettify: boolean = false) { + static async write(settings: Settings, files: string[], prettify: boolean = false) { + const metaData = await generateMetadata(settings) + const manifest: ManifestData = { - ...map.meta.toData(), + ...metaData, files: files.map((file) => { return file.replace(settings.outputDir, '') }), @@ -62,7 +58,7 @@ export class Manifest { return } - const manifest = await Manifest.read(settings) + const manifest = (await Manifest.read(settings)) ?? { files: [] } for (let file of manifest.files) { try { diff --git a/src/MetaData.ts b/src/MetaData.ts index be3682a6..fcd07d35 100644 --- a/src/MetaData.ts +++ b/src/MetaData.ts @@ -1,25 +1,37 @@ -export class MetaData { - name = '' - description = '' - version = '' - author = '' - url = '' - generator = '' - generatorUrl = '' - generatorVersion = '' - seed = '' +import { Settings, Variant } from './Settings.js' +import { getGeneratorPackageJSON, getProjectPackageJSON } from './helpers.js' - toData() { - return { - name: this.name, - description: this.description, - version: this.version, - author: this.author, - url: this.url, - generator: this.generator, - generatorVersion: this.generatorVersion, - generatorUrl: this.generatorUrl, - seed: this.seed, - } +export type MetaData = { + seed: string + variant: Variant + + generator: string + generatorVersion: string + generatorUrl: string + + name: string + version: string + description: string + author: string + url: string +} + +export const generateMetadata = async (settings: Settings): Promise => { + const generator = await getGeneratorPackageJSON() + const project = await getProjectPackageJSON() + + return { + seed: settings.seed, + variant: settings.variant, + + generator: generator.name, + generatorVersion: generator.version, + generatorUrl: generator.homepage, + + name: project.name, + version: project.version, + description: project.description, + author: project.author, + url: project.homepage, } } diff --git a/src/Settings.ts b/src/Settings.ts index ca630bd5..08c258ae 100644 --- a/src/Settings.ts +++ b/src/Settings.ts @@ -11,7 +11,7 @@ type LightingCalculatorModes = | 'DistanceAngleShadowNoTransparency' | 'GI' -type Versions = 'normal' | 'premium' +export type Variant = 'normal' | 'premium' type Modes = 'development' | 'production' @@ -57,11 +57,11 @@ type SettingsConstructorProps = { */ seed?: string /** - * This field allows branching between normal and premium versions + * This field allows branching between "normal" and "premium" variants * - * default value is Versions.Normal + * default value is "normal" */ - version?: Versions + variant?: Variant /** * This field allows branching the code based on what phase the project * is in. For example a cutscene in the beginning of a map can be turned @@ -115,11 +115,11 @@ export class Settings { */ readonly seed: string /** - * This field allows branching between "normal" and "premium" versions + * This field allows branching between "normal" and "premium" variants * * default value is "normal" */ - readonly version: Versions + readonly variant: Variant /** * This field allows branching the code based on what phase the project * is in. For example a cutscene in the beginning of a map can be turned @@ -142,7 +142,7 @@ export class Settings { this.calculateLighting = props.calculateLighting ?? true this.lightingCalculatorMode = props.lightingCalculatorMode ?? 'DistanceAngleShadowNoTransparency' this.seed = props.seed ?? randomIntBetween(100_000_000, 999_999_999).toString() - this.version = props.version ?? 'normal' + this.variant = props.variant ?? 'normal' this.mode = props.mode ?? 'production' seedrandom(this.seed, { global: true }) diff --git a/src/Texture.ts b/src/Texture.ts index 7d434570..9b869c44 100644 --- a/src/Texture.ts +++ b/src/Texture.ts @@ -155,7 +155,7 @@ export class Texture extends ThreeJsTextue { const image = await getSharpInstance(originalSource) let quality = 100 - if (settings.version !== 'premium' && !this.filename.endsWith('[icon].bmp')) { + if (settings.variant !== 'premium' && !this.filename.endsWith('[icon].bmp')) { image.resize(Math.floor(this._width / 2), Math.floor(this._height / 2), { fit: 'cover' }) quality = 70 } @@ -195,7 +195,7 @@ export class Texture extends ThreeJsTextue { let newSize = powerOfTwo let quality = 100 - if (settings.version !== 'premium' && !this.filename.endsWith('[icon].bmp')) { + if (settings.variant !== 'premium' && !this.filename.endsWith('[icon].bmp')) { newSize = newSize / 2 quality = 70 } diff --git a/src/helpers.ts b/src/helpers.ts index c171ccf4..630ebd00 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -5,7 +5,7 @@ import { Mesh, Object3D } from 'three' import { Vector3 } from '@src/Vector3.js' import { mean } from '@src/faux-ramda.js' -type PackageJsonProps = { +export type PackageJsonProps = { name: string version: string description: string diff --git a/src/index.ts b/src/index.ts index e3f0740a..e64e5ca9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,6 @@ export { LevelLoader } from '@src/LevelLoader.js' export { Light } from '@src/Light.js' export { Lights } from '@src/Lights.js' export { Material } from '@src/Material.js' -export { MetaData } from '@src/MetaData.js' export { Path } from '@src/Path.js' export { Player } from '@src/Player.js' export { Polygon } from '@src/Polygon.js'