forked from michaljaz/webmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInventoryBar.coffee
More file actions
93 lines (92 loc) · 2.86 KB
/
InventoryBar.coffee
File metadata and controls
93 lines (92 loc) · 2.86 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
class InventoryBar
constructor:(game)->
@game=game
for i in [0..9]
$(".player_hp").append("<span class='hp'></span> ")
for i in [0..9]
$(".player_food").append("<span class='food'></span> ")
for i in [1..9]
$(".inv_bar").append("<span class='inv_box item' data-texture=''></span> ")
@listen()
setHp: (points)->
lista={}
for i in [1..10]
lista[i-1]="empty"
$(".hp").eq(i-1).removeClass("empty")
$(".hp").eq(i-1).removeClass("full")
$(".hp").eq(i-1).removeClass("half")
if points isnt 0
for i in [1..(points+points%2)/2]
lista[i-1]="full"
if points%2 is 1
lista[(points+points%2)/2-1]="half"
for i in [1..10]
$(".hp").eq(i-1).addClass(lista[i-1])
return
setFood: (points)->
lista={}
for i in [1..10]
lista[10-i]="empty"
$(".food").eq(10-i).removeClass("empty")
$(".food").eq(10-i).removeClass("full")
$(".food").eq(10-i).removeClass("half")
if points isnt 0
for i in [1..(points+points%2)/2]
lista[10-i]="full"
if points%2 is 1
lista[10-(points+points%2)/2]="half"
for i in [1..10]
$(".food").eq(10-i).addClass(lista[10-i])
return
setXp: (level,progress)->
if level is 0
$(".player_xp").hide()
else
$(".player_xp").show()
$(".player_xp").text level
$(".xp_bar").css "width","#{500*progress}px"
setFocus:(num)->
$(".inv_cursor").css("left","calc(50vw - 253px + 55*#{num}px)")
@game.socket.emit "invc",num
return
updateInv:(inv)->
for i in [36..44]
if inv[i] isnt null
$(".inv_box").eq(i-36).attr("data-texture",inv[i].name)
$(".inv_box").eq(i-36).attr("data-amount",String(inv[i].count))
else
$(".inv_box").eq(i-36).attr("data-texture","")
$(".inv_box").eq(i-36).attr("data-amount","0")
return
listen:()->
focus=0
@setFocus focus
_this=@
$(window).on 'wheel', (e)->
if _this.game.FPC.gameState is "gameLock"
if e.originalEvent.deltaY > 0
focus++
else
focus--
focus=focus %% 9
_this.setFocus focus
return
tick:()->
list = $(".item")
for i in [0..list.length-1]
if $(list[i]).attr('data-texture') is ""
url=""
else
url="/assets/items/items-Atlas.png"
tex=43
items=@game.al.get "itemsMapping"
$(list[i]).css("background-repeat","no-repeat")
pos=items[$(list[i]).attr('data-texture')]
$(list[i]).css("background-position","-#{(pos.x-1)*tex}px -#{(pos.y-1)*tex}px")
$(list[i]).css("background-size","calc(1600px * #{tex/50})")
$(list[i]).css("background-image","url(#{url})")
$(list[i]).html("<div style='z-index:99;text-align:right;position:relative;bottom:-22px;color:white;font-weight:bold;'>"+$(list[i]).attr('data-amount')+"</div>")
if $(list[i]).attr('data-amount') is "0" or $(list[i]).attr('data-amount') is "1"
$(list[i]).html("<div style='z-index:99;text-align:right;position:relative;bottom:-22px;color:white;font-weight:bold;'>⁣</div>")
return
export {InventoryBar}