Added the same api to Auras.

This commit is contained in:
Relintai 2020-02-26 16:57:17 +01:00
parent 58e62da501
commit a040f946fc
2 changed files with 88 additions and 0 deletions

View File

@ -80,6 +80,13 @@ void Aura::set_rank(const int value) {
_rank = value; _rank = value;
} }
String Aura::get_text_translation_key() const {
return _text_translation_key;
}
void Aura::set_text_translation_key(const String &value) {
_text_translation_key = value;
}
String Aura::get_text_description() const { String Aura::get_text_description() const {
return _text_description; return _text_description;
} }
@ -1030,6 +1037,69 @@ void Aura::handle_aura_heal(Ref<AuraData> aura_data, Ref<SpellHealInfo> data) {
call("_handle_aura_heal", aura_data, data); call("_handle_aura_heal", aura_data, data);
} }
String Aura::get_name_translated() const {
if (_text_translation_key != "") {
return tr(_text_translation_key);
}
return get_name();
}
String Aura::get_description(const int class_level, const int character_level) {
return call("_get_description", class_level, character_level);
}
String Aura::_get_description(const int class_level, const int character_level) {
String str;
if (_text_translation_key != "") {
str = tr(_text_translation_key + "_DESC");
}
str = _text_description;
int pos = str.find_char('%');
while (pos > 0) {
if (pos == str.size() - 1)
break;
CharType o = str[pos + 1];
if (o == '#' || o == '$' || o == '%') {
int nsp = str.find_char(' ', pos + 1);
if (pos < 0)
break;
String prop = str.substr(pos + 2, nsp - pos - 2);
StringName psm = prop;
bool valid = false;
Variant value = get(psm, &valid);
if (valid) {
if (o == '#') {
value = Variant::evaluate(Variant::OP_MULTIPLY, value, class_level / static_cast<float>(EntityEnums::MAX_CLASS_LEVEL));
value = static_cast<int>(value);
}
if (o == '$') {
value = Variant::evaluate(Variant::OP_MULTIPLY, value, character_level / static_cast<float>(EntityEnums::MAX_CHARACTER_LEVEL));
value = static_cast<int>(value);
}
str = str.replace(str.substr(pos, nsp - pos) + " ", value);
}
}
pos = str.find_char('%', pos + 1);
}
return str;
}
void Aura::_sapply(Ref<AuraApplyInfo> info) { void Aura::_sapply(Ref<AuraApplyInfo> info) {
ERR_FAIL_COND(info->get_target() == NULL || info->get_caster() == NULL || !info->get_aura().is_valid()); ERR_FAIL_COND(info->get_target() == NULL || info->get_caster() == NULL || !info->get_aura().is_valid());
@ -1518,12 +1588,22 @@ void Aura::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "ability_scale_data_id"), "set_ability_scale_data_id", "get_ability_scale_data_id"); ADD_PROPERTY(PropertyInfo(Variant::INT, "ability_scale_data_id"), "set_ability_scale_data_id", "get_ability_scale_data_id");
ADD_GROUP("Texts", "text"); ADD_GROUP("Texts", "text");
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::STRING, "desc"), "_get_description", PropertyInfo(Variant::INT, "class_level"), PropertyInfo(Variant::INT, "character_level")));
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_name"), "set_name", "get_name"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_name"), "set_name", "get_name");
ClassDB::bind_method(D_METHOD("get_text_translation_key"), &Aura::get_text_translation_key);
ClassDB::bind_method(D_METHOD("set_text_translation_key", "value"), &Aura::set_text_description);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_translation_key"), "set_text_translation_key", "get_text_translation_key");
ClassDB::bind_method(D_METHOD("get_text_description"), &Aura::get_text_description); ClassDB::bind_method(D_METHOD("get_text_description"), &Aura::get_text_description);
ClassDB::bind_method(D_METHOD("set_text_description", "value"), &Aura::set_text_description); ClassDB::bind_method(D_METHOD("set_text_description", "value"), &Aura::set_text_description);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_description", PROPERTY_HINT_MULTILINE_TEXT), "set_text_description", "get_text_description"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "text_description", PROPERTY_HINT_MULTILINE_TEXT), "set_text_description", "get_text_description");
ClassDB::bind_method(D_METHOD("get_name_translated"), &Aura::get_name_translated);
ClassDB::bind_method(D_METHOD("get_description", "class_level", "character_level"), &Aura::get_description);
ClassDB::bind_method(D_METHOD("_get_description", "class_level", "character_level"), &Aura::_get_description);
ClassDB::bind_method(D_METHOD("get_visual_spell_effects"), &Aura::get_visual_spell_effects); ClassDB::bind_method(D_METHOD("get_visual_spell_effects"), &Aura::get_visual_spell_effects);
ClassDB::bind_method(D_METHOD("set_visual_spell_effects", "value"), &Aura::set_visual_spell_effects); ClassDB::bind_method(D_METHOD("set_visual_spell_effects", "value"), &Aura::set_visual_spell_effects);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "visual_spell_effects", PROPERTY_HINT_RESOURCE_TYPE, "SpellEffectVisual"), "set_visual_spell_effects", "get_visual_spell_effects"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "visual_spell_effects", PROPERTY_HINT_RESOURCE_TYPE, "SpellEffectVisual"), "set_visual_spell_effects", "get_visual_spell_effects");

View File

@ -85,6 +85,9 @@ public:
int get_rank() const; int get_rank() const;
void set_rank(const int value); void set_rank(const int value);
String get_text_translation_key() const;
void set_text_translation_key(const String &value);
String get_text_description() const; String get_text_description() const;
void set_text_description(const String description); void set_text_description(const String description);
@ -350,6 +353,10 @@ public:
_FORCE_INLINE_ bool is_talent() const { return _aura_type == SpellEnums::AURA_TYPE_TALENT; } _FORCE_INLINE_ bool is_talent() const { return _aura_type == SpellEnums::AURA_TYPE_TALENT; }
String get_name_translated() const;
String get_description(const int class_level, const int character_level);
String _get_description(const int class_level, const int character_level);
Aura(); Aura();
~Aura(); ~Aura();
@ -393,6 +400,7 @@ private:
bool _hide; bool _hide;
Ref<Spell> _teaches_spell; Ref<Spell> _teaches_spell;
String _text_translation_key;
String _text_description; String _text_description;
int ability_scale_data_id; int ability_scale_data_id;
int _rank; int _rank;