diff options
author | ubq323 <ubq323@ubq323.website> | 2023-01-30 20:17:41 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-01-30 20:17:41 +0000 |
commit | b4dc431b6f7d655142295e33b9228be243ab2969 (patch) | |
tree | 0d08286b18710de63f3037324bcaeaf2c44f7b04 /client | |
parent | ebe12a65c07bccfbc704667c88d8125be33067cf (diff) |
switch to using json for packet formatting
Diffstat (limited to 'client')
-rw-r--r-- | client/drawing.lua | 1 | ||||
-rw-r--r-- | client/main.lua | 40 |
2 files changed, 12 insertions, 29 deletions
diff --git a/client/drawing.lua b/client/drawing.lua index 21513cb..c8be5fd 100644 --- a/client/drawing.lua +++ b/client/drawing.lua @@ -53,7 +53,6 @@ local function draw_chunk(camera,the_chunk) local rowidx = r-tlh.r local minq = tlh.q - math.floor((rowidx+1)/2) local maxq = minq+(trh.q-tlh.q)+1 - print(string.format("r=%d; q = %d to %d",r,minq,maxq)) for q = minq,maxq do local h = coords.Hex.make(q,r) local t = the_chunk:tile_at_offset(h) diff --git a/client/main.lua b/client/main.lua index 14392d1..b2e2b3f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,5 +1,5 @@ local enet = require"enet" -local words = require"common.words" +local json = require"common.dkjson" -- local SERVER_HOSTNAME = "ubq323.website" local SERVER_HOSTNAME = "localhost" @@ -64,7 +64,7 @@ end local function sync_local_player(pl,peer) -- send updated info about local player to server if pl.pos_dirty then - peer:send(words.join("ppos",pl.pos.x,pl.pos.y)) + peer:send(json.encode{t="ppos",x=pl.pos.x,y=pl.pos.y}) end end @@ -78,38 +78,22 @@ function love.update(dt) repeat local ev = host:service() if ev and ev.type == "receive" then - local w = words.split(ev.data) - local op = w[1] + local j = json.decode(ev.data) + local op = j.t if op == "join" then - local id,x,y,r,g,b = unpack(w,2) - -- blegh - id=tonumber(id) - x=tonumber(x) - y=tonumber(y) - r=tonumber(r) - g=tonumber(g) - b=tonumber(b) - remote_players[id] = {pos=coords.Pos.make(x,y),color={r,g,b},id=id} + local pl = j.pl + remote_players[pl.id] = {pos=coords.Pos.make(pl.x,pl.y),color=pl.color,id=pl.id} elseif op == "leave" then - local id = tonumber(w[2]) + local id = j.id remote_players[id]=nil elseif op == "move" then - local id,x,y = unpack(w,2) - id=tonumber(id) - x=tonumber(x) - y=tonumber(y) - assert(remote_players[id],"wheeze") + 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 - local id,x,y,r,g,b = unpack(w,2) - id=tonumber(id) - x=tonumber(x) - y=tonumber(y) - r=tonumber(r) - g=tonumber(g) - b=tonumber(b) - local_player = {pos=coords.Pos.make(x,y),color={r,g,b},id=id} + local pl = j.pl + local_player = {pos=coords.Pos.make(pl.x,pl.y),color=pl.color,id=pl.id} end end until not ev @@ -143,7 +127,7 @@ function love.draw() love.graphics.origin() love.graphics.scale(2) - love.graphics.setColor(1,1,1) + love.graphics.setColor(0,0,0) love.graphics.print(table.concat( {"sm "..tostring(sm), "wm "..tostring(wm), |