bitburner-src/src/ui/setSettingsLabels.js

117 lines
4.6 KiB
JavaScript
Raw Normal View History

import {Engine} from "../engine";
import {Settings} from "../Settings/Settings";
import {numeralWrapper} from "./numeralFormat";
function setSettingsLabels() {
function setAutosaveLabel(elem) {
if(Settings.AutosaveInterval === 0) {
elem.innerHTML = `disabled`;
} else {
elem.innerHTML = `every ${Settings.AutosaveInterval}s`;
}
}
const nsExecTime = document.getElementById("settingsNSExecTimeRangeValLabel");
const nsLogLimit = document.getElementById("settingsNSLogRangeValLabel");
const nsPortLimit = document.getElementById("settingsNSPortRangeValLabel");
const suppressMsgs = document.getElementById("settingsSuppressMessages");
const suppressFactionInv = document.getElementById("settingsSuppressFactionInvites")
const suppressTravelConfirmation = document.getElementById("settingsSuppressTravelConfirmation");
const suppressBuyAugmentationConfirmation = document.getElementById("settingsSuppressBuyAugmentationConfirmation");
const suppressHospitalizationPopup = document.getElementById("settingsSuppressHospitalizationPopup");
const autosaveInterval = document.getElementById("settingsAutosaveIntervalValLabel");
const disableHotkeys = document.getElementById("settingsDisableHotkeys");
const locale = document.getElementById("settingsLocale");
//Initialize values on labels
nsExecTime.innerHTML = Settings.CodeInstructionRunTime + "ms";
nsLogLimit.innerHTML = Settings.MaxLogCapacity;
nsPortLimit.innerHTML = Settings.MaxPortCapacity;
suppressMsgs.checked = Settings.SuppressMessages;
suppressFactionInv.checked = Settings.SuppressFactionInvites;
suppressTravelConfirmation.checked = Settings.SuppressTravelConfirmation;
suppressBuyAugmentationConfirmation.checked = Settings.SuppressBuyAugmentationConfirmation;
suppressHospitalizationPopup.checked = Settings.SuppressHospitalizationPopup;
setAutosaveLabel(autosaveInterval);
disableHotkeys.checked = Settings.DisableHotkeys;
locale.value = Settings.Locale;
numeralWrapper.updateLocale(Settings.Locale); //Initialize locale
//Set handlers for when input changes for sliders
const nsExecTimeInput = document.getElementById("settingsNSExecTimeRangeVal");
const nsLogRangeInput = document.getElementById("settingsNSLogRangeVal");
const nsPortRangeInput = document.getElementById("settingsNSPortRangeVal");
const nsAutosaveIntervalInput = document.getElementById("settingsAutosaveIntervalVal");
2018-01-20 05:47:57 +01:00
nsExecTimeInput.value = Settings.CodeInstructionRunTime;
nsLogRangeInput.value = Settings.MaxLogCapacity;
nsPortRangeInput.value = Settings.MaxPortCapacity;
nsAutosaveIntervalInput.value = Settings.AutosaveInterval;
nsExecTimeInput.oninput = function() {
nsExecTime.innerHTML = this.value + 'ms';
Settings.CodeInstructionRunTime = this.value;
};
2018-01-20 05:47:57 +01:00
nsLogRangeInput.oninput = function() {
nsLogLimit.innerHTML = this.value;
Settings.MaxLogCapacity = this.value;
};
2018-01-20 05:47:57 +01:00
nsPortRangeInput.oninput = function() {
nsPortLimit.innerHTML = this.value;
Settings.MaxPortCapacity = this.value;
};
2018-01-20 05:47:57 +01:00
nsAutosaveIntervalInput.oninput = function() {
Settings.AutosaveInterval = Number(this.value);
setAutosaveLabel(autosaveInterval)
2018-01-20 05:47:57 +01:00
if (Number(this.value) === 0) {
Engine.Counters.autoSaveCounter = Infinity;
} else {
Engine.Counters.autoSaveCounter = Number(this.value) * 5;
}
};
//Set handlers for when settings change on checkboxes
suppressMsgs.onclick = function() {
Settings.SuppressMessages = this.checked;
};
suppressFactionInv.onclick = function() {
Settings.SuppressFactionInvites = this.checked;
};
2018-02-15 05:26:43 +01:00
suppressTravelConfirmation.onclick = function() {
Settings.SuppressTravelConfirmation = this.checked;
};
suppressBuyAugmentationConfirmation.onclick = function() {
Settings.SuppressBuyAugmentationConfirmation = this.checked;
};
suppressHospitalizationPopup.onclick = function() {
Settings.SuppressHospitalizationPopup = this.checked;
}
disableHotkeys.onclick = function() {
Settings.DisableHotkeys = this.checked;
}
//Locale selector
locale.onchange = function() {
if (!numeralWrapper.updateLocale(locale.value)) {
console.warn(`Invalid locale for numeral: ${locale.value}`);
let defaultValue = 'en';
Settings.Locale = defaultValue;
locale.value = defaultValue;
return;
}
Settings.Locale = locale.value;
}
}
export { setSettingsLabels };