mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-11-21 23:13:53 +01:00
File colors.txt compiled into binary
This commit is contained in:
parent
4a8c041bc1
commit
112ccc5d08
@ -19,11 +19,32 @@ find_path(LIBSQLITE3_INCLUDE_DIR sqlite3.h HINTS ${PC_LIBSQLITE_INCLUDEDIR} ${PC
|
||||
find_library(LIBSQLITE3_LIBRARY NAMES sqlite3 libsqlite3 HINTS ${PC_LIBSQLITE_LIBDIR} ${PC_LIBSQLITE_LIBRARY_DIRS})
|
||||
|
||||
set(LIBSQLITE3_LIBRARIES ${LIBSQLITE3_LIBRARY} )
|
||||
set(LIBSQLITE3_INCLUDE_DIRS ${LIBSQLITE3_INCLUDE_DIR} )
|
||||
set(LIBSQLITE3_INCLUDE_DIRS ${LIBSQLITE3_INCLUDE_DIR})
|
||||
|
||||
find_package_handle_standard_args(LibSqlite3 DEFAULT_MSG LIBSQLITE3_LIBRARY LIBSQLITE3_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(LIBSQLITE3_INCLUDE_DIR LIBSQLITE3_LIBRARY )
|
||||
mark_as_advanced(LIBSQLITE3_INCLUDE_DIR LIBSQLITE3_LIBRARY)
|
||||
|
||||
if (LIBSQLITE3_INCLUDE_DIR)
|
||||
else (LIBSQLITE3_INCLUDE_DIR)
|
||||
message(FATAL_ERROR "Could not find sqlite3")
|
||||
endif (LIBSQLITE3_INCLUDE_DIR)
|
||||
|
||||
find_program(XXD_EXECUTABLE xxd)
|
||||
|
||||
if (XXD_EXECUTABLE)
|
||||
message(STATUS "Found xxd")
|
||||
else (XXD_EXECUTABLE)
|
||||
message(FATAL_ERROR "Executable xxd not found")
|
||||
endif (XXD_EXECUTABLE)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT colors.h
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/colors.txt colors.txt
|
||||
COMMAND xxd -i colors.txt colors.h
|
||||
DEPENDS colors.txt
|
||||
)
|
||||
set_property(SOURCE TileGenerator.cpp APPEND PROPERTY OBJECT_DEPENDS colors.h)
|
||||
|
||||
include_directories(
|
||||
"${PROJECT_BINARY_DIR}"
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <dirent.h>
|
||||
#include "config.h"
|
||||
#include "TileGenerator.h"
|
||||
#include "colors.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -132,6 +133,9 @@ TileGenerator::TileGenerator():
|
||||
m_zMin(0),
|
||||
m_zMax(0)
|
||||
{
|
||||
string colors_txt_data(reinterpret_cast<char *>(colors_txt), colors_txt_len);
|
||||
istringstream colors_stream(colors_txt_data);
|
||||
parseColorsStream(colors_stream);
|
||||
}
|
||||
|
||||
TileGenerator::~TileGenerator()
|
||||
@ -203,32 +207,9 @@ void TileGenerator::parseColorsFile(const std::string &fileName)
|
||||
ifstream in;
|
||||
in.open(fileName.c_str(), ifstream::in);
|
||||
if (!in.is_open()) {
|
||||
std::cerr << "File colors.txt does not exist" << std::endl;
|
||||
exit(-2);
|
||||
}
|
||||
|
||||
while (in.good()) {
|
||||
string name;
|
||||
Color color;
|
||||
in >> name;
|
||||
if (name[0] == '#') {
|
||||
in.ignore(65536, '\n');
|
||||
in >> name;
|
||||
}
|
||||
while (name == "\n" && in.good()) {
|
||||
in >> name;
|
||||
}
|
||||
int r, g, b;
|
||||
in >> r;
|
||||
in >> g;
|
||||
in >> b;
|
||||
if (in.good()) {
|
||||
color.r = r;
|
||||
color.g = g;
|
||||
color.b = b;
|
||||
m_colors[name] = color;
|
||||
}
|
||||
return;
|
||||
}
|
||||
parseColorsStream(in);
|
||||
}
|
||||
|
||||
void TileGenerator::generate(const std::string &input, const std::string &output)
|
||||
@ -255,6 +236,32 @@ void TileGenerator::generate(const std::string &input, const std::string &output
|
||||
printUnknown();
|
||||
}
|
||||
|
||||
void TileGenerator::parseColorsStream(std::istream &in)
|
||||
{
|
||||
while (in.good()) {
|
||||
string name;
|
||||
Color color;
|
||||
in >> name;
|
||||
if (name[0] == '#') {
|
||||
in.ignore(65536, '\n');
|
||||
in >> name;
|
||||
}
|
||||
while (name == "\n" && in.good()) {
|
||||
in >> name;
|
||||
}
|
||||
int r, g, b;
|
||||
in >> r;
|
||||
in >> g;
|
||||
in >> b;
|
||||
if (in.good()) {
|
||||
color.r = r;
|
||||
color.g = g;
|
||||
color.b = b;
|
||||
m_colors[name] = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TileGenerator::openDb(const std::string &input)
|
||||
{
|
||||
string db_name = input + "map.sqlite";
|
||||
|
@ -11,12 +11,13 @@
|
||||
#define TILEGENERATOR_H_JJNUCARH
|
||||
|
||||
#include <gd.h>
|
||||
#include <iosfwd>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <sqlite3.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include "PixelAttributes.h"
|
||||
|
||||
struct Color {
|
||||
@ -89,6 +90,7 @@ public:
|
||||
void generate(const std::string &input, const std::string &output);
|
||||
|
||||
private:
|
||||
void parseColorsStream(std::istream &in);
|
||||
void openDb(const std::string &input);
|
||||
void loadBlocks();
|
||||
BlockPos decodeBlockPos(sqlite3_int64 blockId) const;
|
||||
|
Loading…
Reference in New Issue
Block a user