Editor partially started.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
from dusk.event import Event
|
||||
from editortool.map.mapdefs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, CHUNK_VERTEX_COUNT_MAX
|
||||
from editortool.map.mapdefs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, CHUNK_VERTEX_COUNT_MAX, TILE_SHAPE_NULL
|
||||
from editortool.map.tile import Tile
|
||||
from editortool.map.vertexbuffer import VertexBuffer
|
||||
from OpenGL.GL import *
|
||||
@@ -54,29 +54,41 @@ class Chunk:
|
||||
|
||||
self.tileUpdateVertices()
|
||||
self.dirty = False
|
||||
self.onChunkData.invoke(self.current)
|
||||
self.onChunkData.invoke(self)
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to load chunk file: {e}")
|
||||
|
||||
def save(self):
|
||||
if not self.isDirty():
|
||||
return
|
||||
|
||||
dataOut = {
|
||||
'shapes': []
|
||||
}
|
||||
|
||||
for tile in self.tiles.values():
|
||||
dataOut['shapes'].append(tile.shape)
|
||||
|
||||
fname = self.getFilename()
|
||||
if not fname:
|
||||
raise ValueError("No filename specified for saving chunk.")
|
||||
try:
|
||||
with open(fname, 'w') as f:
|
||||
json.dump(self.current, f, indent=2)
|
||||
json.dump(dataOut, f)
|
||||
self.dirty = False
|
||||
except Exception as e:
|
||||
raise RuntimeError(f"Failed to save chunk file: {e}")
|
||||
|
||||
def new(self):
|
||||
self.current = {}
|
||||
self.original = {}
|
||||
self.onChunkData.invoke(self.current)
|
||||
for tile in self.tiles.values():
|
||||
tile.shape = TILE_SHAPE_NULL
|
||||
|
||||
self.tileUpdateVertices()
|
||||
self.dirty = False
|
||||
self.onChunkData.invoke(self)
|
||||
|
||||
def isDirty(self):
|
||||
return False
|
||||
# return json.dumps(self.current, sort_keys=True) != json.dumps(self.original, sort_keys=True)
|
||||
return self.dirty
|
||||
|
||||
def getFilename(self):
|
||||
if not self.map or not hasattr(self.map, 'getMapDirectory'):
|
||||
@@ -87,5 +99,4 @@ class Chunk:
|
||||
return f"{dir_path}/{self.x}_{self.y}_{self.z}.json"
|
||||
|
||||
def draw(self):
|
||||
glColor3f(0.0, 1.0, 1.0)
|
||||
self.vertexBuffer.draw()
|
||||
Reference in New Issue
Block a user