Skip to content

Commit

Permalink
Add aux data field for event-hooked enchantments
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Shih committed Apr 17, 2017
1 parent 13e1202 commit b1e2108
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions include/FlowControl/enchantment/Enchantments.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ namespace FlowControl
using IdentifierType = Utils::CloneableContainers::RemovableVectorIdentifier;

typedef void(*ApplyFunctor)(state::Cards::EnchantableStates &);
typedef void(*RegisterEventFunctor)(FlowControl::Manipulate &, state::CardRef, IdentifierType);

struct AuraEnchantment {
ApplyFunctor apply_functor;
Expand All @@ -38,11 +37,17 @@ namespace FlowControl
};
struct EventHookedEnchantment {
bool Apply(state::State const& state, state::Cards::EnchantableStates & stats) const { apply_functor(stats); return true; }
void RegisterEvent(FlowControl::Manipulate & manipulate, state::CardRef card_ref, IdentifierType id) const {
register_functor(manipulate, card_ref, id);
}

ApplyFunctor apply_functor;

struct AuxData {
AuxData() : valid(false) {}
bool valid;
} aux_data;

typedef void(*RegisterEventFunctor)(FlowControl::Manipulate &, state::CardRef, IdentifierType, AuxData &);
void RegisterEvent(FlowControl::Manipulate & manipulate, state::CardRef card_ref, IdentifierType id, AuxData & aux_data) const {
register_functor(manipulate, card_ref, id, aux_data);
}
RegisterEventFunctor register_functor;
};
using EnchantmentType = std::variant<NormalEnchantment, AuraEnchantment, EventHookedEnchantment>;
Expand Down Expand Up @@ -87,7 +92,8 @@ namespace FlowControl
assert(item.apply_functor);
assert(item.register_functor);
IdentifierType id = enchantments_.PushBack(EventHookedEnchantment{ item.apply_functor, item.register_functor });
item.register_functor(manipulate, card_ref, id);
item.register_functor(manipulate, card_ref, id,
std::get<EventHookedEnchantment>(enchantments_.Get(id)).aux_data);
}

void Remove(IdentifierType id)
Expand All @@ -111,15 +117,15 @@ namespace FlowControl
: manipulate_(manipulate), card_ref_(card_ref), enchantments_(enchantments), id_(id)
{}

void operator()(NormalEnchantment const& arg) {
void operator()(NormalEnchantment & arg) {
// do nothing
}
void operator()(AuraEnchantment const& arg) {
void operator()(AuraEnchantment & arg) {
// All aura enchantments are removed
enchantments_.Remove(id_);
}
void operator()(EventHookedEnchantment const& arg) {
arg.RegisterEvent(manipulate_, card_ref_, id_);
void operator()(EventHookedEnchantment & arg) {
arg.RegisterEvent(manipulate_, card_ref_, id_, arg.aux_data);
}

FlowControl::Manipulate & manipulate_;
Expand Down

0 comments on commit b1e2108

Please sign in to comment.