forked from cartoon-battle/cartoon-battle.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetailed-recipes.html
139 lines (109 loc) · 4.21 KB
/
detailed-recipes.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
---
title: Detailed Combo Recipes
weight: 12
---
<style type="text/css">
cb-card { font-size: 34%; cursor: pointer; }
.jumbotron { text-align: center; width: 12em; height: 19em; }
</style>
<div class="panel panel-default">
<div class="panel-heading">
Detailed Combo stats for two selected cards
</div>
<div class="panel-body">
<form onsubmit="return false;">
<fieldset class="form-group">
<div class="col-md-6">
<label class="form-label" for="first">First card</label>
<input class="form-control" id=first placeholder="Please wait for cards to load..."
data-cards="deck, -precombo" data-target-button=".first-button" data-target="#character">
<input class="form-control" placeholder="Select card level" pattern='^(\d+|\^)\s*[*]{0,2}$' name="level">
<button class="btn btn-default first-button" type="submit" disabled>
<span class="glyphicon glyphicon-plus"></span> Set first card
</button>
</div>
<div class="col-md-6">
<label class="form-label" for="second">Second card</label>
<input class="form-control" id=second placeholder="Please wait for cards to load..."
data-cards="deck, -precombo" data-target-button=".second-button" data-target="#item">
<input class="form-control" placeholder="Select card level" pattern='^(\d+|\^)\s*[*]{0,2}$' name="level">
<button class="btn btn-default second-button" type="submit" disabled>
<span class="glyphicon glyphicon-plus"></span> Set second card
</button>
</div>
</fieldset>
</form>
</div>
<table class="table">
<tbody>
<tr>
<td id="character"></td>
<td id="item"></td>
<td id="result"></td>
</tr>
</tbody>
</table>
<script>require(['cartoon-battle', 'cartoon-battle/util'], function (getCards, util) {
var first = document.getElementById('first');
var second = document.getElementById('second');
var character = document.getElementById('character');
var item = document.getElementById('item');
var result = document.getElementById('result');
function showResult(cards) {
var items = [character.querySelector('cb-card'), item.querySelector('cb-card')]
.filter(function (x) { return !!x; })
.map(function (card) { return card.card; });
while (result.firstChild) result.removeChild(result.firstChild);
var title = items.map(function (card) {
return card.name + " " + card.getLevelString();
}).join(" + ");
window.history.pushState({}, title ? title + " — " + originalTitle : originalTitle, "?" + title);
setTitle(title);
var combo = items.length == 2 && cards.getCombo.apply(cards, items);
if (!combo) {
return result
.appendChild(document.createElement('div'))
.appendChild(document.createElement('h2'))
.appendChild(document.createTextNode('n/a'))
.parentNode.parentNode.className = 'jumbotron';
}
result.appendChild(cards.forLevel(combo.result).node);
}
function showCard(cards, e) {
e.preventDefault();
var target = document.querySelector(this.dataset.target);
var level = this.parentNode.querySelector('[name="level"]').value;
try {
var card = e.detail ? cards.forLevel(e.detail, level) : null;
while (target.firstChild) target.removeChild(target.firstChild);
card && target.appendChild(card.node);
showResult(cards);
} catch (E) {
showMessage(E, 'danger');
}
}
getCards(function (cards) {
first.addEventListener('card', showCard.bind(first, cards));
second.addEventListener('card', showCard.bind(second, cards));
function deferred_combos() {
if (!first.find) { // wait for other scripts to attach to the input
setTimeout(deferred_combos, 250);
return ;
}
var targets = [first, second];
decodeURIComponent(window.location.search.substr(1)).split(/\s*\+\s*/).map(function (s) {
return s.match(util.card_with_level_re).slice(1, 3);
}).forEach(function (card, idx) {
var target = targets[idx];
if (target) {
target.value = card.shift();
target.parentNode.querySelector('[name="level"]').value = card.shift() || "1";
target.form.querySelector(target.dataset.targetButton).onclick();
}
});
}
window.onpopstate = deferred_combos;
deferred_combos();
});
});</script>
</div>