-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.js
More file actions
223 lines (212 loc) · 7.98 KB
/
interface.js
File metadata and controls
223 lines (212 loc) · 7.98 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
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
//Jquery. plz replace with basic javascript from here out
$(function() {
var lastAccordion = 0;
$("#content").accordion({
active: 6,
collapsible: true,
heightStyle: 'content',
animate: {
easing: 'linear',
duration: 100,
},
activate: function(event, ui) {
var active = $("#content").accordion("option", "active");
if (active === false && lastAccordion == 6) {
$("#content").accordion("option", "active", 6);
krunchit();
} else if (active === false && lastAccordion == 7) {
parseImport();
$("#content").accordion("option", "active", 7);
} else if (active === false && lastAccordion === 0) {
flipArmy();
$("#content").accordion("option", "active", 0);
} else if (active == 7) {
if (!active_army) {
document.getElementById('importButton').innerHTML = 'Tap to Import Attacker';
} else {
document.getElementById('importButton').innerHTML = 'Tap to Import Defender';
}
} else if (active == 6) {
document.getElementById('simulateButton').innerHTML = 'Tap to Simulate';
} else if (active === false) {
$("#content").accordion("option", "active", 6);
}
if (!active_army) {
document.getElementById('statlinesButton').innerHTML = '⚔️ Statlines ⚔️';
} else {
document.getElementById('statlinesButton').innerHTML = '🛡️ Statlines 🛡️';
}
},
beforeActivate: function(event, ui) {
lastAccordion = $("#content").accordion("option", "active");
if (lastAccordion == 7) {
document.getElementById('importButton').innerHTML = 'Import';
} else if (lastAccordion == 6) {
document.getElementById('simulateButton').innerHTML = 'Simulation';
}
}
});
$(document).tooltip({
show: {
delay: 1500,
duration: 500
},
hide: {
delay: 0,
duration: 0
}
});
});
var dragTarget;
var startValue;
var startPos;
// for (spinner of document.getElementsByClassName('*')) {
// spinner.addEventListener("mousedown", spinnerDrag);
// }
for (mod of document.getElementsByClassName('mod')) {
let checkBox = mod.getElementsByClassName('selectMod');
if (checkBox[0]) {
mod.addEventListener('click', function() {
checkBox[0].checked = !checkBox[0].checked;
});
}
}
for (spinner of document.getElementsByClassName('spinner')) {
spinner.addEventListener("mousedown", spinnerDown);
spinner.addEventListener("touchstart", spinnerDown);
}
document.body.addEventListener("mousemove", spinnerDrag);
document.body.addEventListener("mouseup", spinnerUp);
document.body.addEventListener("touchmove", spinnerDrag);
document.body.addEventListener("touchend", spinnerUp);
document.body.addEventListener("touchcancel", spinnerUp);
function spinnerDown(e) {
dragTarget = e.currentTarget
startValue = Number(dragTarget.value)
startPos = Number(e.clientY || e.targetTouches[0].pageY)
}
function spinnerUp(e) {
dragTarget = null;
}
function spinnerDrag(e) {
if (dragTarget) {
let drag = e.clientY || e.targetTouches[0].pageY;
dragTarget.value = startValue - Math.floor((drag - startPos) / 40);
}
}
//
function openNav(navDiv) {
document.getElementById(navDiv).style.width = "100%";
document.getElementById(navDiv).style.backgroundColor = "#332211";
for (bar of Array.from(document.getElementsByClassName('sidenav')).concat(Array.from(document.getElementsByClassName('sidenav')))) {
bar.style.opacity = '1';
}
}
function closeNav() {
for (bar of document.getElementsByClassName('sidenav')) {
bar.style.width = "0";
bar.style.backgroundColor = "#000000";
// bar.style.opacity = '0';
}
for (bar of Array.from(document.getElementsByClassName('sidenav')).concat(Array.from(document.getElementsByClassName('sidenav')))) {
bar.style.opacity = '0';
}
}
function populateNav(navDiv) {
//We will populate the current army later
let currentArmy;
let atkrdfdr;
// Grab the correct sidebar
let sideBarNav = document.getElementById(navDiv)
//Create a close button
let closeButton = document.createElement('a');
closeButton.appendChild(document.createTextNode("×"));
closeButton.classList.add('closebtn');
//Get the side of screen you will be viewing
//And populate the current army with the correct side
if (navDiv == 'leftSidenav') {
closeButton.classList.add('leftPos');
currentArmy = atkr_army;
atkrdfdr = 'attacker';
var currentNav = document.getElementsByClassName('sidenav')[0];
} else {
closeButton.classList.add('rightPos');
currentArmy = dfdr_army;
atkrdfdr = 'defender';
var currentNav = document.getElementsByClassName('sidenav')[1];
}
closeButton.href = 'javascript:void(0)';
closeButton.setAttribute('onclick', 'closeNav(this.parentNode)');
//Clear old data from sidebar
sideBarNav.innerHTML = '';
if (!currentArmy.units.length) {
// let newTextarea = document.createElement('textarea');
// newTextarea.classList.add('importer')
// currentNav.appendChild(newTextarea)
// currentNav.innerHTML += '<textarea name="importBox" id="importBox" class="importer" rows="8" cols="38" placeholder="In Battlescribe, View a unit, switch the view type to \'Markdown\', and copy/paste into this box. Then hit \'Import\' again.">'
}
//Declare the units and models trackers
let newUnit, newModel;
//Loop through every unit in the army
currentArmy.units.forEach((unit, i) => {
newUnit = document.createElement('div');
newUnit.classList.add('unitNav');
newUnit.appendChild(document.createTextNode(unit.name));
newUnit.addEventListener("click", function() {
if (this.getElementsByClassName('abilNav').length) {
for (var abilNode of this.getElementsByClassName('abilNav')) {
abilNode.parentNode.removeChild(abilNode);
}
} else {
// for (var tag of document.getElementsByClassName('tag')) {
// tag.style = 'visibility: hidden; height: 0; margin: 0;'
// }
let newAbil = document.createElement('div')
newAbil.classList.add('abilNav');
unit.abilities.forEach((abil, i) => {
let ability = document.createElement('div');
ability.appendChild(document.createTextNode(abil));
ability.classList.add('tag', 'abilTag')
newAbil.appendChild(ability);
});
unit.rules.forEach((rule, i) => {
let newRule = document.createElement('div');
newRule.appendChild(document.createTextNode(rule));
newRule.classList.add('tag', 'ruleTag')
newAbil.appendChild(newRule);
});
console.log(unit);
unit.weaponQty.forEach((weap, i) => {
let newWeap = document.createElement('div');
newWeap.appendChild(document.createTextNode(Object.keys(weap)[0] + " x" + weap[Object.keys(weap)[0]]));
newWeap.classList.add('tag', 'weapTag')
newAbil.appendChild(newWeap);
});
this.appendChild(newAbil);
}
});
unit.models.forEach((model, j) => {
newModel = document.createElement('div');
newModel.setAttribute("onclick", 'closeNav()');
newModel.classList.add('modelNav');
let newName = document.createElement('div');
newName.classList.add('modelName');
// newName.appendChild(document.createTextNode(model.name + " x" + unit.modelQty.find(element => element[model.name])[model.name]));
newName.appendChild(document.createTextNode(model.name));
newModel.appendChild(newName);
newModel.appendChild(document.createElement('br'));
for (stat in model.statlines) {
let newStat = document.createElement('div');
newStat.appendChild(document.createTextNode(stat + " " + model.statlines[stat] + " "));
newStat.classList.add('tag')
newModel.appendChild(newStat);
}
newModel.addEventListener("click", function() {
loadModel(model);
});
newUnit.appendChild(newModel);
});
sideBarNav.appendChild(newUnit);
});
sideBarNav.appendChild(closeButton);
}