From 970905fcd528e6640a7c5d7b250ab98c2e6c64cc Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Wed, 2 Jul 2025 23:55:06 -0400 Subject: [PATCH] Make the player's inventory just a regular entity attached to the player.entity. --- gui/status_ui.cpp | 18 +++++++++++++----- systems.cpp | 5 +++-- worldbuilder.cpp | 7 ++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/gui/status_ui.cpp b/gui/status_ui.cpp index c88edfa..31b9939 100644 --- a/gui/status_ui.cpp +++ b/gui/status_ui.cpp @@ -75,7 +75,8 @@ namespace gui { } void StatusUI::update() { - auto& inventory = $level.world->get_the(); + auto player = $level.world->get_the(); + auto& inventory = $level.world->get(player.entity); for(auto& [slot, world_entity] : inventory.by_slot) { auto gui_id = $gui.entity(slot); @@ -102,7 +103,8 @@ namespace gui { bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) { auto& slot_name = $slot_to_name.at(gui_id); - auto& inventory = $level.world->get_the(); + auto player = $level.world->get_the(); + auto& inventory = $level.world->get(player.entity); if(inventory.add(slot_name, world_entity)) { $level.world->make_constant(world_entity); @@ -128,7 +130,10 @@ namespace gui { // do it. dbc::log(fmt::format("removing slot: {}", slot_id)); auto& slot_name = $slot_to_name.at(slot_id); - auto& inventory = $level.world->get_the(); + + auto player = $level.world->get_the(); + auto& inventory = $level.world->get(player.entity); + auto world_entity = inventory.get(slot_name); inventory.remove(world_entity); @@ -138,7 +143,9 @@ namespace gui { void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) { if(gui_a != gui_b) { - auto& inventory = $level.world->get_the(); + auto player = $level.world->get_the(); + auto& inventory = $level.world->get(player.entity); + auto& a_name = $slot_to_name.at(gui_a); auto& b_name = $slot_to_name.at(gui_b); auto a_ent = inventory.get(a_name); @@ -152,7 +159,8 @@ namespace gui { bool StatusUI::occupied(guecs::Entity slot) { dbc::check($slot_to_name.contains(slot), "jank ass slot to name thing isn't loaded right you idiot."); - auto& inventory = $level.world->get_the(); + auto player = $level.world->get_the(); + auto& inventory = $level.world->get(player.entity); auto& slot_name = $slot_to_name.at(slot); return inventory.has(slot_name); } diff --git a/systems.cpp b/systems.cpp index 3213555..0c2c486 100644 --- a/systems.cpp +++ b/systems.cpp @@ -102,7 +102,8 @@ void System::enemy_pathing(GameLevel &level) { } void System::init_positions(World &world, SpatialMap &collider) { - auto& inv = world.get_the(); + auto player = world.get_the(); + auto& inv = world.get(player.entity); world.query([&](auto ent, auto &pos) { if(world.has(ent)) { @@ -507,7 +508,7 @@ bool System::drop_item(GameLevel& level, Entity item) { auto player = world.get_the(); auto player_pos = world.get(player.entity); - auto& player_inv = world.get_the(); + auto& player_inv = world.get(player.entity); // doesn't compass already avoid walls? for(matrix::box it{map.walls(), player_pos.location.x, player_pos.location.y, 1}; it.next();) diff --git a/worldbuilder.cpp b/worldbuilder.cpp index 271b232..5138fef 100644 --- a/worldbuilder.cpp +++ b/worldbuilder.cpp @@ -167,8 +167,9 @@ void WorldBuilder::place_stairs(DinkyECS::World& world, GameConfig& config) { } void WorldBuilder::configure_starting_items(DinkyECS::World &world) { + auto& player = world.get_the(); auto& blanket = world.get_the(); - auto& config = world.get_the().rituals; + auto& config = world.get_the().rituals; for(auto& el : config["starting_junk"]) { ritual::JunkItem name = el; @@ -177,7 +178,7 @@ void WorldBuilder::configure_starting_items(DinkyECS::World &world) { auto torch_id = System::spawn_item(world, "TORCH_BAD"); - auto &inventory = world.get_the(); + auto &inventory = world.get(player.entity); inventory.add("hand_r", torch_id); world.make_constant(torch_id); @@ -214,7 +215,7 @@ void WorldBuilder::place_entities(DinkyECS::World &world) { world.set_the(player); world.set_the({}); world.set_the({}); - world.set_the({}); + world.set(player_ent, {}); configure_starting_items(world); world.make_constant(player.entity); }