-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcard.js
116 lines (91 loc) · 2.26 KB
/
card.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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Define exports
var exports = module.exports = function Card() {
this.properties = {};
}
// Constants
const REGEX_STRIP = /(<(.*?)>)/g
// Private methods
function strip(value) {
if (value == undefined) {
return "";
}
return value.replace(REGEX_STRIP, "").trim();
}
// Public methods
exports.prototype.parse = function(key, value) {
key = strip(key);
value = strip(value);
//console.log(key + ": " + value);
switch(key) {
case "English":
this.set("name", value);
break;
case "text":
case "Attribute":
case "Type":
case "Types":
case "Level":
case "Rank":
case "Materials":
case "Pendulum Scale":
case "Property":
if (key == "Types") {
key = "Type";
}
this.set(key.toLowerCase(), value);
break;
// It's a monster
case "ATK/DEF":
vals = value.split("/");
this.set("attack", vals[0]);
this.set("defense", vals[1]);
this.set("monster", "true");
break;
}
}
exports.prototype.set = function(key, value) {
this.properties[key] = value;
}
exports.prototype.get = function(key) {
return this.properties[key];
}
exports.prototype.has = function(key) {
return this.properties[key] !== undefined;
}
exports.prototype.format = function() {
var output = "";
if (this.has("monster")) {
// Name
output += "**" + this.get("name") + "**\n";
// Category
output += "Category: __Monster Card__, ";
// Level/Rank
if (this.has("level")) {
output += "Level: __" + this.get("level") + "__, ";
} else if (this.has("rank")) {
output += "Rank: __" + this.get("rank") + "__, ";
}
if (this.has("pendulum scale")) {
output += "Scale: __" + this.get("pendulum scale") + "__, ";
}
// Type
output += "Type: __" + this.get("type") + "__, ";
// Attribute
output += "Attribute: __" + this.get("attribute") + "__\n\n";
// Text
output += "*" + this.get("text") + "*\n";
// Stats
output += "ATK: __" + this.get("attack") + "__ DEF: __" + this.get("defense") + "__";
return output;
} else {
// Name
output += "**" + this.get("name") + "**\n";
// Category
output += "Category: __" + this.get("type") + "__, ";
// Property
output += "Property: __" + this.get("property") + "__\n\n";
// Text
output += "*" + this.get("text") + "*";
return output;
}
}