forked from billyvg/OverlayPlugin-themes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
miniparseGlowIconGraph.html
489 lines (423 loc) · 15.7 KB
/
miniparseGlowIconGraph.html
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
* {
font-family: "Meiryo";
font-size: 11px;
}
body, html {
margin: 0;
}
html {
background-image: url(handle.png);
background-position: bottom right;
background-repeat: no-repeat;
box-sizing: border-box;
height: 100%;
background-color: transparent;
overflow: hidden;
}
#combatantTable {
width: 100%;
table-layout: fixed;
border-collapse: collapse;
}
#combatantTableBody * {
color: #cccccc;
text-shadow: -1px 0 3px #4596ba, 0 1px 3px #4596ba, 1px 0 3px #4596ba, 0 -1px 3px #4596ba;
font-weight: 300;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
#combatantTableBody .mc * {
color: #ffffff;
text-shadow: 1px 1px 0px #000000, -1px 0 2px #4eb84b, 0 1px 2px #4eb84b, 1px 0 2px #4eb84b, 0 -1px 2px #4eb84b;
}
.textred {
color: #ffcdd2 !important;
text-shadow: -1px 0 3px #fc5161, 0 1px 3px #fc5161, 1px 0 3px #fc5161, 0 -1px 3px #fc5161 !important;
}
#encounter,
#combatantTableHeader * {
color: #DED7BE;
text-shadow: -1px 0 2px #795516, 0 1px 2px #795516, 1px 0 2px #795516, 0 -1px 2px #795516;
font-weight: 300;
white-space: nowrap;
}
#combatantTableHeader tr {
border-bottom: 1px solid #DED7BE;
}
th:first-child,
td:first-child {
padding-left:3px !important;
}
th:last-child,
td:last-child {
padding-right:3px !important;
}
#combatantTableBody tr:nth-child(2n+1) {
background-color: rgba(0,0,0,0.2);
}
#combatantTableBody tr:nth-child(2n) {
background-color: rgba(0,0,0,0.6);
}
#combatantTableBody td {
padding: 0px;
background: linear-gradient(to top, rgba(0,0,0,0.25) 0%,rgba(255,255,255,0.1) 100%);
background-blend-mode: soft-light;
}
#combatantTableBody .Gla td,
#combatantTableBody .Pld td,
#combatantTableBody .Mrd td,
#combatantTableBody .War td,
#combatantTableBody .Drk td {
color: #ffffff;
background-color: rgba(41,112,243,0.2);
background-blend-mode: soft-light;
}
#combatantTableBody .Cnj td,
#combatantTableBody .Whm td,
#combatantTableBody .Sch td,
#combatantTableBody .Ast td {
color: #ffffff;
background-color: rgba(107,240,86,0.2);
background-blend-mode: soft-light;
}
#combatantTableBody .Pgl td,
#combatantTableBody .Mnk td,
#combatantTableBody .Lnc td,
#combatantTableBody .Drg td,
#combatantTableBody .Arc td,
#combatantTableBody .Brd td,
#combatantTableBody .Rog td,
#combatantTableBody .Nin td,
#combatantTableBody .Acn td,
#combatantTableBody .Smn td,
#combatantTableBody .Thm td,
#combatantTableBody .Blm td,
#combatantTableBody .Mch td,
#combatantTableBody .Sam td,
#combatantTableBody .Rdm td, {
color: #ffffff;
background-color: rgba(200,3,8,0.2);
background-blend-mode: soft-light;
}
#combatantTableBody td.graphCell {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAZCAYAAADHXotLAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBXaW5kb3dzIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOkQ0MjhFNzkxODVFMzExRTRCRTAzRTY2N0MwOUY1N0RBIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOkQ0MjhFNzkyODVFMzExRTRCRTAzRTY2N0MwOUY1N0RBIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0UmVmOmluc3RhbmNlSUQ9InhtcC5paWQ6RDQyOEU3OEY4NUUzMTFFNEJFMDNFNjY3QzA5RjU3REEiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6RDQyOEU3OTA4NUUzMTFFNEJFMDNFNjY3QzA5RjU3REEiLz4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz7jNdeQAAAAe0lEQVR42uzRUQqAIBBAwTbt/ke2BItYhL6CgnkgSglpE6215c0iYj2mPmLMfZS0Lml9jjqe18m6pLmmd9vt3TbZd+6Z7a8P35mdKZ893y3f+/4/rtZFnwoIEAEBIiBABASIgAAREAEBIiBABASIgAAREAEBIiC/bxdgAMq9BBg2HXTvAAAAAElFTkSuQmCC), linear-gradient(to top, rgba(0,0,0,0.65) 0%,rgba(255,255,255,0.1) 100%);
background-blend-mode: soft-light;
background-position: left center;
background-repeat: repeat-y;
background-size: 100% 100%, 100% 100%;
}
.enc{
color: #E2EBF5;
text-shadow: -1px 0 3px #217AA2, 0 1px 3px #217AA2, 1px 0 3px #217AA2, 0 -1px 3px #217AA2;
font-weight: 300;
/* はみ出たテキストを「…」で省略する */
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
<script src="./lib/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
//
// プラグイン側から以下のような ActXiv オブジェクトとしてデータが提供される
//
// var ActXiv = {
// "Encounter": {...},
// "Combatant": {
// "PlayerName1": {...},
// "PlayerName2": {...},
// ...
// }
// };
//
// データの更新は 1 秒毎。
//
// プラグインから onOverlayDataUpdate イベントが発行されるので、それを受信することもできる
// イベントハンドラの第一引数の detail プロパティ内に上記のオブジェクトが入る
//
//
// 表示設定 (2)
//
// エンカウント情報の定義
var encounterDefine = "Time:<span class='enc'>{duration}</span> Total DPS:<span class='enc'>{dps}</span> Top Hit:<span class='enc'>{maxhit}</span>";
// 上記のエンカウント情報を HTML として扱うなら true
var useHTMLEncounterDefine = true;
// ヘッダの定義
var headerDefine =
[
{ text: "Job", width: "2em", align: "center" },
{ text: "Name", width: "9em", align: "center" },
{ text: "DPS", width: "3em", align: "center" },
{ text: "HPS", width: "3.3em", align: "center" },
{ text: "Crit", width: "2.5em", align: "center" },
{ text: "Miss", width: "2.5em", align: "center" },
{ text: "Best Hit", width: "7.5em", align: "center" }
];
// 表示するデータの定義
var bodyDefine =
[
{ html: "<img src='./images/glow/{JobOrName}.png' onerror='$(this).attr(\"src\", \"./images/error.png\");' style='width=60%;height:60%;' />", align: "center", effect: dpsBarEffect },
{ text: "{name}", width: "", align: "center",effect: myCharacterEffect },
{ text: "{encdps}", width: "", align: "center" },
{ text: "{enchps}", width: "", align: "center" },
{ text: "{crithit%}", width: "", align: "center" },
{ text: "{misses}", width: "", align: "center", effect: redTextEffect },
{ text: "{maxhit}", width: "", align: "center", }
];
function myCharacterEffect(cell, combatant, index) {
var myname = "YOU";
if (myname == combatant["name"]) {
$(cell).parents("tr").addClass("mc");
}
}
function jobColorEffect(cell, combatant, index) {
$(cell).parents("tr").addClass(combatant["Job"]);
}
function insertCommaEffect(cell) {
cell.innerText = cell.innerText.replace( /(\d)(?=(\d\d\d)+(?!\d))/g,'$1,');
}
function redTextEffect(cell) {
var num = parseInt(cell.innerText)
if (num > 0) {
$(cell).addClass("textred");
}
}
function graphEffect(cell) {
$(cell).addClass("graphCell");
}
function dpsBarEffect(cell, combatant, index) {
var tank = ["Gla", "Gld", "Pld", "Mrd", "War", "Drk"]
var dps = ["Pgl", "Mnk", "Lnc", "Drg", "Arc", "Brd", "Rog", "Nin", "Acn", "Smn", "Thm", "Blm", "Mch", "Rdm", "Sam"]
var healer = ["Cnj", "Whm", "Sch", "Ast"]
if (index == 0 || typeof dpsBarEffect.topdeeps == 'undefined') {
dpsBarEffect.topdeeps = combatant["encdps"];
}
var deeps = combatant["encdps"];
// 色指定
var job = combatant["Job"];
if (dps.indexOf(job) > -1){
var color = "rgba(200,3,8,0.3)";
} else if (tank.indexOf(job) > -1){
var color = "rgba(41,112,243,0.3)";
} else if (healer.indexOf(job) > -1){
var color = "rgba(107,240,86,0.3)";
} else {
var color = "rgba(128,0,255,0.3)";
}
var tableRow = cell.parentNode;
tableRow.style.background = "-webkit-gradient(linear, left top,right top, color-stop(0.95,"+ color + "), to(rgba(24,24,24,0.0)))";
tableRow.style.backgroundSize = (parseInt(deeps) * 100 / parseInt(dpsBarEffect.topdeeps)) + "% 100%";
tableRow.style.backgroundAttachment = "fixed";
tableRow.style.backgroundRepeat = "no-repeat";
}
function graphRendering(table) {
$("tr:eq(0) > td.graphCell", table).each(function(){
var max = 0;
$("tr > td:nth-child("+($("tr:eq(0) td", table).index($(this))+1)+")", table).each(function(){
max = (max < parseInt($(this).text().replace(/[^\d]/g,""))) ? parseInt($(this).text().replace(/[^\d]/g,"")) : max;
});
$("tr > td:nth-child("+($("tr:eq(0) td", table).index($(this))+1)+")", table).each(function(){
p = (max == 0) ? "0%" : (parseInt($(this).text().replace(/[^\d]/g,"")) / max *100) + "%";
$(this).css("background-size", p+" 100%, 100% 100%");
});
});
}
//
// 以下表示用スクリプト
//
// onOverlayDataUpdate イベントを購読
document.addEventListener("onOverlayDataUpdate", function (e) {
update(e.detail);
});
window.addEventListener("message", function (e) {
if (e.data.type === "onOverlayDataUpdate") {
update(e.data.detail);
}
});
// 表示要素の更新
function update(data) {
updateEncounter(data);
if (document.getElementById("combatantTableHeader") == null) {
updateCombatantListHeader();
}
updateCombatantList(data);
}
// エンカウント情報を更新する
function updateEncounter(data) {
// 要素取得
var encounterElem = document.getElementById('encounter');
// テキスト取得
var elementText;
if (typeof encounterDefine === 'function') {
elementText = encounterDefine(data.Encounter);
if (typeof elementText !== 'string') {
console.log("updateEncounter: 'encounterDefine' is declared as function but not returns a value as string.");
return;
}
} else if (typeof encounterDefine === 'string') {
elementText = parseActFormat(encounterDefine, data.Encounter);
} else {
console.log("updateEncounter: Could not update the encounter element due to invalid type.");
return;
}
// テキスト設定
if (!useHTMLEncounterDefine) {
encounterElem.innerText = parseActFormat(encounterDefine, data.Encounter);
} else {
encounterElem.innerHTML = parseActFormat(encounterDefine, data.Encounter);
}
}
// ヘッダを更新する
function updateCombatantListHeader() {
var table = document.getElementById('combatantTable');
var tableHeader = document.createElement("thead");
tableHeader.id = "combatantTableHeader";
var headerRow = tableHeader.insertRow();
for (var i = 0; i < headerDefine.length; i++) {
var cell = document.createElement("th");
// テキスト設定
if (typeof headerDefine[i].text !== 'undefined') {
cell.innerText = headerDefine[i].text;
} else if (typeof headerDefine[i].html !== 'undefined') {
cell.innerHTML = headerDefine[i].html;
}
// 幅設定
cell.style.width = headerDefine[i].width;
cell.style.maxWidth = headerDefine[i].width;
// 横結合数設定
if (typeof headerDefine[i].span !== 'undefined') {
cell.colSpan = headerDefine[i].span;
}
// 行揃え設定
if (typeof headerDefine[i].align !== 'undefined') {
cell.style["textAlign"] = headerDefine[i].align;
}
headerRow.appendChild(cell);
}
table.tHead = tableHeader;
}
// プレイヤーリストを更新する
function updateCombatantList(data) {
// 要素取得&作成
var table = document.getElementById('combatantTable');
var oldTableBody = table.tBodies.namedItem('combatantTableBody');
var newTableBody = document.createElement("tbody");
newTableBody.id = "combatantTableBody";
// tbody の内容を作成
var combatantIndex = 0;
for (var combatantName in data.Combatant) {
var combatant = data.Combatant[combatantName];
combatant.JobOrName = combatant.Job.toLowerCase() || combatantName;
var egiSearch = combatant.JobOrName.indexOf("-Egi (");
if (egiSearch != -1) {
combatant.JobOrName = combatant.JobOrName.substring(0, egiSearch);
}
else if (combatant.JobOrName.indexOf("Eos (") == 0) {
combatant.JobOrName = "Eos";
}
else if (combatant.JobOrName.indexOf("Selene (") == 0) {
combatant.JobOrName = "Selene";
}
else if (combatant.JobOrName.indexOf("Carbuncle (") != -1) {
// currently no carbuncle pics
}
else if (combatant.JobOrName.indexOf(" (") != -1) {
combatant.JobOrName = "choco";
}
var tableRow = newTableBody.insertRow(newTableBody.rows.length);
for (var i = 0; i < bodyDefine.length; i++)
{
var cell = tableRow.insertCell(i);
// テキスト設定
if (typeof bodyDefine[i].text !== 'undefined') {
var cellText;
if (typeof bodyDefine[i].text === 'function') {
cellText = bodyDefine[i].text(combatant, combatantIndex);
} else {
cellText = parseActFormat(bodyDefine[i].text, combatant);
}
cell.innerText = cellText;
} else if (typeof bodyDefine[i].html !== 'undefined') {
var cellHTML;
if (typeof bodyDefine[i].html === 'function') {
cellHTML = bodyDefine[i].html(combatant, combatantIndex);
} else {
cellHTML = parseActFormat(bodyDefine[i].html, combatant);
}
cell.innerHTML = cellHTML;
}
// 幅設定
cell.style.width = bodyDefine[i].width;
cell.style.maxWidth = bodyDefine[i].width;
// 行構え設定
if (typeof(bodyDefine[i].align) !== 'undefined') {
cell.style.textAlign = bodyDefine[i].align;
}
// エフェクト実行
if (typeof bodyDefine[i].effect === 'function') {
bodyDefine[i].effect(cell, combatant, combatantIndex);
}
}
combatantIndex++;
}
graphRendering(newTableBody);
// tbody が既に存在していたら置換、そうでないならテーブルに追加
if (oldTableBody != void(0)) {
table.replaceChild(newTableBody, oldTableBody);
}
else {
table.appendChild(newTableBody);
}
}
// Miniparse フォーマット文字列を解析し、表示文字列を取得する
function parseActFormat(str, dictionary)
{
var result = "";
var currentIndex = 0;
do {
var openBraceIndex = str.indexOf('{', currentIndex);
if (openBraceIndex < 0) {
result += str.slice(currentIndex);
break;
}
else {
result += str.slice(currentIndex, openBraceIndex);
var closeBraceIndex = str.indexOf('}', openBraceIndex);
if (closeBraceIndex < 0) {
// parse error!
console.log("parseActFormat: Parse error: missing close-brace for " + openBraceIndex.toString() + ".");
return "ERROR";
}
else {
var tag = str.slice(openBraceIndex + 1, closeBraceIndex);
if (typeof dictionary[tag] !== 'undefined') {
result += dictionary[tag];
} else {
console.log("parseActFormat: Unknown tag: " + tag);
result += "ERROR";
}
currentIndex = closeBraceIndex + 1;
}
}
} while (currentIndex < str.length);
return result;
}
</script>
</head>
<body>
<div id="encounter">
No data to show.
<!-- ここにエンカウント情報が入る -->
</div>
<table id="combatantTable">
<!-- ここにヘッダが入る -->
<!-- ここに各キャラの情報が入る -->
</table>
</body>
</html>