Skip to content

Issue 14 #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,9 @@ venv/

# project-specific files and directories
assets/
manifest.json
manifest.json

# VSCode, clangd etc
.vscode/
.cache/
compile_commands.json
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libs/djson"]
path = libs/djson
url = https://github.com/karnkaul/djson
[submodule "libs/include/str_format"]
path = libs/include/str_format
url = https://github.com/karnkaul/str-format
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.*
add_subdirectory(libs/djson)

add_executable(${PROJECT_NAME} ${SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE libs/include)

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

if(MSVC)
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(${PROJECT_NAME} PRIVATE $<$<NOT:$<CONFIG:Debug>>:/WX>)
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${PROJECT_NAME})
endif()

Expand Down
1 change: 1 addition & 0 deletions libs/include/str_format
Submodule str_format added at 123b3a
2 changes: 1 addition & 1 deletion src/anim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <vector>
#include "models.hpp"
#include "utils.hpp"
#include "str_format.hpp"
#include <str_format/str_format.hpp>

std::vector<std::string> gen_healthbar(Pokemon& pkmn)
{
Expand Down
30 changes: 15 additions & 15 deletions src/models.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#include <numeric>
#include <vector>
#include "utils.hpp"
#include "str_format.hpp"
#include <dumb_json/djson.hpp>
#include <str_format/str_format.hpp>
#include <dumb_json/json.hpp>

Move::Move(std::string name, MoveType type, int accuracy, int effect_chance, int power, std::string flavor_text)
: name(name), type(type), accuracy(accuracy), effect_chance(effect_chance), power(power), flavor_text(flavor_text)
: name(name), type(type), accuracy(accuracy), power(power), effect_chance(effect_chance), flavor_text(flavor_text)
{
}

Expand Down Expand Up @@ -43,28 +43,28 @@ void Pokemon::configure_move_set()
}
}

Pokemon::Pokemon(int id, std::filesystem::path assets_dir) : id{id}, assets_dir{assets_dir}
Pokemon::Pokemon(int id, std::filesystem::path assets_dir) : assets_dir{assets_dir}, id{id}
{
this->sprite = read_asset("txt");
auto lines = read_asset("json");
this->json = std::accumulate(lines.begin(), lines.end(), std::string(""));
if (auto n = dj::node_t::make(this->json))
this->json_str = std::accumulate(lines.begin(), lines.end(), std::string(""));
dj::json_t json;
if (json.read(this->json_str) && json.is_object())
{
// pkmn data
dj::node_t& node = *n;
this->id = id;
this->name = node["name"].as<std::string>();
this->level = node["level"].as<int>();
this->hp = node["hp"].as<int>();
this->name = json["name"].as<std::string>();
this->level = json["level"].as<int>();
this->hp = json["hp"].as<int>();
this->max_hp = this->hp;
this->atk = node["atk"].as<int>();
this->def = node["def"].as<int>();
this->atk = json["atk"].as<int>();
this->def = json["def"].as<int>();
// move data
if (auto moves = node.find("moves"))
if (auto moves = json.find("moves"))
{
for (auto const& [num, m] : moves->as<dj::map_nodes_t>())
for (auto const& [num, m] : moves->as<dj::map_t>())
{
dj::node_t& move = *m;
dj::json_t& move = *m;

this->all_moves.push_back(
Move(
Expand Down
2 changes: 1 addition & 1 deletion src/models.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Pokemon
std::vector<std::string> read_asset(std::string ext);
void configure_move_set();

std::string json{};
std::string json_str{};
std::vector<Move> all_moves{};

public:
Expand Down
38 changes: 0 additions & 38 deletions src/str_format.hpp

This file was deleted.

18 changes: 9 additions & 9 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <string>
#include <thread>
#include "utils.hpp"
#include "str_format.hpp"
#include <dumb_json/djson.hpp>
#include <str_format/str_format.hpp>
#include <dumb_json/json.hpp>

void clear_screen()
{
Expand Down Expand Up @@ -74,14 +74,14 @@ Manifest check_manifest(const std::filesystem::path& path)

if (std::filesystem::exists(path))
{
auto file = read_file(path);
auto json = std::accumulate(file.begin(), file.end(), std::string(""));
if (auto n = dj::node_t::make(json))
auto const file = read_file(path);
auto const str = std::accumulate(file.begin(), file.end(), std::string(""));
dj::json_t json;
if (json.read(str) && json.is_object())
{
dj::node_t& node = *n;
manifest.game_ready = node["game_ready"].as<bool>();
manifest.duplicates = node["duplicates"].as<std::vector<int>>();
manifest.files = node["files"].as<std::vector<std::string>>();
manifest.game_ready = json["game_ready"].as<bool>();
manifest.duplicates = json["duplicates"].as<std::vector<int>>();
manifest.files = json["files"].as<std::vector<std::string>>();
}
}
else
Expand Down