-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparams.js
More file actions
88 lines (88 loc) · 2.58 KB
/
params.js
File metadata and controls
88 lines (88 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(function (app) {
let module = {}
class Param {
constructor(id, initvalue, type) {
this.ID = id
this.Value = initvalue
this.Type = type
}
WithName(name) {
this.Name = name
return this
}
WithDesc(desc) {
this.Desc = desc
return this
}
WithIntro(intro) {
this.Intro = intro
return this
}
Name = ""
Desc = ""
Intro = ""
ID = ""
Value = null
Type = Params.TypeString
}
class Params {
static TypeString = 0
static TypeNumber = 1
static TypeBool = 2
constructor(data) {
this.#data = data
}
Data() {
return this.#data
}
AddNumber(id, initvalue) {
let p = new Param(id, initvalue, Params.TypeNumber)
this.Params.push(p)
this.#data[id] = initvalue
return p
}
AddString(id, initvalue) {
let p = new Param(id, initvalue, Params.TypeString)
this.Params.push(p)
this.#data[id] = initvalue
return p
}
AddBool(id, initvalue) {
let p = new Param(id, initvalue, Params.TypeBool)
this.Params.push(p)
this.#data[id] = initvalue
return p
}
SetStringValues(data) {
this.Params.forEach((p) => {
let val = data[p.ID]
if (val != null) {
switch (p.Type) {
case Params.TypeString:
this.#data[p.ID] = val
break
case Params.TypeNumber:
if (!isNaN(val)) {
this.#data[p.ID] = (val - 0)
} else {
PrintSystem("无效的数字参数 " + p.ID + " : " + val)
}
break
case Params.TypeBool:
let v = val.trim().toLowerCase()
if (v == "t" || t == "true" || t == "1") {
this.#data[p.ID] = true
} else {
this.#data[p.ID] = false
}
break
}
}
})
}
Params = []
#data = {}
}
module.Params = Params
return module
})