summaryrefslogtreecommitdiff
path: root/common/chunk.lua
diff options
context:
space:
mode:
Diffstat (limited to 'common/chunk.lua')
-rw-r--r--common/chunk.lua9
1 files changed, 4 insertions, 5 deletions
diff --git a/common/chunk.lua b/common/chunk.lua
index 790e5a4..39fcaaf 100644
--- a/common/chunk.lua
+++ b/common/chunk.lua
@@ -20,27 +20,26 @@ function Chunk.make(cls,cp,tiles)
return setmetatable({cp=cp,tiles=tiles},cls)
end
function Chunk.at(self,hoffs)
+ -- errors if invalid offset
return self:_atqr(hoffs.q,hoffs.r)
end
function Chunk._atqr(self,q,r)
- if not index_ok(q,r) then return nil end
return self.tiles[index(q,r)]
end
function Chunk.set_at(self,hoffs,tile)
- if not index_ok(hoffs.q,hoffs.r) then return end
+ -- errors if invalid offset
self.tiles[index(hoffs.q,hoffs.r)] = tile
end
function Chunk.data_packet(self)
return json.encode{t="chunk",tiles=self.tiles,u=self.cp.u,v=self.cp.v}
end
-function Chunk.from_packet_data(packet)
+function Chunk.from_packet_data(cls,packet)
-- assuming packet has already been json.decoded
-- since otherwise how would we know it's a chunk packet
local cp = coords.ChunkPos:make(packet.u,packet.v)
- print("making from packet",packet.u,packet.v)
- return Chunk:make(cp,packet.tiles)
+ return cls:make(cp,packet.tiles)
end
return {