diff --git a/gui/combat_ui.cpp b/gui/combat_ui.cpp index 0717df2..8713333 100644 --- a/gui/combat_ui.cpp +++ b/gui/combat_ui.cpp @@ -4,12 +4,12 @@ #include #include "gui/guecstra.hpp" #include "inventory.hpp" +#include "game_level.hpp" namespace gui { using namespace guecs; - CombatUI::CombatUI(GameLevel level) : - $level(level) + CombatUI::CombatUI() { $gui.position(COMBAT_UI_X, COMBAT_UI_Y, COMBAT_UI_WIDTH, COMBAT_UI_HEIGHT); $gui.layout( @@ -31,15 +31,16 @@ namespace gui { $gui.set(button, {sound}); $gui.set(button, {.duration=0.5f, .name=effect_name}); $gui.set(button, - guecs::make_action($level, button, event, {action})); + guecs::make_action(button, event, {action})); return button; } void CombatUI::init() { + auto world = Game::current_world(); using guecs::THEME; $gui.set($gui.MAIN, {$gui.$parser, THEME.DARK_MID}); - auto& the_belt = $level.world->get_the(); + auto& the_belt = world->get_the(); for(int slot = 0; slot < the_belt.max_slots; slot++) { if(the_belt.has(slot)) { @@ -67,7 +68,7 @@ namespace gui { auto hp_gauge = $gui.entity("hp_gauge"); $gui.set(hp_gauge, {"stone_doll_cursed"}); $gui.set(hp_gauge, - guecs::make_action($level, hp_gauge, Events::GUI::HP_STATUS, {})); + guecs::make_action(hp_gauge, Events::GUI::HP_STATUS, {})); $gui.init(); } @@ -76,8 +77,7 @@ namespace gui { $gui.render(window); } - void CombatUI::update_level(GameLevel &level) { - $level = level; + void CombatUI::update_level() { init(); } diff --git a/gui/combat_ui.hpp b/gui/combat_ui.hpp index f52643c..c14898d 100644 --- a/gui/combat_ui.hpp +++ b/gui/combat_ui.hpp @@ -1,5 +1,4 @@ #pragma once -#include "levelmanager.hpp" #include #include #include @@ -9,13 +8,12 @@ namespace gui { class CombatUI { public: guecs::UI $gui; - GameLevel $level; - CombatUI(GameLevel level); + CombatUI(); void init(); void render(sf::RenderWindow& window); - void update_level(GameLevel &level); + void update_level(); bool mouse(float x, float y, guecs::Modifiers mods); guecs::Entity make_button(std::string name, Events::GUI event, int action, const std::string &icon_name, diff --git a/gui/fsm.cpp b/gui/fsm.cpp index cb55847..f64ad3c 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -21,10 +21,6 @@ namespace gui { $window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"), $debug_ui(Game::get_the_manager()), $main_ui($window), - $combat_ui(Game::current()), - $status_ui(Game::current()), - $map_ui(Game::current()), - $loot_ui(Game::current()), $font{FONT_FILE_NAME}, $dnd_loot($status_ui, $loot_ui, $window, $router) { @@ -47,8 +43,7 @@ namespace gui { } void FSM::START(Event ) { - auto& level = Game::current(); - $main_ui.update_level(level); + $main_ui.update_level(); $main_ui.init(); $loot_ui.init(); @@ -545,13 +540,10 @@ namespace gui { } void FSM::next_level() { - auto& level = Game::create_level(); - - $status_ui.update_level(level); - $map_ui.update_level(level); - $combat_ui.update_level(level); - $main_ui.update_level(level); - $loot_ui.update_level(level); + $status_ui.update_level(); + $combat_ui.update_level(); + $main_ui.update_level(); + $loot_ui.update_level(); $boss_fight_ui = Game::create_bossfight(); $boss_fight_ui->init(); diff --git a/gui/guecstra.cpp b/gui/guecstra.cpp index 89f316a..6967210 100644 --- a/gui/guecstra.cpp +++ b/gui/guecstra.cpp @@ -1,16 +1,19 @@ #include "gui/guecstra.hpp" +#include "game_level.hpp" namespace guecs { - Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event) { + Clickable make_action(guecs::Entity gui_id, Events::GUI event) { return {[&, gui_id, event](auto){ - target.world->send(event, gui_id, {}); + auto world = Game::current_world(); + world->send(event, gui_id, {}); }}; } - Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event, std::any data) { + Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data) { return {[&, event, data](auto){ - target.world->send(event, gui_id, data); + auto world = Game::current_world(); + world->send(event, gui_id, data); }}; } diff --git a/gui/guecstra.hpp b/gui/guecstra.hpp index f8e7a6d..41f71e4 100644 --- a/gui/guecstra.hpp +++ b/gui/guecstra.hpp @@ -3,11 +3,10 @@ #include "events.hpp" #include #include "textures.hpp" -#include "levelmanager.hpp" namespace guecs { - Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event); - Clickable make_action(GameLevel& target, guecs::Entity gui_id, Events::GUI event, std::any data); + Clickable make_action(guecs::Entity gui_id, Events::GUI event); + Clickable make_action(guecs::Entity gui_id, Events::GUI event, std::any data); struct GrabSource { DinkyECS::Entity world_entity; diff --git a/gui/loot_ui.cpp b/gui/loot_ui.cpp index 22edc38..1ffe6c7 100644 --- a/gui/loot_ui.cpp +++ b/gui/loot_ui.cpp @@ -2,13 +2,13 @@ #include "constants.hpp" #include #include "systems.hpp" +#include "game_level.hpp" namespace gui { using namespace guecs; - LootUI::LootUI(GameLevel level) : - $level(level), - $temp_loot($level.world->entity()), + LootUI::LootUI() : + $temp_loot(Game::current_world()->entity()), $target($temp_loot) { $gui.position(RAY_VIEW_X+RAY_VIEW_WIDTH/2-200, @@ -21,8 +21,9 @@ namespace gui { "[=item_12| =item_13|=item_14|=item_15 ]" "[ =take_all | =close| =destroy]"); - $level.world->set($temp_loot, {}); - $level.world->make_constant($temp_loot); + auto world = Game::current_world(); + world->set($temp_loot, {}); + world->make_constant($temp_loot); } void LootUI::make_button(const std::string &name, const std::wstring& label, Events::GUI event) { @@ -31,7 +32,7 @@ namespace gui { $gui.set(button, {}); $gui.set(button, {label}); $gui.set(button, - guecs::make_action($level, button, event)); + guecs::make_action(button, event)); } void LootUI::init() { @@ -52,7 +53,7 @@ namespace gui { THEME.TRANSPARENT, THEME.LIGHT_MID }); $gui.set(id, {0.4f, "ui_shader"}); $gui.set(id, { - guecs::make_action($level, id, Events::GUI::LOOT_SELECT, {id}) + guecs::make_action(id, Events::GUI::LOOT_SELECT, {id}) }); } @@ -61,10 +62,12 @@ namespace gui { } void LootUI::update() { - dbc::check($level.world->has($target), + auto world = Game::current_world(); + + dbc::check(world->has($target), "update called but $target isn't in world"); - auto& contents = $level.world->get($target); + auto& contents = world->get($target); for(size_t i = 0; i < INV_SLOTS; i++) { auto id = $gui.entity("item_", int(i)); @@ -72,9 +75,9 @@ namespace gui { if(contents.has(slot_name)) { auto item = contents.get(slot_name); - dbc::check($level.world->has(item), + dbc::check(world->has(item), "item in inventory UI doesn't exist in world. New level?"); - auto& sprite = $level.world->get(item); + auto& sprite = world->get(item); $gui.set_init(id, {sprite.name}); guecs::GrabSource grabber{ @@ -98,7 +101,7 @@ namespace gui { void LootUI::remove_slot(guecs::Entity slot_id) { auto& name = $gui.name_for(slot_id); fmt::println("LootUI remove slot inv::Model id={} slot={}", $target, name); - System::remove_from_container(*$level.world, $target, name); + System::remove_from_container($target, name); update(); } @@ -107,7 +110,7 @@ namespace gui { $target, id, world_entity); auto& name = $gui.name_for(id); - bool worked = System::place_in_container(*$level.world, $target, name, world_entity); + bool worked = System::place_in_container($target, name, world_entity); if(worked) update(); return worked; } @@ -116,13 +119,12 @@ namespace gui { $gui.render(window); } - void LootUI::update_level(GameLevel &level) { - $level = level; + void LootUI::update_level() { init(); } void LootUI::add_loose_item(DinkyECS::Entity entity) { - System::place_in_container(*$level.world, $temp_loot, "item_0", entity); + System::place_in_container($temp_loot, "item_0", entity); set_target($temp_loot); update(); } diff --git a/gui/loot_ui.hpp b/gui/loot_ui.hpp index d5513d9..204751e 100644 --- a/gui/loot_ui.hpp +++ b/gui/loot_ui.hpp @@ -1,6 +1,5 @@ #pragma once #include "gui/guecstra.hpp" -#include "levelmanager.hpp" #include #include #include @@ -12,11 +11,10 @@ namespace gui { public: bool active = false; guecs::UI $gui; - GameLevel $level; DinkyECS::Entity $temp_loot; DinkyECS::Entity $target; - LootUI(GameLevel level); + LootUI(); void set_target(DinkyECS::Entity entity) { $target = entity; @@ -25,7 +23,7 @@ namespace gui { void init(); void update(); void render(sf::RenderWindow& window); - void update_level(GameLevel &level); + void update_level(); bool mouse(float x, float y, guecs::Modifiers mods); void make_button(const std::string &name, const std::wstring& label, Events::GUI event); diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 9ddebe6..5aa2cd1 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -3,6 +3,7 @@ #include "easings.hpp" #include #include "constants.hpp" +#include "game_level.hpp" namespace gui { using namespace components; @@ -20,7 +21,7 @@ namespace gui { } void MainUI::init() { - auto& player_position = $level.world->get($level.player); + auto& player_position = Game::player_position(); auto player = player_position.location; $rayview->init_shaders(); @@ -31,9 +32,10 @@ namespace gui { } DinkyECS::Entity MainUI::camera_aim() { + auto& level = Game::current(); // what happens if there's two things at that spot - if($level.collision->something_there($rayview->aiming_at)) { - return $level.collision->get($rayview->aiming_at); + if(level.collision->something_there($rayview->aiming_at)) { + return level.collision->get($rayview->aiming_at); } else { return 0; } @@ -88,27 +90,26 @@ namespace gui { } void MainUI::dead_entity(DinkyECS::Entity entity) { - // BUG: this is kind of weird, but I think when I switch to dead bodies for things - // (see System::distribute_loot) then this can be fixed or improved - if($level.world->has(entity)) { - auto &sprite = $level.world->get(entity); + auto world = Game::current_world(); + if(world->has(entity)) { + auto &sprite = world->get(entity); $rayview->update_sprite(entity, sprite); } } - void MainUI::update_level(GameLevel level) { - $level = level; - auto& player_position = $level.world->get($level.player); + void MainUI::update_level() { + auto& level = Game::current(); + auto& player_position = Game::player_position(); auto player = player_position.location; - $rayview->update_level($level); + $rayview->update_level(level); $rayview->position_camera(player.x + 0.5, player.y + 0.5); player_position.aiming_at = $rayview->aiming_at; $compass_dir = 0; - $overlay_ui.update_level(level); + $overlay_ui.update_level(); dirty(); } diff --git a/gui/main_ui.hpp b/gui/main_ui.hpp index aabe652..0382595 100644 --- a/gui/main_ui.hpp +++ b/gui/main_ui.hpp @@ -1,5 +1,4 @@ #pragma once -#include "levelmanager.hpp" #include #include #include "stats.hpp" @@ -32,7 +31,7 @@ namespace gui { std::optional play_move(); Point plan_move(int dir, bool strafe); void abort_plan(); - void update_level(GameLevel level); + void update_level(); DinkyECS::Entity camera_aim(); void init(); diff --git a/gui/map_view.cpp b/gui/map_view.cpp index c1a189b..d6cf196 100644 --- a/gui/map_view.cpp +++ b/gui/map_view.cpp @@ -12,6 +12,7 @@ #include #include #include "palette.hpp" +#include "game_level.hpp" constexpr const int MAP_WIDTH=13; constexpr const int MAP_HEIGHT=13; @@ -20,18 +21,14 @@ namespace gui { using namespace components; using namespace guecs; - MapViewUI::MapViewUI(GameLevel &level) : - $level(level), + MapViewUI::MapViewUI() : $map_render(std::make_shared()), $map_sprite($map_render->getTexture()), $map_tiles(matrix::make(MAP_WIDTH, MAP_HEIGHT)) { - auto player = $level.world->get_the(); - $player_display = $level.world->get(player.entity).display; - } - - void MapViewUI::update_level(GameLevel &level) { - $level = level; + auto world = Game::current_world(); + auto player = Game::the_player(); + $player_display = world->get(player).display; } void MapViewUI::init() { diff --git a/gui/map_view.hpp b/gui/map_view.hpp index 3b277c7..36e859d 100644 --- a/gui/map_view.hpp +++ b/gui/map_view.hpp @@ -1,9 +1,10 @@ #pragma once -#include "levelmanager.hpp" #include "textures.hpp" #include "matrix.hpp" #include #include +#include "dinkyecs.hpp" +#include "map.hpp" namespace gui { class MapViewUI { @@ -13,15 +14,13 @@ namespace gui { DinkyECS::Entity $log_to; EntityGrid $entity_map; std::deque $messages; - GameLevel $level; std::shared_ptr $map_render; sf::Sprite $map_sprite; matrix::Matrix $map_tiles; - MapViewUI(GameLevel &level); + MapViewUI(); void init(); void render(sf::RenderWindow &window, int compass_dir); - void update_level(GameLevel &level); void log(std::wstring msg); void update(); }; diff --git a/gui/mini_map.cpp b/gui/mini_map.cpp index af4702a..b193346 100644 --- a/gui/mini_map.cpp +++ b/gui/mini_map.cpp @@ -14,17 +14,12 @@ namespace gui { using namespace components; - MiniMapUI::MiniMapUI(GameLevel &level) : - $map_grid{L"...", 45, {200, 200, 200, 100}, 10}, - $level(level) + MiniMapUI::MiniMapUI() : + $map_grid{L"...", 45, {200, 200, 200, 100}, 10} { $font = std::make_shared(FONT_FILE_NAME); } - void MiniMapUI::update_level(GameLevel &level) { - $level = level; - } - void MiniMapUI::init(guecs::UI& overlay) { auto top_right = overlay.entity("top_right"); auto cell = overlay.cell_for(top_right); diff --git a/gui/mini_map.hpp b/gui/mini_map.hpp index 38055b0..b26cfcf 100644 --- a/gui/mini_map.hpp +++ b/gui/mini_map.hpp @@ -1,19 +1,17 @@ #pragma once -#include "levelmanager.hpp" #include "textures.hpp" #include +#include namespace gui { class MiniMapUI { public: guecs::Text $map_grid; guecs::UI $gui; - GameLevel $level; - shared_ptr $font = nullptr; + std::shared_ptr $font = nullptr; - MiniMapUI(GameLevel &level); + MiniMapUI(); void init(guecs::UI& overlay); void render(sf::RenderWindow &window, int compass_dir); - void update_level(GameLevel &level); }; } diff --git a/gui/overlay_ui.cpp b/gui/overlay_ui.cpp index dd46157..8859c1a 100644 --- a/gui/overlay_ui.cpp +++ b/gui/overlay_ui.cpp @@ -3,6 +3,7 @@ #include "constants.hpp" #include "events.hpp" #include +#include "game_level.hpp" namespace gui { using namespace guecs; @@ -17,21 +18,23 @@ namespace gui { $gui.init(); } - inline void make_clickable_area(GameLevel& level, guecs::UI &gui, const std::string &name) { + inline void make_clickable_area(std::shared_ptr world, guecs::UI &gui, const std::string &name) { auto area = gui.entity(name); gui.set(area, { [&](auto) { - level.world->send(Events::GUI::AIM_CLICK, area, {}); + world->send(Events::GUI::AIM_CLICK, area, {}); } }); } void OverlayUI::init() { + auto world = Game::current_world(); + // gui.init is in the constructor - make_clickable_area($level, $gui, "top"); - make_clickable_area($level, $gui, "middle"); - make_clickable_area($level, $gui, "bottom"); + make_clickable_area(world, $gui, "top"); + make_clickable_area(world, $gui, "middle"); + make_clickable_area(world, $gui, "bottom"); } void OverlayUI::render(sf::RenderWindow& window) { @@ -55,8 +58,7 @@ namespace gui { $gui.close(region); } - void OverlayUI::update_level(GameLevel level) { - $level = level; + void OverlayUI::update_level() { init(); } } diff --git a/gui/overlay_ui.hpp b/gui/overlay_ui.hpp index 62f23eb..4cbf21f 100644 --- a/gui/overlay_ui.hpp +++ b/gui/overlay_ui.hpp @@ -2,7 +2,6 @@ #include #include #include -#include "levelmanager.hpp" namespace gui { using std::string; @@ -10,12 +9,11 @@ namespace gui { class OverlayUI { public: guecs::UI $gui; - GameLevel $level; OverlayUI(); void init(); - void update_level(GameLevel level); + void update_level(); void render(sf::RenderWindow& window); void show_sprite(string region, string sprite_name); diff --git a/gui/ritual_ui.cpp b/gui/ritual_ui.cpp index cd731fc..ae8d389 100644 --- a/gui/ritual_ui.cpp +++ b/gui/ritual_ui.cpp @@ -6,15 +6,14 @@ #include "rand.hpp" #include "sound.hpp" #include "events.hpp" +#include "game_level.hpp" namespace gui { namespace ritual { using namespace guecs; using std::any, std::any_cast, std::string, std::make_any; - UI::UI(GameLevel level) : - $level(level) - { + UI::UI() { $gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT); $gui.layout( "[_]" @@ -186,11 +185,14 @@ namespace gui { } void UI::complete_combine() { + auto world = Game::current_world(); + auto player = Game::the_player(); + if($craft_state.is_combined()) { auto ritual = $ritual_engine.finalize($craft_state); - auto& belt = $level.world->get_the<::ritual::Belt>(); + auto& belt = world->get_the<::ritual::Belt>(); belt.equip(belt.next(), ritual); - $level.world->send(Events::GUI::NEW_RITUAL, $level.player, {}); + world->send(Events::GUI::NEW_RITUAL, player, {}); blanket().consume_crafting(); clear_craft_result(); @@ -240,14 +242,15 @@ namespace gui { } } - void UI::update_level(GameLevel& level) { - $level = level; - } - void UI::clear_craft_result() { blanket().reset(); $gui.close("result_text"); $gui.close("result_image"); } + + ::ritual::Blanket& UI::blanket() { + auto world = Game::current_world(); + return world->get_the<::ritual::Blanket>(); + } } } diff --git a/gui/ritual_ui.hpp b/gui/ritual_ui.hpp index 7737ae2..60d2736 100644 --- a/gui/ritual_ui.hpp +++ b/gui/ritual_ui.hpp @@ -1,5 +1,4 @@ #pragma once -#include "levelmanager.hpp" #include "constants.hpp" #include #include "textures.hpp" @@ -37,12 +36,11 @@ namespace gui { sf::IntRect $ritual_open_rect{{380 * 2,0},{380,720}}; components::Animation $ritual_anim; guecs::UI $gui; - GameLevel $level; textures::SpriteTexture $ritual_ui; ::ritual::Engine $ritual_engine; ::ritual::CraftingState $craft_state; - UI(GameLevel level); + UI(); void event(Event ev, std::any data={}); void START(Event); @@ -63,11 +61,7 @@ namespace gui { void run_crafting_engine(); void complete_combine(); void update_selection_state(); - void update_level(GameLevel &level); - - ::ritual::Blanket& blanket() { - return $level.world->get_the<::ritual::Blanket>(); - } + ::ritual::Blanket& blanket(); }; } } diff --git a/gui/status_ui.cpp b/gui/status_ui.cpp index 8b989ab..55590f4 100644 --- a/gui/status_ui.cpp +++ b/gui/status_ui.cpp @@ -6,13 +6,14 @@ #include "gui/guecstra.hpp" #include "systems.hpp" #include "inventory.hpp" +#include "game_level.hpp" +#include "levelmanager.hpp" namespace gui { using namespace guecs; using std::any, std::any_cast, std::string, std::make_any; - StatusUI::StatusUI(GameLevel level) : - $level(level), $ritual_ui(level) + StatusUI::StatusUI() { $gui.position(STATUS_UI_X, STATUS_UI_Y, STATUS_UI_WIDTH, STATUS_UI_HEIGHT); $gui.layout( @@ -45,7 +46,7 @@ namespace gui { } else { $gui.set(gui_id, {guecs::to_wstring(name)}); $gui.set(gui_id, { - guecs::make_action($level, gui_id, Events::GUI::INV_SELECT, {gui_id}) + guecs::make_action(gui_id, Events::GUI::INV_SELECT, {gui_id}) }); $gui.set(gui_id, { .commit=[&, gui_id](DinkyECS::Entity world_target) -> bool { @@ -74,8 +75,9 @@ namespace gui { } void StatusUI::update() { - auto player = $level.world->get_the(); - auto& inventory = $level.world->get(player.entity); + auto world = Game::current_world(); + auto player = world->get_the(); + auto& inventory = world->get(player.entity); for(const auto& [slot, cell] : $gui.cells()) { @@ -83,7 +85,7 @@ namespace gui { auto gui_id = $gui.entity(slot); auto world_entity = inventory.get(slot); - auto& sprite = $level.world->get(world_entity); + auto& sprite = world->get(world_entity); $gui.set_init(gui_id, {sprite.name}); guecs::GrabSource grabber{ world_entity, [&, gui_id]() { return remove_slot(gui_id); }}; @@ -106,18 +108,17 @@ namespace gui { $ritual_ui.render(window); } - void StatusUI::update_level(GameLevel &level) { - $level = level; + void StatusUI::update_level() { init(); - $ritual_ui.update_level(level); } bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) { + auto& level = Game::current(); auto& slot_name = $gui.name_for(gui_id); - auto& inventory = $level.world->get($level.player); + auto& inventory = level.world->get(level.player); if(inventory.add(slot_name, world_entity)) { - $level.world->make_constant(world_entity); + level.world->make_constant(world_entity); update(); return true; } else { @@ -133,23 +134,25 @@ namespace gui { // NOTE: do I need this or how does it relate to drop_item? void StatusUI::remove_slot(guecs::Entity slot_id) { + auto player = Game::the_player(); auto& slot_name = $gui.name_for(slot_id); - System::remove_from_container(*$level.world, $level.player, slot_name); + System::remove_from_container(player, slot_name); update(); } void StatusUI::swap(guecs::Entity gui_a, guecs::Entity gui_b) { if(gui_a != gui_b) { + auto player = Game::the_player(); auto& a_name = $gui.name_for(gui_a); auto& b_name = $gui.name_for(gui_b); - System::inventory_swap($level.player, a_name, b_name); + System::inventory_swap(player, a_name, b_name); } update(); } bool StatusUI::occupied(guecs::Entity slot) { - auto player = $level.world->get_the(); - return System::inventory_occupied(player.entity, $gui.name_for(slot)); + auto player = Game::the_player(); + return System::inventory_occupied(player, $gui.name_for(slot)); } } diff --git a/gui/status_ui.hpp b/gui/status_ui.hpp index 61396ce..221aa8a 100644 --- a/gui/status_ui.hpp +++ b/gui/status_ui.hpp @@ -1,5 +1,4 @@ #pragma once -#include "levelmanager.hpp" #include "constants.hpp" #include #include "textures.hpp" @@ -11,17 +10,16 @@ namespace gui { class StatusUI { public: guecs::UI $gui; - GameLevel $level; ritual::UI $ritual_ui; - explicit StatusUI(GameLevel level); + explicit StatusUI(); StatusUI(const StatusUI& other) = delete; StatusUI(StatusUI&& other) = delete; ~StatusUI() = default; void select_ritual(); - void update_level(GameLevel &level); + void update_level(); void init(); void render(sf::RenderWindow &window); void update(); diff --git a/systems.cpp b/systems.cpp index a0210f4..86b3780 100644 --- a/systems.cpp +++ b/systems.cpp @@ -470,8 +470,9 @@ void System::drop_item(Entity item) { } // NOTE: I think pickup and this need to be different -bool System::place_in_container(World& world, Entity cont_id, const std::string& name, Entity world_entity) { - auto& container = world.get(cont_id); +bool System::place_in_container(Entity cont_id, const std::string& name, Entity world_entity) { + auto world = Game::current_world(); + auto& container = world->get(cont_id); if(container.has(world_entity)) { fmt::println("container {} already has entity {}, skip", cont_id, world_entity); @@ -489,8 +490,9 @@ bool System::place_in_container(World& world, Entity cont_id, const std::string& } } -void System::remove_from_container(World& world, Entity cont_id, const std::string& slot_id) { - auto& container = world.get(cont_id); +void System::remove_from_container(Entity cont_id, const std::string& slot_id) { + auto world = Game::current_world(); + auto& container = world->get(cont_id); auto entity = container.get(slot_id); container.remove(entity); } diff --git a/systems.hpp b/systems.hpp index e74d21a..9995a5f 100644 --- a/systems.hpp +++ b/systems.hpp @@ -31,9 +31,9 @@ namespace System { void pickup(); - bool place_in_container(World& world, Entity cont_id, const string& name, Entity world_entity); + bool place_in_container(Entity cont_id, const string& name, Entity world_entity); - void remove_from_container(World& world, Entity cont_id, const std::string& name); + void remove_from_container(Entity cont_id, const std::string& name); void remove_from_world(Entity entity); void inventory_swap(Entity container_id, const std::string& a_name, const std::string &b_name); bool inventory_occupied(Entity container_id, const std::string& name); diff --git a/tests/map.cpp b/tests/map.cpp index 8543784..21370b1 100644 --- a/tests/map.cpp +++ b/tests/map.cpp @@ -4,7 +4,8 @@ #include #include "map.hpp" #include "levelmanager.hpp" -#include "systems.hpp" +#include "game_level.hpp" +#include "systems.hpp." using namespace fmt; using namespace nlohmann; @@ -84,9 +85,9 @@ TEST_CASE("dijkstra algo test", "[map]") { TEST_CASE("map image test", "[map]") { components::init(); textures::init(); + Game::init(); - LevelManager levels; - GameLevel level = levels.current(); + GameLevel level = Game::current(); Matrix map_tiles = matrix::make(7,7); EntityGrid entity_map; diff --git a/tests/sound.cpp b/tests/sound.cpp index 6f96650..968e650 100644 --- a/tests/sound.cpp +++ b/tests/sound.cpp @@ -2,7 +2,6 @@ #include #include #include "sound.hpp" -#include "levelmanager.hpp" using namespace fmt;