diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-04-21 18:34:15 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-04-21 18:34:15 +0800 |
commit | 4235ffd80ac8829266a7b9528c0205a0831686e2 (patch) | |
tree | f34bdeabbf1d681ea278274cf42925c28bc288cd /features/settings/settingThings | |
parent | 64cff6227af6e5f1df9685c93a2672c00a1ac171 (diff) | |
download | SoopyV2-4235ffd80ac8829266a7b9528c0205a0831686e2.tar.gz SoopyV2-4235ffd80ac8829266a7b9528c0205a0831686e2.tar.bz2 SoopyV2-4235ffd80ac8829266a7b9528c0205a0831686e2.zip |
update
Diffstat (limited to 'features/settings/settingThings')
-rw-r--r-- | features/settings/settingThings/settingBase.js | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/features/settings/settingThings/settingBase.js b/features/settings/settingThings/settingBase.js index 36bfcc1..3108308 100644 --- a/features/settings/settingThings/settingBase.js +++ b/features/settings/settingThings/settingBase.js @@ -9,7 +9,7 @@ import settingsCommunicator from "../settingsCommunicator"; import SoopyMarkdownElement from "../../../../guimanager/GuiElement/SoopyMarkdownElement"; class SettingBase { - constructor(name, description, defaultVal, settingId, module){ + constructor(name, description, defaultVal, settingId, module) { this.name = name; this.description = description; this.defaultVal = defaultVal; @@ -19,7 +19,7 @@ class SettingBase { this.val = defaultVal; - this.guiObject = new BoxWithTextAndDescription().setDesc("§0"+this.description.replace(/\n/g, "\n§0")).setText("§0"+this.name).setLocation(0, 0, 1, 0.175) + this.guiObject = new BoxWithTextAndDescription().setDesc("§0" + this.description.replace(/\n/g, "\n§0")).setText("§0" + this.name).setLocation(0, 0, 1, 0.175) this.settingObject = new SoopyGuiElement().setLocation(0.8, 0, 0.2, 1) @@ -27,22 +27,24 @@ class SettingBase { this.helpButton = new BoxWithText().setText("§0?").setLocation(3, 3, 0.05, 0.5) this.helpButton.location.location.setRelative(false, false) - - this.helpButton.addEvent(new SoopyMouseClickEvent().setHandler(()=>{ - module.FeatureManager.features.soopyGui.class.openSidebarPage(new SoopyGuiElement().setLocation(0.05,0.05,0.9,0.9).setScrollable(true).addChild(new SoopyMarkdownElement().setLocation(0,0,1,1).setText("Loading..."))) - - this.getHelp(helpText=>{ - module.FeatureManager.features.soopyGui.class.openSidebarPage(new SoopyGuiElement().setLocation(0.05,0.05,0.9,0.9).setScrollable(true).addChild(new SoopyMarkdownElement().setLocation(0,0,1,1).setText(helpText))) + + this.helpButton.addEvent(new SoopyMouseClickEvent().setHandler(() => { + module.FeatureManager.features.soopyGui.class.openSidebarPage(new SoopyGuiElement().setLocation(0.05, 0.05, 0.9, 0.9).setScrollable(true).addChild(new SoopyMarkdownElement().setLocation(0, 0, 1, 1).setText("Loading..."))) + + this.getHelp(helpText => { + module.FeatureManager.features.soopyGui.class.openSidebarPage(new SoopyGuiElement().setLocation(0.05, 0.05, 0.9, 0.9).setScrollable(true).addChild(new SoopyMarkdownElement().setLocation(0, 0, 1, 1).setText(helpText))) }) })) + this.helpButton.setLore(["Click for more information about this setting"]) + settingsCommunicator.addSetting(this.moduleId, settingId, this) - if(!module.FeatureManager.featureSettingsData[this.moduleId]){ + if (!module.FeatureManager.featureSettingsData[this.moduleId]) { module.FeatureManager.featureSettingsData[this.moduleId] = {} } - if(!module.FeatureManager.featureSettingsData[this.moduleId].subSettings)module.FeatureManager.featureSettingsData[this.moduleId].subSettings = {} - if(!module.FeatureManager.featureSettingsData[this.moduleId].subSettings[settingId]){ + if (!module.FeatureManager.featureSettingsData[this.moduleId].subSettings) module.FeatureManager.featureSettingsData[this.moduleId].subSettings = {} + if (!module.FeatureManager.featureSettingsData[this.moduleId].subSettings[settingId]) { module.FeatureManager.featureSettingsData[this.moduleId].subSettings[settingId] = { value: this.getDefaultValue(), temp_val: this.getDefaultValue() @@ -50,7 +52,7 @@ class SettingBase { module.FeatureManager.featureSettingsDataLastUpdated = true } - let temp_val_temp =module.FeatureManager.featureSettingsData[this.moduleId].subSettings[settingId].temp_val + let temp_val_temp = module.FeatureManager.featureSettingsData[this.moduleId].subSettings[settingId].temp_val this.setValue(module.FeatureManager.featureSettingsData[this.moduleId].subSettings[settingId].value) this.temp_val = temp_val_temp @@ -61,89 +63,89 @@ class SettingBase { this.initTime = Date.now() } - update(){ - if(this.hasHelp()){ + update() { + if (this.hasHelp()) { this.guiObject.addChild(this.helpButton) - this.guiObject.text.setLocation(0.075, 0, 0.8-0.075, 0.6) - }else{ + this.guiObject.text.setLocation(0.075, 0, 0.8 - 0.075, 0.6) + } else { this.guiObject.text.setLocation(0, 0, 0.8, 0.6) } } - hasHelp(){ + hasHelp() { return helpDataLoader.hasData(this.moduleId, this.settingId) } - getHelp(callback){ + getHelp(callback) { helpDataLoader.getData(this.moduleId, this.settingId, callback) } - getValue(){ + getValue() { return this.val; } - setValue(val){ - if(this.val === val) return + setValue(val) { + if (this.val === val) return this.val = val; - if(!this.requiresO || this.requiresO.getValue()){ + if (!this.requiresO || this.requiresO.getValue()) { this.temp_val = val } - if(this.module.FeatureManager.featureSettingsData[this.moduleId].subSettings[this.settingId].value !== val){ + if (this.module.FeatureManager.featureSettingsData[this.moduleId].subSettings[this.settingId].value !== val) { this.module.FeatureManager.featureSettingsData[this.moduleId].subSettings[this.settingId].value = val this.module.FeatureManager.featureSettingsDataLastUpdated = true } - if(this.module.FeatureManager.featureSettingsData[this.moduleId].subSettings[this.settingId].temp_val !== this.temp_val){ + if (this.module.FeatureManager.featureSettingsData[this.moduleId].subSettings[this.settingId].temp_val !== this.temp_val) { this.module.FeatureManager.featureSettingsData[this.moduleId].subSettings[this.settingId].temp_val = this.temp_val this.module.FeatureManager.featureSettingsDataLastUpdated = true } - if(this.onchangethings && Date.now()-this.initTime > 1000) this.onchangethings.forEach(([fun, context])=>{fun.call(context)}) + if (this.onchangethings && Date.now() - this.initTime > 1000) this.onchangethings.forEach(([fun, context]) => { fun.call(context) }) } - getName(){ + getName() { return this.name; } - getDescription(){ + getDescription() { return this.description; } - getDefaultValue(){ + getDefaultValue() { return this.defaultVal; } - getGuiObject(){ + getGuiObject() { return this.guiObject; } - requires(toggleSetting){ + requires(toggleSetting) { this.requiresO = toggleSetting - toggleSetting.toggleObject.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun)=>{ - if(newVal){ + toggleSetting.toggleObject.addEvent(new SoopyContentChangeEvent().setHandler((newVal, oldVal, resetFun) => { + if (newVal) { this.guiObject.location.size.y.set(0.2, 500) - }else{ + } else { this.guiObject.location.size.y.set(0, 500) } })) let newVal = this.requiresO.getValue() - if(!newVal){ + if (!newVal) { this.guiObject.location.size.y.set(0, 0) } return this } - delete(){ + delete() { settingsCommunicator.removeSetting(this.module, this.settingId) } - onchange(context, fun){ + onchange(context, fun) { this.onchangethings.push([fun, context]) return this } |