#include "entity_skill.h" #include "../../database/ess_resource_db.h" #include "../../singletons/ess.h" Ref EntitySkill::get_skill() { return _skill; } void EntitySkill::set_skill(Ref value) { _skill = value; if (_skill.is_valid()) { _skill_id = _skill->get_id(); _skill_path = _skill->get_path(); } else { _skill_id = 0; _skill_path = ""; } emit_signal("skill_changed", Ref(this)); } int EntitySkill::get_skill_id() { return _skill_id; } void EntitySkill::set_skill_id(int value) { _skill_id = value; if (ESS::get_singleton() != NULL) { _skill = ESS::get_singleton()->get_resource_db()->get_entity_skill(_skill_id); } emit_signal("skill_changed", Ref(this)); } int EntitySkill::get_current() { return _current; } void EntitySkill::set_current(int value) { _current = value; emit_signal("current_changed", Ref(this)); } int EntitySkill::get_max() { return _max; } void EntitySkill::set_max(int value) { _max = value; emit_signal("max_changed", Ref(this)); } bool EntitySkill::get_disabled() { return _disabled; } void EntitySkill::set_disabled(bool value) { _disabled = value; emit_signal("skill_changed", Ref(this)); } Dictionary EntitySkill::to_dict() { return call("_to_dict"); } void EntitySkill::from_dict(const Dictionary &dict) { call("_from_dict", dict); } Dictionary EntitySkill::_to_dict() { Dictionary dict; dict["skill_id"] = _skill_id; dict["skill_path"] = _skill_path; dict["current"] = _current; dict["max"] = _max; dict["disabled"] = _disabled; return dict; } void EntitySkill::_from_dict(const Dictionary &dict) { ERR_FAIL_COND(dict.empty()); _skill_id = dict.get("skill_id", 0); _skill_path = dict.get("skill_path", ""); _current = dict.get("current", 0); _max = dict.get("max", 0); _disabled = dict.get("disabled", true); } EntitySkill::EntitySkill() { _skill_id = 0; _current = 0; _max = 0; _disabled = false; } EntitySkill::~EntitySkill() { _skill.unref(); } void EntitySkill::_bind_methods() { ADD_SIGNAL(MethodInfo("skill_changed", PropertyInfo(Variant::OBJECT, "skill", PROPERTY_HINT_RESOURCE_TYPE, "EntitySkill"))); ADD_SIGNAL(MethodInfo("current_changed", PropertyInfo(Variant::OBJECT, "skill", PROPERTY_HINT_RESOURCE_TYPE, "EntitySkill"))); ADD_SIGNAL(MethodInfo("max_changed", PropertyInfo(Variant::OBJECT, "skill", PROPERTY_HINT_RESOURCE_TYPE, "EntitySkill"))); ClassDB::bind_method(D_METHOD("get_skill"), &EntitySkill::get_skill); ClassDB::bind_method(D_METHOD("set_skill", "value"), &EntitySkill::set_skill); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skill", PROPERTY_HINT_RESOURCE_TYPE, "EntitySkillData"), "set_skill", "get_skill"); ClassDB::bind_method(D_METHOD("get_skill_id"), &EntitySkill::get_skill_id); ClassDB::bind_method(D_METHOD("set_skill_id", "value"), &EntitySkill::set_skill_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "skill_id"), "set_skill_id", "get_skill_id"); ClassDB::bind_method(D_METHOD("get_current"), &EntitySkill::get_current); ClassDB::bind_method(D_METHOD("set_current", "value"), &EntitySkill::set_current); ADD_PROPERTY(PropertyInfo(Variant::INT, "current"), "set_current", "get_current"); ClassDB::bind_method(D_METHOD("get_max"), &EntitySkill::get_max); ClassDB::bind_method(D_METHOD("set_max", "value"), &EntitySkill::set_max); ADD_PROPERTY(PropertyInfo(Variant::INT, "max"), "set_max", "get_max"); ClassDB::bind_method(D_METHOD("get_disabled"), &EntitySkill::get_disabled); ClassDB::bind_method(D_METHOD("set_disabled", "value"), &EntitySkill::set_disabled); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "get_disabled"); //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"), &EntitySkill::from_dict); ClassDB::bind_method(D_METHOD("to_dict"), &EntitySkill::to_dict); ClassDB::bind_method(D_METHOD("_from_dict", "dict"), &EntitySkill::_from_dict); ClassDB::bind_method(D_METHOD("_to_dict"), &EntitySkill::_to_dict); }