diff options
Diffstat (limited to 'client/game.lua')
-rw-r--r-- | client/game.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/client/game.lua b/client/game.lua index 43e2352..ede8d98 100644 --- a/client/game.lua +++ b/client/game.lua @@ -214,11 +214,12 @@ local function handle_net() 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) + elseif op == "give" then + local old_count = local_player.inv[j.tile] or 0 + local_player.inv[j.tile] = old_count + 1 elseif op == "settile" then local h = coords.Hex:make(j.q,j.r) map:set_at(h,j.tile) @@ -241,10 +242,13 @@ local function update(dt) local msx,msy = love.mouse.getPosition() local mh = camera:screen_to_world(Pos:make(msx,msy)):to_hex():round() + local inv = local_player.inv if map:at(mh) == 0 and love.mouse.isDown(1) then - if (local_player.inv[selected_tile] or 0) > 0 then + local old_count = inv[selected_tile] or 0 + if old_count > 0 then map:set_at(mh,selected_tile) send_settile(mh,selected_tile) + inv[selected_tile] = old_count - 1 end elseif map:at(mh) ~= 0 and love.mouse.isDown(2) then map:set_at(mh,0) @@ -350,7 +354,7 @@ local function draw() end table.insert(inv_rows, s) end - util.print_good(table.concat(inv_rows,'\n'),0,0) + util.print_good(table.concat(inv_rows,'\n'),"end",0) if show_controls then |