diff --git a/assets/devices.json b/assets/devices.json index 9108d00..89e02eb 100644 --- a/assets/devices.json +++ b/assets/devices.json @@ -12,8 +12,8 @@ "background": [24, 205, 189] }, {"_type": "Device", - "config": {"test": true}, - "events": ["Events::GUI::STAIRS_DOWN"]}, + "config": {}, + "events": ["STAIRS_DOWN"]}, {"_type": "Sprite", "name": "well_down", "width": 256, "height": 256, "scale": 1.0} ] }, @@ -29,8 +29,8 @@ "background": [24, 205, 189] }, {"_type": "Device", - "config": {"test": true}, - "events": ["Events::GUI::STAIRS_UP"]}, + "config": {}, + "events": ["STAIRS_UP"]}, {"_type": "Sprite", "name": "rope_vines_up", "width": 256, "height": 256, "scale": 1.0} ] }, @@ -44,10 +44,38 @@ "foreground": [24, 205, 189], "background": [24, 205, 189] }, - {"_type": "Device", - "config": {"test": true}, - "events": ["Events::GUI::TRAP"]}, + {"_type": "Device", "config": {}, "events": ["TRAP"]}, {"_type": "Sprite", "name": "tripwire_trap", "width": 256, "height": 256, "scale": 1.0} ] + }, + "BARREL_SMALL": { + "id": "BARREL_SMALL", + "name": "Small Barrel", + "description": "A small rotten barrel that may hold things.", + "components": [ + {"_type": "Tile", "display": 85, + "foreground": [150, 100, 189], + "background": [150, 100, 189] + }, + {"_type": "Device", "config": {}, "events": ["LOOT_OPEN"]}, + {"_type": "Sprite", "name": "barrel_small", "width": 256, "height": 256, "scale": 1.0}, + {"_type": "Sound", "attack": "pickup", "death": "blank"} + ], + "inventory_count": 1 + }, + "GRAVE_STONE": { + "id": "GRAVE_STONE", + "name": "Grave Stone", + "description": "Something died here. Was this your doing?", + "inventory_count": 1, + "components": [ + {"_type": "Tile", "display": 8687, + "foreground": [32, 123, 164], + "background": [24, 205, 189] + }, + {"_type": "Device", "config": {}, "events": ["LOOT_OPEN"]}, + {"_type": "Sprite", "name": "grave_stone", "width": 256, "height": 256, "scale": 1.0}, + {"_type": "Sound", "attack": "pickup", "death": "blank"} + ] } } diff --git a/assets/items.json b/assets/items.json index ee75cd3..d523e57 100644 --- a/assets/items.json +++ b/assets/items.json @@ -14,20 +14,6 @@ {"_type": "Sound", "attack": "pickup", "death": "blank"} ] }, - "BARREL_SMALL": { - "id": "BARREL_SMALL", - "name": "Small Barrel", - "description": "A small rotten barrel that may hold things.", - "components": [ - {"_type": "Tile", "display": 85, - "foreground": [150, 100, 189], - "background": [150, 100, 189] - }, - {"_type": "Sprite", "name": "barrel_small", "width": 256, "height": 256, "scale": 1.0}, - {"_type": "Sound", "attack": "pickup", "death": "blank"} - ], - "inventory_count": 1 - }, "POTION_HEALING_SMALL": { "id": "POTION_HEALING_SMALL", "name": "Small Healing Potion", @@ -42,19 +28,5 @@ {"_type": "Sprite", "name": "healing_potion_small", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sound", "attack": "pickup", "death": "blank"} ] - }, - "GRAVE_STONE": { - "id": "GRAVE_STONE", - "name": "Grave Stone", - "description": "Something died here. Was this your doing?", - "inventory_count": 1, - "components": [ - {"_type": "Tile", "display": 8687, - "foreground": [32, 123, 164], - "background": [24, 205, 189] - }, - {"_type": "Sprite", "name": "grave_stone", "width": 256, "height": 256, "scale": 1.0}, - {"_type": "Sound", "attack": "pickup", "death": "blank"} - ] } } diff --git a/components.hpp b/components.hpp index c30ed93..dbb9862 100644 --- a/components.hpp +++ b/components.hpp @@ -95,8 +95,6 @@ namespace components { struct Device { json config; std::vector events; - - void configure_events(std::vector &event_names); }; struct Sprite { diff --git a/devices.cpp b/devices.cpp deleted file mode 100644 index a770632..0000000 --- a/devices.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include "components.hpp" -#include "events.hpp" -#include "dbc.hpp" - -namespace components { - /* - * Note: This should go away or at least the event names to - * numbers should probably be automatically created. - */ - void Device::configure_events(std::vector &event_names) { - (void)event_names; - /* - for(string name : event_names) { - if(name == "Events::GUI::STAIRS_DOWN") { - events.push_back(Events::GUI::STAIRS_DOWN); - } else if(name == "Events::GUI::STAIRS_UP") { - events.push_back(Events::GUI::STAIRS_UP); - } else if(name == "Events::GUI::TRAP") { - events.push_back(Events::GUI::TRAP); - } else { - dbc::sentinel(fmt::format("Unknown device event {}", name)); - } - } - */ - } -} diff --git a/gui/fsm.cpp b/gui/fsm.cpp index aaf868d..aa19955 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -296,25 +296,13 @@ namespace gui { sound::stop("ambient"); state(State::NEXT_LEVEL); break; - case LOOT_OPEN: { - Config items("assets/items.json"); - auto& data = items["TORCH_BAD"]; - - for(int i = 0; $loot_ui.contents.size() < 10; i++) { - auto gui_id = $loot_ui.$gui.entity("item_", i); - if(!$loot_ui.contents.contains(gui_id)) { - auto torch = $level.world->entity(); - components::configure_entity(*$level.world, torch, data["components"]); - $loot_ui.contents.try_emplace(gui_id, torch); - } - } - - $loot_ui.update(); + case LOOT_OPEN: $loot_ui.active = true; state(State::LOOTING); - } break; + break; case INV_SELECT: - state(State::INV_GRAB); + dbc::log("Dropping/grabbing items not yet supported."); + state(State::IDLE); break; case MOUSE_CLICK: mouse_action(false); @@ -580,8 +568,12 @@ namespace gui { event(Event::INV_SELECT, data); break; case eGUI::LOOT: { - $map_ui.log(L"You picked up an item."); - } break; + dbc::check(world.has(entity), "inventory doesn't have a sprite"); + auto gui_id = $loot_ui.$gui.entity("item_0"); + $loot_ui.contents.insert_or_assign(gui_id, entity); + $loot_ui.update(); + event(Event::LOOT_OPEN); + } break; case eGUI::HP_STATUS: System::player_status($level); break; diff --git a/meson.build b/meson.build index 183d88c..83503cf 100644 --- a/meson.build +++ b/meson.build @@ -91,7 +91,6 @@ sources = [ 'components.cpp', 'config.cpp', 'dbc.cpp', - 'devices.cpp', 'goap.cpp', 'gui/boss_fight_ui.cpp', 'gui/combat_ui.cpp', diff --git a/systems.cpp b/systems.cpp index 35ba130..54da3e7 100644 --- a/systems.cpp +++ b/systems.cpp @@ -206,7 +206,7 @@ void System::death(GameLevel &level) { sound::play(snd->death); } - auto entity_data = config.items["GRAVE_STONE"]; + auto entity_data = config.devices["GRAVE_STONE"]; components::configure_entity(world, ent, entity_data["components"]); if(entity_data["inventory_count"] > 0) { System::distribute_loot(world, ent, entity_data); @@ -306,40 +306,21 @@ void System::collision(GameLevel &level) { // call into that to work it, rather than this hard coded crap auto item = world.get(entity); auto& item_pos = world.get(entity); - dbc::log("REWRITE ME!"); - - if(world.has(entity)) { - // inventory.add(item); - world.remove(entity); - } if(world.has(entity)) { auto& pile = world.get(entity); auto& blanket = world.get_the(); for(auto& junk : pile.contents) { - fmt::println("adding {} to blanket", junk); blanket.add(junk); } } - if(world.has(entity)) { - // inventory.add(item); - world.remove(entity); - } - - if(world.has(entity)) { - // inventory.add(item); - world.remove(entity); - } - - if(auto snd = world.get_if(entity)) { - sound::play(snd->attack); - } - collider.remove(item_pos.location); world.remove(entity); - world.remove(entity); + + + fmt::println("LOOT EVENT, picking up {}", int(entity)); world.send(Events::GUI::LOOT, entity, item); } else if(world.has(entity)) { System::device(world, player.entity, entity); @@ -357,18 +338,23 @@ void System::collision(GameLevel &level) { void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) { auto& device = world.get(item); + dbc::log(fmt::format("entity {} INTERACTED WITH DEVICE {}", actor, item)); for(auto event : device.events) { - dbc::log(fmt::format("Device event received {}", event)); - - if(event == "Events::GUI::STAIRS_DOWN") { + if(event == "STAIRS_DOWN") { world.send(Events::GUI::STAIRS_DOWN, actor, device); + } else if(event == "STAIRS_UP") { + world.send(Events::GUI::STAIRS_UP, actor, device); + } else if(event == "TRAP") { + world.send(Events::GUI::TRAP, actor, device); + } else if(event == "LOOT_OPEN") { + world.send(Events::GUI::LOOT, actor, device); } else { - dbc::log(fmt::format("EVENT IGNORED {}", event)); + dbc::log(fmt::format( + "INVALID EVENT {} for device {}", + event, (std::string)device.config["name"])); } } - - dbc::log(fmt::format("entity {} INTERACTED WITH DEVICE {}", actor, item)); } void System::plan_motion(DinkyECS::World& world, Point move_to) { diff --git a/tests/mazes.cpp b/tests/mazes.cpp index a2c846e..2653bfb 100644 --- a/tests/mazes.cpp +++ b/tests/mazes.cpp @@ -14,7 +14,7 @@ TEST_CASE("hunt-and-kill", "[mazes]") { maze::Builder maze(map); maze.hunt_and_kill(); - maze.dump("BASIC MAZE"); + // maze.dump("BASIC MAZE"); maze.randomize_rooms(); maze.hunt_and_kill(); @@ -29,8 +29,6 @@ TEST_CASE("hunt-and-kill", "[mazes]") { maze.$walls[it.y][it.x] = WALL_PATH_LIMIT; } } - - maze.dump("MAZE WITH ROOMS"); } TEST_CASE("hunt-and-kill box", "[mazes]") { @@ -43,7 +41,7 @@ TEST_CASE("hunt-and-kill box", "[mazes]") { for(auto at : maze.$dead_ends) { maze.$walls[at.y][at.x]=32; } - maze.dump("INNER BOX"); + // maze.dump("INNER BOX"); REQUIRE(maze.$rooms.size() == 0); } @@ -58,7 +56,7 @@ TEST_CASE("hunt-and-kill ring", "[mazes]") { for(auto at : maze.$dead_ends) { maze.$walls[at.y][at.x]=32; } - maze.dump("INNER RING"); + // maze.dump("INNER RING"); REQUIRE(maze.$rooms.size() == 0); } @@ -73,7 +71,7 @@ TEST_CASE("hunt-and-kill fissure", "[mazes]") { for(auto at : maze.$dead_ends) { maze.$walls[at.y][at.x]=32; } - maze.dump("FISSURE MAZE"); + // maze.dump("FISSURE MAZE"); REQUIRE(maze.$rooms.size() == 0); } @@ -88,7 +86,7 @@ TEST_CASE("hunt-and-kill no-dead-ends", "[mazes]") { maze.remove_dead_ends(); - maze.dump("NO DEAD ENDS"); + // maze.dump("NO DEAD ENDS"); } TEST_CASE("hunt-and-kill too much", "[mazes]") { @@ -102,5 +100,5 @@ TEST_CASE("hunt-and-kill too much", "[mazes]") { maze.divide({3,3}, {19,18}); maze.hunt_and_kill(); - maze.dump("COMBINED"); + // maze.dump("COMBINED"); }