Make the player's inventory just a regular entity attached to the player.entity.
This commit is contained in:
parent
2421a33bb0
commit
970905fcd5
3 changed files with 20 additions and 10 deletions
|
@ -75,7 +75,8 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatusUI::update() {
|
void StatusUI::update() {
|
||||||
auto& inventory = $level.world->get_the<inventory::Model>();
|
auto player = $level.world->get_the<components::Player>();
|
||||||
|
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
||||||
for(auto& [slot, world_entity] : inventory.by_slot) {
|
for(auto& [slot, world_entity] : inventory.by_slot) {
|
||||||
auto gui_id = $gui.entity(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) {
|
bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) {
|
||||||
auto& slot_name = $slot_to_name.at(gui_id);
|
auto& slot_name = $slot_to_name.at(gui_id);
|
||||||
auto& inventory = $level.world->get_the<inventory::Model>();
|
auto player = $level.world->get_the<components::Player>();
|
||||||
|
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
||||||
|
|
||||||
if(inventory.add(slot_name, world_entity)) {
|
if(inventory.add(slot_name, world_entity)) {
|
||||||
$level.world->make_constant(world_entity);
|
$level.world->make_constant(world_entity);
|
||||||
|
@ -128,7 +130,10 @@ namespace gui {
|
||||||
// do it.
|
// do it.
|
||||||
dbc::log(fmt::format("removing slot: {}", slot_id));
|
dbc::log(fmt::format("removing slot: {}", slot_id));
|
||||||
auto& slot_name = $slot_to_name.at(slot_id);
|
auto& slot_name = $slot_to_name.at(slot_id);
|
||||||
auto& inventory = $level.world->get_the<inventory::Model>();
|
|
||||||
|
auto player = $level.world->get_the<components::Player>();
|
||||||
|
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
||||||
|
|
||||||
auto world_entity = inventory.get(slot_name);
|
auto world_entity = inventory.get(slot_name);
|
||||||
inventory.remove(world_entity);
|
inventory.remove(world_entity);
|
||||||
|
|
||||||
|
@ -138,7 +143,9 @@ namespace gui {
|
||||||
|
|
||||||
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
|
void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) {
|
||||||
if(gui_a != gui_b) {
|
if(gui_a != gui_b) {
|
||||||
auto& inventory = $level.world->get_the<inventory::Model>();
|
auto player = $level.world->get_the<components::Player>();
|
||||||
|
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
||||||
|
|
||||||
auto& a_name = $slot_to_name.at(gui_a);
|
auto& a_name = $slot_to_name.at(gui_a);
|
||||||
auto& b_name = $slot_to_name.at(gui_b);
|
auto& b_name = $slot_to_name.at(gui_b);
|
||||||
auto a_ent = inventory.get(a_name);
|
auto a_ent = inventory.get(a_name);
|
||||||
|
@ -152,7 +159,8 @@ namespace gui {
|
||||||
bool StatusUI::occupied(guecs::Entity slot) {
|
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.");
|
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<inventory::Model>();
|
auto player = $level.world->get_the<components::Player>();
|
||||||
|
auto& inventory = $level.world->get<inventory::Model>(player.entity);
|
||||||
auto& slot_name = $slot_to_name.at(slot);
|
auto& slot_name = $slot_to_name.at(slot);
|
||||||
return inventory.has(slot_name);
|
return inventory.has(slot_name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,8 @@ void System::enemy_pathing(GameLevel &level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::init_positions(World &world, SpatialMap &collider) {
|
void System::init_positions(World &world, SpatialMap &collider) {
|
||||||
auto& inv = world.get_the<inventory::Model>();
|
auto player = world.get_the<Player>();
|
||||||
|
auto& inv = world.get<inventory::Model>(player.entity);
|
||||||
|
|
||||||
world.query<Position>([&](auto ent, auto &pos) {
|
world.query<Position>([&](auto ent, auto &pos) {
|
||||||
if(world.has<Combat>(ent)) {
|
if(world.has<Combat>(ent)) {
|
||||||
|
@ -507,7 +508,7 @@ bool System::drop_item(GameLevel& level, Entity item) {
|
||||||
|
|
||||||
auto player = world.get_the<Player>();
|
auto player = world.get_the<Player>();
|
||||||
auto player_pos = world.get<Position>(player.entity);
|
auto player_pos = world.get<Position>(player.entity);
|
||||||
auto& player_inv = world.get_the<inventory::Model>();
|
auto& player_inv = world.get<inventory::Model>(player.entity);
|
||||||
|
|
||||||
// doesn't compass already avoid walls?
|
// 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();)
|
||||||
|
|
|
@ -167,8 +167,9 @@ void WorldBuilder::place_stairs(DinkyECS::World& world, GameConfig& config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldBuilder::configure_starting_items(DinkyECS::World &world) {
|
void WorldBuilder::configure_starting_items(DinkyECS::World &world) {
|
||||||
|
auto& player = world.get_the<Player>();
|
||||||
auto& blanket = world.get_the<ritual::Blanket>();
|
auto& blanket = world.get_the<ritual::Blanket>();
|
||||||
auto& config = world.get_the<components::GameConfig>().rituals;
|
auto& config = world.get_the<GameConfig>().rituals;
|
||||||
|
|
||||||
for(auto& el : config["starting_junk"]) {
|
for(auto& el : config["starting_junk"]) {
|
||||||
ritual::JunkItem name = el;
|
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 torch_id = System::spawn_item(world, "TORCH_BAD");
|
||||||
|
|
||||||
auto &inventory = world.get_the<inventory::Model>();
|
auto &inventory = world.get<inventory::Model>(player.entity);
|
||||||
inventory.add("hand_r", torch_id);
|
inventory.add("hand_r", torch_id);
|
||||||
world.make_constant(torch_id);
|
world.make_constant(torch_id);
|
||||||
|
|
||||||
|
@ -214,7 +215,7 @@ void WorldBuilder::place_entities(DinkyECS::World &world) {
|
||||||
world.set_the<Player>(player);
|
world.set_the<Player>(player);
|
||||||
world.set_the<ritual::Belt>({});
|
world.set_the<ritual::Belt>({});
|
||||||
world.set_the<ritual::Blanket>({});
|
world.set_the<ritual::Blanket>({});
|
||||||
world.set_the<inventory::Model>({});
|
world.set<inventory::Model>(player_ent, {});
|
||||||
configure_starting_items(world);
|
configure_starting_items(world);
|
||||||
world.make_constant(player.entity);
|
world.make_constant(player.entity);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue