Map exec
Some checks failed
Build Dusk / build-linux (push) Successful in 1m40s
Build Dusk / build-psp (push) Failing after 1m38s

This commit is contained in:
2025-12-26 20:38:24 +10:00
parent 7940f4c487
commit 726233e55f
29 changed files with 152 additions and 33 deletions

View File

@@ -111,11 +111,11 @@ def processMap(asset):
map = Map(None)
map.load(asset['path'])
dir = map.getMapDirectory()
chunksDir = map.getChunkDirectory()
files = os.listdir(dir)
files = os.listdir(chunksDir)
if len(files) == 0:
print(f"Error: No chunk files found in map directory {dir}.")
print(f"Error: No chunk files found in {chunksDir}.")
sys.exit(1)
chunkFiles = []
@@ -133,21 +133,22 @@ def processMap(asset):
result = processChunk(chunk)
chunkFiles.extend(result['files'])
outMap = {
'files': chunkFiles
}
return assetCache(asset['path'], outMap)
# List files
chunkFiles = []
for fileName in os.listdir(asset['path']):
if not fileName.endswith('.json'):
continue
result = processChunk(os.path.join(asset['path'], fileName))
chunkFiles.extend(result['files'])
# Map file
outBuffer = bytearray()
outBuffer.extend(b'DMF')
outBuffer.extend(len(chunkFiles).to_bytes(4, 'little'))
# DMF (Dusk Map file)
fileRelative = getAssetRelativePath(asset['path'])
fileNameWithoutExt = os.path.splitext(os.path.basename(fileRelative))[0]
outputMapRelative = os.path.join(os.path.dirname(fileRelative), f"{fileNameWithoutExt}.dmf")
outputMapPath = os.path.join(args.output_assets, outputMapRelative)
os.makedirs(os.path.dirname(outputMapPath), exist_ok=True)
with open(outputMapPath, "wb") as f:
f.write(outBuffer)
outMap = {
'files': chunkFiles
}
outMap['files'].append(outputMapPath)
return assetCache(asset['path'], outMap)

View File

@@ -131,12 +131,12 @@ class Chunk:
return self.dirty
def getFilename(self):
if not self.map or not hasattr(self.map, 'getMapDirectory'):
if not self.map or not hasattr(self.map, 'getChunkDirectory'):
return None
dir_path = self.map.getMapDirectory()
if dir_path is None:
dirPath = self.map.getChunkDirectory()
if dirPath is None:
return None
return f"{dir_path}/{self.x}_{self.y}_{self.z}.json"
return f"{dirPath}/{self.x}_{self.y}_{self.z}.json"
def draw(self):
self.vertexBuffer.draw()

View File

@@ -1,4 +1,5 @@
import json
import sys
from dusk.event import Event
from PyQt5.QtWidgets import QFileDialog, QMessageBox
from PyQt5.QtCore import QTimer
@@ -129,11 +130,17 @@ class Map:
return self.mapFileName if self.mapFileName and os.path.exists(self.mapFileName) else None
def getMapDirectory(self):
fname = self.getMapFilename()
if not fname or not fname.endswith('.json'):
if self.mapFileName is None:
return None
return fname[:-5] # Remove '.json' extension
dirname = os.path.dirname(self.mapFileName)
return dirname
def getChunkDirectory(self):
dirName = self.getMapDirectory()
if dirName is None:
return None
return os.path.join(dirName, 'chunks')
def anyChunksDirty(self):
for chunk in self.chunks.values():
if chunk.isDirty():