Almost done with new language tools
This commit is contained in:
@ -1,21 +1,21 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Check for build target, or default
|
||||
if(NOT DEFINED DAWN_BUILD_TARGET)
|
||||
if(WIN32)
|
||||
set(DAWN_BUILD_TARGET "target-pokergame-win32-glfw")
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
set(DAWN_BUILD_TARGET "target-pokergame-linux64-glfw")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Now validate we have a build target for real
|
||||
if(NOT DEFINED DAWN_BUILD_TARGET)
|
||||
message(FATAL_ERROR "You need to define a DAWN_BUILD_TARGET")
|
||||
endif()
|
||||
|
||||
# Include the build target
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Check for build target, or default. This is pretty much not guaranteed.
|
||||
if(NOT DEFINED DAWN_BUILD_TARGET)
|
||||
if(WIN32)
|
||||
set(DAWN_BUILD_TARGET "target-pokergame-win32-glfw")
|
||||
elseif(UNIX AND NOT APPLE)
|
||||
set(DAWN_BUILD_TARGET "target-pokergame-linux64-glfw")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Now validate we have a build target for real
|
||||
if(NOT DEFINED DAWN_BUILD_TARGET)
|
||||
message(FATAL_ERROR "You need to define a DAWN_BUILD_TARGET")
|
||||
endif()
|
||||
|
||||
# Include the build target
|
||||
add_subdirectory(${DAWN_BUILD_TARGET})
|
@ -3,16 +3,22 @@
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Custom variables
|
||||
set(
|
||||
DAWN_TARGET_DEPENDENCIES_LAST
|
||||
CACHE INTERNAL ${DAWN_CACHE_TARGET}
|
||||
)
|
||||
|
||||
# Include shared libs
|
||||
add_subdirectory(dawnshared)
|
||||
|
||||
# Include tools
|
||||
add_subdirectory(dawntools)
|
||||
|
||||
# Change what we are building
|
||||
# Change what we are building. Pulled from the cmake/targets dir.
|
||||
add_subdirectory(${DAWN_BUILDING})
|
||||
|
||||
# Check the game project includes the target name
|
||||
# Validate game project includes the target name
|
||||
if(NOT DEFINED DAWN_TARGET_NAME)
|
||||
message(FATAL_ERROR "You need to define a DAWN_TARGET_NAME")
|
||||
endif()
|
||||
@ -46,4 +52,11 @@ if(DAWN_TARGET_SDL2)
|
||||
add_subdirectory(dawnopengl)
|
||||
endif()
|
||||
|
||||
add_subdirectory(dawnopenal)
|
||||
add_subdirectory(dawnopenal)
|
||||
|
||||
# Late definitions, used by tools
|
||||
if(NOT DAWN_TARGET_DEPENDENCIES_LAST)
|
||||
# message(FATAL_ERROR "List empty")
|
||||
else()
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${DAWN_TARGET_DEPENDENCIES_LAST})
|
||||
endif()
|
@ -29,29 +29,9 @@ add_subdirectory(scenes)
|
||||
# Assets
|
||||
set(DIR_GAME_ASSETS games/pokergame)
|
||||
tool_texture(texture_test texture_test.png)
|
||||
|
||||
tool_language(locale_poker ${DIR_GAME_ASSETS}/locale/locale.xml)
|
||||
|
||||
tool_tileset(tileset_death texture_death ${DIR_GAME_ASSETS}/characters/death/sheet.png 1 3)
|
||||
tool_tileset(tileset_penny texture_penny ${DIR_GAME_ASSETS}/characters/penny/sheet.png 1 3)
|
||||
|
||||
tool_truetype(truetype_alice ${DIR_GAME_ASSETS}/font/Alice-Regular.ttf truetype_alice 2048 2048 120)
|
||||
|
||||
tool_audio(audio_test borrowed/sample_short.wav)
|
||||
|
||||
tool_vnscene(Scene_1 ${DIR_GAME_ASSETS}/vn/Scene_1.xml)
|
||||
|
||||
add_dependencies(${DAWN_TARGET_NAME}
|
||||
locale_poker
|
||||
|
||||
tileset_death
|
||||
tileset_penny
|
||||
|
||||
truetype_alice
|
||||
|
||||
texture_test
|
||||
|
||||
audio_test
|
||||
|
||||
Scene_1
|
||||
)
|
||||
tool_vnscene(Scene_1 ${DIR_GAME_ASSETS}/vn/Scene_1.xml)
|
@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
@ -11,21 +11,12 @@ set(
|
||||
)
|
||||
|
||||
set(
|
||||
DAWN_TOOL_SOURCES
|
||||
|
||||
CACHE INTERNAL
|
||||
${DAWN_CACHE_TARGET}
|
||||
DAWN_TOOL_GENERATED_DEPENDENCIES
|
||||
CACHE INTERNAL ${DAWN_CACHE_TARGET}
|
||||
)
|
||||
|
||||
# Tool-Utils
|
||||
include(util/CMakeLists.txt)
|
||||
|
||||
# Tools
|
||||
add_subdirectory(audio)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(file)
|
||||
add_subdirectory(locale)
|
||||
|
||||
if(DAWN_VISUAL_NOVEL)
|
||||
add_subdirectory(visualnovel)
|
||||
endif()
|
||||
add_subdirectory(tools)
|
@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(audiogen)
|
||||
|
||||
# Texture Tool
|
||||
function(tool_audio target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND audiogen --input="${DAWN_ASSETS_SOURCE_DIR}/${in}" --output="${DAWN_ASSETS_BUILD_DIR}/${target}"
|
||||
COMMENT "Generating audio ${target} from ${in}"
|
||||
DEPENDS audiogen
|
||||
)
|
||||
endfunction()
|
@ -1,50 +0,0 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(texturegen)
|
||||
add_subdirectory(tilesetgen)
|
||||
add_subdirectory(truetypegen)
|
||||
add_subdirectory(uigen)
|
||||
|
||||
# Texture Tool
|
||||
function(tool_texture target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND texturegen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_ASSETS_BUILD_DIR}/${target}"
|
||||
COMMENT "Generating texture ${target} from ${in}"
|
||||
DEPENDS texturegen
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# Tileset Tool
|
||||
function(tool_tileset targetTileset targetTexture in cols rows)
|
||||
tool_texture(${targetTexture} ${in})
|
||||
add_custom_target(${targetTileset}
|
||||
COMMAND tilesetgen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_ASSETS_BUILD_DIR}/${targetTileset}" "${cols}" "${rows}"
|
||||
COMMENT "Generating tileset ${target} from ${in}"
|
||||
DEPENDS tilesetgen ${targetTexture}
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# TrueType Tool
|
||||
function(tool_truetype target in out width height fontSize)
|
||||
add_custom_target(${target}
|
||||
COMMAND truetypegen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_ASSETS_BUILD_DIR}/${out}" "${width}" "${height}" "${fontSize}"
|
||||
COMMENT "Generating truetype ${target} from ${in}"
|
||||
DEPENDS truetypegen
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# UI Tool
|
||||
function(tool_ui target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND uigen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_GENERATED_DIR}/ui/${target}"
|
||||
COMMENT "Generating ui ${target} from ${in}"
|
||||
DEPENDS uigen
|
||||
)
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_GENERATED_DIR}/ui
|
||||
)
|
||||
endfunction()
|
@ -1,87 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "dawnsharedlibs.hpp"
|
||||
#include "../../util/file.hpp"
|
||||
#include "../../util/image.hpp"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *file;
|
||||
char path[FILENAME_MAX + 1];
|
||||
uint8_t headerBuffer[32];
|
||||
char *in;
|
||||
char *out;
|
||||
int w, h, channels, headerBufferLength;
|
||||
stbi_uc *dataImageRaw, dataIn;
|
||||
float *dataImage;
|
||||
size_t i, len;
|
||||
|
||||
if(argc != 3) {
|
||||
printf("Invalid number of arguments\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Set up strings
|
||||
in = argv[1];
|
||||
out = argv[2];
|
||||
|
||||
// Normalize slashes
|
||||
fileNormalizeSlashes(in);
|
||||
fileNormalizeSlashes(out);
|
||||
|
||||
// Check the output doesn't already exist
|
||||
sprintf(path, "%s.texture", out);
|
||||
file = fopen(path, "rb");
|
||||
if(file != NULL) {
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read in original texture
|
||||
file = fopen(in, "rb");
|
||||
if(file == NULL) {
|
||||
printf("Failed to open file!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
dataImageRaw = stbi_load_from_file(file, &w, &h, &channels, STBI_rgb_alpha);
|
||||
if(dataImageRaw == NULL) {
|
||||
printf("Failed to load input texture!\n");
|
||||
return 1;
|
||||
}
|
||||
fclose(file);
|
||||
|
||||
// Convert to floating points
|
||||
len = STBI_rgb_alpha * w * h;
|
||||
dataImage = (float *)malloc(sizeof(float) * len);
|
||||
for(i = 0; i < len; i++) {
|
||||
dataIn = dataImageRaw[i];
|
||||
dataImage[i] = ((float)dataIn) / 255.0f;
|
||||
}
|
||||
stbi_image_free(dataImageRaw);
|
||||
|
||||
// Open output file
|
||||
fileMkdirp(path);
|
||||
file = fopen(path, "wb");
|
||||
if(file == NULL) {
|
||||
printf("Invalid texture file out!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write info
|
||||
headerBufferLength = sprintf((char *)headerBuffer, "%i|%i|", w, h);
|
||||
fwrite(headerBuffer, sizeof(uint8_t), headerBufferLength, file);
|
||||
|
||||
// Write texture
|
||||
fwrite(dataImage, sizeof(float), len, file);
|
||||
|
||||
// Cleanup
|
||||
fclose(file);
|
||||
free(dataImage);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
# Copyright (c) 2022 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
function(tool_copy target)
|
||||
math(EXPR CARGSN "${ARGC} - 1")
|
||||
set(LOOP_DEPENDENCIES)
|
||||
|
||||
foreach(index RANGE 1 ${CARGSN} 2)
|
||||
math(EXPR indexnext "${index} + 1")
|
||||
set(LOOP_TARGET "item_${target}_${index}")
|
||||
|
||||
LIST(GET ARGV ${index} from)
|
||||
LIST(GET ARGV ${indexnext} to)
|
||||
LIST(APPEND LOOP_DEPENDENCIES ${LOOP_TARGET})
|
||||
add_custom_command(OUTPUT ${LOOP_TARGET}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${from}" "${ASSETS_BUILD_DIR}/${to}"
|
||||
COMMENT "Copying ${from} => ${to}"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
add_custom_target(${target}
|
||||
DEPENDS ${LOOP_DEPENDENCIES}
|
||||
COMMENT "Creating dependency set ${target}"
|
||||
)
|
||||
endfunction()
|
@ -1,15 +0,0 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(languagegen)
|
||||
|
||||
# Language Tool
|
||||
function(tool_language target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND languagegen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_ASSETS_BUILD_DIR}"
|
||||
COMMENT "Generating language set ${target} from ${in}"
|
||||
DEPENDS languagegen
|
||||
)
|
||||
endfunction()
|
116
src/dawntools/tools/CMakeLists.txt
Normal file
116
src/dawntools/tools/CMakeLists.txt
Normal file
@ -0,0 +1,116 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(texturegen)
|
||||
add_subdirectory(tilesetgen)
|
||||
add_subdirectory(truetypegen)
|
||||
add_subdirectory(uigen)
|
||||
add_subdirectory(languagegen)
|
||||
add_subdirectory(audiogen)
|
||||
add_subdirectory(generatedlanguages)
|
||||
|
||||
# Settings
|
||||
set(DAWN_TOOL_GENERATED_LANG_DIR "${DAWN_TEMP_DIR}/languages" CACHE INTERNAL ${DAWN_CACHE_TARGET})
|
||||
|
||||
# Texture Tool
|
||||
function(tool_texture target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND texturegen --input="${DAWN_ASSETS_SOURCE_DIR}/${in}" --output="${DAWN_ASSETS_BUILD_DIR}/${target}"
|
||||
COMMENT "Generating texture ${target} from ${in}"
|
||||
DEPENDS texturegen
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${target})
|
||||
endfunction()
|
||||
|
||||
# Tileset Tool
|
||||
function(tool_tileset targetTileset targetTexture in cols rows)
|
||||
tool_texture(${targetTexture} ${in})
|
||||
add_custom_target(${targetTileset}
|
||||
COMMAND tilesetgen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_ASSETS_BUILD_DIR}/${targetTileset}" "${cols}" "${rows}"
|
||||
COMMENT "Generating tileset ${target} from ${in}"
|
||||
DEPENDS tilesetgen ${targetTexture}
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${targetTileset})
|
||||
endfunction()
|
||||
|
||||
# TrueType Tool
|
||||
function(tool_truetype target in out width height fontSize)
|
||||
add_custom_target(${target}
|
||||
COMMAND truetypegen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_ASSETS_BUILD_DIR}/${out}" "${width}" "${height}" "${fontSize}"
|
||||
COMMENT "Generating truetype ${target} from ${in}"
|
||||
DEPENDS truetypegen
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${target})
|
||||
endfunction()
|
||||
|
||||
# UI Tool
|
||||
function(tool_ui target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND uigen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_GENERATED_DIR}/ui/${target}"
|
||||
COMMENT "Generating ui ${target} from ${in}"
|
||||
DEPENDS uigen
|
||||
)
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_GENERATED_DIR}/ui
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${target})
|
||||
endfunction()
|
||||
|
||||
# Generated Language Rollup Tool
|
||||
function(tool_generatedlanguages in)
|
||||
add_custom_target(generatedlanguages
|
||||
COMMAND generatedlanguagestool --input="${DAWN_TOOL_GENERATED_LANG_DIR}" --output="${DAWN_ASSETS_BUILD_DIR}"
|
||||
COMMENT "Generating all languages"
|
||||
DEPENDS generatedlanguagestool
|
||||
)
|
||||
|
||||
if(NOT generatedlanguages IN_LIST DAWN_TARGET_DEPENDENCIES_LAST)
|
||||
set(
|
||||
DAWN_TARGET_DEPENDENCIES_LAST
|
||||
generatedlanguages
|
||||
CACHE INTERNAL ${DAWN_CACHE_TARGET}
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# Language Tool
|
||||
function(tool_language target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND languagegen "${DAWN_ASSETS_SOURCE_DIR}/${in}" "${DAWN_ASSETS_BUILD_DIR}"
|
||||
COMMENT "Generating language set ${target} from ${in}"
|
||||
DEPENDS languagegen
|
||||
)
|
||||
endfunction()
|
||||
|
||||
# Audio Tool
|
||||
function(tool_audio target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND audiogen --input="${DAWN_ASSETS_SOURCE_DIR}/${in}" --output="${DAWN_ASSETS_BUILD_DIR}/${target}"
|
||||
COMMENT "Generating audio ${target} from ${in}"
|
||||
DEPENDS audiogen
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${target})
|
||||
endfunction()
|
||||
|
||||
|
||||
if(DAWN_VISUAL_NOVEL)
|
||||
add_subdirectory(vnscenegen)
|
||||
|
||||
# VN Scene Tool
|
||||
function(tool_vnscene target in)
|
||||
tool_generatedlanguages("${DAWN_TOOL_GENERATED_LANG_DIR}/${target}.language")
|
||||
add_custom_target(${target}
|
||||
COMMAND vnscenegen --input="${DAWN_ASSETS_SOURCE_DIR}/${in}" --output="${DAWN_GENERATED_DIR}/scenes/${target}" --language-out="${DAWN_TOOL_GENERATED_LANG_DIR}/${target}.language"
|
||||
COMMENT "Generating VN Scene ${target} from ${in}"
|
||||
DEPENDS vnscenegen
|
||||
)
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_GENERATED_DIR}
|
||||
)
|
||||
add_dependencies(${DAWN_TARGET_NAME} ${target})
|
||||
endfunction()
|
||||
endif()
|
@ -1,9 +1,8 @@
|
||||
# Copyright (c) 2021 Dominic Msters
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Texture Build Tool
|
||||
project(audiogen VERSION 1.0)
|
||||
add_executable(audiogen)
|
||||
|
34
src/dawntools/tools/generatedlanguages/CMakeLists.txt
Normal file
34
src/dawntools/tools/generatedlanguages/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Generated Languages Tool
|
||||
project(generatedlanguagestool VERSION 1.0)
|
||||
add_executable(generatedlanguagestool)
|
||||
|
||||
target_sources(generatedlanguagestool
|
||||
PRIVATE
|
||||
${DAWN_SHARED_SOURCES}
|
||||
${DAWN_TOOL_SOURCES}
|
||||
GeneratedLanguages.cpp
|
||||
)
|
||||
|
||||
target_include_directories(generatedlanguagestool
|
||||
PUBLIC
|
||||
${DAWN_SHARED_INCLUDES}
|
||||
${DAWN_TOOL_INCLUDES}
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(generatedlanguagestool
|
||||
PUBLIC
|
||||
${DAWN_SHARED_DEFINITIONS}
|
||||
DAWN_TOOL_INSTANCE=GeneratedLanguages
|
||||
DAWN_TOOL_HEADER="GeneratedLanguages.hpp"
|
||||
)
|
||||
|
||||
target_link_libraries(generatedlanguagestool
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
||||
)
|
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/DawnTool.hpp"
|
||||
#include "util/Xml.hpp"
|
||||
#include "util/File.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class GeneratedLanguages : public DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
|
||||
int32_t scanDir(
|
||||
std::string dir,
|
||||
std::string *error,
|
||||
std::vector<std::string> *files
|
||||
);
|
||||
|
||||
public:
|
||||
int32_t start() override;
|
||||
};
|
||||
}
|
@ -6,18 +6,31 @@
|
||||
# Texture Build Tool
|
||||
project(texturegen VERSION 1.0)
|
||||
add_executable(texturegen)
|
||||
|
||||
target_sources(texturegen
|
||||
PRIVATE
|
||||
main.cpp
|
||||
../../util/file.cpp
|
||||
${DAWN_SHARED_SOURCES}
|
||||
${DAWN_TOOL_SOURCES}
|
||||
TextureGen.cpp
|
||||
../../util/image.cpp
|
||||
)
|
||||
|
||||
target_include_directories(texturegen
|
||||
PUBLIC
|
||||
${DAWN_SHARED_INCLUDES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../
|
||||
${DAWN_TOOL_INCLUDES}
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# Definitions
|
||||
target_compile_definitions(texturegen
|
||||
PUBLIC
|
||||
${DAWN_SHARED_DEFINITIONS}
|
||||
DAWN_TOOL_INSTANCE=TextureGen
|
||||
DAWN_TOOL_HEADER="TextureGen.hpp"
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(texturegen
|
||||
PUBLIC
|
||||
${DAWN_BUILD_HOST_LIBS}
|
67
src/dawntools/tools/texturegen/TextureGen.cpp
Normal file
67
src/dawntools/tools/texturegen/TextureGen.cpp
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TextureGen.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> TextureGen::getRequiredFlags() {
|
||||
return std::vector<std::string>{ "input", "output" };
|
||||
}
|
||||
|
||||
int32_t TextureGen::start() {
|
||||
// Finished with XML data, now we can write data out.
|
||||
File fileOut(flags["output"] + ".texture");
|
||||
if(fileOut.exists()) return 0;
|
||||
|
||||
// Load input file
|
||||
File in(flags["input"]);
|
||||
if(!in.open(FILE_MODE_READ)) return 1;
|
||||
|
||||
int w, h, channels;
|
||||
auto imageRaw = stbi_load_from_file(in.file, &w, &h, &channels, STBI_rgb_alpha);
|
||||
if(imageRaw == NULL) {
|
||||
std::cout << "Failed to load input texture!" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
in.close();
|
||||
|
||||
// Convert to floating points
|
||||
size_t len = STBI_rgb_alpha * w * h;
|
||||
float_t *dataImage = (float_t*)malloc(sizeof(float) * len);
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
auto dataIn = imageRaw[i];
|
||||
dataImage[i] = ((float_t)dataIn) / 255.0f;
|
||||
}
|
||||
stbi_image_free(imageRaw);
|
||||
|
||||
// Open and create output
|
||||
File out(flags["output"] + ".texture");
|
||||
if(!out.mkdirp()) {
|
||||
std::cout << "Failed to make output dir " << out.filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if(!out.open(FILE_MODE_WRITE)) {
|
||||
std::cout << "Failed to open texture file for writing " << out.filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write info
|
||||
char headerBuffer[64];
|
||||
size_t headerBufferLength = sprintf((char *)headerBuffer, "%i|%i|", w, h);
|
||||
if(!out.writeRaw(headerBuffer, headerBufferLength)) {
|
||||
std::cout << "Failed to write texture header for " << out.filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Write texture
|
||||
if(!out.writeRaw((char *)dataImage, sizeof(float_t) * len)) {
|
||||
std::cout << "Failed to write texture data for " << out.filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
free(dataImage);
|
||||
|
||||
return 0;
|
||||
}
|
19
src/dawntools/tools/texturegen/TextureGen.hpp
Normal file
19
src/dawntools/tools/texturegen/TextureGen.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/DawnTool.hpp"
|
||||
#include "util/File.hpp"
|
||||
#include "../../util/image.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class TextureGen : public DawnTool {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredFlags() override;
|
||||
|
||||
public:
|
||||
int32_t start();
|
||||
};
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
project(vnscenegen VERSION 1.1)
|
||||
add_executable(vnscenegen)
|
||||
|
||||
|
||||
# Sources
|
||||
target_sources(vnscenegen
|
||||
PRIVATE
|
@ -8,7 +8,7 @@
|
||||
using namespace Dawn;
|
||||
|
||||
std::vector<std::string> VnSceneGen::getRequiredFlags() {
|
||||
return std::vector<std::string>{ "input", "output" };
|
||||
return std::vector<std::string>{ "input", "output", "language-out" };
|
||||
}
|
||||
|
||||
int32_t VnSceneGen::start() {
|
||||
@ -52,5 +52,9 @@ int32_t VnSceneGen::start() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Now dump out the language strings to be picked up later.
|
||||
ret = languageSaveStrings(flags["language-out"], info.strings);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
return 0;
|
||||
}
|
@ -7,6 +7,7 @@
|
||||
#include "util/DawnTool.hpp"
|
||||
#include "util/File.hpp"
|
||||
#include "parse/root.hpp"
|
||||
#include "util/Language.cpp"
|
||||
|
||||
namespace Dawn {
|
||||
class VnSceneGen : public DawnTool {
|
@ -6,22 +6,17 @@
|
||||
#pragma once
|
||||
#include "util/XmlParser.hpp"
|
||||
#include "util/CodeGen.hpp"
|
||||
#include "util/Language.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct TextStringInfo {
|
||||
std::string lang;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
struct TextEventInfo {
|
||||
std::string character;
|
||||
std::string emotion;
|
||||
std::vector<struct TextStringInfo> strings;
|
||||
|
||||
std::string key = "scene.1.1";
|
||||
std::vector<struct LanguageString> strings;
|
||||
std::string key;
|
||||
};
|
||||
|
||||
class TextStringParser : public XmlParser<struct TextStringInfo> {
|
||||
class TextStringParser : public XmlParser<struct LanguageString> {
|
||||
protected:
|
||||
std::vector<std::string> getRequiredAttributes() {
|
||||
return std::vector<std::string>{ "lang" };
|
||||
@ -34,7 +29,7 @@ namespace Dawn {
|
||||
int32_t onParse(
|
||||
Xml *node,
|
||||
std::map<std::string, std::string> values,
|
||||
struct TextStringInfo *out,
|
||||
struct LanguageString *out,
|
||||
std::string *error
|
||||
) {
|
||||
out->lang = values["lang"];
|
||||
@ -66,12 +61,18 @@ namespace Dawn {
|
||||
out->character = values["character"];
|
||||
out->emotion = values["emotion"];
|
||||
|
||||
if(out->key.size() <= 0) {
|
||||
*error = "Text Event requries a language key to be defined.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto itChildren = node->children.begin();
|
||||
while(itChildren != node->children.end()) {
|
||||
auto c = *itChildren;
|
||||
if(c->node == "string") {
|
||||
struct TextStringInfo str;
|
||||
struct LanguageString str;
|
||||
ret = (TextStringParser()).parse(c, &str, error);
|
||||
str.key = out->key;
|
||||
out->strings.push_back(str);
|
||||
}
|
||||
++itChildren;
|
@ -22,6 +22,9 @@ namespace Dawn {
|
||||
std::map<int32_t, struct CharacterFadeEventInfo> characterFadeEvents;
|
||||
std::map<int32_t, struct PauseEventInfo> pauseEvents;
|
||||
std::vector<std::string> includes;
|
||||
|
||||
std::vector<struct LanguageString> strings;
|
||||
std::string key;
|
||||
};
|
||||
|
||||
class EventsParser : public XmlParser<struct EventsInformation> {
|
||||
@ -43,15 +46,24 @@ namespace Dawn {
|
||||
) {
|
||||
int32_t ret = 0;
|
||||
int32_t i = 0;
|
||||
int32_t languageKeyNumber = 1;
|
||||
|
||||
if(out->key.size() <= 0) {
|
||||
*error = "Events requries a language key to be defined.";
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto itChildren = node->children.begin();
|
||||
while(itChildren != node->children.end()) {
|
||||
auto c = *itChildren;
|
||||
|
||||
if(c->node == "text") {
|
||||
struct TextEventInfo textEvent;
|
||||
textEvent.key = out->key + "." + std::to_string(languageKeyNumber++);
|
||||
ret = (TextEventParser()).parse(c, &textEvent, error);
|
||||
out->eventTypes[i] = EVENT_TYPE_TEXT;
|
||||
out->textEvents[i++] = textEvent;
|
||||
vectorAppend(&out->strings, textEvent.strings);
|
||||
|
||||
} else if(c->node == "character-fade") {
|
||||
struct CharacterFadeEventInfo charFadeEvent;
|
@ -11,6 +11,8 @@ namespace Dawn {
|
||||
struct RootInformation {
|
||||
struct HeaderInformation header;
|
||||
struct EventsInformation events;
|
||||
|
||||
std::vector<struct LanguageString> strings;
|
||||
};
|
||||
|
||||
class RootParser : public XmlParser<struct RootInformation> {
|
||||
@ -38,7 +40,9 @@ namespace Dawn {
|
||||
if(c->node == "head") {
|
||||
ret = (HeaderParser()).parse(c, &out->header, error);
|
||||
} else if(c->node == "events") {
|
||||
out->events.key = out->header.scene.name;
|
||||
ret = (EventsParser()).parse(c, &out->events, error);
|
||||
vectorAppend(&out->strings, out->events.strings);
|
||||
}
|
||||
|
||||
if(ret != 0) return ret;
|
@ -5,8 +5,12 @@
|
||||
|
||||
set(D ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
list(APPEND
|
||||
set(
|
||||
DAWN_TOOL_SOURCES
|
||||
${D}/DawnTool.cpp
|
||||
${D}/File.cpp
|
||||
${D}/Language.cpp
|
||||
|
||||
CACHE INTERNAL
|
||||
${DAWN_CACHE_TARGET}
|
||||
)
|
@ -20,6 +20,7 @@
|
||||
#define FILE_PATH_SEP '/'
|
||||
#define fileMkdir(path, perms) mkdir(path, perms)
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#define FILE_BUFFER_SIZE 512
|
||||
|
||||
@ -31,11 +32,11 @@ namespace Dawn {
|
||||
|
||||
class File {
|
||||
private:
|
||||
FILE *file = nullptr;
|
||||
enum FileMode mode;
|
||||
size_t length;
|
||||
|
||||
public:
|
||||
FILE *file = nullptr;
|
||||
static std::string normalizeSlashes(std::string str);
|
||||
static void mkdirp(std::string path);
|
||||
|
||||
|
36
src/dawntools/util/Language.cpp
Normal file
36
src/dawntools/util/Language.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Language.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
int32_t languageSaveStrings(
|
||||
std::string languagesDir,
|
||||
std::vector<struct LanguageString> strings
|
||||
) {
|
||||
if(languagesDir.size() <= 0) {
|
||||
std::cout << "Languages dir is not defined" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
File file(languagesDir);
|
||||
if(!file.mkdirp()) {
|
||||
std::cout << "Failed to create languages string output dir " << file.filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Now convert to xml
|
||||
std::string buffer;
|
||||
auto it = strings.begin();
|
||||
while(it != strings.end()) {
|
||||
auto s = *it;
|
||||
buffer += s.lang + "|" + s.key + "|" + s.text + "|";
|
||||
++it;
|
||||
}
|
||||
file.writeString(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
19
src/dawntools/util/Language.hpp
Normal file
19
src/dawntools/util/Language.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/Xml.hpp"
|
||||
#include "util/File.hpp"
|
||||
|
||||
struct LanguageString {
|
||||
std::string key;
|
||||
std::string lang;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
static int32_t languageSaveStrings(
|
||||
std::string languagesDir,
|
||||
std::vector<struct LanguageString> strings
|
||||
);
|
@ -1,19 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Msters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
add_subdirectory(vnscenegen)
|
||||
|
||||
# UI Tool
|
||||
function(tool_vnscene target in)
|
||||
add_custom_target(${target}
|
||||
COMMAND vnscenegen --input="${DAWN_ASSETS_SOURCE_DIR}/${in}" --output="${DAWN_GENERATED_DIR}/scenes/${target}"
|
||||
COMMENT "Generating VN Scene ${target} from ${in}"
|
||||
DEPENDS vnscenegen
|
||||
)
|
||||
target_include_directories(${DAWN_TARGET_NAME}
|
||||
PUBLIC
|
||||
${DAWN_GENERATED_DIR}
|
||||
)
|
||||
endfunction()
|
Reference in New Issue
Block a user