Skip to content

Commit

Permalink
Merge pull request #6 from LuciaRolon/feature/performance
Browse files Browse the repository at this point in the history
Presets are now loaded on demand rather than loading them all by default
  • Loading branch information
eldri7ch2 authored Jul 19, 2024
2 parents 39beb2e + 5356f0b commit 711eecb
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 71 deletions.
45 changes: 10 additions & 35 deletions build/presets/index.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,24 @@
(function(self) {

let exports
if (self) {
if (self) {
exports = self.sotnRando.presets
} else {
// Load the basic presets. All preset used as part of inheritance must be here.
exports = [
require('./casual'),
require('./safe'),
require('./adventure'),
require('./og'),
require('./guarded-og'),
require('./speedrun'),
require('./lycanthrope'),
require('./warlock'),
require('./nimble'),
require('./expedition'),
require('./glitch'),
require('./scavenger'),
require('./empty-hand'),
require('./bat-master'),
require('./gem-farmer'),
require('./third-castle'),
require('./rat-race'),
require('./magic-mirror'),
require('./leg-day'),
require('./boss-rush'),
require('./aperture'),
require('./big-toss'),
require('./bountyhunter'),
require('./bountyhuntertc'),
require('./hitman'),
require('./chaos-lite'),
require('./beyond'),
require('./breach'),
require('./grand-tour'),
require('./crash-course'),
require('./forge'),
require('./lookingglass'),
require('./skinwalker'),
require('./summoner'),
require('./agonizetwtw'),
require('./stwosafe'),
require('./open'),
require('./brawler'),
]
// We will use this to know which preset we loaded already. If you add any new inheritance preset, add it here.
let loadedPresets = ["casual", "safe", "adventure", "nimble"]
// Then only load the file of the specified preset
if(!(process.env.chosenPreset in loadedPresets) && process.env.chosenPreset !== undefined){
let presetToLoad = process.env.chosenPreset
loadPreset = require(`./${presetToLoad}`)
exports.push(loadPreset)
}
}

if (self) {
Expand Down
73 changes: 37 additions & 36 deletions randomize
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const Worker = require('worker_threads').Worker
const constants = require('./src/constants')
const errors = require('./src/errors')
const extension = require('./src/extension')
const presets = require('./build/presets')
const randomizeStats = require('./src/randomize_stats')
const randomizeRelics = require('./src/randomize_relics')
const randomizeItems = require('./src/randomize_items')
Expand Down Expand Up @@ -407,39 +406,6 @@ const tournamentHelp = [
'- The clock room statue is always open.',
].join('\n')

const presetHelp = [
'Presets specify collection of randomization options. A preset is enabled',
'by using argument syntax.',
'',
'Preset format:',
' p:<preset>',
'',
'This randomizer has several built-in presets:',
].concat(presets.filter(function(preset) {
return !preset.hidden
}).map(function(preset) {
return ' ' + preset.id + (preset.id === 'safe' ? ' (default)' : '')
})).concat([
'',
'Use `--help <preset>` for information on a specific preset.',
'',
'Examples:',
' p:safe Use Safe preset',
' p:empty-hand Use Empty Hand preset',
'',
'When using the `$0` utility, you can use the `--preset` shorthand to',
'specify a preset:',
' $0 -p speedrun # Use speedrun preset',
'',
'Preset options may be overridden by specifying an options string:',
' $0 -p adventure --opt d:*:Peanuts- # Adventure with only Peanut drops',
'',
'A special negation syntax can be used in the options string to disable',
'randomizations that a preset would otherwise enable. To negate a',
'randomization, precede its letter with a tilde ("~"):',
' $0 -p adventure --opt ~m # Adventure but without music randomization',
]).join('\n')

function presetMetaHelp(preset) {
const options = preset.options()
let locations = relics.filter(function(relic) {
Expand Down Expand Up @@ -689,6 +655,39 @@ if ('help' in argv) {
yargs.showHelp()
process.exit()
}
const presets = require('./build/presets')
const presetHelp = [
'Presets specify collection of randomization options. A preset is enabled',
'by using argument syntax.',
'',
'Preset format:',
' p:<preset>',
'',
'This randomizer has several built-in presets:',
].concat(presets.filter(function(preset) {
return !preset.hidden
}).map(function(preset) {
return ' ' + preset.id + (preset.id === 'safe' ? ' (default)' : '')
})).concat([
'',
'Use `--help <preset>` for information on a specific preset.',
'',
'Examples:',
' p:safe Use Safe preset',
' p:empty-hand Use Empty Hand preset',
'',
'When using the `$0` utility, you can use the `--preset` shorthand to',
'specify a preset:',
' $0 -p speedrun # Use speedrun preset',
'',
'Preset options may be overridden by specifying an options string:',
' $0 -p adventure --opt d:*:Peanuts- # Adventure with only Peanut drops',
'',
'A special negation syntax can be used in the options string to disable',
'randomizations that a preset would otherwise enable. To negate a',
'randomization, precede its letter with a tilde ("~"):',
' $0 -p adventure --opt ~m # Adventure but without music randomization',
]).join('\n')
const topics = {
options: optionsHelp,
drops: dropsHelp,
Expand Down Expand Up @@ -774,6 +773,8 @@ if ('preset' in argv) {
options || {},
util.optionsFromString('p:' + argv.preset)
)
// This env variable is then used in index.js to determine which preset files to load from.
process.env.chosenPreset = argv.preset
} catch (e) {
yargs.showHelp()
console.error('\n' + e.message)
Expand Down Expand Up @@ -1024,8 +1025,8 @@ if ('inBin' in argv) {
let startTime
let endTime

startTime = performance.now()

startTime = performance.now()
const presets = require('./build/presets')
if (!argv.noSeed) {
check = new util.checked(typeof(fd) === 'object' ? undefined : fd)
let applied
Expand Down

0 comments on commit 711eecb

Please sign in to comment.