feat: added activation state and interrupt event to utility lock
This commit is contained in:
parent
44476103c2
commit
7f6be4c48e
|
@ -7,6 +7,7 @@ void UtilityLock::_bind_methods() {
|
||||||
GDPROPERTY_HINTED(allowed_items, gd::Variant::ARRAY, gd::PROPERTY_HINT_ARRAY_TYPE, ItemDB::get_array_hint());
|
GDPROPERTY_HINTED(allowed_items, gd::Variant::ARRAY, gd::PROPERTY_HINT_ARRAY_TYPE, ItemDB::get_array_hint());
|
||||||
GDSIGNAL("begin_activate", gd::PropertyInfo(gd::Variant::INT, "with_item"), gd::PropertyInfo(gd::Variant::OBJECT, "by_unit", gd::PROPERTY_HINT_NODE_TYPE, "Unit"));
|
GDSIGNAL("begin_activate", gd::PropertyInfo(gd::Variant::INT, "with_item"), gd::PropertyInfo(gd::Variant::OBJECT, "by_unit", gd::PROPERTY_HINT_NODE_TYPE, "Unit"));
|
||||||
GDSIGNAL("finish_activate", gd::PropertyInfo(gd::Variant::INT, "with_item"), gd::PropertyInfo(gd::Variant::OBJECT, "by_unit", gd::PROPERTY_HINT_NODE_TYPE, "Unit"));
|
GDSIGNAL("finish_activate", gd::PropertyInfo(gd::Variant::INT, "with_item"), gd::PropertyInfo(gd::Variant::OBJECT, "by_unit", gd::PROPERTY_HINT_NODE_TYPE, "Unit"));
|
||||||
|
GDSIGNAL("interrupt_activate");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UtilityLock::can_use(Item const *with, Unit *by) const {
|
bool UtilityLock::can_use(Item const *with, Unit *by) const {
|
||||||
|
@ -15,22 +16,35 @@ bool UtilityLock::can_use(Item const *with, Unit *by) const {
|
||||||
|
|
||||||
bool UtilityLock::begin_activate(Item const *with, Unit *by) {
|
bool UtilityLock::begin_activate(Item const *with, Unit *by) {
|
||||||
if(this->can_use(with, by)) {
|
if(this->can_use(with, by)) {
|
||||||
|
this->activation_state = ActivationState::InProgress;
|
||||||
this->user = by;
|
this->user = by;
|
||||||
this->emit_signal("begin_activate", with->get_id(), by);
|
|
||||||
this->_begin_activate(with, by);
|
this->_begin_activate(with, by);
|
||||||
|
this->emit_signal("begin_activate", with->get_id(), by);
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
} else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UtilityLock::finish_activate(Item const *with, Unit *by) {
|
bool UtilityLock::finish_activate(Item const *with, Unit *by) {
|
||||||
if(this->user != nullptr && this->user == by) {
|
if(this->user != nullptr && this->user == by) {
|
||||||
|
this->activation_state = ActivationState::Done;
|
||||||
this->user = nullptr;
|
this->user = nullptr;
|
||||||
this->emit_signal("finish_activate", with->get_id(), by);
|
|
||||||
this->_finish_activate(with, by);
|
this->_finish_activate(with, by);
|
||||||
|
this->emit_signal("finish_activate", with->get_id(), by);
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
} else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UtilityLock::interrupt_activate() {
|
||||||
|
this->activation_state = ActivationState::Inactive;
|
||||||
|
this->user = nullptr;
|
||||||
|
this->_interrupt_activate();
|
||||||
|
this->emit_signal("interrupt_activate");
|
||||||
|
}
|
||||||
|
|
||||||
|
UtilityLock::ActivationState UtilityLock::get_activation_state() const {
|
||||||
|
return this->activation_state;
|
||||||
|
}
|
||||||
|
|
||||||
void UtilityLock::set_allowed_items(gd::Array array) {
|
void UtilityLock::set_allowed_items(gd::Array array) {
|
||||||
this->allowed_items.clear();
|
this->allowed_items.clear();
|
||||||
for(int i{0}; i < array.size(); ++i) {
|
for(int i{0}; i < array.size(); ++i) {
|
||||||
|
|
|
@ -12,17 +12,27 @@ class UtilityLock : public GoalMarker {
|
||||||
GDCLASS(UtilityLock, GoalMarker)
|
GDCLASS(UtilityLock, GoalMarker)
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
|
enum ActivationState {
|
||||||
|
Inactive,
|
||||||
|
InProgress,
|
||||||
|
Done
|
||||||
|
};
|
||||||
bool can_use(Item const *with, Unit *by) const;
|
bool can_use(Item const *with, Unit *by) const;
|
||||||
bool begin_activate(Item const *with, Unit *by);
|
bool begin_activate(Item const *with, Unit *by);
|
||||||
bool finish_activate(Item const *with, Unit *by);
|
bool finish_activate(Item const *with, Unit *by);
|
||||||
|
void interrupt_activate();
|
||||||
virtual void _begin_activate(Item const *with, Unit *by) {}
|
virtual void _begin_activate(Item const *with, Unit *by) {}
|
||||||
virtual void _finish_activate(Item const *with, Unit *by) {}
|
virtual void _finish_activate(Item const *with, Unit *by) {}
|
||||||
|
virtual void _interrupt_activate() {}
|
||||||
|
|
||||||
|
ActivationState get_activation_state() const;
|
||||||
|
|
||||||
void set_allowed_items(gd::Array array);
|
void set_allowed_items(gd::Array array);
|
||||||
gd::Array get_allowed_items() const;
|
gd::Array get_allowed_items() const;
|
||||||
private:
|
private:
|
||||||
gd::HashSet<Item const *> allowed_items{};
|
gd::HashSet<Item const *> allowed_items{};
|
||||||
Unit *user{nullptr};
|
Unit *user{nullptr};
|
||||||
|
ActivationState activation_state{ActivationState::Inactive};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !UTILITY_LOCK_HPP
|
#endif // !UTILITY_LOCK_HPP
|
||||||
|
|
Loading…
Reference in a new issue