diff options
author | ubq323 <ubq323@ubq323.website> | 2023-02-11 00:31:54 +0000 |
---|---|---|
committer | ubq323 <ubq323@ubq323.website> | 2023-02-11 00:31:54 +0000 |
commit | 81ee73e37348eaae6b1e4a23378d13d129133904 (patch) | |
tree | f764a6d08ab788b797fb99a9e4e1ff99fba05cb6 /common | |
parent | 7952bbc2a606ab22e04112eb2f21a573d0db116e (diff) |
rework of tick interval, refactor of chunk loading/generation into ChunkS class
Diffstat (limited to 'common')
-rw-r--r-- | common/chunk.lua | 9 |
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 { |