forked from antialiasis/favorite-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpicker.html
248 lines (221 loc) · 7.48 KB
/
picker.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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0">
<link rel="stylesheet" href="picker.css">
<title>Favorite Monster Picker</title>
</head>
<body>
<h1>Favorite Monster Picker</h1>
<p>
How to use:
<ol>
<li>Pick any number of monsters you like</li>
<li>Click "pick" to comfirm the pick of this round</li>
<li>Repeat to list your top favorites</li>
</ol>
</p>
<div>
<div class="settings-container">
<div class="settings-child">Include the monsters appeared in games/expensions:</div>
<div class="settings-child">
<label>
<!-- <input type="checkbox" name="games_appeared" class="games_appeared" value="any">
Any</label><br> -->
<label>
<input type="checkbox" name="games_appeared" class="games_appeared" value="world_iceborne">
World / Iceborne</label><br>
<label>
<input type="checkbox" name="games_appeared" class="games_appeared" value="rise_sunbreak">
Rise / Sunbreak</label><br>
</div>
</div>
<div class="settings-container">
<div class="settings-child">Include subspecies:</div>
<div class="settings-child">
<label>
<input type="radio" name="subspecies" class="subspecies" value="all">
All</label><br>
<label>
<input type="radio" name="subspecies" class="subspecies" value="soft">
Only if the base species is not in the the selected game(s)</label><br>
<label>
<input type="radio" name="subspecies" class="subspecies" value="none">
None</label><br>
</div>
</div>
<div class="settings-container">
<div class="settings-child">Icon priority (drag to reorder):</div>
<div class="settings-child" id="icon_priority_list">
<div><label value="rise_sunbreak">Rise/Sunbreak</label></div>
<div><label value="world_iceborne">World/Iceborne</label></div>
<div><label value="official_render">Official render</label></div>
</div>
</div>
</div>
<div id="container">
<div id="picking">
<ul id="evaluating" class="item-list">
</ul>
<p id="buttons">
<button id="pick">Pick</button> <button id="pass">Pass</button>
<button id="undo">Undo</button> <button id="redo">Redo</button>
<button id="reset">Reset</button>
</p>
<p id="status">
<p id="message">
Monsters to be elimated for this round: <span id="competing_num">0</span><br>
Monsters to yet to be picked as favorite: <span id="remaining_num">0</span>
</p>
</p>
</div>
<div id="secondary">
<h2>Found favorites</h2>
<ol id="favorites" class="item-list">
</ol>
</div>
</div>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="picker.js"></script>
<script src="picker-ui.js"></script>
<script src="items-data.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/Sortable.min.js"></script>
<script>
'use strict';
const items = items_all;
const items_obj = items.reduce((acc, curr) => {
acc[curr.id] = curr;
return acc;
}, {})
function is_in_game(id, games){
let item = items_obj[id];
let is_in_games_appeared = false;
for (let game of games) {
if (item.games.indexOf(game) !== -1) {
is_in_games_appeared = true;
break;
}
}
return is_in_games_appeared;
}
var myPicker = new picker.Picker({
items: items,
localStorageKey: 'picker-state',
defaultSettings: {
maxBatchSize: 10,
games_appeared: ['world_iceborne', 'rise_sunbreak'],
subspecies: 'all'
},
shouldIncludeItem: function (item, settings) {
let games = settings.games_appeared;
let self_in_game = is_in_game(item.id, games);
if(!self_in_game){
return false;
}
let base_mon = item.base;
switch (settings.subspecies) {
case 'all':
return true;
break;
case 'none':
return !base_mon;
break;
case 'soft':
return !base_mon || !is_in_game(base_mon, games);
break;
default:
break;
}
return self_in_game;
}
});
var pickerUI = new PickerUI(myPicker, {
elements: {
pick: "#pick",
pass: "#pass",
undo: "#undo",
redo: "#redo",
reset: "#reset",
evaluating: "#evaluating",
favorites: "#favorites",
settings: {
games_appeared: '.games_appeared',
subspecies: '.subspecies',
}
},
getItemImageUrl: function (item, settings) {
let itemHandlers = {
rise_sunbreak: function (item) {
if (item.games.indexOf('rise_sunbreak') !== -1) {
return 'image/rise_sunbreak/' + item.image;
}
return null;
},
world_iceborne: function (item) {
if (item.games.indexOf('world_iceborne') !== -1) {
return 'image/world_iceborne/' + item.image;
}
return null;
},
official_render: function (item) {
return 'image/official_render/' + item.image;
},
};
for (let sel of icon_priority) {
let url = itemHandlers[sel](item);
if (url) {
return url;
}
}
return itemHandlers.official_render(item);
},
onUpdate: function(){
let state = this.picker.state.getState();
const competing_span = document.getElementById('competing_num');
const competing_num =
state.current.length + state.evaluating.length + state.survived.length;
competing_span.textContent = competing_num - 1;
const remaining_span = document.getElementById('remaining_num');
const remaining_num =
state.current.length + state.evaluating.length
+ state.survived.length + state.eliminated.length;
remaining_span.textContent = remaining_num;
},
});
pickerUI.initialize();
/* Sortable icon priority list */
var icon_priority = [];
var icon_priority_list = document.getElementById('icon_priority_list');
var sortable_icon_priority = new Sortable(icon_priority_list, {
onUpdate: function (event) {
let labels = Array.from(event.to.getElementsByTagName('label'));
icon_priority = labels.map(e => e.getAttribute('value'));
pickerUI.update();
}
});
{
let labels = Array.from(icon_priority_list.getElementsByTagName('label'));
icon_priority = labels.map(e => e.getAttribute('value'));
pickerUI.update();
}
/* Sortable favorites - you can safely remove this, and the Sortable.min.js script, if you don't want to be able to sort your favorite list. */
var sortable_favorite = new Sortable(pickerUI.elem.favorites.get(0), {
draggable: '.item',
animation: 100,
onStart: function () {
pickerUI.elem.favorites.addClass("sorting");
},
onEnd: function () {
pickerUI.elem.favorites.removeClass("sorting");
},
onUpdate: function () {
myPicker.setFavorites(pickerUI.elem.favorites.children().map(function () {
return pickerUI.getItem(this);
}).get());
pickerUI.update();
}
});
/* End sortable favorites */
</script>
</body>
</html>