2019-05-06 18:07:07 +02:00
|
|
|
#include "category_cooldown.h"
|
|
|
|
|
2020-01-09 04:27:19 +01:00
|
|
|
int CategoryCooldown::get_category_id() const {
|
|
|
|
return _category_id;
|
2019-05-06 18:07:07 +02:00
|
|
|
}
|
|
|
|
|
2020-01-09 04:27:19 +01:00
|
|
|
void CategoryCooldown::set_category_id(const int value) {
|
|
|
|
_category_id = value;
|
2019-05-06 18:07:07 +02:00
|
|
|
}
|
|
|
|
|
2020-01-09 04:27:19 +01:00
|
|
|
float CategoryCooldown::get_remaining() const {
|
|
|
|
return _remaining;
|
2019-05-06 18:07:07 +02:00
|
|
|
}
|
|
|
|
|
2020-01-09 04:27:19 +01:00
|
|
|
void CategoryCooldown::set_remaining(const float value) {
|
|
|
|
_remaining = value;
|
2019-05-06 18:07:07 +02:00
|
|
|
}
|
|
|
|
|
2019-08-05 01:36:33 +02:00
|
|
|
bool CategoryCooldown::update(const float delta) {
|
2020-01-09 04:27:19 +01:00
|
|
|
_remaining -= delta;
|
|
|
|
|
|
|
|
if (_remaining <= 0) {
|
|
|
|
_remaining = 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2019-05-27 18:28:27 +02:00
|
|
|
}
|
|
|
|
|
2019-09-13 15:21:07 +02:00
|
|
|
Dictionary CategoryCooldown::to_dict() {
|
|
|
|
return call("_to_dict");
|
|
|
|
}
|
|
|
|
void CategoryCooldown::from_dict(const Dictionary &dict) {
|
|
|
|
call("_from_dict", dict);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary CategoryCooldown::_to_dict() {
|
|
|
|
Dictionary dict;
|
|
|
|
|
|
|
|
dict["category_id"] = _category_id;
|
|
|
|
dict["remaining"] = _remaining;
|
|
|
|
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
void CategoryCooldown::_from_dict(const Dictionary &dict) {
|
|
|
|
ERR_FAIL_COND(dict.empty());
|
2019-09-14 20:44:50 +02:00
|
|
|
|
|
|
|
_category_id = dict.get("category_id", 0);
|
|
|
|
_remaining = dict.get("remaining", 0);
|
2019-09-13 15:21:07 +02:00
|
|
|
}
|
|
|
|
|
2019-05-06 18:07:07 +02:00
|
|
|
void CategoryCooldown::_bind_methods() {
|
2020-01-09 04:27:19 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("get_category_id"), &CategoryCooldown::get_category_id);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_category_id", "value"), &CategoryCooldown::set_category_id);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "category_id"), "set_category_id", "get_category_id");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("get_remaining"), &CategoryCooldown::get_remaining);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_remaining", "value"), &CategoryCooldown::set_remaining);
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::REAL, "remaining"), "set_remaining", "get_remaining");
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("update", "delta"), &CategoryCooldown::update);
|
2019-09-13 15:21:07 +02:00
|
|
|
|
|
|
|
//Serialization
|
|
|
|
BIND_VMETHOD(MethodInfo("_from_dict", PropertyInfo(Variant::DICTIONARY, "dict")));
|
|
|
|
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::DICTIONARY, "dict"), "_to_dict"));
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("from_dict", "dict"), &CategoryCooldown::from_dict);
|
|
|
|
ClassDB::bind_method(D_METHOD("to_dict"), &CategoryCooldown::to_dict);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &CategoryCooldown::_from_dict);
|
|
|
|
ClassDB::bind_method(D_METHOD("_to_dict"), &CategoryCooldown::_to_dict);
|
2019-05-06 18:07:07 +02:00
|
|
|
}
|