Solid progress on Game Settings
This commit is contained in:
@@ -18,12 +18,15 @@ window.addEventListener('load', () => {
|
||||
|
||||
// Update localStorage with three settings objects. Preserve original objects if present.
|
||||
for (let i=1; i<=3; i++) {
|
||||
const localSettings = localStorage.getItem(`gameSettings${i}`);
|
||||
const updatedObj = localSettings ? Object.assign(sourceData, JSON.parse(localSettings)) : sourceData;
|
||||
const localSettings = JSON.parse(localStorage.getItem(`gameSettings${i}`));
|
||||
const updatedObj = localSettings ? Object.assign(sourceData, localSettings) : sourceData;
|
||||
localStorage.setItem(`gameSettings${i}`, JSON.stringify(updatedObj));
|
||||
}
|
||||
|
||||
console.info(sourceData);
|
||||
populateSettings();
|
||||
document.getElementById('preset-number').addEventListener('change', populateSettings);
|
||||
gameSettings.addEventListener('change', handleOptionChange);
|
||||
gameSettings.addEventListener('keyup', handleOptionChange);
|
||||
}).catch((error) => {
|
||||
gameSettings.innerHTML = `
|
||||
<h2>Something went wrong while loading your game settings page.</h2>
|
||||
@@ -32,3 +35,67 @@ window.addEventListener('load', () => {
|
||||
`
|
||||
});
|
||||
});
|
||||
|
||||
const handleOptionChange = (event) => {
|
||||
if(!event.target.matches('.setting')) { return; }
|
||||
const presetNumber = document.getElementById('preset-number').value;
|
||||
const settings = JSON.parse(localStorage.getItem(`gameSettings${presetNumber}`))
|
||||
const settingString = event.target.getAttribute('data-setting');
|
||||
document.getElementById(settingString).innerText = event.target.value;
|
||||
if(getSettingValue(settings, settingString) !== false){
|
||||
const keys = settingString.split('.');
|
||||
switch (keys.length) {
|
||||
case 1:
|
||||
settings[keys[0]] = event.target.value;
|
||||
break;
|
||||
case 2:
|
||||
settings[keys[0]][keys[1]] = event.target.value;
|
||||
break;
|
||||
case 3:
|
||||
settings[keys[0]][keys[1]][keys[2]] = event.target.value;
|
||||
break;
|
||||
default:
|
||||
console.warn(`Unknown setting string received: ${settingString}`)
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the updated settings object bask to localStorage
|
||||
localStorage.setItem(`gameSettings${presetNumber}`, JSON.stringify(settings));
|
||||
}else{
|
||||
console.warn(`Unknown setting string received: ${settingString}`)
|
||||
}
|
||||
};
|
||||
|
||||
const populateSettings = () => {
|
||||
const presetNumber = document.getElementById('preset-number').value;
|
||||
const settings = JSON.parse(localStorage.getItem(`gameSettings${presetNumber}`))
|
||||
const settingsInputs = Array.from(document.querySelectorAll('.setting'));
|
||||
settingsInputs.forEach((input) => {
|
||||
const settingString = input.getAttribute('data-setting');
|
||||
const settingValue = getSettingValue(settings, settingString);
|
||||
console.info(`${settingString}: ${settingValue}`);
|
||||
if(settingValue !== false){
|
||||
input.value = settingValue;
|
||||
document.getElementById(settingString).innerText = settingValue;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the value of the settings object, or false if the settings object does not exist
|
||||
* @param settings
|
||||
* @param keyString
|
||||
* @returns {string} | bool
|
||||
*/
|
||||
const getSettingValue = (settings, keyString) => {
|
||||
const keys = keyString.split('.');
|
||||
let currentVal = settings;
|
||||
keys.forEach((key) => {
|
||||
if(typeof(key) === 'string' && currentVal.hasOwnProperty(key)){
|
||||
currentVal = currentVal[key];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return currentVal;
|
||||
};
|
||||
|
||||
@@ -145,18 +145,25 @@ item_functionality:
|
||||
progression_balancing:
|
||||
on: 1 # A system to reduce BK, as in times during which you can't do anything by moving your items into an earlier access sphere to make it likely you have stuff to do
|
||||
off: 0 # Turn this off if you don't mind a longer multiworld, or can glitch around missing items.
|
||||
### Enemizer Section ###
|
||||
boss_shuffle:
|
||||
none: 1 # Vanilla bosses
|
||||
simple: 0 # Existing bosses except Ganon and Agahnim are shuffled throughout dungeons
|
||||
full: 0 # 3 bosses can occur twice
|
||||
random: 0 # Any boss can appear any amount of times
|
||||
singularity: 0 # Picks any boss that can appear anywhere and puts that boss into every arena
|
||||
duality: 0 # Picks a boss that can only appear in some places and a boss that can appear anywhere, then attempts to put both in that order in every arena
|
||||
enemy_shuffle:
|
||||
none: 1 # Vanilla enemy placement
|
||||
chaos: 0 # Enemies are randomized
|
||||
random: 0 # Also shuffle bush enemies, random tile rooms, and random bush enemy spawn chance
|
||||
chaosthieves: 0 # Random + thieves may not be killable
|
||||
singularity: 0 # Picks a boss, tries to put it everywhere that works, if there's spaces remaining it picks a boss to fill those
|
||||
enemy_shuffle: # randomize enemy placement
|
||||
on: 0
|
||||
off: 1
|
||||
killable_thieves: # make thieves killable.
|
||||
on: 0 # usually turned on together with enemy_shuffle to make annoying thief placement more manageable
|
||||
off: 1
|
||||
tile_shuffle: # randomize the tile layouts in flying tile rooms
|
||||
on: 0
|
||||
off: 1
|
||||
bush_shuffle: # randomize the chance that bushes have enemies and the enemies under said bush
|
||||
on: 0
|
||||
off: 1
|
||||
enemy_damage:
|
||||
default: 1 # Vanilla enemy damage
|
||||
shuffled: 0 # Enemies deal 0 to 4 hearts and armor helps
|
||||
@@ -169,6 +176,7 @@ enemy_health:
|
||||
pot_shuffle:
|
||||
'on': 0 # Keys, items, and buttons hidden under pots in dungeons are shuffled with other pots in their supertile
|
||||
'off': 1 # Default pot item locations
|
||||
### End of Enemizer Section ###
|
||||
beemizer: # Remove items from the global item pool and replace them with single bees and bee traps
|
||||
0: 1 # No bee traps are placed
|
||||
1: 0 # 25% of the non-essential item pool is replaced with bee traps
|
||||
|
||||
@@ -3,22 +3,39 @@
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
#game-settings table{
|
||||
|
||||
#game-settings code{
|
||||
background-color: #dbe1bc;
|
||||
border-radius: 4px;
|
||||
padding-left: 0.25rem;
|
||||
padding-right: 0.25rem;
|
||||
}
|
||||
|
||||
#game-settings table td.option-name{
|
||||
|
||||
#game-settings #instructions{
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
#game-settings table td.option-name label{
|
||||
#game-settings #settings-wrapper{
|
||||
margin-top: 1.5rem;
|
||||
}
|
||||
|
||||
#game-settings table.option-set{
|
||||
width: 100%;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
#game-settings table.option-set td.option-name{
|
||||
width: 150px;
|
||||
font-weight: bold;
|
||||
font-size: 1rem;
|
||||
line-height: 2rem;
|
||||
}
|
||||
|
||||
#game-settings table .option-value{
|
||||
|
||||
#game-settings table.option-set td.option-value{
|
||||
line-height: 2rem;
|
||||
}
|
||||
|
||||
#game-settings table .option-value input{
|
||||
|
||||
#game-settings table.option-set td.option-value input[type=range]{
|
||||
width: 90%;
|
||||
min-width: 300px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ button:hover, input[type=submit]:hover{
|
||||
max-width: 1000px;
|
||||
border-radius: 8px;
|
||||
background-color: #bbb288;
|
||||
padding: 0.5em 1.5rem 1.5rem;=
|
||||
padding: 0.5em 1.5rem 1.5rem;
|
||||
color: #282b28;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user