Skip to content

Commit 0afc430

Browse files
committed
Upgrade djson to v0.1
- Emit all compile warnings as errors except on Debug.
1 parent b750c0b commit 0afc430

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ add_executable(${PROJECT_NAME} ${SOURCES})
3535
target_include_directories(${PROJECT_NAME} PRIVATE libs/include)
3636

3737
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL GNU)
38-
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra)
38+
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra $<$<NOT:$<CONFIG:Debug>>:-Werror>)
3939
endif()
4040

41-
if(MSVC)
41+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
42+
target_compile_options(${PROJECT_NAME} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/WX>)
4243
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
4344
endif()
4445

src/models.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <vector>
55
#include "utils.hpp"
66
#include <str_format/str_format.hpp>
7-
#include <dumb_json/djson.hpp>
7+
#include <dumb_json/json.hpp>
88

99
Move::Move(std::string name, MoveType type, int accuracy, int effect_chance, int power, std::string flavor_text)
1010
: name(name), type(type), accuracy(accuracy), power(power), effect_chance(effect_chance), flavor_text(flavor_text)
@@ -47,24 +47,24 @@ Pokemon::Pokemon(int id, std::filesystem::path assets_dir) : assets_dir{assets_d
4747
{
4848
this->sprite = read_asset("txt");
4949
auto lines = read_asset("json");
50-
this->json = std::accumulate(lines.begin(), lines.end(), std::string(""));
51-
if (auto n = dj::node_t::make(this->json))
50+
this->json_str = std::accumulate(lines.begin(), lines.end(), std::string(""));
51+
dj::json_t json;
52+
if (json.read(this->json_str) && json.is_object())
5253
{
5354
// pkmn data
54-
dj::node_t& node = *n;
5555
this->id = id;
56-
this->name = node["name"].as<std::string>();
57-
this->level = node["level"].as<int>();
58-
this->hp = node["hp"].as<int>();
56+
this->name = json["name"].as<std::string>();
57+
this->level = json["level"].as<int>();
58+
this->hp = json["hp"].as<int>();
5959
this->max_hp = this->hp;
60-
this->atk = node["atk"].as<int>();
61-
this->def = node["def"].as<int>();
60+
this->atk = json["atk"].as<int>();
61+
this->def = json["def"].as<int>();
6262
// move data
63-
if (auto moves = node.find("moves"))
63+
if (auto moves = json.find("moves"))
6464
{
65-
for (auto const& [num, m] : moves->as<dj::map_nodes_t>())
65+
for (auto const& [num, m] : moves->as<dj::map_t>())
6666
{
67-
dj::node_t& move = *m;
67+
dj::json_t& move = *m;
6868

6969
this->all_moves.push_back(
7070
Move(

src/models.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct Pokemon
3131
std::vector<std::string> read_asset(std::string ext);
3232
void configure_move_set();
3333

34-
std::string json{};
34+
std::string json_str{};
3535
std::vector<Move> all_moves{};
3636

3737
public:

src/utils.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <thread>
1010
#include "utils.hpp"
1111
#include <str_format/str_format.hpp>
12-
#include <dumb_json/djson.hpp>
12+
#include <dumb_json/json.hpp>
1313

1414
void clear_screen()
1515
{
@@ -74,14 +74,14 @@ Manifest check_manifest(const std::filesystem::path& path)
7474

7575
if (std::filesystem::exists(path))
7676
{
77-
auto file = read_file(path);
78-
auto json = std::accumulate(file.begin(), file.end(), std::string(""));
79-
if (auto n = dj::node_t::make(json))
77+
auto const file = read_file(path);
78+
auto const str = std::accumulate(file.begin(), file.end(), std::string(""));
79+
dj::json_t json;
80+
if (json.read(str) && json.is_object())
8081
{
81-
dj::node_t& node = *n;
82-
manifest.game_ready = node["game_ready"].as<bool>();
83-
manifest.duplicates = node["duplicates"].as<std::vector<int>>();
84-
manifest.files = node["files"].as<std::vector<std::string>>();
82+
manifest.game_ready = json["game_ready"].as<bool>();
83+
manifest.duplicates = json["duplicates"].as<std::vector<int>>();
84+
manifest.files = json["files"].as<std::vector<std::string>>();
8585
}
8686
}
8787
else

0 commit comments

Comments
 (0)