Now when you loot an item the loot UI works.

master
Zed A. Shaw 1 day ago
parent 38159a5f84
commit 86eabed3db
  1. 42
      assets/devices.json
  2. 28
      assets/items.json
  3. 2
      components.hpp
  4. 26
      devices.cpp
  5. 28
      gui/fsm.cpp
  6. 1
      meson.build
  7. 44
      systems.cpp
  8. 14
      tests/mazes.cpp

@ -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"}
]
}
}

@ -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"}
]
}
}

@ -95,8 +95,6 @@ namespace components {
struct Device {
json config;
std::vector<std::string> events;
void configure_events(std::vector<std::string> &event_names);
};
struct Sprite {

@ -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<std::string> &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));
}
}
*/
}
}

@ -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<components::Sprite>(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;

@ -91,7 +91,6 @@ sources = [
'components.cpp',
'config.cpp',
'dbc.cpp',
'devices.cpp',
'goap.cpp',
'gui/boss_fight_ui.cpp',
'gui/combat_ui.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<InventoryItem>(entity);
auto& item_pos = world.get<Position>(entity);
dbc::log("REWRITE ME!");
if(world.has<LightSource>(entity)) {
// inventory.add(item);
world.remove<LightSource>(entity);
}
if(world.has<ritual::JunkPile>(entity)) {
auto& pile = world.get<ritual::JunkPile>(entity);
auto& blanket = world.get_the<ritual::Blanket>();
for(auto& junk : pile.contents) {
fmt::println("adding {} to blanket", junk);
blanket.add(junk);
}
}
if(world.has<Weapon>(entity)) {
// inventory.add(item);
world.remove<Weapon>(entity);
}
if(world.has<Curative>(entity)) {
// inventory.add(item);
world.remove<Curative>(entity);
}
if(auto snd = world.get_if<Sound>(entity)) {
sound::play(snd->attack);
}
collider.remove(item_pos.location);
world.remove<Tile>(entity);
world.remove<InventoryItem>(entity);
fmt::println("LOOT EVENT, picking up {}", int(entity));
world.send<Events::GUI>(Events::GUI::LOOT, entity, item);
} else if(world.has<Device>(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<Device>(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>(Events::GUI::STAIRS_DOWN, actor, device);
} else if(event == "STAIRS_UP") {
world.send<Events::GUI>(Events::GUI::STAIRS_UP, actor, device);
} else if(event == "TRAP") {
world.send<Events::GUI>(Events::GUI::TRAP, actor, device);
} else if(event == "LOOT_OPEN") {
world.send<Events::GUI>(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) {

@ -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");
}

Loading…
Cancel
Save