summaryrefslogtreecommitdiff
path: root/common/chunk.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-03 19:37:28 +0000
committerubq323 <ubq323@ubq323.website>2023-02-03 19:51:07 +0000
commit1ebd7d9b7b62c8e05d527611a1944ed1a876b890 (patch)
treecfc5ddf3fc15985c4369aa12d56de5fa8d6fc7e5 /common/chunk.lua
parentec6a391cb9cf0c0feac0fe3615a59cc7cb6db2d5 (diff)
debug drawing change, zoom clamping, partial refactoring of class mechanisms to allow inheritance, minor refactor of noise generator, changes to temp worldgen, rework of class constructor mechanism
Diffstat (limited to 'common/chunk.lua')
-rw-r--r--common/chunk.lua15
1 files changed, 8 insertions, 7 deletions
diff --git a/common/chunk.lua b/common/chunk.lua
index 8e2ec40..1d3faa6 100644
--- a/common/chunk.lua
+++ b/common/chunk.lua
@@ -1,6 +1,7 @@
local json = require"common.dkjson"
+local class = require"common.class"
-local CHUNK_SIZE = 128
+local CHUNK_SIZE = 64
-- for now tiles shall be booleans
@@ -15,10 +16,9 @@ local function index(offq,offr)
return CHUNK_SIZE*offq + offr + 1
end
-local Chunk = {}
-Chunk.__index = Chunk
-function Chunk.make(tiles)
- return setmetatable({tiles=tiles},Chunk)
+local Chunk = class()
+function Chunk.make(cls,tiles)
+ return setmetatable({tiles=tiles},cls)
end
function Chunk.at(self,hoffs)
if not index_ok(hoffs.q,hoffs.r) then return nil end
@@ -35,11 +35,12 @@ end
function Chunk.from_packet_data(packet)
-- assuming packet has already been json.decoded
-- since otherwise how would we know it's a chunk packet
- return Chunk.make(packet.tiles)
+ return Chunk:make(packet.tiles)
end
return {
Chunk=Chunk,
SIZE=CHUNK_SIZE,
- index=index
+ index=index,
+ index_ok=index_ok,
}