Dusk progress
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@ -93,3 +93,5 @@ assets/borrowed
|
|||||||
/archive0
|
/archive0
|
||||||
/archive1
|
/archive1
|
||||||
/archive
|
/archive
|
||||||
|
|
||||||
|
__pycache__
|
@ -21,8 +21,9 @@ set(DUSK_BUILD_DIR "${CMAKE_BINARY_DIR}")
|
|||||||
set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src")
|
set(DUSK_SOURCES_DIR "${DUSK_ROOT_DIR}/src")
|
||||||
set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
set(DUSK_TEMP_DIR "${DUSK_BUILD_DIR}/temp")
|
||||||
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
set(DUSK_TOOLS_DIR "${DUSK_ROOT_DIR}/tools")
|
||||||
set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
# set(DUSK_ASSETS_DIR "${DUSK_ROOT_DIR}/assets")
|
||||||
set(DUSK_ASSETS_BUILD_DIR "${DUSK_BUILD_DIR}/assets")
|
# set(DUSK_ASSETS_BUILD_DIR "${DUSK_BUILD_DIR}/assets")
|
||||||
|
set(DUSK_DATA_DIR "${DUSK_ROOT_DIR}/data")
|
||||||
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
set(DUSK_GENERATED_HEADERS_DIR "${DUSK_BUILD_DIR}/generated")
|
||||||
set(DUSK_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
set(DUSK_TARGET_NAME "Dusk" CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
set(DUSK_BUILD_BINARY ${DUSK_BUILD_DIR}/Dusk CACHE INTERNAL ${DUSK_CACHE_TARGET})
|
||||||
@ -46,9 +47,6 @@ add_executable(${DUSK_TARGET_NAME})
|
|||||||
# Add tools
|
# Add tools
|
||||||
add_subdirectory(tools)
|
add_subdirectory(tools)
|
||||||
|
|
||||||
# Add data
|
|
||||||
add_subdirectory(data)
|
|
||||||
|
|
||||||
# Add code
|
# Add code
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
|
|
||||||
|
@ -4,5 +4,4 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
# Tools
|
# Tools
|
||||||
add_subdirectory(assetstool)
|
add_subdirectory(mapcompile)
|
||||||
add_subdirectory(copytool)
|
|
@ -1,19 +0,0 @@
|
|||||||
# Copyright (c) 2023 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
|
||||||
|
|
||||||
add_custom_target(duskassets
|
|
||||||
COMMAND
|
|
||||||
${Python3_EXECUTABLE}
|
|
||||||
${DUSK_TOOLS_DIR}/assetstool/assetstool.py
|
|
||||||
--input=${DUSK_ASSETS_BUILD_DIR}
|
|
||||||
--output=${DUSK_BUILD_DIR}/dusk.tar
|
|
||||||
COMMENT "Bundling assets..."
|
|
||||||
USES_TERMINAL
|
|
||||||
DEPENDS ${DUSK_ASSETS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_dependencies(${DUSK_TARGET_NAME} duskassets)
|
|
@ -1,67 +0,0 @@
|
|||||||
# Copyright (c) 2023 Dominic Masters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
import os
|
|
||||||
import tarfile
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
# Args
|
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
description='Bundles all assets into the internal archive format.'
|
|
||||||
)
|
|
||||||
parser.add_argument('-i', '--input');
|
|
||||||
parser.add_argument('-o', '--output');
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
# Ensure the directory for the output path exists
|
|
||||||
if not os.path.exists(os.path.dirname(args.output)):
|
|
||||||
os.makedirs(os.path.dirname(args.output))
|
|
||||||
|
|
||||||
# Create a ZIP archive and add the specified directory
|
|
||||||
# archive = tarfile.open(args.output, 'w:bz2') # BZ2 Compression
|
|
||||||
|
|
||||||
# Does the archive already exist?
|
|
||||||
filesInArchive = []
|
|
||||||
|
|
||||||
if os.path.exists(args.output) and False:
|
|
||||||
# if os.path.exists(args.output):
|
|
||||||
# Yes, open it
|
|
||||||
archive = tarfile.open(args.output, 'a:')
|
|
||||||
|
|
||||||
# Get all the files in the archive
|
|
||||||
for member in archive.getmembers():
|
|
||||||
filesInArchive.append(member.name)
|
|
||||||
|
|
||||||
archive.close()
|
|
||||||
|
|
||||||
# Open archive for appending.
|
|
||||||
archive = tarfile.open(args.output, 'a:')
|
|
||||||
else:
|
|
||||||
# No, create it
|
|
||||||
archive = tarfile.open(args.output, 'w:')
|
|
||||||
|
|
||||||
# Add all files in the input directory
|
|
||||||
for foldername, subfolders, filenames in os.walk(args.input):
|
|
||||||
for filename in filenames:
|
|
||||||
|
|
||||||
# Is the file already in the archive?
|
|
||||||
absolute_path = os.path.join(foldername, filename)
|
|
||||||
relative_path = os.path.relpath(absolute_path, args.input)
|
|
||||||
|
|
||||||
if relative_path in filesInArchive:
|
|
||||||
if relative_path.endswith('.texture'):
|
|
||||||
print(f"Skipping {filename}...")
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
print(f"Overwriting {filename}...")
|
|
||||||
# Does not work in python, throw error
|
|
||||||
exit (1)
|
|
||||||
else:
|
|
||||||
print(f"Archiving asset {filename}...")
|
|
||||||
|
|
||||||
archive.add(absolute_path, arcname=relative_path)
|
|
||||||
|
|
||||||
# Close the archive
|
|
||||||
archive.close()
|
|
@ -1,16 +0,0 @@
|
|||||||
# Copyright (c) 2023 Dominic Msters
|
|
||||||
#
|
|
||||||
# This software is released under the MIT License.
|
|
||||||
# https://opensource.org/licenses/MIT
|
|
||||||
|
|
||||||
function(copytool file)
|
|
||||||
set(TARGET_NAME "copytool_${file}")
|
|
||||||
|
|
||||||
# Replace slashes with underscores
|
|
||||||
string(REPLACE "/" "_" TARGET_NAME ${TARGET_NAME})
|
|
||||||
|
|
||||||
add_custom_target(${TARGET_NAME}
|
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy ${DUSK_ASSETS_DIR}/${file} ${DUSK_ASSETS_BUILD_DIR}/${file}
|
|
||||||
)
|
|
||||||
add_dependencies(duskassets ${TARGET_NAME})
|
|
||||||
endfunction()
|
|
@ -8,8 +8,8 @@ find_package(Python3 COMPONENTS Interpreter REQUIRED)
|
|||||||
# Custom command to generate all header files
|
# Custom command to generate all header files
|
||||||
add_custom_target(DUSK_CHUNKS
|
add_custom_target(DUSK_CHUNKS
|
||||||
# OUTPUT ${DUSK_GENERATED_HEADERS_DIR}/world/world.h
|
# OUTPUT ${DUSK_GENERATED_HEADERS_DIR}/world/world.h
|
||||||
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/chunks.py --output ${DUSK_GENERATED_HEADERS_DIR}
|
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mapcompile.py --output ${DUSK_GENERATED_HEADERS_DIR}
|
||||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/chunks.py
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/mapcompile.py
|
||||||
COMMENT "Generating chunk header files"
|
COMMENT "Generating chunk header files"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
@ -1,17 +1,16 @@
|
|||||||
#!/usr/bin/python3
|
import sys, os
|
||||||
import os
|
|
||||||
import argparse
|
import argparse
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# Constants that are defined in the C code
|
shared_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'shared'))
|
||||||
CHUNK_WIDTH = 8
|
sys.path.append(shared_path)
|
||||||
CHUNK_HEIGHT = 8
|
|
||||||
CHUNK_ENTITY_COUNT_MAX = 8
|
|
||||||
|
|
||||||
ENTITY_TYPE = {
|
from worlddefs import CHUNK_WIDTH, CHUNK_HEIGHT, ENTITY_TYPE_MAP, CHUNK_DATA_DIR
|
||||||
"npc": "ENTITY_TYPE_NPC",
|
|
||||||
}
|
# Dynamically add ../shared to sys.path
|
||||||
|
shared_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'shared'))
|
||||||
|
sys.path.append(shared_path)
|
||||||
|
|
||||||
# Check if the script is run with the correct arguments
|
# Check if the script is run with the correct arguments
|
||||||
parser = argparse.ArgumentParser(description="Generate chunk header files")
|
parser = argparse.ArgumentParser(description="Generate chunk header files")
|
||||||
@ -30,12 +29,6 @@ os.makedirs(worldDir, exist_ok=True)
|
|||||||
chunksDir = os.path.join(worldDir, "chunk")
|
chunksDir = os.path.join(worldDir, "chunk")
|
||||||
os.makedirs(chunksDir, exist_ok=True)
|
os.makedirs(chunksDir, exist_ok=True)
|
||||||
|
|
||||||
# Scan ./chunks folder
|
|
||||||
chunks_dir = os.path.join(os.path.dirname(__file__), "chunks")
|
|
||||||
if not os.path.exists(chunks_dir):
|
|
||||||
print(f"Error: Chunks directory '{chunks_dir}' does not exist.")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# Some vars used during printing
|
# Some vars used during printing
|
||||||
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
@ -46,8 +39,8 @@ chunksDone = []
|
|||||||
entityIdNext = 1
|
entityIdNext = 1
|
||||||
|
|
||||||
# For each chunk file
|
# For each chunk file
|
||||||
for chunkFile in os.listdir(chunks_dir):
|
for chunkFile in os.listdir(CHUNK_DATA_DIR):
|
||||||
data = json.load(open(os.path.join(chunks_dir, chunkFile)))
|
data = json.load(open(os.path.join(CHUNK_DATA_DIR, chunkFile)))
|
||||||
print(f"Processing chunk: {chunkFile}")
|
print(f"Processing chunk: {chunkFile}")
|
||||||
|
|
||||||
if not 'chunk' in data:
|
if not 'chunk' in data:
|
||||||
@ -103,7 +96,9 @@ for chunkFile in os.listdir(chunks_dir):
|
|||||||
if 'overlayLayer' not in data['chunk']:
|
if 'overlayLayer' not in data['chunk']:
|
||||||
print(f"Error: Chunk file '{chunkFile}' does not contain 'overlayLayer' key.")
|
print(f"Error: Chunk file '{chunkFile}' does not contain 'overlayLayer' key.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
overlayLayer = data['chunk']['overlayLayer']
|
overlayLayer = data['chunk']['overlayLayer']
|
||||||
|
|
||||||
# Overlay layer should exactly CHUNK_WIDTH * CHUNK_HEIGHT elements
|
# Overlay layer should exactly CHUNK_WIDTH * CHUNK_HEIGHT elements
|
||||||
if len(overlayLayer) != CHUNK_HEIGHT:
|
if len(overlayLayer) != CHUNK_HEIGHT:
|
||||||
print(f"Error: Chunk file '{chunkFile}' has invalid 'overlayLayer' length.")
|
print(f"Error: Chunk file '{chunkFile}' has invalid 'overlayLayer' length.")
|
||||||
@ -160,7 +155,7 @@ for chunkFile in os.listdir(chunks_dir):
|
|||||||
|
|
||||||
f.write(" {\n")
|
f.write(" {\n")
|
||||||
f.write(f" .id = {entityId},\n")
|
f.write(f" .id = {entityId},\n")
|
||||||
f.write(f" .type = {ENTITY_TYPE.get(entity['type'], 'ENTITY_TYPE_UNKNOWN')},\n"),
|
f.write(f" .type = {ENTITY_TYPE_MAP.get(entity['type'], 'ENTITY_TYPE_UNKNOWN')},\n"),
|
||||||
f.write(f" .x = {entity['x']},\n")
|
f.write(f" .x = {entity['x']},\n")
|
||||||
f.write(f" .y = {entity['y']},\n")
|
f.write(f" .y = {entity['y']},\n")
|
||||||
f.write(f" }},\n")
|
f.write(f" }},\n")
|
10
tools/mapeditor/mapeditor.py
Executable file
10
tools/mapeditor/mapeditor.py
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
import sys, os
|
||||||
|
|
||||||
|
# Dynamically add ../shared to sys.path
|
||||||
|
shared_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'shared'))
|
||||||
|
sys.path.append(shared_path)
|
||||||
|
|
||||||
|
# Import shared modules
|
||||||
|
from worlddefs import CHUNK_WIDTH, CHUNK_HEIGHT, ENTITY_TYPE_MAP, CHUNK_DATA_DIR
|
||||||
|
|
11
tools/shared/worlddefs.py
Normal file
11
tools/shared/worlddefs.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
CHUNK_WIDTH = 8
|
||||||
|
CHUNK_HEIGHT = 8
|
||||||
|
CHUNK_ENTITY_COUNT_MAX = 8
|
||||||
|
|
||||||
|
ENTITY_TYPE_MAP = {
|
||||||
|
"npc": "ENTITY_TYPE_NPC",
|
||||||
|
}
|
||||||
|
|
||||||
|
CHUNK_DATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'data', 'chunks'))
|
Reference in New Issue
Block a user