Add asset loading support.
This commit is contained in:
14
tools/CMakeLists.txt
Normal file
14
tools/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Tool Level Values
|
||||
set(
|
||||
DAWN_TOOL_GENERATED_DEPENDENCIES
|
||||
CACHE INTERNAL ${DAWN_CACHE_TARGET}
|
||||
)
|
||||
|
||||
# Tools
|
||||
add_subdirectory(assetstool)
|
||||
add_subdirectory(copytool)
|
17
tools/assetstool/CMakeLists.txt
Normal file
17
tools/assetstool/CMakeLists.txt
Normal file
@ -0,0 +1,17 @@
|
||||
# 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(dawnassets
|
||||
COMMAND
|
||||
${Python3_EXECUTABLE}
|
||||
${DAWN_TOOLS_DIR}/assetstool/assetstool.py
|
||||
--input=${DAWN_ASSETS_BUILD_DIR}
|
||||
--output=${DAWN_BUILD_DIR}/dawn.tar
|
||||
COMMENT "Bundling assets..."
|
||||
USES_TERMINAL
|
||||
DEPENDS ${DAWN_ASSETS}
|
||||
)
|
62
tools/assetstool/assetstool.py
Executable file
62
tools/assetstool/assetstool.py
Executable file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python
|
||||
# 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):
|
||||
# Yes, open it
|
||||
archive = tarfile.open(args.output, 'r:')
|
||||
|
||||
# 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:
|
||||
# Yes, skip it
|
||||
continue
|
||||
|
||||
# No, add it
|
||||
print(f"Archiving asset {filename}...")
|
||||
archive.add(absolute_path, arcname=relative_path)
|
||||
|
||||
# Close the archive
|
||||
archive.close()
|
11
tools/copytool/CMakeLists.txt
Normal file
11
tools/copytool/CMakeLists.txt
Normal file
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(tool_copy target input output)
|
||||
add_custom_target(${target}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${input} ${output}
|
||||
)
|
||||
add_dependencies(dawnassets ${target})
|
||||
endfunction()
|
Reference in New Issue
Block a user