Skip to content

Commit

Permalink
feat(Settings): add support for uncompressed fts files for Arx Libert…
Browse files Browse the repository at this point in the history
…atis 1.3+
  • Loading branch information
meszaros-lajos-gyorgy committed May 25, 2024
1 parent 4d64655 commit 24c464f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -122,4 +122,4 @@
"keywords": [
"arx-fatalis"
]
}
}
13 changes: 13 additions & 0 deletions src/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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')
Expand All @@ -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)
Expand Down
49 changes: 28 additions & 21 deletions src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
1 change: 1 addition & 0 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare global {
lightingCalculatorMode?: string
seed?: string
mode?: string
uncompressedFTS?: string
}
}
}
Expand Down

0 comments on commit 24c464f

Please sign in to comment.