diff --git a/gui/dnd_loot.cpp b/gui/dnd_loot.cpp index 57d4055..f4ede8c 100644 --- a/gui/dnd_loot.cpp +++ b/gui/dnd_loot.cpp @@ -114,6 +114,8 @@ namespace gui { case MOUSE_DROP: { auto& grab = $status_ui.$gui.get(*$grab_source); grab.commit(); + bool dropped = $status_ui.drop_item(grab.world_entity); + dbc::check(dropped, "DROP FAILED!"); END(Event::CLOSE); } break; default: diff --git a/gui/fsm.cpp b/gui/fsm.cpp index 3d919df..28356e8 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -68,6 +68,8 @@ namespace gui { $mini_map.init($main_ui.$overlay_ui.$gui); run_systems(); + + this_crap_must_die(); state(State::IDLE); } @@ -430,7 +432,8 @@ namespace gui { event(Event::START_COMBAT); break; case eGUI::ENEMY_SPAWN: - $main_ui.update_level($level); + $main_ui.$rayview.update_level($level); + $main_ui.dirty(); run_systems(); break; case eGUI::NO_NEIGHBORS: @@ -514,4 +517,10 @@ namespace gui { run_systems(); } + + void FSM::this_crap_must_die() { + auto torch_id = System::spawn_item($level, "TORCH_BAD"); + auto hand_l = $status_ui.$gui.entity("hand_l"); + $status_ui.place_slot(hand_l, torch_id); + } } diff --git a/gui/fsm.hpp b/gui/fsm.hpp index 6000820..2ca27bb 100644 --- a/gui/fsm.hpp +++ b/gui/fsm.hpp @@ -79,5 +79,6 @@ namespace gui { void handle_world_events(); void next_level(); void debug_render(); + void this_crap_must_die(); }; } diff --git a/gui/status_ui.cpp b/gui/status_ui.cpp index 65fff82..1d82542 100644 --- a/gui/status_ui.cpp +++ b/gui/status_ui.cpp @@ -4,6 +4,7 @@ #include "rand.hpp" #include #include "gui/guecstra.hpp" +#include "systems.hpp" namespace gui { using namespace guecs; @@ -85,7 +86,7 @@ namespace gui { init(); } - bool StatusUI::place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity) { + bool StatusUI::place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity) { if($level.world->has(world_entity)) { auto& sprite = $level.world->get(world_entity); $gui.set_init(gui_id, {sprite.name}); @@ -101,7 +102,11 @@ namespace gui { } } - void StatusUI::remove_slot(DinkyECS::Entity slot_id) { + bool StatusUI::drop_item(DinkyECS::Entity item_id) { + return System::drop_item($level, item_id); + } + + void StatusUI::remove_slot(guecs::Entity slot_id) { if(contents.contains(slot_id)) { contents.erase(slot_id); $gui.remove(slot_id); diff --git a/gui/status_ui.hpp b/gui/status_ui.hpp index 4537966..a900ede 100644 --- a/gui/status_ui.hpp +++ b/gui/status_ui.hpp @@ -12,7 +12,7 @@ namespace gui { public: guecs::UI $gui; GameLevel $level; - std::unordered_map contents; + std::unordered_map contents; ritual::UI $ritual_ui; StatusUI(GameLevel level); @@ -23,7 +23,8 @@ namespace gui { void update(); bool mouse(float x, float y, bool hover); - void remove_slot(DinkyECS::Entity slot_id); - bool place_slot(DinkyECS::Entity gui_id, DinkyECS::Entity world_entity); + void remove_slot(guecs::Entity slot_id); + bool place_slot(guecs::Entity gui_id, DinkyECS::Entity world_entity); + bool drop_item(DinkyECS::Entity item_id); }; } diff --git a/systems.cpp b/systems.cpp index 6086525..d02be0e 100644 --- a/systems.cpp +++ b/systems.cpp @@ -460,3 +460,35 @@ std::shared_ptr System::sprite_effect(GameLevel &level, DinkyECS::En return nullptr; } } + +DinkyECS::Entity System::spawn_item(GameLevel& level, const std::string& name) { + Config config("assets/items.json"); + auto& item_config = config[name]; + auto item_id = level.world->entity(); + level.world->set(item_id, {1, item_config}); + components::configure_entity(*level.world, item_id, item_config["components"]); + + return item_id; +} + +bool System::drop_item(GameLevel& level, DinkyECS::Entity item) { + auto& world = *level.world; + auto& map = *level.map; + auto& collision = *level.collision; + + auto player = world.get_the(); + auto player_pos = 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();) { + Position pos{it.x, it.y}; + if(map.can_move(pos.location) && !collision.occupied(pos.location)) { + world.set(item, pos); + collision.insert(pos.location, item); + level.world->send(Events::GUI::ENEMY_SPAWN, item, {}); + return true; + } + } + + return false; +} diff --git a/systems.hpp b/systems.hpp index 12c33f3..d071175 100644 --- a/systems.hpp +++ b/systems.hpp @@ -18,6 +18,8 @@ namespace System { void device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item); void plan_motion(DinkyECS::World& world, Point move_to); std::wstring draw_map(GameLevel level, size_t view_x, size_t view_y, int compass_dir); + DinkyECS::Entity spawn_item(GameLevel& level, const std::string& name); + bool drop_item(GameLevel& level, DinkyECS::Entity item); void enemy_ai(GameLevel &level); void combat(GameLevel &level, int attack_id);