Big BIG refactor to make inventory use a model that's placed into the world, following a more sane MVC style.

This commit is contained in:
Zed A. Shaw 2025-06-20 13:17:12 -04:00
parent 119b3ed11d
commit a0eff927b6
21 changed files with 270 additions and 123 deletions

View file

@ -15,6 +15,7 @@
#include "battle.hpp"
#include <iostream>
#include "shaders.hpp"
#include "inventory.hpp"
using std::string;
using namespace fmt;
@ -461,12 +462,12 @@ std::shared_ptr<sf::Shader> System::sprite_effect(GameLevel &level, DinkyECS::En
}
}
DinkyECS::Entity System::spawn_item(GameLevel& level, const std::string& name) {
DinkyECS::Entity System::spawn_item(DinkyECS::World& world, const std::string& name) {
Config config("assets/items.json");
auto& item_config = config[name];
auto item_id = level.world->entity();
level.world->set<InventoryItem>(item_id, {1, item_config});
components::configure_entity(*level.world, item_id, item_config["components"]);
auto item_id = world.entity();
world.set<InventoryItem>(item_id, {1, item_config});
components::configure_entity(world, item_id, item_config["components"]);
return item_id;
}
@ -478,13 +479,17 @@ bool System::drop_item(GameLevel& level, DinkyECS::Entity item) {
auto player = world.get_the<Player>();
auto player_pos = world.get<Position>(player.entity);
auto& player_inv = world.get_the<inventory::Model>();
// doesn't compass already avoid walls?
for(matrix::box it{map.walls(), player_pos.location.x, player_pos.location.y, 1}; it.next();) {
for(matrix::box it{map.walls(), player_pos.location.x, player_pos.location.y, 1}; it.next();)
{
Position pos{it.x, it.y};
if(map.can_move(pos.location) && !collision.occupied(pos.location)) {
world.set<Position>(item, pos);
collision.insert(pos.location, item);
// BUG: really there should be another system that handles loot->inv moves
if(player_inv.has(item)) player_inv.remove(item);
level.world->send<Events::GUI>(Events::GUI::ENEMY_SPAWN, item, {});
return true;
}