diff --git a/.env.sample b/.env.sample index 4e229cfd..6b7bbe2b 100644 --- a/.env.sample +++ b/.env.sample @@ -45,3 +45,9 @@ seed=12345 # can be either "production" or "development" # the default value is "production" mode=production + +# Whether to compress the FTS file with pkware after compiling, or keep it uncompressed +# can be either "true" or "false" +# the default value is "false" +# uncompressed FTS is an Arx Libertatis 1.3+ feature, so it should be disabled when releasing a map +uncompressedFTS=false diff --git a/package-lock.json b/package-lock.json index b8f44235..88edcff5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,7 +41,7 @@ "npm": ">=8.0.0" }, "peerDependencies": { - "arx-convert": "^8.2.0", + "arx-convert": "^9.0.0", "three": "0.158.0" } }, @@ -880,9 +880,9 @@ } }, "node_modules/arx-convert": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/arx-convert/-/arx-convert-8.2.0.tgz", - "integrity": "sha512-j4/jiPUOXbllIlCAJlB7J6Huh3sT0ZY+2k0VsQXCXto/aUxvBW50Y2y6dTH50yd+L4P5kmf/em3csL0JZbC3HA==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/arx-convert/-/arx-convert-9.0.0.tgz", + "integrity": "sha512-VlssE6ljO1KbBbuoFkEb+gun05hhpGEQr75klzh+m0GZ4pzsWZ9mucrqf4azmvfpgCazm7N2Cihl2K+aruyYiw==", "peer": true, "dependencies": { "minimist-lite": "^2.2.1", @@ -3499,9 +3499,9 @@ "dev": true }, "arx-convert": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/arx-convert/-/arx-convert-8.2.0.tgz", - "integrity": "sha512-j4/jiPUOXbllIlCAJlB7J6Huh3sT0ZY+2k0VsQXCXto/aUxvBW50Y2y6dTH50yd+L4P5kmf/em3csL0JZbC3HA==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/arx-convert/-/arx-convert-9.0.0.tgz", + "integrity": "sha512-VlssE6ljO1KbBbuoFkEb+gun05hhpGEQr75klzh+m0GZ4pzsWZ9mucrqf4azmvfpgCazm7N2Cihl2K+aruyYiw==", "peer": true, "requires": { "minimist-lite": "^2.2.1", diff --git a/package.json b/package.json index 810cf2bc..bb6c6f03 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "sharp-bmp": "^0.1.5" }, "peerDependencies": { - "arx-convert": "^8.2.0", + "arx-convert": "^9.0.0", "three": "0.158.0" }, "devDependencies": { @@ -122,4 +122,4 @@ "keywords": [ "arx-fatalis" ] -} +} \ No newline at end of file diff --git a/src/Settings.ts b/src/Settings.ts index 5244653a..4121127e 100644 --- a/src/Settings.ts +++ b/src/Settings.ts @@ -91,6 +91,11 @@ type SettingsConstructorProps = { * default value is "production" */ mode?: Modes + /** + * When this is set to true FTS files will not get compressed with pkware + * after compiling. This is an Arx Libertatis 1.3+ feature! + */ + uncompressedFTS?: boolean } export class Settings { @@ -167,6 +172,12 @@ export class Settings { */ readonly internalAssetsDir: string + /** + * When this is set to true FTS files will not get compressed with pkware + * after compiling. This is an Arx Libertatis 1.3+ feature! + */ + readonly uncompressedFTS: boolean + constructor(props: SettingsConstructorProps = {}) { this.originalLevelFiles = props.originalLevelFiles ?? process.env.originalLevelFiles ?? path.resolve('../pkware-test-files') @@ -186,6 +197,8 @@ export class Settings { this.seed = props.seed ?? process.env.seed ?? randomIntBetween(100_000_000, 999_999_999).toString() this.mode = props.mode ?? (process.env.mode === 'development' ? process.env.mode : 'production') + this.uncompressedFTS = props.uncompressedFTS ?? process.env.uncompressedFTS === 'true' + seedrandom(this.seed, { global: true }) const __filename = fileURLToPath(import.meta.url) diff --git a/src/compile.ts b/src/compile.ts index 861ba90b..5d1c85cc 100644 --- a/src/compile.ts +++ b/src/compile.ts @@ -17,29 +17,36 @@ const compileFTS = async (settings: Settings, fts: ArxFTS) => { const ftsPath = path.join(settings.outputDir, `game/graph/levels/level${settings.levelIdx}`) const repackedFts = FTS.save(fts) - const { total: ftsHeaderSize } = getHeaderSize(repackedFts, 'fts') - return new Promise((resolve, reject) => { - const writeStream = fs.createWriteStream(path.join(ftsPath, 'fast.fts')) - writeStream - .on('close', () => { - resolve(true) - }) - .on('error', (e) => { - reject(e) - }) - Readable.from(repackedFts) - .pipe( - through( - transformSplitBy( - splitAt(ftsHeaderSize), - transformIdentity(), - implode(Compression.Binary, DictionarySize.Large), + if (settings.uncompressedFTS) { + return fs.promises.writeFile(path.join(ftsPath, 'fast.fts'), repackedFts) + } else { + const { total: ftsHeaderSize } = getHeaderSize(repackedFts, 'fts') + + return new Promise((resolve, reject) => { + const writeStream = fs.createWriteStream(path.join(ftsPath, 'fast.fts')) + + writeStream + .on('close', () => { + resolve(true) + }) + .on('error', (e) => { + reject(e) + }) + + Readable.from(repackedFts) + .pipe( + through( + transformSplitBy( + splitAt(ftsHeaderSize), + transformIdentity(), + implode(Compression.Binary, DictionarySize.Large), + ), ), - ), - ) - .pipe(writeStream) - }) + ) + .pipe(writeStream) + }) + } } const compileLLF = async (settings: Settings, llf: ArxLLF) => { diff --git a/src/globals.d.ts b/src/globals.d.ts index 8f4ecf7c..948bd7c3 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -10,6 +10,7 @@ declare global { lightingCalculatorMode?: string seed?: string mode?: string + uncompressedFTS?: string } } }