Skip to content

Commit

Permalink
Merge pull request #7 from LuciaRolon/master
Browse files Browse the repository at this point in the history
Load only the required files for the browser
  • Loading branch information
eldri7ch2 authored Jul 19, 2024
2 parents 711eecb + 766b8d0 commit 160c09b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 41 deletions.
24 changes: 17 additions & 7 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
const workers = Array(count)
const url = new URL(window.location.href)
if (url.protocol === 'file:') {
const source = '(' + randomizeWorker.toString() + ')()'
randomizeWorkerString = randomizeWorker.toString()
const source = '(' + randomizeWorkerString + ')()'
for (let i = 0; i < count; i++) {
workers[i] = new Worker(
URL.createObjectURL(new Blob([source], {
Expand Down Expand Up @@ -652,19 +653,23 @@
}

function submitListener(event) {
// Get seed.
let selectedPreset = null
if(elems.preset.checked) {
selectedPreset = elems.presetId.childNodes[elems.presetId.selectedIndex].value
self.sotnRando.selectedPreset = selectedPreset
}else{
self.sotnRando.selectedPreset = null
}

event.preventDefault()
event.stopPropagation()
// Disable UI.
disableDownload()
// Show loading bar.
showLoader()
// Create new info collection.
info = util.newInfo()
// Get seed.
let selectedPreset = null
if(elems.preset.checked) {
selectedPreset = elems.presetId.childNodes[elems.presetId.selectedIndex].value
}
info = util.newInfo()

let seed = generateSeedName()
if (elems.seed.value.length) {
Expand Down Expand Up @@ -716,6 +721,11 @@
const newNames = result.newNames
check.apply(result.data)
// Randomize relics.
let selectedPreset = null
if(elems.preset.checked) {
selectedPreset = elems.presetId.childNodes[elems.presetId.selectedIndex].value
util.selectedPreset = selectedPreset
}
return util.randomizeRelics(
version,
applied,
Expand Down
3 changes: 2 additions & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4754,6 +4754,7 @@
function loadWorker(worker, url) {
worker.postMessage({
url: url,
selectedPreset: self.sotnRando.selectedPreset
})
}

Expand Down Expand Up @@ -5042,7 +5043,7 @@
function postMessage(bootstrap) {
const message = {
action: constants.WORKER_ACTION.RELICS,
nonce: nonce++,
nonce: nonce++
}
if (bootstrap) {
Object.assign(message, {
Expand Down
44 changes: 11 additions & 33 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ function randomizeWorker() {
let randomizeItems
let seedrandom

function loadBrowser(url) {
function loadBrowser(url, selectedPreset = null) {
// This allows the presets to be loaded from the browser
// If you add any inheritance preset, add it to this list.
importScripts(
'https://cdnjs.cloudflare.com/ajax/libs/seedrandom/3.0.1/seedrandom.min.js',
url + 'src/constants.js',
Expand All @@ -21,42 +23,18 @@ function randomizeWorker() {
url + 'build/presets/casual.js',
url + 'build/presets/safe.js',
url + 'build/presets/adventure.js',
url + 'build/presets/og.js',
url + 'build/presets/guarded-og.js',
url + 'build/presets/speedrun.js',
url + 'build/presets/lycanthrope.js',
url + 'build/presets/warlock.js',
url + 'build/presets/nimble.js',
url + 'build/presets/expedition.js',
url + 'build/presets/glitch.js',
url + 'build/presets/bat-master.js',
url + 'build/presets/scavenger.js',
url + 'build/presets/empty-hand.js',
url + 'build/presets/gem-farmer.js',
url + 'build/presets/third-castle.js',
url + 'build/presets/rat-race.js',
url + 'build/presets/magic-mirror.js',
url + 'build/presets/leg-day.js',
url + 'build/presets/boss-rush.js',
url + 'build/presets/aperture.js',
url + 'build/presets/bountyhunter.js',
url + 'build/presets/bountyhuntertc.js',
url + 'build/presets/hitman.js',
url + 'build/presets/chaos-lite.js',
url + 'build/presets/big-toss.js',
url + 'build/presets/beyond.js',
url + 'build/presets/breach.js',
url + 'build/presets/grand-tour.js',
url + 'build/presets/crash-course.js',
url + 'build/presets/forge.js',
url + 'build/presets/lookingglass.js',
url + 'build/presets/skinwalker.js',
url + 'build/presets/summoner.js',
url + 'build/presets/brawler.js',
url + 'src/randomize_items.js',
url + 'src/randomize_relics.js',
url + 'src/ecc-edc-recalc-js.js',
)
let loadedPresets = ["casual", "safe", "adventure", "nimble"]
console.log(selectedPreset)

if(selectedPreset !== null && !(selectedPreset in loadedPresets)){
importScripts(url + `build/presets/${selectedPreset}.js`)
}

constants = self.sotnRando.constants
eccEdcCalc = self.eccEdcCalc
errors = self.sotnRando.errors
Expand Down Expand Up @@ -96,7 +74,7 @@ function randomizeWorker() {
}
if (!('action' in message)) {
if (typeof(module) === 'undefined') {
loadBrowser(message.url)
loadBrowser(message.url, message.selectedPreset)
} else {
loadNode()
}
Expand Down

0 comments on commit 160c09b

Please sign in to comment.