diff --git a/autowalker.cpp b/autowalker.cpp index ba2bc95..50fcfa7 100644 --- a/autowalker.cpp +++ b/autowalker.cpp @@ -1,5 +1,4 @@ #include "autowalker.hpp" -#include "inventory.hpp" #include "ai_debug.hpp" #include "gui/ritual_ui.hpp" @@ -344,31 +343,12 @@ bool Autowalker::player_health_good() { } InventoryStats Autowalker::player_item_count() { - auto& inventory = fsm.$level.world->get(fsm.$level.player); InventoryStats stats; - - for(auto& item : inventory.items) { - if(item.data["id"] == "POTION_HEALING_SMALL") { - stats.healing += item.count; - } else { - stats.other += item.count; - } - } - + stats.healing = 0; return stats; } void Autowalker::player_use_healing() { - auto& inventory = fsm.$level.world->get(fsm.$level.player); - // find the healing slot - for(size_t slot = 0; slot < inventory.count(); slot++) { - auto& item = inventory.get(slot); - if(item.data["id"] == "POTION_HEALING_SMALL") { - inventory.use(fsm.$level, slot); - fsm.$status_ui.update(); - return; - } - } } void Autowalker::start_autowalk() { diff --git a/components.hpp b/components.hpp index b603ec7..a2b506f 100644 --- a/components.hpp +++ b/components.hpp @@ -16,6 +16,11 @@ namespace components { using std::string; using namespace nlohmann; + struct InventoryItem { + int count; + json data; + }; + struct SpriteEffect { int frames; std::shared_ptr effect; diff --git a/gui/status_ui.cpp b/gui/status_ui.cpp index b3173b4..fd85d34 100644 --- a/gui/status_ui.cpp +++ b/gui/status_ui.cpp @@ -1,6 +1,5 @@ #include "gui/status_ui.hpp" #include "components.hpp" -#include "inventory.hpp" #include #include "rand.hpp" #include @@ -14,12 +13,12 @@ namespace gui { { $gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT); $gui.layout( - "[ ritual_ui ]" - "[inv_1|inv_2|inv_3]" - "[inv_4|*%(200,300)character_view|_|inv_5]" - "[inv_6|_|_ |inv_7]" - "[inv_8|_|_ |inv_9]" - "[inv_10|inv_11|inv_12]"); + "[ritual_ui]" + "[earing|armor_head|amulet]" + "[back|*%(200,300)character_view|_|armor_bdy]" + "[hand_r|_|_ |hand_l]" + "[ring_r|_|_ |ring_l]" + "[pocket_r|armor_leg|pocket_l]"); size_t inv_id = 0; for(auto [name, entity] : $gui.$name_ents) { @@ -36,7 +35,7 @@ namespace gui { if(name == "character_view") { auto char_view = $gui.entity(name); $gui.set(char_view, {}); - $gui.set(char_view, {"peasant_girl"}); + $gui.set(char_view, {"armored_knight"}); } else { auto button = $gui.entity(name); $gui.set(button, {}); @@ -73,47 +72,14 @@ namespace gui { } void StatusUI::select_slot(DinkyECS::Entity ent, any slot_name) { - dbc::check(slot_name.has_value(), "passed select_slot an any without a value"); - - auto cn = $gui.get(ent); - auto world = $level.world; - - if(world->has($level.player)) { - auto& inventory = world->get($level.player); - size_t inv_id = $slots[any_cast(slot_name)]; - - if(inventory.has_item(inv_id)) { - auto [used, name] = inventory.use($level, inv_id); - } - } + (void)ent; + (void)slot_name; + dbc::log("REWRITE!"); } /* WARNING: This is really not the greatest way to do this. */ void StatusUI::update() { - auto world = $level.world; - if(world->has($level.player)) { - auto& inventory = world->get($level.player); - - for(auto& [slot_name, inv_id] : $slots) { - if(inventory.has_item(inv_id)) { - auto slot = $gui.entity(slot_name); - auto& item = inventory.get(inv_id); - auto comp_sprite = components::get(item.data); - $gui.set_init(slot, {comp_sprite.name}); - string count_label = fmt::format("{}", item.count); - auto& label = $gui.get(slot); - label.text->setString(count_label); - - auto& sprite = $gui.get(slot); - - if(item.count == 0) { - sprite.sprite->setColor({125, 125, 125}); - } else { - sprite.sprite->setColor({255, 255, 255}); - } - } - } - } + dbc::log("REWRITE ME!"); } void StatusUI::render(sf::RenderWindow &window) { diff --git a/inventory.cpp b/inventory.cpp deleted file mode 100644 index 0aec16c..0000000 --- a/inventory.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include "inventory.hpp" -#include - - -namespace components { - void Inventory::add(InventoryItem new_item) { - for(auto &slot : items) { - if(new_item.data["id"] == slot.data["id"]) { - slot.count += new_item.count; - return; - } - } - - items.push_back(new_item); - } - - bool Inventory::has_item(size_t at) { - return at < items.size(); - } - - InventoryItem& Inventory::get(size_t at) { - dbc::check(at < items.size(), fmt::format("inventory index {} too big", at)); - return items[at]; - } - - bool Inventory::decrease(size_t at, int count) { - dbc::check(at < items.size(), fmt::format("inventory index {} too big", at)); - auto &slot = items[at]; - slot.count -= count; - return slot.count > 0; - } - - void Inventory::erase_item(size_t at) { - dbc::check(at < items.size(), fmt::format("inventory index {} too big", at)); - items.erase(items.begin() + at); - } - - int Inventory::item_index(std::string id) { - for(size_t i = 0; i < items.size(); i++) { - if(items[i].data["id"] == id) { - return i; - } - } - - return -1; - } - - std::pair Inventory::use(GameLevel &level, size_t at) { - auto& player_combat = level.world->get(level.player); - auto& item = get(at); - - if(item.count == 0) return {false, item.data["name"]}; - - dbc::log("INVENTORY IS HARDCODED YOU FUCKING MORON!!!!!"); - - if(item.data["id"] == "SWORD_RUSTY") { - auto weapon = components::get(item.data); - player_combat.damage = weapon.damage; - } else if(item.data["id"] == "POTION_HEALING_SMALL") { - auto cure = components::get(item.data); - player_combat.hp = std::min(player_combat.hp + cure.hp, player_combat.max_hp); - } else if(item.data["id"] == "TORCH_BAD") { - auto new_light = components::get(item.data); - level.world->set(level.player, new_light); - light = new_light; - } else { - return {false, fmt::format("UNKNOWN ITEM: {}", (std::string)item.data["id"])}; - } - - decrease(at, 1); - return {true, item.data["name"]}; - } - - - -} diff --git a/inventory.hpp b/inventory.hpp deleted file mode 100644 index 9083cab..0000000 --- a/inventory.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include "components.hpp" -#include -#include "levelmanager.hpp" - -namespace components { - using namespace nlohmann; - - struct InventoryItem { - int count; - json data; - }; - - struct Inventory { - int gold=0; - LightSource light{0, 0}; - std::vector items{}; - - size_t count() { return items.size(); } - - void add(InventoryItem item); - - bool decrease(size_t at, int count); - - bool has_item(size_t at); - - InventoryItem& get(size_t at); - - int item_index(std::string id); - - void erase_item(size_t at); - - std::pair use(GameLevel &level, size_t at); - }; -} diff --git a/meson.build b/meson.build index 772a1fe..510528b 100644 --- a/meson.build +++ b/meson.build @@ -105,7 +105,6 @@ sources = [ 'gui/overlay_ui.cpp', 'gui/ritual_ui.cpp', 'gui/status_ui.cpp', - 'inventory.cpp', 'levelmanager.cpp', 'lights.cpp', 'map.cpp', @@ -137,7 +136,6 @@ executable('runtests', sources + [ 'tests/dinkyecs.cpp', 'tests/easings.cpp', 'tests/fsm.cpp', - 'tests/inventory.cpp', 'tests/levelmanager.cpp', 'tests/lighting.cpp', 'tests/map.cpp', diff --git a/systems.cpp b/systems.cpp index 84615be..ee7d21e 100644 --- a/systems.cpp +++ b/systems.cpp @@ -6,7 +6,6 @@ #include "spatialmap.hpp" #include "dbc.hpp" #include "lights.hpp" -#include "inventory.hpp" #include "events.hpp" #include "sound.hpp" #include "ai.hpp" @@ -307,16 +306,17 @@ void System::collision(GameLevel &level) { // call into that to work it, rather than this hard coded crap auto item = world.get(entity); auto& item_pos = world.get(entity); - auto& inventory = world.get(player.entity); + dbc::log("REWRITE ME!"); if(world.has(entity)) { - inventory.add(item); + // inventory.add(item); world.remove(entity); } if(world.has(entity)) { auto& pile = world.get(entity); auto& blanket = world.get_the(); + for(auto& junk : pile.contents) { fmt::println("adding {} to blanket", junk); blanket.add(junk); @@ -324,12 +324,12 @@ void System::collision(GameLevel &level) { } if(world.has(entity)) { - inventory.add(item); + // inventory.add(item); world.remove(entity); } if(world.has(entity)) { - inventory.add(item); + // inventory.add(item); world.remove(entity); } diff --git a/tests/inventory.cpp b/tests/inventory.cpp deleted file mode 100644 index 56cccd4..0000000 --- a/tests/inventory.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include -#include "rand.hpp" -#include -#include -#include "components.hpp" -#include "inventory.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(components::ComponentMap component_map, DinkyECS::World &world, GameConfig &config) { - auto sword = world.entity(); - json& item_data = config.items["SWORD_RUSTY"]; - world.set(sword, {item_data["inventory_count"], item_data}); - components::configure_entity(component_map, world, sword, item_data); - return sword; -} - -TEST_CASE("basic inventory test", "[inventory]") { - // BUG: rewrite this - /* - 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); - - int item_at = inventory.item_index("SWORD_RUSTY"); - REQUIRE(item_at == 0); - - REQUIRE(inventory.item_index("SADFASFSADF") == -1); - - System::pickup(world, player, sword); - REQUIRE(item1.count == 2); - - System::pickup(world, player, sword); - REQUIRE(item1.count == 3); - - 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); - */ -} diff --git a/worldbuilder.cpp b/worldbuilder.cpp index cd300d4..add538d 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -3,9 +3,9 @@ #include #include #include "components.hpp" -#include "inventory.hpp" #include "rituals.hpp" #include "maze.hpp" +#include "textures.hpp" using namespace fmt; using namespace components; @@ -203,7 +203,6 @@ void WorldBuilder::place_entities(DinkyECS::World &world) { world.set_the({}); world.set_the({}); configure_starting_items(world); - world.set(player.entity, {5}); world.make_constant(player.entity); }