#include #include #include #include "rand.hpp" #include #include #include "components.hpp" #include "dinkyecs.hpp" #include "save.hpp" #include "systems.hpp" using namespace nlohmann; using namespace fmt; using std::string; using namespace components; DinkyECS::Entity add_items(DinkyECS::World &world, GameConfig &config) { auto sword = world.entity(); world.set(sword, {1, config.items["SWORD_RUSTY"]}); world.set(sword, {config.items["SWORD_RUSTY"]["display"]}); return sword; } TEST_CASE("basic inventory test", "[inventory]") { DinkyECS::World world; save::load_configs(world); auto& config = world.get_the(); auto sword = add_items(world, config); auto player = world.entity(); world.set(player, {}); auto &inventory = world.get(player); System::pickup(world, player, sword); REQUIRE(inventory.count() == 1); // get the item and confirm there is 1 auto &item1 = inventory.get(0); REQUIRE(item1.count == 1); System::pickup(world, player, sword); System::pickup(world, player, sword); System::pickup(world, player, sword); REQUIRE(inventory.count() == 1); REQUIRE(item1.count == 4); inventory.decrease(0, 1); REQUIRE(item1.count == 3); inventory.decrease(0, 2); REQUIRE(item1.count == 1); bool active = inventory.decrease(0, 1); REQUIRE(item1.count == 0); REQUIRE(active == false); inventory.erase_item(0); REQUIRE(inventory.count() == 0); }