diff --git a/CMakeLists.txt b/CMakeLists.txt index f041f4c..fe19089 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,9 +56,6 @@ pkg_search_module(SDL2MIXER REQUIRED SDL2_mixer) pkg_search_module(SDL2IMAGE REQUIRED SDL2_image) pkg_search_module(SDL2TTF REQUIRED SDL2_ttf) -pkg_search_module(JSONCPP REQUIRED jsoncpp) -include_directories(${JSONCPP_INCLUDE_DIRS}) - find_package(Boost COMPONENTS program_options REQUIRED) #Find all sources but one @@ -71,13 +68,13 @@ message("${SOURCES}") message("${CMAKE_EXE_LINKER_FLAGS}") include_directories("source/code/Libs/include") +include_directories("source/code/Libs/include/cereal/external") #Contains rapidjson #building/compiling/linking add_executable(blockattack ${GUI_TYPE} ${SOURCES} ${RES_FILES}) target_link_libraries( blockattack ${SDL2_LIBRARY}) target_link_libraries( blockattack physfs) target_link_libraries( blockattack ${SDL2MIXER_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES}) -target_link_libraries( blockattack ${JSONCPP_LIBRARIES} ) target_link_libraries( blockattack ${Boost_LIBRARIES} ) set_target_properties( blockattack PROPERTIES RUNTIME_OUTPUT_DIRECTORY Game) diff --git a/README.md b/README.md index 90cf0d9..7eb550f 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ Source: https://github.com/blockattack/blockattack-game * libboost (only needed for compiling) * libboost-program-options * libutfcpp (only needed for compiling) - * jsoncpp # Building The only supported build method is using the CMake
@@ -44,7 +43,7 @@ sudo make install Windows build uses MXE (mxe.cc) with these installed: ``` -sdl2 sdl2_image sdl2_mixer sdl2_ttf physfs jsoncpp libtool gettext freetype zlib boost +sdl2 sdl2_image sdl2_mixer sdl2_ttf physfs libtool gettext freetype zlib boost ``` and libutfcpp copied from "source/misc/travis_help/utf8_v2_3_4/source/" to "/path/to/mxe/usr/lib/gcc/i686-w64-mingw32.static/4.9.3/include" diff --git a/source/code/sago/Makefile.sago b/source/code/sago/Makefile.sago index 5e4f0d4..700f529 100644 --- a/source/code/sago/Makefile.sago +++ b/source/code/sago/Makefile.sago @@ -1,4 +1,4 @@ -SAGO_BASE_LIBS+= -lphysfs -ljsoncpp +SAGO_BASE_LIBS+= -lphysfs SAGO_O_FILES+= sago/SagoDataHolder.o sago/SagoSprite.o sago/SagoSpriteHolder.o sago/SagoMisc.o \ No newline at end of file diff --git a/source/code/sago/SagoSpriteHolder.cpp b/source/code/sago/SagoSpriteHolder.cpp index 2e50864..d880f52 100644 --- a/source/code/sago/SagoSpriteHolder.cpp +++ b/source/code/sago/SagoSpriteHolder.cpp @@ -26,7 +26,7 @@ SOFTWARE. #include "SagoMisc.hpp" #include #include -#include +#include "rapidjson/document.h" #include #include #include @@ -61,36 +61,50 @@ SagoSpriteHolder::~SagoSpriteHolder() { delete data; } +static int getDefaultValue(const rapidjson::Value& value, const char* name, int defaultValue) { + assert(value.IsObject()); + const auto& t = value.GetObject().FindMember(name); + if (t->value.IsInt()) { + return t->value.GetInt(); + } + return defaultValue; +} + +static std::string getDefaultValue(const rapidjson::Value& value, const char* name, std::string defaultValue) { + assert(value.IsObject()); + const auto& t = value.GetObject().FindMember(name); + if (t->value.IsString()) { + defaultValue = t->value.GetString(); + } + return defaultValue; +} + void SagoSpriteHolder::ReadSpriteFile(const std::string& filename) { string fullfile = "sprites/"+filename; string content = sago::GetFileContent(fullfile.c_str()); - Json::Value root; // will contains the root value after parsing - Json::Reader reader; - bool parsingSuccessful = reader.parse( content, root ); - if ( !parsingSuccessful ) { - cerr << "Failed to parse: " << fullfile << "\n" - << reader.getFormattedErrorMessages() << "\n"; + rapidjson::Document document; + document.Parse(content.c_str()); + if ( !document.IsObject() ) { + cerr << "Failed to parse: " << fullfile << "\n"; return; } - for (Json::Value::iterator it = root.begin(); it != root.end() ; ++it) { - string spriteName = it.key().asString(); - Json::Value value = (*it); - if (!value.isObject()) { - if (spriteName.c_str()[0] != '_') { - //We ignore errors if the name starts with an underscore like "_comment" + for (auto& m : document.GetObject()) { + const std::string& spriteName = m.name.GetString(); + if (!m.value.IsObject()) { + if (spriteName[0] == '_') { std::cerr << "Invalid sprite: " << spriteName << "\n"; } continue; } - string textureName = value.get("texture","fallback").asString(); - int topx = value.get("topx",0).asInt(); - int topy = value.get("topy",0).asInt(); - int height = value.get("height",0).asInt(); - int width = value.get("width",0).asInt(); - int number_of_frames = value.get("number_of_frames",1).asInt(); - int frame_time = value.get("frame_time",1).asInt(); - int originx = value.get("originx",0).asInt(); - int originy = value.get("originy",0).asInt(); + string textureName = getDefaultValue(m.value, "texture", "fallback"); + int topx = getDefaultValue(m.value, "topx", 0); + int topy = getDefaultValue(m.value, "topy",0); + int height = getDefaultValue(m.value, "height",0); + int width = getDefaultValue(m.value, "width",0); + int number_of_frames = getDefaultValue(m.value, "number_of_frames",1); + int frame_time = getDefaultValue(m.value, "frame_time",1); + int originx = getDefaultValue(m.value, "originx",0); + int originy = getDefaultValue(m.value, "originy",0); if (number_of_frames < 1) { number_of_frames = 1; } diff --git a/source/misc/docker/Dockerfile.Ubuntu14.04build b/source/misc/docker/Dockerfile.Ubuntu14.04build index 2d1fc1e..7cdcdf3 100644 --- a/source/misc/docker/Dockerfile.Ubuntu14.04build +++ b/source/misc/docker/Dockerfile.Ubuntu14.04build @@ -1,6 +1,6 @@ FROM ubuntu:14.04 -RUN apt-get update && apt-get install -y build-essential libphysfs-dev libboost-dev libjsoncpp-dev cmake libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libboost-program-options-dev libutfcpp-dev zip gettext +RUN apt-get update && apt-get install -y build-essential libphysfs-dev libboost-dev cmake libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libboost-program-options-dev libutfcpp-dev zip gettext RUN mkdir -p /staging/blockattack-game