8std::vector<std::string> TagStore::values(
const ValueSet* set) {
9 return set ? std::vector<std::string>(set->begin(), set->end()) :
std::vector<
std::
string>{};
12bool TagStore::requireAll(
const ValueSet* held,
const std::vector<std::string>& requested) {
13 return std::all_of(requested.begin(), requested.end(),
14 [held](
const auto&
value) { return held && held->contains(value); });
17bool TagStore::requireAny(
const ValueSet* held,
const std::vector<std::string>& requested) {
19 std::any_of(requested.begin(), requested.end(), [held](
const auto&
value) { return held->contains(value); });
23 events_.push_back({nextSequence_++, std::move(
action), std::move(
subject), std::move(
value)});
26bool TagStore::mutate(std::map<SubjectId, ValueSet>& valuesBySubject, Index* reverse,
const SubjectId&
subject,
27 const std::string&
value,
bool add,
const char* addedAction,
const char* removedAction) {
37 if (
found == valuesBySubject.end() ||
found->second.erase(
value) == 0)
return false;
38 if (
found->second.empty()) valuesBySubject.erase(
found);
40 auto indexed = reverse->find(
value);
41 if (indexed != reverse->end()) {
43 if (indexed->second.empty()) reverse->erase(indexed);
51 return mutate(tags_, &subjectsByTag_,
subject,
tag,
true,
"tag_added",
"tag_removed");
54 return mutate(tags_, &subjectsByTag_,
subject,
tag,
false,
"tag_added",
"tag_removed");
62 return found != tags_.end() && std::any_of(
found->second.begin(),
found->second.end(), [&](
const auto& held) {
63 return gameplayTagMatches(held, tag, match);
70std::vector<SubjectId> TagStore::subjectsWithTag(
const std::string&
tag)
const {
71 const auto found = subjectsByTag_.find(
tag);
72 return found == subjectsByTag_.end() ? std::vector<SubjectId>{}
73 : std::vector<SubjectId>(
found->second.begin(),
found->second.end());
75std::vector<SubjectId> TagStore::subjectsWithTagMatching(
const std::string&
tag,
GameplayTagMatch match)
const {
76 if (match == GameplayTagMatch::Exact)
return subjectsWithTag(
tag);
77 std::set<SubjectId> matches;
78 for (
const auto& [held, subjects] : subjectsByTag_)
80 return {matches.begin(), matches.end()};
82bool TagStore::requireAllTags(
const SubjectId&
subject,
const std::vector<std::string>& requested)
const {
84 return requireAll(
found == tags_.end() ?
nullptr : &
found->second, requested);
86bool TagStore::requireAnyTag(
const SubjectId&
subject,
const std::vector<std::string>& requested)
const {
88 return requireAny(
found == tags_.end() ?
nullptr : &
found->second, requested);
90bool TagStore::matchesAllTags(
const SubjectId&
subject,
const std::vector<std::string>& requested,
92 return std::all_of(requested.begin(), requested.end(),
93 [&](
const auto& query) { return hasTagMatching(subject, query, match); });
95bool TagStore::matchesAnyTag(
const SubjectId&
subject,
const std::vector<std::string>& requested,
97 return std::any_of(requested.begin(), requested.end(),
98 [&](
const auto& query) { return hasTagMatching(subject, query, match); });
102 return mutate(capabilities_,
nullptr,
subject, capability,
true,
"capability_added",
"capability_removed");
105 return mutate(capabilities_,
nullptr,
subject, capability,
false,
"capability_added",
"capability_removed");
107bool TagStore::hasCapability(
const SubjectId&
subject,
const std::string& capability)
const {
109 return found != capabilities_.end() &&
found->second.contains(capability);
115bool TagStore::requireAllCapabilities(
const SubjectId&
subject,
const std::vector<std::string>& requested)
const {
117 return requireAll(
found == capabilities_.end() ?
nullptr : &
found->second, requested);
119bool TagStore::requireAnyCapability(
const SubjectId&
subject,
const std::vector<std::string>& requested)
const {
121 return requireAny(
found == capabilities_.end() ?
nullptr : &
found->second, requested);
125 const auto tags = tagsOf(
subject);
126 const auto capabilities = capabilitiesOf(
subject);
128 for (
const auto& capability : capabilities) removeCapability(
subject, capability);
129 if (tags.empty() && capabilities.empty())
return false;
130 emit(
"subject_removed",
subject, {});
134void TagStore::clear() {
136 capabilities_.clear();
137 subjectsByTag_.clear();
std::map< std::string, Var > values