Ent saving and loading
This commit is contained in:
@@ -22,9 +22,6 @@ class Chunk:
|
||||
self.tiles = {}
|
||||
self.vertexBuffer = VertexBuffer()
|
||||
|
||||
# TEST
|
||||
self.addEntity()
|
||||
|
||||
tileIndex = 0
|
||||
for tz in range(CHUNK_DEPTH):
|
||||
for ty in range(CHUNK_HEIGHT):
|
||||
@@ -56,10 +53,19 @@ class Chunk:
|
||||
# For each tile.
|
||||
for tile in self.tiles.values():
|
||||
tile.load(data)
|
||||
|
||||
# For each entity.
|
||||
self.entities = {}
|
||||
if 'entities' in data:
|
||||
for id, entData in enumerate(data['entities']):
|
||||
ent = Entity(self)
|
||||
ent.load(entData)
|
||||
self.entities[id] = ent
|
||||
|
||||
self.tileUpdateVertices()
|
||||
self.dirty = False
|
||||
self.onChunkData.invoke(self)
|
||||
self.map.onEntityData.invoke()
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to load chunk file: {e}")
|
||||
|
||||
@@ -68,11 +74,17 @@ class Chunk:
|
||||
return
|
||||
|
||||
dataOut = {
|
||||
'shapes': []
|
||||
'shapes': [],
|
||||
'entities': []
|
||||
}
|
||||
|
||||
for tile in self.tiles.values():
|
||||
dataOut['shapes'].append(tile.shape)
|
||||
|
||||
for ent in self.entities.values():
|
||||
entData = {}
|
||||
ent.save(entData)
|
||||
dataOut['entities'].append(entData)
|
||||
|
||||
fname = self.getFilename()
|
||||
if not fname:
|
||||
@@ -107,10 +119,11 @@ class Chunk:
|
||||
def draw(self):
|
||||
self.vertexBuffer.draw()
|
||||
|
||||
def addEntity(self):
|
||||
ent = Entity()
|
||||
def addEntity(self, localX=0, localY=0, localZ=0):
|
||||
ent = Entity(self, localX, localY, localZ)
|
||||
self.entities[len(self.entities)] = ent
|
||||
self.map.onEntityData.invoke()
|
||||
self.dirty = True
|
||||
return ent
|
||||
|
||||
def removeEntity(self, entity):
|
||||
@@ -118,5 +131,6 @@ class Chunk:
|
||||
if val == entity:
|
||||
del self.entities[key]
|
||||
self.map.onEntityData.invoke()
|
||||
self.dirty = True
|
||||
return True
|
||||
return False
|
||||
Reference in New Issue
Block a user