Save some settings to localstorage

This commit is contained in:
Evan Barger 2020-07-18 13:13:29 -04:00
parent 20bb05d404
commit 7050143831
2 changed files with 38 additions and 5 deletions

View File

@ -147,12 +147,12 @@
<div class="flex-item">
<input id="englishPatch-input" type="checkbox" v-model:checked="englishPatch"/>
<label for="englishPatch-input">Translate the menu into English.</label>
<!-- <a href="img/menu_comparison.png">Comparison here.</a> -->
<!-- <a href="img/menu_comparison.png">?</a> -->
</div>
<div class="flex-item">
<input id="forceDMG-input" type="checkbox" v-model:checked="forceDMG"/>
<label for="forceDMG-input">Use the DMG menu and music on color systems.</label>
<!-- <a href="img/menu_comparison.png">Comparison here.</a> -->
<a href="img/menu_comparison.png">?</a>
</div>
</div>
</div>

View File

@ -1,3 +1,7 @@
const parseBool = (boolString) => {
return boolString.toLowerCase() === 'true';
};
Vue.component('bitmap-preview', {
props: ['data'],
mounted: function() {
@ -74,6 +78,8 @@ let app = new Vue({
fontsLoaded: false,
},
created: function() {
this.loadSettingsFromStorage();
this.processor.menu = this.menu;
this.processor.tickerText = this.tickerText;
this.processor.forceDMG = this.forceDMG;
@ -94,11 +100,21 @@ let app = new Vue({
},
watch: {
roms: function() { this.processor.roms = this.roms; },
forceDMG: function() { this.processor.forceDMG = this.forceDMG; },
cartType: function() { this.processor.cartType = this.cartType; },
englishPatch: function() { this.processor.englishPatch = this.englishPatch; },
forceDMG: function() {
this.processor.forceDMG = this.forceDMG;
this.writeSettingsToStorage();
},
cartType: function() {
this.processor.cartType = this.cartType;
this.writeSettingsToStorage();
},
englishPatch: function() {
this.processor.englishPatch = this.englishPatch;
this.writeSettingsToStorage();
},
fontIndex: function() {
for (let i = 0; i < this.roms.length; i++) { this.roms[i].updateBitmap(this.fontIndex); }
this.writeSettingsToStorage();
},
},
methods: {
@ -169,6 +185,23 @@ let app = new Vue({
e.target.classList.remove('over')
e.preventDefault();
},
writeSettingsToStorage: function () {
window.localStorage.setItem('fontIndex', this.fontIndex);
window.localStorage.setItem('forceDMG', this.forceDMG);
window.localStorage.setItem('englishPatch', this.englishPatch);
window.localStorage.setItem('cartType', this.cartType);
},
loadSettingsFromStorage: function() {
const fontIndex = window.localStorage.getItem('fontIndex');
const forceDMG = window.localStorage.getItem('forceDMG');
const englishPatch = window.localStorage.getItem('englishPatch');
const cartType = window.localStorage.getItem('cartType');
if (fontIndex) { this.fontIndex = parseInt(fontIndex); }
if (forceDMG) { this.forceDMG = parseBool(forceDMG); }
if (englishPatch) { this.englishPatch = parseBool(englishPatch); }
if (cartType) { this.cartType = parseInt(cartType); }
},
triggerAddMenuLabel: function(e) { this.$refs.addMenuLabel.click(); },
triggerAddRomLabel: function(e) { this.$refs.addRomLabel.click(); },
stopPropagation: function(e) { e.stopImmediatePropagation(); },