Removing typed config functions in Helper.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2995b2271a
commit
b33e1329db
11 changed files with 53 additions and 149 deletions
|
@ -138,7 +138,7 @@ class HistoryAPI extends Module {
|
|||
if(action instanceof Action) {
|
||||
console.log("Added new entry to history: " + action.getReadableString())
|
||||
this.undoStack.push(action)
|
||||
if(this.#helper.getSettingBool("reset_redo_stack"))
|
||||
if(this.#helper.getSetting("reset_redo_stack"))
|
||||
this.redoStack = []
|
||||
this.emit(new AddedEvent(action))
|
||||
}
|
||||
|
|
|
@ -109,37 +109,13 @@ export class HelperInterface extends Interface {
|
|||
/**
|
||||
* Gets a setting from the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||
* @returns {boolean} Value of the setting
|
||||
*/
|
||||
getSettingBool = FUNCTION
|
||||
/**
|
||||
* Gets a setting from the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||
* @returns {number} Value of the setting
|
||||
*/
|
||||
getSettingInt = FUNCTION
|
||||
/**
|
||||
* Gets a setting from the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||
* @returns {string} Value of the setting
|
||||
* @returns {string|number|boolean} Value of the setting
|
||||
*/
|
||||
getSetting = FUNCTION
|
||||
/**
|
||||
* Sets a setting in the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||
* @param {boolean} value
|
||||
*/
|
||||
setSettingBool = FUNCTION
|
||||
/**
|
||||
* Sets a setting in the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||
* @param {number} value
|
||||
*/
|
||||
setSettingInt = FUNCTION
|
||||
/**
|
||||
* Sets a setting in the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||
* @param {string} value
|
||||
* @param {string|number|boolean} value
|
||||
*/
|
||||
setSetting = FUNCTION
|
||||
/**
|
||||
|
|
|
@ -81,7 +81,7 @@ class LatexAPI extends Module {
|
|||
initialize({ latex, helper }) {
|
||||
super.initialize({ latex, helper })
|
||||
this.#latex = latex
|
||||
this.enabled = helper.getSettingBool("enable_latex")
|
||||
this.enabled = helper.getSetting("enable_latex")
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -81,21 +81,9 @@ class SettingsAPI extends Module {
|
|||
initialize({ helper }) {
|
||||
super.initialize({ helper })
|
||||
// Initialize default values.
|
||||
for(const key of this.#properties.keys()) {
|
||||
if(!this.#nonConfigurable.includes(key)) {
|
||||
switch(typeof this.#properties.get(key)) {
|
||||
case "boolean":
|
||||
this.set(key, helper.getSettingBool("default_graph."+key), false)
|
||||
break
|
||||
case "number":
|
||||
this.set(key, helper.getSettingInt("default_graph."+key), false)
|
||||
break
|
||||
case "string":
|
||||
this.set(key, helper.getSetting("default_graph."+key), false)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
for(const key of this.#properties.keys())
|
||||
if(!this.#nonConfigurable.includes(key))
|
||||
this.set(key, helper.getSetting("default_graph."+key), false)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -53,11 +53,11 @@ export class BoolSetting extends Setting {
|
|||
}
|
||||
|
||||
value() {
|
||||
return Helper.getSettingBool(this.nameInConfig)
|
||||
return Helper.getSetting(this.nameInConfig)
|
||||
}
|
||||
|
||||
set(value) {
|
||||
Helper.setSettingBool(this.nameInConfig, value)
|
||||
Helper.setSetting(this.nameInConfig, value === true)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,11 +69,11 @@ export class NumberSetting extends Setting {
|
|||
}
|
||||
|
||||
value() {
|
||||
return Helper.getSettingInt(this.nameInConfig)
|
||||
return Helper.getSetting(this.nameInConfig)
|
||||
}
|
||||
|
||||
set(value) {
|
||||
Helper.setSettingInt(this.nameInConfig, value)
|
||||
Helper.setSetting(this.nameInConfig, +value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,11 +84,11 @@ export class EnumIntSetting extends Setting {
|
|||
}
|
||||
|
||||
value() {
|
||||
return Helper.getSettingInt(this.nameInConfig)
|
||||
return Helper.getSetting(this.nameInConfig)
|
||||
}
|
||||
|
||||
set(value) {
|
||||
Helper.setSettingInt(this.nameInConfig, value)
|
||||
Helper.setSetting(this.nameInConfig, +value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,6 +131,6 @@ export class StringSetting extends Setting {
|
|||
}
|
||||
|
||||
set(value) {
|
||||
Helper.setSetting(this.nameInConfig, value)
|
||||
Helper.setSetting(this.nameInConfig, ""+value)
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ const XMIN = new NumberSetting(
|
|||
qsTranslate("Settings", "Min X"),
|
||||
"default_graph.xmin",
|
||||
"xmin",
|
||||
() => Helper.getSettingBool("default_graph.logscalex") ? 1e-100 : -Infinity
|
||||
() => Helper.getSetting("default_graph.logscalex") ? 1e-100 : -Infinity
|
||||
)
|
||||
|
||||
const YMAX = new NumberSetting(
|
||||
|
|
|
@ -53,7 +53,13 @@ export class MockHelper {
|
|||
this.__settings = { ...DEFAULT_SETTINGS }
|
||||
}
|
||||
|
||||
__getSetting(settingName) {
|
||||
|
||||
/**
|
||||
* Gets a setting from the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||
* @returns {string|number|boolean} Value of the setting
|
||||
*/
|
||||
getSetting(settingName) {
|
||||
const namespace = settingName.split(".")
|
||||
let data = this.__settings
|
||||
for(const name of namespace)
|
||||
|
@ -64,7 +70,12 @@ export class MockHelper {
|
|||
return data
|
||||
}
|
||||
|
||||
__setSetting(settingName, value) {
|
||||
/**
|
||||
* Sets a setting in the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||
* @param {string|number|boolean} value
|
||||
*/
|
||||
setSetting(settingName, value) {
|
||||
const namespace = settingName.split(".")
|
||||
const finalName = namespace.pop()
|
||||
let data = this.__settings
|
||||
|
@ -76,60 +87,6 @@ export class MockHelper {
|
|||
data[finalName] = value
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a setting from the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||
* @returns {boolean} Value of the setting
|
||||
*/
|
||||
getSettingBool(settingName) {
|
||||
return this.__getSetting(settingName) === true
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a setting from the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||
* @returns {number} Value of the setting
|
||||
*/
|
||||
getSettingInt(settingName) {
|
||||
return +(this.__getSetting(settingName))
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a setting from the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to get (e.g. "default_graph.xmin")
|
||||
* @returns {string} Value of the setting
|
||||
*/
|
||||
getSetting(settingName) {
|
||||
return this.__getSetting(settingName).toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a setting in the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||
* @param {boolean} value
|
||||
*/
|
||||
setSettingBool(settingName, value) {
|
||||
return this.__setSetting(settingName, value === true)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a setting in the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||
* @param {number} value
|
||||
*/
|
||||
setSettingInt(settingName, value) {
|
||||
return this.__setSetting(settingName, +(value))
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a setting in the config
|
||||
* @param {string} settingName - Setting (and its dot-separated namespace) to set (e.g. "default_graph.xmin")
|
||||
* @param {string} value
|
||||
*/
|
||||
setSetting(settingName, value) {
|
||||
return this.__setSetting(settingName, value.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends data to be written
|
||||
* @param {string} file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue