Ritual blanket now has its own internal id but I'm sort of thinking it needs to be more like inventory::Model. Closes #47.
This commit is contained in:
parent
cad51f4908
commit
b28b76ee2d
5 changed files with 22 additions and 23 deletions
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
namespace DinkyECS
|
namespace DinkyECS
|
||||||
{
|
{
|
||||||
typedef unsigned long Entity;
|
using Entity = unsigned long;
|
||||||
|
|
||||||
using EntityMap = std::unordered_map<Entity, size_t>;
|
using EntityMap = std::unordered_map<Entity, size_t>;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace gui {
|
||||||
|
|
||||||
struct SelectedItem {
|
struct SelectedItem {
|
||||||
guecs::Entity slot_id;
|
guecs::Entity slot_id;
|
||||||
DinkyECS::Entity item_id;
|
::ritual::Entity item_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UI : public DeadSimpleFSM<State, Event> {
|
class UI : public DeadSimpleFSM<State, Event> {
|
||||||
|
|
16
rituals.cpp
16
rituals.cpp
|
@ -151,35 +151,35 @@ namespace ritual {
|
||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
DinkyECS::Entity Blanket::add(JunkItem name) {
|
Entity Blanket::add(JunkItem name) {
|
||||||
DinkyECS::Entity id = ++entity_counter;
|
Entity id = ++entity_counter;
|
||||||
|
|
||||||
contents.insert_or_assign(id, name);
|
contents.insert_or_assign(id, name);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string& Blanket::get(DinkyECS::Entity ent) {
|
std::string& Blanket::get(Entity ent) {
|
||||||
return contents.at(ent);
|
return contents.at(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Blanket::has(DinkyECS::Entity ent) {
|
bool Blanket::has(Entity ent) {
|
||||||
return contents.contains(ent);
|
return contents.contains(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blanket::remove(DinkyECS::Entity ent) {
|
void Blanket::remove(Entity ent) {
|
||||||
contents.erase(ent);
|
contents.erase(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blanket::select(DinkyECS::Entity ent) {
|
void Blanket::select(Entity ent) {
|
||||||
selected.insert_or_assign(ent, true);
|
selected.insert_or_assign(ent, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Blanket::deselect(DinkyECS::Entity ent) {
|
void Blanket::deselect(Entity ent) {
|
||||||
selected.erase(ent);
|
selected.erase(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Blanket::is_selected(DinkyECS::Entity ent) {
|
bool Blanket::is_selected(Entity ent) {
|
||||||
return selected.contains(ent) && selected.at(ent);
|
return selected.contains(ent) && selected.at(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
rituals.hpp
20
rituals.hpp
|
@ -2,10 +2,10 @@
|
||||||
#include "goap.hpp"
|
#include "goap.hpp"
|
||||||
#include "ai.hpp"
|
#include "ai.hpp"
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
#include "dinkyecs.hpp"
|
|
||||||
|
|
||||||
namespace ritual {
|
namespace ritual {
|
||||||
using JunkItem = std::string;
|
using JunkItem = std::string;
|
||||||
|
using Entity = unsigned long;
|
||||||
|
|
||||||
struct JunkPile {
|
struct JunkPile {
|
||||||
std::vector<JunkItem> contents;
|
std::vector<JunkItem> contents;
|
||||||
|
@ -82,17 +82,17 @@ namespace ritual {
|
||||||
|
|
||||||
struct Blanket {
|
struct Blanket {
|
||||||
size_t entity_counter = 0;
|
size_t entity_counter = 0;
|
||||||
std::unordered_map<DinkyECS::Entity, JunkItem> contents;
|
std::unordered_map<Entity, JunkItem> contents;
|
||||||
std::unordered_map<DinkyECS::Entity, bool> selected;
|
std::unordered_map<Entity, bool> selected;
|
||||||
|
|
||||||
DinkyECS::Entity add(JunkItem name);
|
Entity add(JunkItem name);
|
||||||
JunkItem& get(DinkyECS::Entity ent);
|
JunkItem& get(Entity ent);
|
||||||
bool has(DinkyECS::Entity ent);
|
bool has(Entity ent);
|
||||||
void remove(DinkyECS::Entity ent);
|
void remove(Entity ent);
|
||||||
void select(DinkyECS::Entity ent);
|
void select(Entity ent);
|
||||||
void deselect(DinkyECS::Entity ent);
|
void deselect(Entity ent);
|
||||||
void reset();
|
void reset();
|
||||||
bool is_selected(DinkyECS::Entity ent);
|
bool is_selected(Entity ent);
|
||||||
bool no_selections();
|
bool no_selections();
|
||||||
void consume_crafting();
|
void consume_crafting();
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "rituals.hpp"
|
#include "rituals.hpp"
|
||||||
#include "simplefsm.hpp"
|
#include "simplefsm.hpp"
|
||||||
#include "dinkyecs.hpp"
|
|
||||||
#include "levelmanager.hpp"
|
#include "levelmanager.hpp"
|
||||||
#include "ai_debug.hpp"
|
#include "ai_debug.hpp"
|
||||||
|
|
||||||
|
@ -107,8 +106,8 @@ TEST_CASE("the ritual belt works", "[rituals]") {
|
||||||
TEST_CASE("ritual blanket basic operations", "[rituals-blanket]") {
|
TEST_CASE("ritual blanket basic operations", "[rituals-blanket]") {
|
||||||
ritual::Blanket blanket;
|
ritual::Blanket blanket;
|
||||||
|
|
||||||
DinkyECS::Entity other = blanket.add("rusty_nails");
|
ritual::Entity other = blanket.add("rusty_nails");
|
||||||
DinkyECS::Entity ent = blanket.add("severed_finger");
|
ritual::Entity ent = blanket.add("severed_finger");
|
||||||
auto& name = blanket.get(ent);
|
auto& name = blanket.get(ent);
|
||||||
REQUIRE(name == "severed_finger");
|
REQUIRE(name == "severed_finger");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue