From a538178c9cacd94ce1e50b20ce53100edf3f578c Mon Sep 17 00:00:00 2001 From: sillysagiri Date: Thu, 17 Oct 2024 09:58:22 +0700 Subject: [PATCH] Initial load text from file method --- .gitignore | 3 +- assets/silly/txt/t_mainmenu.silly | Bin 0 -> 77 bytes raw/text/t_mainmenu.txt | 7 ++++ src/dothack/DotHack.java | 4 +- src/sillysagiri/Utils.java | 37 +++++++++++++++++++ src/sillysagiri/scene/MainMenu.java | 42 ++++++++++++++------- tools/string2bin/string2bin.cpp | 55 ++++++++++++++++++++++++++++ 7 files changed, 132 insertions(+), 16 deletions(-) create mode 100644 assets/silly/txt/t_mainmenu.silly create mode 100644 raw/text/t_mainmenu.txt create mode 100644 tools/string2bin/string2bin.cpp diff --git a/.gitignore b/.gitignore index d85b69c..cbdb52a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build -ideas.txt \ No newline at end of file +ideas.txt +tools/bin \ No newline at end of file diff --git a/assets/silly/txt/t_mainmenu.silly b/assets/silly/txt/t_mainmenu.silly new file mode 100644 index 0000000000000000000000000000000000000000..60835f4b8bf1a24b7af6eecf7195ef129a505c90 GIT binary patch literal 77 zcmW;DK?;B{3= list_strmenu[maxlength].length()) + maxlength = i; + + list_strmenu[i] = list_strmenu[i].toUpperCase(); + } + + System.out.println(list_strmenu[maxlength]); + + int boxw = (int)(bmf_blue.Measure(list_strmenu[maxlength])[0]+bmf_blue.lineHeight*1.4); + int boxh = bmf_blue.lineHeight*(list_strmenu.length+1); int[] temp = new int[boxw*boxh]; for (int i=0; i 360) counter = 0; diff --git a/tools/string2bin/string2bin.cpp b/tools/string2bin/string2bin.cpp new file mode 100644 index 0000000..954aa07 --- /dev/null +++ b/tools/string2bin/string2bin.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include + +void writeBinaryFile(const std::string& inputFileName, const std::string& outputFileName) { + std::ifstream inputFile(inputFileName); + std::ofstream outputFile(outputFileName, std::ios::binary); + + if (!inputFile) { + std::cerr << "Error opening input file: " << inputFileName << std::endl; + std::exit(EXIT_FAILURE); + } + + if (!outputFile) { + std::cerr << "Error opening output file: " << outputFileName << std::endl; + std::exit(EXIT_FAILURE); + } + + std::string line; + while (std::getline(inputFile, line)) { + // Get the size of the string + std::size_t size = line.size(); + + // Write size as 2 bytes (big-endian) + uint16_t sizeInBytes = static_cast(size); + outputFile.write(reinterpret_cast(&sizeInBytes), sizeof(sizeInBytes)); + + // Write the string followed by a null terminator + outputFile.write(line.c_str(), size); + + // char nullChar = '\0'; + // outputFile.write(&nullChar, sizeof(nullChar)); + } + + inputFile.close(); + outputFile.close(); +} + +int main(int argc, char* argv[]) { + if (argc != 3) { + std::cerr << "Usage: " << argv[0] << " " << std::endl; + return EXIT_FAILURE; + } + + std::string inputFileName = argv[1]; // Input file name from args + std::string outputFileName = argv[2]; // Output binary file name from args + + writeBinaryFile(inputFileName, outputFileName); + + std::cout << "Strings written to binary file successfully." << std::endl; + + return EXIT_SUCCESS; +}