-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlistDict.js
59 lines (53 loc) · 1.7 KB
/
PlistDict.js
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
class PlistVector {
/**
* @param {string} string
*/
constructor(string) {
// string should be formatted like {x,y}
let split = string.split(",")
this.x = Number(split[0].replace("{", ""))
this.y = Number(split[1].replace("}", ""))
}
toString(isSize=false) {
if (isSize) return `${this.x}x${this.y}`
else return `${this.x}, ${this.y}`
}
static createString(x, y) {
return `{${x},${y}}`
}
}
class PlistRect {
/**
* @param {string} string
*/
constructor(string) {
// string should be formatted like {{x,y},{w,h}}
let split = string.split(",")
this.x = Number(split[0].replace("{{", ""))
this.y = Number(split[1].replace("}", ""))
this.w = Number(split[2].replace("{", ""))
this.h = Number(split[3].replace("}}", ""))
}
toString() {
return `${this.w}x${this.h} @ ${this.x}, ${this.y}`
}
static createString(x, y, w, h) {
return `{{${x},${y}},{${w},${h}}}`
}
}
class PlistDict {
/**
* @param {string} key
* @param {HTMLElement} plistDictElement
*/
constructor(key, plistDictElement) {
this.key = key
// unused afaik
//this.aliases = plistDictElement.children[1].innerHTML
this.spriteOffset = new PlistVector(plistDictElement.children[3].innerHTML)
this.spriteSize = new PlistVector(plistDictElement.children[5].innerHTML)
this.spriteSourceSize = new PlistVector(plistDictElement.children[7].innerHTML)
this.textureRect = new PlistRect(plistDictElement.children[9].innerHTML)
this.textureRotated = plistDictElement.children[11].tagName == "true"
}
}