forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryBar.js
More file actions
90 lines (82 loc) · 2.31 KB
/
InventoryBar.js
File metadata and controls
90 lines (82 loc) · 2.31 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
// Generated by CoffeeScript 2.5.1
var InventoryBar,
modulo = function(a, b) { return (+a % (b = +b) + b) % b; };
InventoryBar = class InventoryBar {
setHp(points) {
var i, j, k, l, lista, ref;
lista = {};
for (i = j = 1; j <= 10; i = ++j) {
lista[i - 1] = "empty";
$(".hp").eq(i - 1).removeClass("empty");
$(".hp").eq(i - 1).removeClass("full");
$(".hp").eq(i - 1).removeClass("half");
}
if (points !== 0) {
for (i = k = 1, ref = (points + points % 2) / 2; (1 <= ref ? k <= ref : k >= ref); i = 1 <= ref ? ++k : --k) {
lista[i - 1] = "full";
}
if (points % 2 === 1) {
lista[(points + points % 2) / 2 - 1] = "half";
}
}
for (i = l = 1; l <= 10; i = ++l) {
$(".hp").eq(i - 1).addClass(lista[i - 1]);
}
}
setFood(points) {
var i, j, k, l, lista, ref;
lista = {};
for (i = j = 1; j <= 10; i = ++j) {
lista[10 - i] = "empty";
$(".food").eq(10 - i).removeClass("empty");
$(".food").eq(10 - i).removeClass("full");
$(".food").eq(10 - i).removeClass("half");
}
if (points !== 0) {
for (i = k = 1, ref = (points + points % 2) / 2; (1 <= ref ? k <= ref : k >= ref); i = 1 <= ref ? ++k : --k) {
lista[10 - i] = "full";
}
if (points % 2 === 1) {
lista[10 - (points + points % 2) / 2] = "half";
}
}
for (i = l = 1; l <= 10; i = ++l) {
$(".food").eq(10 - i).addClass(lista[10 - i]);
}
}
setXp(level, progress) {
$(".player_xp").text(level);
return $(".xp_bar").css("width", `${500 * progress}px`);
}
setFocus(num) {
return $(".inv_cursor").css("left", `calc(50vw - 253px + 55*${num}px)`);
}
updateInv(inv) {
var i, j;
for (i = j = 36; j <= 44; i = ++j) {
if (inv[i] !== null) {
$(".inv_box").eq(i - 36).css("background-image", `url(/assets/items/${inv[i].name}.png)`);
} else {
$(".inv_box").eq(i - 36).css("background-image", "");
}
}
}
listen() {
var _this, focus;
focus = 0;
this.setFocus(focus);
_this = this;
return $(window).on('wheel', function(e) {
if (e.originalEvent.deltaY > 0) {
focus++;
} else {
focus--;
}
focus = modulo(focus, 9);
return _this.setFocus(focus);
});
}
};
export {
InventoryBar
};