Skip to content

Commit 95ff9ce

Browse files
committed
data-item and data-texture for Item class
1 parent a5e1844 commit 95ff9ce

File tree

8 files changed

+73
-60
lines changed

8 files changed

+73
-60
lines changed

coffee/client/module/InventoryBar.coffee

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class InventoryBar
66
for i in [0..9]
77
$(".player_food").append("<span class='food'></span> ")
88
for i in [1..9]
9-
$(".inv_bar").append("<span class='inv_box'></span> ")
9+
$(".inv_bar").append("<span class='inv_box item' data-texture=''></span> ")
1010
setHp: (points)->
1111
lista={}
1212
for i in [1..10]
@@ -49,9 +49,11 @@ class InventoryBar
4949
updateInv:(inv)->
5050
for i in [36..44]
5151
if inv[i] isnt null
52-
$(".inv_box").eq(i-36).css("background-image","url(/assets/items/#{inv[i].name}.png)")
52+
$(".inv_box").eq(i-36).attr("data-texture",inv[i].name)
53+
$(".inv_box").eq(i-36).attr("data-amount",String(inv[i].count))
5354
else
54-
$(".inv_box").eq(i-36).css("background-image","")
55+
$(".inv_box").eq(i-36).attr("data-texture","")
56+
$(".inv_box").eq(i-36).attr("data-amount","0")
5557
return
5658
listen:()->
5759
focus=0
@@ -64,4 +66,17 @@ class InventoryBar
6466
focus--
6567
focus=focus %% 9
6668
_this.setFocus focus
69+
tick:()->
70+
#background-image:url('/assets/items/' attr(data-texture) '.png');
71+
list = $(".item")
72+
for i in [0..list.length-1]
73+
if $(list[i]).attr('data-texture') is ""
74+
url=""
75+
else
76+
url="'/assets/items/#{$(list[i]).attr('data-texture')}.png'"
77+
$(list[i]).css("background-image","url(#{url})")
78+
$(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>")
79+
if $(list[i]).attr('data-amount') is "0" or $(list[i]).attr('data-amount') is "1"
80+
$(list[i]).html("<div style='z-index:99;text-align:right;position:relative;bottom:-22px;color:white;font-weight:bold;'>&#8291</div>")
81+
6782
export {InventoryBar}

coffee/client/module/World/chunk.worker.coffee

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,12 @@ class TerrainManager
1414
@blocksTex=options.blocksTex
1515
console.log @blocksTex
1616
genBlockFace: (type,block,pos)->
17-
if @blocksTex[block.name] isnt undefined
18-
if @blocksTex[block.name]["all"] isnt undefined
19-
toxX=@blocksMapping[@blocksTex[block.name].all]["x"]
20-
toxY=@blocksMapping[@blocksTex[block.name].all]["y"]
21-
else if @blocksTex[block.name]["side"] isnt undefined
22-
mapka={
23-
"py":"top"
24-
"ny":"bottom"
25-
}
26-
if mapka[type] isnt undefined
27-
toxX=@blocksMapping[@blocksTex[block.name][mapka[type]]]["x"]
28-
toxY=@blocksMapping[@blocksTex[block.name][mapka[type]]]["y"]
29-
else
30-
toxX=@blocksMapping[@blocksTex[block.name]["side"]]["x"]
31-
toxY=@blocksMapping[@blocksTex[block.name]["side"]]["y"]
17+
if @blocksTex[block.name] isnt undefined or @blocksTex[String(block.stateId)] isnt undefined
18+
if @blocksTex[String(block.stateId)] isnt undefined
19+
xd=@blocksTex[String(block.stateId)]
3220
else
33-
toxX=@blocksMapping[@blocksTex[block.name][type]]["x"]
34-
toxY=@blocksMapping[@blocksTex[block.name][type]]["y"]
35-
else if @blocksTex[String(block.stateId)] isnt undefined
36-
xd=@blocksTex[String(block.stateId)]
21+
xd=@blocksTex[block.name]
3722
if xd["all"] isnt undefined
38-
console.log "1"
3923
toxX=@blocksMapping[xd.all]["x"]
4024
toxY=@blocksMapping[xd.all]["y"]
4125
else if xd["side"] isnt undefined
@@ -44,15 +28,12 @@ class TerrainManager
4428
"ny":"bottom"
4529
}
4630
if mapka[type] isnt undefined
47-
console.log "2"
4831
toxX=@blocksMapping[xd[mapka[type]]]["x"]
4932
toxY=@blocksMapping[xd[mapka[type]]]["y"]
5033
else
51-
console.log xd["side"]
5234
toxX=@blocksMapping[xd["side"]]["x"]
5335
toxY=@blocksMapping[xd["side"]]["y"]
5436
else
55-
console.log xd[type]
5637
toxX=@blocksMapping[xd[type]]["x"]
5738
toxY=@blocksMapping[xd[type]]["y"]
5839
else if block.name is "water"

coffee/client/module/index.coffee

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ render = ->
197197
world.updateCellsAroundPlayer camera.position,params.chunkdist
198198

199199
#Updatowanie sceny i animacji TWEEN
200-
TWEEN.update();
200+
TWEEN.update()
201201
renderer.render scene, camera
202+
inv_bar.tick()
202203
return
203204

204205
#Funkcja animate

src/client/css/style.css

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,26 @@ canvas {
219219
height:485px;
220220
transform: translate(-50%,-50%);
221221
}
222-
.inv_box{
223-
background-repeat: no-repeat;
222+
.item{
223+
background-repeat: no-repeat;
224224
background-size: 43px 43px;
225+
width:43px;
226+
height:43px;
227+
-webkit-text-stroke: 1px black;
228+
color: white;
229+
text-shadow:
230+
1px 1px 0 #000,
231+
-1px -1px 0 #000,
232+
1px -1px 0 #000,
233+
-1px 1px 0 #000,
234+
1px 1px 0 #000;
235+
font-weight:bold;
236+
font-size:17px;
237+
}
238+
.inv_box{
225239
display:inline-block;
226240
margin-left:9px;
227241
margin-top:9px;
228-
width:43px;
229-
height:43px;
230242
margin-right:-1px;
231243
}
232244
.inv_cursor{

src/client/module/InventoryBar.js

Lines changed: 27 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/module/World/chunk.worker.js

Lines changed: 4 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/client/module/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ module.exports = {
2828
new CopyWebpackPlugin({
2929
patterns:[
3030
{from: 'src/client/assets',to: 'assets'},
31-
{from: 'src/client/css',to: 'css'},
32-
{from: 'src/client/index.html',to: 'index.html'}
31+
{from: 'src/client/css',to: 'css'}
3332
]
3433
})
3534
]

0 commit comments

Comments
 (0)