summaryrefslogtreecommitdiff
path: root/client/game.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-08-26 08:22:06 +0100
committerubq323 <ubq323@ubq323.website>2023-08-26 08:22:06 +0100
commite95fc908f3952737e41efce88c83ce7414e130b0 (patch)
tree42795f0bd98a7e790005ac6d5f41a0f836e5e8ea /client/game.lua
parentaace7b1f9c80f5cb4b155d8b2db51f355b6f81b2 (diff)
add player inventories
Diffstat (limited to 'client/game.lua')
-rw-r--r--client/game.lua22
1 files changed, 19 insertions, 3 deletions
diff --git a/client/game.lua b/client/game.lua
index 4fc148b..43e2352 100644
--- a/client/game.lua
+++ b/client/game.lua
@@ -204,7 +204,6 @@ local function handle_net()
remote_players[id]=nil
elseif op == "move" then
local id,x,y = j.id,j.x,j.y
- assert(remote_players[id],"wheeze "..id)
remote_players[id].pos.x = x
remote_players[id].pos.y = y
elseif op == "you" then
@@ -213,7 +212,10 @@ local function handle_net()
pos=coords.Pos:make(pl.x,pl.y),
color=pl.color, id=pl.id,
username=pl.username,
+ inv = {},
}
+ elseif op == "inv" then
+ local_player.inv = j.inv
elseif op == "chunk" then
local ch = ChunkC:from_packet_data(j)
map:add_chunk(ch)
@@ -240,8 +242,10 @@ local function update(dt)
local mh =
camera:screen_to_world(Pos:make(msx,msy)):to_hex():round()
if map:at(mh) == 0 and love.mouse.isDown(1) then
- map:set_at(mh,selected_tile)
- send_settile(mh,selected_tile)
+ if (local_player.inv[selected_tile] or 0) > 0 then
+ map:set_at(mh,selected_tile)
+ send_settile(mh,selected_tile)
+ end
elseif map:at(mh) ~= 0 and love.mouse.isDown(2) then
map:set_at(mh,0)
send_settile(mh,0)
@@ -337,6 +341,18 @@ local function draw()
},"\n"),10,10)
end
+ local inv_rows = {'inventory:'}
+ for t=1,9 do
+ local c = local_player.inv[t] or 0
+ local s = t..': '..util.tile_names[t]..' x'..c
+ if selected_tile == t then
+ s = s .. ' <--'
+ end
+ table.insert(inv_rows, s)
+ end
+ util.print_good(table.concat(inv_rows,'\n'),0,0)
+
+
if show_controls then
util.print_good(help_text,"center","center")
end