Skip to content

Commit

Permalink
feat(Settings): add seed property and make all properties readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Aug 10, 2023
1 parent 04c3869 commit ff5328d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import seedrandom from 'seedrandom'
import { randomBetween } from './random.js'

type LightingCalculatorModes =
| 'Distance'
Expand Down Expand Up @@ -39,16 +41,21 @@ type SettingsConstructorProps = {
* default value is "DistanceAngleShadowNoTransparency"
*/
lightingCalculatorMode?: LightingCalculatorModes
/**
* default value is a random number between 100.000.000 and 999.999.999
*/
seed?: string
}

export class Settings {
originalLevelFiles: string
cacheFolder: string
outputDir: string
levelIdx: number
assetsDir: string
calculateLighting: boolean
lightingCalculatorMode: LightingCalculatorModes
readonly originalLevelFiles: string
readonly cacheFolder: string
readonly outputDir: string
readonly levelIdx: number
readonly assetsDir: string
readonly calculateLighting: boolean
readonly lightingCalculatorMode: LightingCalculatorModes
readonly seed: string
/**
* arx-level-generator comes with its own assets folder
*/
Expand All @@ -62,6 +69,9 @@ export class Settings {
this.assetsDir = props.assetsDir ?? path.resolve('./assets')
this.calculateLighting = props.calculateLighting ?? true
this.lightingCalculatorMode = props.lightingCalculatorMode ?? 'DistanceAngleShadowNoTransparency'
this.seed = props.seed ?? randomBetween(100_000_000, 999_999_999).toString()

seedrandom(this.seed, { global: true })

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
Expand Down

0 comments on commit ff5328d

Please sign in to comment.