-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminiparse.js
executable file
·141 lines (128 loc) · 4.19 KB
/
miniparse.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
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
/*
Placeholder available
Title: #{title}
Name: #{name}
job: #{Job}
Duration: #{duration}
DPS: #{ENCDPS}
Crt %: #{crithit%}
*/
"use strict";
const encounterDefinition = '#{title} / Time: #{duration} / DPS: #{ENCDPS}';
const headerDefinition =
[
{ text: 'Name', width: '25%', align: 'left' },
{ text: 'Job', width: '8%', align: 'center' },
{ text: 'DPS', width: '18%', align: 'center' },
{ text: 'Crt.(%)', width: '14%', align: 'right' },
];
const bodyDefinition =
[
{ text: '#{name}', width: '25%' },
{ html: '<img src="./img/class/#{Job}.png" height="22px" />', width: '8%', align: 'center' },
{ text: '#{encdps}', width: '16%', align: 'right' },
{ text: '#{crithit%}', width: '14%', align: 'right' },
];
const pet_mapping = {
'Emerald Carbuncle': 'acn-pet',
'Topaz Carbuncle': 'acn-pet',
'Ruby Carbuncle': 'acn-pet',
'Garuda-Egi': 'garuda',
'Titan-Egi': 'titan',
'Ifrit-Egi': 'ifrit',
'Eos': 'eos',
'Selene': 'selene',
'Rook Autoturret': 'rook',
'Bishop Autoturret': 'bishop',
};
function resizeHandler(e) {
if (!e.detail.isLocked) {
document.documentElement.classList.add('resizeHandle');
} else {
document.documentElement.classList.remove('resizeHandle');
}
}
function updateDataHandler(e) {
updateEncounter(e.detail.Encounter);
if (!document.getElementById("combatantsTable").tHead) {
createPayersListHeader();
}
updatePlayersList(e.detail.Combatant);
}
function updateEncounter(data) {
document.getElementById("encounter").innerText = fillTemplate(encounterDefinition, data);
}
function createPayersListHeader() {
const fillHeader = (row) => (elem) => {
let cell = row.insertCell(-1);
if ('text' in elem) {
cell.innerText = elem.text;
}
if ('html' in elem) {
cell.innerHTML = elem.html;
}
if ('width' in elem) {
cell.style.width = elem.width;
cell.style.maxWidth = elem.width;
}
if ('span' in elem) {
cell.colSpan = elem.span;
}
if ('align' in elem) {
cell.style.textAlign = elem.align;
}
};
let header = document.createElement("tHead");
let row = header.insertRow();
headerDefinition.forEach(fillHeader(row));
document.getElementById("combatantsTable").tHead = header;
}
function updatePlayersList(data) {
const resolveClass = (player) => {
if (player.Job !== '') {
player.Job = player.Job.toLowerCase();
} else if (player.name === 'Limit Break'){
player.Job = 'limit';
} else if (player.name in pet_mapping) {
player.Job = pet_mapping[player.name]
}
return player;
};
const shouldDisplay = (player) => player.Job !== '';
const updatePlayerRow = (row, player) => (elem) => {
let cell = row.insertCell(-1);
if ('text' in elem) {
cell.innerText = fillTemplate(elem.text, player);
}
if ('html' in elem) {
cell.innerHTML = fillTemplate(elem.html, player);
}
if ('width' in elem) {
cell.style.width = elem.width;
cell.style.maxWidth = elem.width;
}
if ('align' in elem) {
cell.style.textAlign = elem.align;
}
};
let body = document.createElement("tbody");
for(let combatantName in data) {
let combatant = resolveClass(data[combatantName]);
if (shouldDisplay(combatant)) {
let row = body.insertRow(-1);
bodyDefinition.forEach(updatePlayerRow(row, combatant));
}
}
let oldBody = document.getElementById("combatantsTable").tBodies[0];
if(!oldBody){
document.getElementById("combatantsTable").appendChild(body);
} else {
document.getElementById("combatantsTable").replaceChild(body, oldBody);
}
}
function fillTemplate(str, dict) {
const getValue = (match, key) => key in dict ? dict[key] : 'N/A';
return str.replace(/#{([^}]+)}/g, getValue);
}
document.addEventListener('onOverlayStateUpdate', resizeHandler);
document.addEventListener('onOverlayDataUpdate', updateDataHandler);