Adding new test for Settings Module
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
974baa6cc2
commit
345458f453
8 changed files with 169 additions and 26 deletions
|
@ -23,11 +23,17 @@
|
|||
|
||||
|
||||
export class BaseEvent {
|
||||
#name
|
||||
|
||||
/**
|
||||
* @property {string} name - Name of the event.
|
||||
*/
|
||||
constructor(name) {
|
||||
this.name = name
|
||||
this.#name = name
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.#name
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,10 @@ class ObjectsAPI extends Module {
|
|||
constructor() {
|
||||
super("Objects")
|
||||
|
||||
/**
|
||||
* List of object constructors.
|
||||
* @type {Object.<string,typeof DrawableObject>}
|
||||
*/
|
||||
this.types = {}
|
||||
/**
|
||||
* List of objects for each type of object.
|
||||
|
@ -65,7 +69,7 @@ class ObjectsAPI extends Module {
|
|||
* @param {string} newName - Name to rename the object to.
|
||||
*/
|
||||
renameObject(oldName, newName) {
|
||||
let obj = this.currentObjectsByName[oldName]
|
||||
const obj = this.currentObjectsByName[oldName]
|
||||
delete this.currentObjectsByName[oldName]
|
||||
this.currentObjectsByName[newName] = obj
|
||||
obj.name = newName
|
||||
|
@ -76,7 +80,7 @@ class ObjectsAPI extends Module {
|
|||
* @param {string} objName - Current name of the object.
|
||||
*/
|
||||
deleteObject(objName) {
|
||||
let obj = this.currentObjectsByName[objName]
|
||||
const obj = this.currentObjectsByName[objName]
|
||||
if(obj !== undefined) {
|
||||
this.currentObjects[obj.type].splice(this.currentObjects[obj.type].indexOf(obj), 1)
|
||||
obj.delete()
|
||||
|
|
|
@ -49,7 +49,8 @@ class SettingsAPI extends Module {
|
|||
static emits = ["changed"]
|
||||
|
||||
#nonConfigurable = ["saveFilename"]
|
||||
|
||||
|
||||
/** @type {Map<string, string|number|boolean>} */
|
||||
#properties = new Map([
|
||||
["saveFilename", ""],
|
||||
["xzoom", 100],
|
||||
|
@ -105,9 +106,8 @@ class SettingsAPI extends Module {
|
|||
* @param {boolean} byUser - Set to true if the user is at the origin of this change.
|
||||
*/
|
||||
set(property, value, byUser) {
|
||||
if(!this.#properties.has(property)) {
|
||||
if(!this.#properties.has(property))
|
||||
throw new Error(`Property ${property} is not a setting.`)
|
||||
}
|
||||
const oldValue = this.#properties.get(property)
|
||||
const propType = typeof oldValue
|
||||
if(byUser)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue