-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.js
More file actions
168 lines (153 loc) · 2.92 KB
/
graph.js
File metadata and controls
168 lines (153 loc) · 2.92 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// broken or uncompleteable quests
let bad = new Set([
190
]);
// completeable quests
let good = new Set([
99,
100,
// dream carnival
768,
755,
761,
735,
770,
736,
744,
773,
760,
753,
774,
749,
809,
810,
811,
745,
746,
772,
762,
742,
743,
771,
766,
763,
756,
757,
758,
759,
737,
// sanrio harbour
101,
1001,
104,
1002,
1003,
108,
1005,
1004,
1009,
111,
112,
1007,
1008,
113,
114,
115,
116,
117,
118,
119,
120,
121,
122,
123,
124,
// Florapolis
151,
1012,
1013,
1014,
160,
1015,
162,
163,
1016,
164,
165,
1017,
1018,
167,
168,
1019,
1020,
1021,
173,
174,
1022,
176,
1023,
179,
1024,
1025,
183,
184,
1026,
186,
187,
189,
]);
let quests = await(await fetch("./data/quests.json")).json();
let str = "digraph G {\nbgcolor=transparent\n"
for (const quest of quests) {
let color = "white";
if (bad.has(quest.Id)) {
color = "red3"; // manual not completable
} else if (good.has(quest.Id)) {
color = "green3"; // tested completable
} else if (quest.Sections.length == 0 || quest.Sections.some(x => x.Requirements.some(y => y.Type == "Idk")) || !quest.Sections.some(x => x.Rewards.some(y => y.Type == "EndQuest")) ) {
color = "red3"; // cannot meet requirements
}
str += `n${quest.Id} [shape=record label="${quest.Name}" style=filled fillcolor=${color}]\n`;
}
let arrows = new Set();
for (const quest of quests) {
for (const sub of quest.Sections) {
for (const item of sub.Requirements) {
if (item.Type == "Quest") {
if (item.Id == quest.Id && (item.Flags == 1 || item.Flags == 2)) continue;
arrows.add(`n${item.Id} -> n${quest.Id}\n`);
}
}
}
}
for (const item of arrows) {
str += item;
}
str += "}";
let viz = new Viz();
window.viz = viz;
let button = document.createElement("button");
button.innerText = "Save png";
button.addEventListener("click", () => {
viz.renderImageElement(str).then(x => {
window.open(x.src);
});
});
document.body.append(button);
viz.renderSVGElement(str)
.then(function (element) {
element.addEventListener("mousedown", e => {
if (e.button == 1 && e.target.tagName == "text") {
let q = quests[parseInt(e.target.parentElement.id.substring(4)) - 1];
window.open(`./view.html#${q.Id}`)
e.preventDefault();
}
});
document.body.appendChild(element);
})
.catch(error => {
// Create a new Viz instance (@see Caveats page for more info)
viz = new Viz();
// Possibly display the error
console.error(error);
});