Now when you loot an item the loot UI works.
This commit is contained in:
parent
38159a5f84
commit
86eabed3db
8 changed files with 66 additions and 119 deletions
|
@ -12,8 +12,8 @@
|
||||||
"background": [24, 205, 189]
|
"background": [24, 205, 189]
|
||||||
},
|
},
|
||||||
{"_type": "Device",
|
{"_type": "Device",
|
||||||
"config": {"test": true},
|
"config": {},
|
||||||
"events": ["Events::GUI::STAIRS_DOWN"]},
|
"events": ["STAIRS_DOWN"]},
|
||||||
{"_type": "Sprite", "name": "well_down", "width": 256, "height": 256, "scale": 1.0}
|
{"_type": "Sprite", "name": "well_down", "width": 256, "height": 256, "scale": 1.0}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -29,8 +29,8 @@
|
||||||
"background": [24, 205, 189]
|
"background": [24, 205, 189]
|
||||||
},
|
},
|
||||||
{"_type": "Device",
|
{"_type": "Device",
|
||||||
"config": {"test": true},
|
"config": {},
|
||||||
"events": ["Events::GUI::STAIRS_UP"]},
|
"events": ["STAIRS_UP"]},
|
||||||
{"_type": "Sprite", "name": "rope_vines_up", "width": 256, "height": 256, "scale": 1.0}
|
{"_type": "Sprite", "name": "rope_vines_up", "width": 256, "height": 256, "scale": 1.0}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -44,10 +44,38 @@
|
||||||
"foreground": [24, 205, 189],
|
"foreground": [24, 205, 189],
|
||||||
"background": [24, 205, 189]
|
"background": [24, 205, 189]
|
||||||
},
|
},
|
||||||
{"_type": "Device",
|
{"_type": "Device", "config": {}, "events": ["TRAP"]},
|
||||||
"config": {"test": true},
|
|
||||||
"events": ["Events::GUI::TRAP"]},
|
|
||||||
{"_type": "Sprite", "name": "tripwire_trap", "width": 256, "height": 256, "scale": 1.0}
|
{"_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"}
|
{"_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": {
|
"POTION_HEALING_SMALL": {
|
||||||
"id": "POTION_HEALING_SMALL",
|
"id": "POTION_HEALING_SMALL",
|
||||||
"name": "Small Healing Potion",
|
"name": "Small Healing Potion",
|
||||||
|
@ -42,19 +28,5 @@
|
||||||
{"_type": "Sprite", "name": "healing_potion_small", "width": 256, "height": 256, "scale": 1.0},
|
{"_type": "Sprite", "name": "healing_potion_small", "width": 256, "height": 256, "scale": 1.0},
|
||||||
{"_type": "Sound", "attack": "pickup", "death": "blank"}
|
{"_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 {
|
struct Device {
|
||||||
json config;
|
json config;
|
||||||
std::vector<std::string> events;
|
std::vector<std::string> events;
|
||||||
|
|
||||||
void configure_events(std::vector<std::string> &event_names);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Sprite {
|
struct Sprite {
|
||||||
|
|
26
devices.cpp
26
devices.cpp
|
@ -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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
28
gui/fsm.cpp
28
gui/fsm.cpp
|
@ -296,25 +296,13 @@ namespace gui {
|
||||||
sound::stop("ambient");
|
sound::stop("ambient");
|
||||||
state(State::NEXT_LEVEL);
|
state(State::NEXT_LEVEL);
|
||||||
break;
|
break;
|
||||||
case LOOT_OPEN: {
|
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();
|
|
||||||
$loot_ui.active = true;
|
$loot_ui.active = true;
|
||||||
state(State::LOOTING);
|
state(State::LOOTING);
|
||||||
} break;
|
break;
|
||||||
case INV_SELECT:
|
case INV_SELECT:
|
||||||
state(State::INV_GRAB);
|
dbc::log("Dropping/grabbing items not yet supported.");
|
||||||
|
state(State::IDLE);
|
||||||
break;
|
break;
|
||||||
case MOUSE_CLICK:
|
case MOUSE_CLICK:
|
||||||
mouse_action(false);
|
mouse_action(false);
|
||||||
|
@ -580,8 +568,12 @@ namespace gui {
|
||||||
event(Event::INV_SELECT, data);
|
event(Event::INV_SELECT, data);
|
||||||
break;
|
break;
|
||||||
case eGUI::LOOT: {
|
case eGUI::LOOT: {
|
||||||
$map_ui.log(L"You picked up an item.");
|
dbc::check(world.has<components::Sprite>(entity), "inventory doesn't have a sprite");
|
||||||
} break;
|
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:
|
case eGUI::HP_STATUS:
|
||||||
System::player_status($level);
|
System::player_status($level);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -91,7 +91,6 @@ sources = [
|
||||||
'components.cpp',
|
'components.cpp',
|
||||||
'config.cpp',
|
'config.cpp',
|
||||||
'dbc.cpp',
|
'dbc.cpp',
|
||||||
'devices.cpp',
|
|
||||||
'goap.cpp',
|
'goap.cpp',
|
||||||
'gui/boss_fight_ui.cpp',
|
'gui/boss_fight_ui.cpp',
|
||||||
'gui/combat_ui.cpp',
|
'gui/combat_ui.cpp',
|
||||||
|
|
44
systems.cpp
44
systems.cpp
|
@ -206,7 +206,7 @@ void System::death(GameLevel &level) {
|
||||||
sound::play(snd->death);
|
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"]);
|
components::configure_entity(world, ent, entity_data["components"]);
|
||||||
if(entity_data["inventory_count"] > 0) {
|
if(entity_data["inventory_count"] > 0) {
|
||||||
System::distribute_loot(world, ent, entity_data);
|
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
|
// call into that to work it, rather than this hard coded crap
|
||||||
auto item = world.get<InventoryItem>(entity);
|
auto item = world.get<InventoryItem>(entity);
|
||||||
auto& item_pos = world.get<Position>(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)) {
|
if(world.has<ritual::JunkPile>(entity)) {
|
||||||
auto& pile = world.get<ritual::JunkPile>(entity);
|
auto& pile = world.get<ritual::JunkPile>(entity);
|
||||||
auto& blanket = world.get_the<ritual::Blanket>();
|
auto& blanket = world.get_the<ritual::Blanket>();
|
||||||
|
|
||||||
for(auto& junk : pile.contents) {
|
for(auto& junk : pile.contents) {
|
||||||
fmt::println("adding {} to blanket", junk);
|
|
||||||
blanket.add(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);
|
collider.remove(item_pos.location);
|
||||||
world.remove<Tile>(entity);
|
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);
|
world.send<Events::GUI>(Events::GUI::LOOT, entity, item);
|
||||||
} else if(world.has<Device>(entity)) {
|
} else if(world.has<Device>(entity)) {
|
||||||
System::device(world, player.entity, 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) {
|
void System::device(DinkyECS::World &world, DinkyECS::Entity actor, DinkyECS::Entity item) {
|
||||||
auto& device = world.get<Device>(item);
|
auto& device = world.get<Device>(item);
|
||||||
|
dbc::log(fmt::format("entity {} INTERACTED WITH DEVICE {}", actor, item));
|
||||||
|
|
||||||
for(auto event : device.events) {
|
for(auto event : device.events) {
|
||||||
dbc::log(fmt::format("Device event received {}", event));
|
if(event == "STAIRS_DOWN") {
|
||||||
|
|
||||||
if(event == "Events::GUI::STAIRS_DOWN") {
|
|
||||||
world.send<Events::GUI>(Events::GUI::STAIRS_DOWN, actor, device);
|
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 {
|
} 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) {
|
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::Builder maze(map);
|
||||||
|
|
||||||
maze.hunt_and_kill();
|
maze.hunt_and_kill();
|
||||||
maze.dump("BASIC MAZE");
|
// maze.dump("BASIC MAZE");
|
||||||
|
|
||||||
maze.randomize_rooms();
|
maze.randomize_rooms();
|
||||||
maze.hunt_and_kill();
|
maze.hunt_and_kill();
|
||||||
|
@ -29,8 +29,6 @@ TEST_CASE("hunt-and-kill", "[mazes]") {
|
||||||
maze.$walls[it.y][it.x] = WALL_PATH_LIMIT;
|
maze.$walls[it.y][it.x] = WALL_PATH_LIMIT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
maze.dump("MAZE WITH ROOMS");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("hunt-and-kill box", "[mazes]") {
|
TEST_CASE("hunt-and-kill box", "[mazes]") {
|
||||||
|
@ -43,7 +41,7 @@ TEST_CASE("hunt-and-kill box", "[mazes]") {
|
||||||
for(auto at : maze.$dead_ends) {
|
for(auto at : maze.$dead_ends) {
|
||||||
maze.$walls[at.y][at.x]=32;
|
maze.$walls[at.y][at.x]=32;
|
||||||
}
|
}
|
||||||
maze.dump("INNER BOX");
|
// maze.dump("INNER BOX");
|
||||||
|
|
||||||
REQUIRE(maze.$rooms.size() == 0);
|
REQUIRE(maze.$rooms.size() == 0);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +56,7 @@ TEST_CASE("hunt-and-kill ring", "[mazes]") {
|
||||||
for(auto at : maze.$dead_ends) {
|
for(auto at : maze.$dead_ends) {
|
||||||
maze.$walls[at.y][at.x]=32;
|
maze.$walls[at.y][at.x]=32;
|
||||||
}
|
}
|
||||||
maze.dump("INNER RING");
|
// maze.dump("INNER RING");
|
||||||
|
|
||||||
REQUIRE(maze.$rooms.size() == 0);
|
REQUIRE(maze.$rooms.size() == 0);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +71,7 @@ TEST_CASE("hunt-and-kill fissure", "[mazes]") {
|
||||||
for(auto at : maze.$dead_ends) {
|
for(auto at : maze.$dead_ends) {
|
||||||
maze.$walls[at.y][at.x]=32;
|
maze.$walls[at.y][at.x]=32;
|
||||||
}
|
}
|
||||||
maze.dump("FISSURE MAZE");
|
// maze.dump("FISSURE MAZE");
|
||||||
|
|
||||||
REQUIRE(maze.$rooms.size() == 0);
|
REQUIRE(maze.$rooms.size() == 0);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +86,7 @@ TEST_CASE("hunt-and-kill no-dead-ends", "[mazes]") {
|
||||||
|
|
||||||
maze.remove_dead_ends();
|
maze.remove_dead_ends();
|
||||||
|
|
||||||
maze.dump("NO DEAD ENDS");
|
// maze.dump("NO DEAD ENDS");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("hunt-and-kill too much", "[mazes]") {
|
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.divide({3,3}, {19,18});
|
||||||
maze.hunt_and_kill();
|
maze.hunt_and_kill();
|
||||||
|
|
||||||
maze.dump("COMBINED");
|
// maze.dump("COMBINED");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue