From 903dab49e3b367844ad70ab5b20a5308f0a06c22 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Wed, 19 Nov 2025 13:00:35 -0600 Subject: [PATCH] Editor partially started. --- assets/map/map/0_0_0.json | 38 +----------------------------- src/duskdefs.env | 4 ++-- src/rpg/entity/entity.c | 20 ++++++++-------- src/rpg/world/map.c | 2 +- src/rpg/world/tile.c | 20 ++++++++-------- src/rpg/world/tile.h | 15 +++--------- src/scene/scene/scenemap.c | 2 +- tools/assetstool/processmap.py | 2 +- tools/editortool/map/chunk.py | 29 ++++++++++++++++------- tools/editortool/map/chunkpanel.py | 37 +++++++++++++++++++++++++++-- tools/editortool/map/map.py | 25 ++++++++++++++++++-- tools/editortool/map/mapdefs.py | 4 +++- tools/editortool/map/tile.py | 5 ++++ 13 files changed, 115 insertions(+), 88 deletions(-) diff --git a/assets/map/map/0_0_0.json b/assets/map/map/0_0_0.json index f24c8f4..4ba9e03 100644 --- a/assets/map/map/0_0_0.json +++ b/assets/map/map/0_0_0.json @@ -1,37 +1 @@ -{ - "shapes": [ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]} \ No newline at end of file diff --git a/src/duskdefs.env b/src/duskdefs.env index bf612be..bf5c40f 100644 --- a/src/duskdefs.env +++ b/src/duskdefs.env @@ -5,8 +5,8 @@ ENTITY_DIR_SOUTH = 0 ENTITY_DIR_WEST = 1 -ENTITY_DIR_NORTH = 2 -ENTITY_DIR_EAST = 3 +ENTITY_DIR_EAST = 2 +ENTITY_DIR_NORTH = 3 CHUNK_WIDTH = 16 CHUNK_HEIGHT = 16 diff --git a/src/rpg/entity/entity.c b/src/rpg/entity/entity.c index c081b59..c7542e7 100644 --- a/src/rpg/entity/entity.c +++ b/src/rpg/entity/entity.c @@ -81,30 +81,30 @@ void entityWalk(entity_t *entity, const entitydir_t direction) { bool_t fall = false; bool_t raise = false; - // Are we walking up stairs? + // Are we walking up a ramp? if( - tileIsStairs(tileCurrent) && - (direction+TILE_STAIRS_SOUTH) == tileCurrent && + tileIsRamp(tileCurrent) && + (direction+TILE_SHAPE_RAMP_SOUTH) == tileCurrent && newPos.z < (MAP_CHUNK_DEPTH - 1) ) { - tileNew = TILE_NULL;// Force check for stairs above. + tileNew = TILE_SHAPE_NULL;// Force check for ramp above. worldpos_t abovePos = newPos; abovePos.z += 1; tile_t tileAbove = mapGetTile(abovePos); - if(tileAbove != TILE_NULL && tileIsWalkable(tileAbove)) { - // We can go up the stairs. + if(tileAbove != TILE_SHAPE_NULL && tileIsWalkable(tileAbove)) { + // We can go up the ramp. raise = true; } - } else if(tileNew == TILE_NULL && newPos.z > 0) { + } else if(tileNew == TILE_SHAPE_NULL && newPos.z > 0) { // Falling down? worldpos_t belowPos = newPos; belowPos.z -= 1; tile_t tileBelow = mapGetTile(belowPos); if( - tileBelow != TILE_NULL && - tileIsStairs(tileBelow) && - (entityDirGetOpposite(direction)+TILE_STAIRS_SOUTH) == tileBelow + tileBelow != TILE_SHAPE_NULL && + tileIsRamp(tileBelow) && + (entityDirGetOpposite(direction)+TILE_SHAPE_RAMP_SOUTH) == tileBelow ) { // We will fall to this tile. fall = true; diff --git a/src/rpg/world/map.c b/src/rpg/world/map.c index b4f83e6..8a68c7e 100644 --- a/src/rpg/world/map.c +++ b/src/rpg/world/map.c @@ -179,7 +179,7 @@ tile_t mapGetTile(const worldpos_t position) { chunkpos_t chunkPos; worldPosToChunkPos(&position, &chunkPos); chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos); - if(chunkIndex == -1) return TILE_NULL; + if(chunkIndex == -1) return TILE_SHAPE_NULL; chunk_t *chunk = mapGetChunk(chunkIndex); assertNotNull(chunk, "Chunk pointer cannot be NULL"); diff --git a/src/rpg/world/tile.c b/src/rpg/world/tile.c index d4c706b..ce78b8c 100644 --- a/src/rpg/world/tile.c +++ b/src/rpg/world/tile.c @@ -9,11 +9,11 @@ bool_t tileIsWalkable(const tile_t tile) { switch(tile) { - case TILE_WALKABLE: - case TILE_STAIRS_NORTH: - case TILE_STAIRS_SOUTH: - case TILE_STAIRS_EAST: - case TILE_STAIRS_WEST: + case TILE_SHAPE_FLOOR: + case TILE_SHAPE_RAMP_NORTH: + case TILE_SHAPE_RAMP_SOUTH: + case TILE_SHAPE_RAMP_EAST: + case TILE_SHAPE_RAMP_WEST: return true; default: @@ -21,12 +21,12 @@ bool_t tileIsWalkable(const tile_t tile) { } } -bool_t tileIsStairs(const tile_t tile) { +bool_t tileIsRamp(const tile_t tile) { switch(tile) { - case TILE_STAIRS_NORTH: - case TILE_STAIRS_SOUTH: - case TILE_STAIRS_EAST: - case TILE_STAIRS_WEST: + case TILE_SHAPE_RAMP_NORTH: + case TILE_SHAPE_RAMP_SOUTH: + case TILE_SHAPE_RAMP_EAST: + case TILE_SHAPE_RAMP_WEST: return true; default: diff --git a/src/rpg/world/tile.h b/src/rpg/world/tile.h index 4f68193..6b1d11b 100644 --- a/src/rpg/world/tile.h +++ b/src/rpg/world/tile.h @@ -10,15 +10,6 @@ typedef uint8_t tile_t; -#define TILE_NULL 0 -#define TILE_WALKABLE 1 -#define TILE_STAIRS_SOUTH (2 + ENTITY_DIR_SOUTH) -#define TILE_STAIRS_EAST (2 + ENTITY_DIR_EAST) -#define TILE_STAIRS_WEST (2 + ENTITY_DIR_WEST) -#define TILE_STAIRS_NORTH (2 + ENTITY_DIR_NORTH) -#define TILE_TEST 6 - - /** * Returns whether or not the given tile is walkable. * @@ -28,9 +19,9 @@ typedef uint8_t tile_t; bool_t tileIsWalkable(const tile_t tile); /** - * Returns whether or not the given tile is a stairs tile. + * Returns whether or not the given tile is a ramp tile. * * @param tile The tile to check. - * @return bool_t True if stairs, false if not. + * @return bool_t True if ramp, false if not. */ -bool_t tileIsStairs(const tile_t tile); \ No newline at end of file +bool_t tileIsRamp(const tile_t tile); \ No newline at end of file diff --git a/src/scene/scene/scenemap.c b/src/scene/scene/scenemap.c index 5b96ea8..a46999b 100644 --- a/src/scene/scene/scenemap.c +++ b/src/scene/scene/scenemap.c @@ -53,7 +53,7 @@ void sceneMapGetWorldPosition(const worldpos_t pos, vec3 outPosition) { // Handle stair tiles. tile_t tile = mapGetTile(pos); - if(tileIsStairs(tile)) { + if(tileIsRamp(tile)) { outPosition[2] += TILE_DEPTH / 2.0f; } } diff --git a/tools/assetstool/processmap.py b/tools/assetstool/processmap.py index d483511..6f8af5a 100644 --- a/tools/assetstool/processmap.py +++ b/tools/assetstool/processmap.py @@ -91,7 +91,7 @@ def processChunk(path): # Append the model to chunk.models chunk['models'].append(baseModel) - for i, tile in enumerate(inData['tiles']): + for i, tile in enumerate(inData['shapes']): # Set to chunk # Calculate x, y, z from i diff --git a/tools/editortool/map/chunk.py b/tools/editortool/map/chunk.py index 303a691..14b5ccd 100644 --- a/tools/editortool/map/chunk.py +++ b/tools/editortool/map/chunk.py @@ -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() \ No newline at end of file diff --git a/tools/editortool/map/chunkpanel.py b/tools/editortool/map/chunkpanel.py index 0e96ffd..dbb68e3 100644 --- a/tools/editortool/map/chunkpanel.py +++ b/tools/editortool/map/chunkpanel.py @@ -1,4 +1,5 @@ -from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QGridLayout, QTreeWidget, QTreeWidgetItem +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QLabel, QPushButton, QGridLayout, QTreeWidget, QTreeWidgetItem, QComboBox +from editortool.map.mapdefs import CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH, TILE_SHAPES class ChunkPanel(QWidget): def __init__(self, parent): @@ -25,6 +26,12 @@ class ChunkPanel(QWidget): grid.addWidget(self.btnE, 1, 2) layout.addLayout(grid) + # Tile shape dropdown + self.tileShapeDropdown = QComboBox() + self.tileShapeDropdown.addItems(TILE_SHAPES.keys()) + self.tileShapeDropdown.setToolTip("Tile Shape") + layout.addWidget(self.tileShapeDropdown) + # Add expandable tree list self.tree = QTreeWidget() self.tree.setHeaderLabel("Chunks") @@ -48,4 +55,30 @@ class ChunkPanel(QWidget): self.btnE.clicked.connect(lambda: self.parent.map.moveRelative(1, 0, 0)) self.btnW.clicked.connect(lambda: self.parent.map.moveRelative(-1, 0, 0)) self.btnUp.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, 1)) - self.btnDown.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, -1)) \ No newline at end of file + self.btnDown.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, -1)) + self.parent.map.onMapData.sub(self.onMapData) + self.parent.map.onPositionChange.sub(self.onPositionChange) + self.tileShapeDropdown.currentTextChanged.connect(self.onTileShapeChanged) + + def onMapData(self, data): + pass + + def onPositionChange(self, pos): + tile = self.parent.map.getTileAtWorldPos(*self.parent.map.position) + if tile is None: + return + + key = "TILE_SHAPE_NULL" + for k, v in TILE_SHAPES.items(): + if v != tile.shape: + continue + key = k + break + self.tileShapeDropdown.setCurrentText(key) + + def onTileShapeChanged(self, shape_key): + tile = self.parent.map.getTileAtWorldPos(*self.parent.map.position) + + if tile is None or shape_key not in TILE_SHAPES: + return + tile.setShape(TILE_SHAPES[shape_key]) \ No newline at end of file diff --git a/tools/editortool/map/map.py b/tools/editortool/map/map.py index da9d327..db85b24 100644 --- a/tools/editortool/map/map.py +++ b/tools/editortool/map/map.py @@ -4,7 +4,7 @@ from PyQt5.QtWidgets import QFileDialog, QMessageBox from PyQt5.QtCore import QTimer import os from editortool.map.chunk import Chunk -from editortool.map.mapdefs import MAP_WIDTH, MAP_HEIGHT, MAP_DEPTH +from editortool.map.mapdefs import MAP_WIDTH, MAP_HEIGHT, MAP_DEPTH, CHUNK_WIDTH, CHUNK_HEIGHT, CHUNK_DEPTH import traceback MAP_DEFAULT_PATH = os.path.join(os.path.dirname(__file__), '../../../assets/map/') @@ -139,4 +139,25 @@ class Map: def draw(self): for chunk in self.chunks.values(): - chunk.draw() \ No newline at end of file + chunk.draw() + + def getChunkAtWorldPos(self, x, y, z): + chunkX = x // CHUNK_WIDTH + chunkY = y // CHUNK_HEIGHT + chunkZ = z // CHUNK_DEPTH + for chunk in self.chunks.values(): + if chunk.x == chunkX and chunk.y == chunkY and chunk.z == chunkZ: + return chunk + return None + + def getTileAtWorldPos(self, x, y, z): + chunk = self.getChunkAtWorldPos(x, y, z) + if not chunk: + print("No chunk found at position:", (x, y, z)) + return None + + tileX = x % CHUNK_WIDTH + tileY = y % CHUNK_HEIGHT + tileZ = z % CHUNK_DEPTH + tileIndex = tileX + tileY * CHUNK_WIDTH + tileZ * CHUNK_WIDTH * CHUNK_HEIGHT + return chunk.tiles.get(tileIndex) \ No newline at end of file diff --git a/tools/editortool/map/mapdefs.py b/tools/editortool/map/mapdefs.py index 564f892..6202e35 100644 --- a/tools/editortool/map/mapdefs.py +++ b/tools/editortool/map/mapdefs.py @@ -19,6 +19,8 @@ MAP_HEIGHT = 5 MAP_DEPTH = 3 MAP_CHUNK_COUNT = MAP_WIDTH * MAP_HEIGHT * MAP_DEPTH +TILE_SHAPES = {} for key in defs.keys(): if key.startswith('TILE_SHAPE_'): - globals()[key] = int(defs.get(key)) \ No newline at end of file + globals()[key] = int(defs.get(key)) + TILE_SHAPES[key] = int(defs.get(key)) \ No newline at end of file diff --git a/tools/editortool/map/tile.py b/tools/editortool/map/tile.py index 238b670..a97b961 100644 --- a/tools/editortool/map/tile.py +++ b/tools/editortool/map/tile.py @@ -23,6 +23,11 @@ class Tile: def load(self, chunkData): self.shape = getItem(chunkData['shapes'], self.index, TILE_SHAPE_NULL) + def setShape(self, shape): + self.shape = shape + self.chunk.dirty = True + self.chunk.tileUpdateVertices() + def getBaseTileModel(self): vertices = [] indices = []