-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pen.aspl
47 lines (41 loc) · 1.39 KB
/
Pen.aspl
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
import graphics
class Pen {
[public]
property Color color
[public]
property int thickness
[public]
method construct(Color color, int thickness){
this.color = color
this.thickness = thickness
}
[public]
[static]
method jsonDecodePens(string str) returns list<Pen>{
var list<Pen> pens = []
var jsonPens = list<any>(json.decode(str))
foreach(jsonPens as jsonPen){
var Color color = Color:fromRGBA(byte(map<string, any>(map<string, any>(jsonPen)["color"])["r"]), byte(map<string, any>(map<string, any>(jsonPen)["color"])["g"]), byte(map<string, any>(map<string, any>(jsonPen)["color"])["b"]), byte(map<string, any>(map<string, any>(jsonPen)["color"])["a"]))
var Pen pen = new Pen(color, int(map<string, any>(jsonPen)["thickness"]))
pens.add(pen)
}
return pens
}
[public]
[static]
method jsonEncodePens(list<Pen> pens) returns string{
var list<any> jsonPens = []
foreach(pens as p){
var map<string, any> jsonPen = {}
jsonPen["thickness"] = p.thickness
jsonPen["color"] = map<string, any>{
"r" => p.color.r,
"g" => p.color.g,
"b" => p.color.b,
"a" => p.color.a
}
jsonPens.add(jsonPen)
}
return json.encode(jsonPens)
}
}