Editor partially started.
All checks were successful
Build Dusk / build-linux (push) Successful in 44s
Build Dusk / build-psp (push) Successful in 55s

This commit is contained in:
2025-11-19 13:00:35 -06:00
parent 1668c4b0d2
commit 903dab49e3
13 changed files with 115 additions and 88 deletions

View File

@@ -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, 5, 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, 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, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0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
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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
]
}

View File

@@ -5,8 +5,8 @@
ENTITY_DIR_SOUTH = 0 ENTITY_DIR_SOUTH = 0
ENTITY_DIR_WEST = 1 ENTITY_DIR_WEST = 1
ENTITY_DIR_NORTH = 2 ENTITY_DIR_EAST = 2
ENTITY_DIR_EAST = 3 ENTITY_DIR_NORTH = 3
CHUNK_WIDTH = 16 CHUNK_WIDTH = 16
CHUNK_HEIGHT = 16 CHUNK_HEIGHT = 16

View File

@@ -81,30 +81,30 @@ void entityWalk(entity_t *entity, const entitydir_t direction) {
bool_t fall = false; bool_t fall = false;
bool_t raise = false; bool_t raise = false;
// Are we walking up stairs? // Are we walking up a ramp?
if( if(
tileIsStairs(tileCurrent) && tileIsRamp(tileCurrent) &&
(direction+TILE_STAIRS_SOUTH) == tileCurrent && (direction+TILE_SHAPE_RAMP_SOUTH) == tileCurrent &&
newPos.z < (MAP_CHUNK_DEPTH - 1) 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; worldpos_t abovePos = newPos;
abovePos.z += 1; abovePos.z += 1;
tile_t tileAbove = mapGetTile(abovePos); tile_t tileAbove = mapGetTile(abovePos);
if(tileAbove != TILE_NULL && tileIsWalkable(tileAbove)) { if(tileAbove != TILE_SHAPE_NULL && tileIsWalkable(tileAbove)) {
// We can go up the stairs. // We can go up the ramp.
raise = true; raise = true;
} }
} else if(tileNew == TILE_NULL && newPos.z > 0) { } else if(tileNew == TILE_SHAPE_NULL && newPos.z > 0) {
// Falling down? // Falling down?
worldpos_t belowPos = newPos; worldpos_t belowPos = newPos;
belowPos.z -= 1; belowPos.z -= 1;
tile_t tileBelow = mapGetTile(belowPos); tile_t tileBelow = mapGetTile(belowPos);
if( if(
tileBelow != TILE_NULL && tileBelow != TILE_SHAPE_NULL &&
tileIsStairs(tileBelow) && tileIsRamp(tileBelow) &&
(entityDirGetOpposite(direction)+TILE_STAIRS_SOUTH) == tileBelow (entityDirGetOpposite(direction)+TILE_SHAPE_RAMP_SOUTH) == tileBelow
) { ) {
// We will fall to this tile. // We will fall to this tile.
fall = true; fall = true;

View File

@@ -179,7 +179,7 @@ tile_t mapGetTile(const worldpos_t position) {
chunkpos_t chunkPos; chunkpos_t chunkPos;
worldPosToChunkPos(&position, &chunkPos); worldPosToChunkPos(&position, &chunkPos);
chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos); chunkindex_t chunkIndex = mapGetChunkIndexAt(chunkPos);
if(chunkIndex == -1) return TILE_NULL; if(chunkIndex == -1) return TILE_SHAPE_NULL;
chunk_t *chunk = mapGetChunk(chunkIndex); chunk_t *chunk = mapGetChunk(chunkIndex);
assertNotNull(chunk, "Chunk pointer cannot be NULL"); assertNotNull(chunk, "Chunk pointer cannot be NULL");

View File

@@ -9,11 +9,11 @@
bool_t tileIsWalkable(const tile_t tile) { bool_t tileIsWalkable(const tile_t tile) {
switch(tile) { switch(tile) {
case TILE_WALKABLE: case TILE_SHAPE_FLOOR:
case TILE_STAIRS_NORTH: case TILE_SHAPE_RAMP_NORTH:
case TILE_STAIRS_SOUTH: case TILE_SHAPE_RAMP_SOUTH:
case TILE_STAIRS_EAST: case TILE_SHAPE_RAMP_EAST:
case TILE_STAIRS_WEST: case TILE_SHAPE_RAMP_WEST:
return true; return true;
default: 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) { switch(tile) {
case TILE_STAIRS_NORTH: case TILE_SHAPE_RAMP_NORTH:
case TILE_STAIRS_SOUTH: case TILE_SHAPE_RAMP_SOUTH:
case TILE_STAIRS_EAST: case TILE_SHAPE_RAMP_EAST:
case TILE_STAIRS_WEST: case TILE_SHAPE_RAMP_WEST:
return true; return true;
default: default:

View File

@@ -10,15 +10,6 @@
typedef uint8_t tile_t; 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. * 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); 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. * @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); bool_t tileIsRamp(const tile_t tile);

View File

@@ -53,7 +53,7 @@ void sceneMapGetWorldPosition(const worldpos_t pos, vec3 outPosition) {
// Handle stair tiles. // Handle stair tiles.
tile_t tile = mapGetTile(pos); tile_t tile = mapGetTile(pos);
if(tileIsStairs(tile)) { if(tileIsRamp(tile)) {
outPosition[2] += TILE_DEPTH / 2.0f; outPosition[2] += TILE_DEPTH / 2.0f;
} }
} }

View File

@@ -91,7 +91,7 @@ def processChunk(path):
# Append the model to chunk.models # Append the model to chunk.models
chunk['models'].append(baseModel) chunk['models'].append(baseModel)
for i, tile in enumerate(inData['tiles']): for i, tile in enumerate(inData['shapes']):
# Set to chunk # Set to chunk
# Calculate x, y, z from i # Calculate x, y, z from i

View File

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

View File

@@ -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): class ChunkPanel(QWidget):
def __init__(self, parent): def __init__(self, parent):
@@ -25,6 +26,12 @@ class ChunkPanel(QWidget):
grid.addWidget(self.btnE, 1, 2) grid.addWidget(self.btnE, 1, 2)
layout.addLayout(grid) 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 # Add expandable tree list
self.tree = QTreeWidget() self.tree = QTreeWidget()
self.tree.setHeaderLabel("Chunks") self.tree.setHeaderLabel("Chunks")
@@ -49,3 +56,29 @@ class ChunkPanel(QWidget):
self.btnW.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.btnUp.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, 1))
self.btnDown.clicked.connect(lambda: self.parent.map.moveRelative(0, 0, -1)) 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])

View File

@@ -4,7 +4,7 @@ from PyQt5.QtWidgets import QFileDialog, QMessageBox
from PyQt5.QtCore import QTimer from PyQt5.QtCore import QTimer
import os import os
from editortool.map.chunk import Chunk 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 import traceback
MAP_DEFAULT_PATH = os.path.join(os.path.dirname(__file__), '../../../assets/map/') MAP_DEFAULT_PATH = os.path.join(os.path.dirname(__file__), '../../../assets/map/')
@@ -140,3 +140,24 @@ class Map:
def draw(self): def draw(self):
for chunk in self.chunks.values(): for chunk in self.chunks.values():
chunk.draw() 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)

View File

@@ -19,6 +19,8 @@ MAP_HEIGHT = 5
MAP_DEPTH = 3 MAP_DEPTH = 3
MAP_CHUNK_COUNT = MAP_WIDTH * MAP_HEIGHT * MAP_DEPTH MAP_CHUNK_COUNT = MAP_WIDTH * MAP_HEIGHT * MAP_DEPTH
TILE_SHAPES = {}
for key in defs.keys(): for key in defs.keys():
if key.startswith('TILE_SHAPE_'): if key.startswith('TILE_SHAPE_'):
globals()[key] = int(defs.get(key)) globals()[key] = int(defs.get(key))
TILE_SHAPES[key] = int(defs.get(key))

View File

@@ -23,6 +23,11 @@ class Tile:
def load(self, chunkData): def load(self, chunkData):
self.shape = getItem(chunkData['shapes'], self.index, TILE_SHAPE_NULL) 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): def getBaseTileModel(self):
vertices = [] vertices = []
indices = [] indices = []