fix a bunch of random stuff ig

This commit is contained in:
GGod 2024-03-22 00:45:41 +01:00
parent ef8a1f788e
commit 2c4a0e3861
5 changed files with 20 additions and 13 deletions

View File

@ -153,7 +153,7 @@ class MenuScreen {
/**
* Sets close button visibility. When false the close button will not be added to the menu screen
* @param {boolean} show Visibility of the close button
* @param {boolean} show Visibility of the close g button
*/
setShowCloseButton(show) {
this.showCloseButton = show;

View File

@ -6,16 +6,19 @@ const settingType = {
SELECT: [4, null]
}
class Setting {
constructor (name, storageName, type, disabled = false, defaultValue = null) {
constructor (name, storageName, type, disabled = false, defaultValue = null, description = "", customValidator = () => true) {
this.tabName = null;
this.name = name;
this.storageName = storageName;
this.type = type[0];
this.disabled = disabled;
this.defaultValue = defaultValue ?? type[1];
this.description = description;
this.validate = customValidator;
}
set(value) {
if (!this.validate(value)) return false;
this.value = value;
const settings = JSON.parse(localStorage.getItem(`${this.tabName}/settings`)) ?? {};
settings[this.name] = value;
@ -61,7 +64,7 @@ class Setting {
const id = "betterSettings/" + this.modName + "/" + this.storageName;
const span = document.createElement("span");
span.className = "setting-span";
span.title = 'Default: "' + this.defaultValue + '"' + (this.disabled ? ". This setting is disabled." : "");
span.title = 'Default: "' + this.defaultValue + '"' + (this.disabled ? ". This setting is disabled" : "") + (this.description ? `. ${this.description}` : "");
span.innerText = this.name + " ";
const element = document.createElement("input");
switch (this.type) {
@ -162,12 +165,14 @@ class SettingsTab {
if (this.categories.has(category)) this.categories.get(category).push(setting);
else this.categories.set(category, [setting]);
this.registry.set(setting.storageName, setting);
return this;
}
registerSettings(category = "General", ...settings) {
for (const setting of settings) {
this.registerSetting(setting, category);
}
return this;
}
set(name, value) {

View File

@ -257,7 +257,7 @@ if (enabledMods.includes("mods/betterMenuScreens.js")) {
// ugly way of doing it but probably works
const checkType = (key, value) => {
if (key == "behavior" && (typeof value == "function" || (value instanceof Array && value.filter(e => e instanceof Array && e.filter(s => typeof s == "string").length == e.length).length == value.length))) return true;
if (key == "behavior" && (typeof value == "function" || (value instanceof Array && value.filter(e => typeof e == "string").length == value.length))) return true;
else if (key == "behavior") return false;
if (["darkText", "hidden", "insulate", "noMix", "isFood", "forceAutoGen", "customColor", "ignoreAir", "excludeRandom", "burning", "flipX", "flipY", "flippableX", "flippableY"].includes(key) && typeof value != "boolean") return false;
if (["name", "category", "desc", "alias", "seed", "baby", "state", "stateHigh", "stateHighName", "stateHighColor", "stateLow", "stateLowNmae", "stateLowColor"].includes(key) && typeof value != "string") return false;

View File

@ -34,18 +34,19 @@ setView = (n) => {
document.querySelector('span[setting="view"]').children[0].value = view ?? 0;
}
for (const i in views) {
if (i < 4) continue;
const option = document.createElement("option");
option.setAttribute("value", i);
option.innerText = views[i];
document.querySelector('.setting-span[setting="view"]').querySelector("select").appendChild(option);
viewKey[i] = views[i];
}
runAfterLoadList.push(() => {
for (const i in views) {
if (i < 4) continue;
const option = document.createElement("option");
option.setAttribute("value", i);
option.innerText = views[i];
document.querySelector('.setting-span[setting="view"]').querySelector("select").appendChild(option);
viewKey[i] = views[i];
}
})
const vcrFont = new FontFace("VCR", "url(mods/VCR_OSD_MONO.ttf)");
vcrFont.load().then(font => {
console.log(font);
document.fonts.add(font);
})

View File

@ -89,6 +89,7 @@ elements.video = {
}
};
currentVideoFrames = [];
video.currentTime = 0;
video.onseeked = () => {