mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-02-20 17:14:44 +01:00
Clean ups to StatData.
This commit is contained in:
parent
ca07679be1
commit
e033d5a988
1
SCsub
1
SCsub
@ -61,7 +61,6 @@ sources = [
|
||||
"skeleton/character_bones.cpp",
|
||||
|
||||
"entities/stats/stat_data.cpp",
|
||||
"entities/stats/stat_data_entry.cpp",
|
||||
"entities/stats/level_stat_data.cpp",
|
||||
"entities/stats/simple_level_stat_data.cpp",
|
||||
"entities/stats/complex_level_stat_data.cpp",
|
||||
|
@ -640,7 +640,7 @@ void Entity::_setup() {
|
||||
ERR_FAIL_COND(!cc.is_valid());
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
stat_set_base(i, _s_entity_data->get_stat_data()->get_stat_for_stat(i));
|
||||
stat_set_base(i, _s_entity_data->get_stat_data()->get_base(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
|
@ -24,13 +24,13 @@ SOFTWARE.
|
||||
|
||||
#include "../../singletons/ess.h"
|
||||
|
||||
Ref<StatDataEntry> StatData::get_stat_data(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entries.size(), Ref<StatDataEntry>(NULL));
|
||||
float StatData::get_base(int index) {
|
||||
ERR_FAIL_INDEX_V(index, _entries.size(), 0);
|
||||
|
||||
return _entries[index];
|
||||
}
|
||||
|
||||
void StatData::set_stat_data(int index, Ref<StatDataEntry> entry) {
|
||||
void StatData::set_base(int index, float entry) {
|
||||
ERR_FAIL_INDEX(index, _entries.size());
|
||||
|
||||
_entries.set(index, entry);
|
||||
@ -44,13 +44,48 @@ void StatData::set_level_stat_data(Ref<LevelStatData> value) {
|
||||
_level_stat_data = value;
|
||||
}
|
||||
|
||||
float StatData::get_stat_for_stat(int index) {
|
||||
//Ref<StatDataEntry> sd = get_stat_data(stat->get_id());
|
||||
Ref<StatDataEntry> sd = get_stat_data(0);
|
||||
bool StatData::has_mod_stats() {
|
||||
return _mod_stat_count > 0;
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(!sd.is_valid(), 0);
|
||||
int StatData::get_mod_stat_count() {
|
||||
return _mod_stat_count;
|
||||
}
|
||||
void StatData::set_mod_stat_count(int value) {
|
||||
_mod_stat_count = value;
|
||||
}
|
||||
|
||||
return sd->get_base();
|
||||
int StatData::get_target_stat_id(int index) {
|
||||
ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, 0);
|
||||
|
||||
return _mod_stats[index].target_stat_id;
|
||||
}
|
||||
void StatData::set_target_stat_id(int index, int value) {
|
||||
ERR_FAIL_INDEX(index, MAX_MOD_STATS);
|
||||
|
||||
_mod_stats[index].target_stat_id = value;
|
||||
}
|
||||
|
||||
int StatData::get_mod_stat_id(int index) {
|
||||
ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, 0);
|
||||
|
||||
return _mod_stats[index].stat_id;
|
||||
}
|
||||
void StatData::set_mod_stat_id(int index, int value) {
|
||||
ERR_FAIL_INDEX(index, MAX_MOD_STATS);
|
||||
|
||||
_mod_stats[index].stat_id = value;
|
||||
}
|
||||
|
||||
float StatData::get_mod_stat_multiplier(int index) {
|
||||
ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, 1);
|
||||
|
||||
return _mod_stats[index].multiplier;
|
||||
}
|
||||
void StatData::set_mod_stat_multiplier(int index, float value) {
|
||||
ERR_FAIL_INDEX(index, 1);
|
||||
|
||||
_mod_stats[index].multiplier = value;
|
||||
}
|
||||
|
||||
StatData::StatData() {
|
||||
@ -58,8 +93,14 @@ StatData::StatData() {
|
||||
_entries.resize(ESS::get_instance()->stat_get_count());
|
||||
|
||||
for (int i = 0; i < _entries.size(); ++i) {
|
||||
Ref<StatDataEntry> entry(memnew(StatDataEntry()));
|
||||
_entries.set(i, Ref<StatDataEntry>(entry));
|
||||
_entries.set(i, 0);
|
||||
}
|
||||
|
||||
_mod_stat_count = 0;
|
||||
|
||||
for (int i = 0; i < MAX_MOD_STATS; ++i) {
|
||||
_mod_stats[i].stat_id = 0;
|
||||
_mod_stats[i].multiplier = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +146,7 @@ bool StatData::_get(const StringName &p_name, Variant &r_ret) const {
|
||||
int stat_id = ESS::get_instance()->stat_get_property_id(prop);
|
||||
|
||||
if (_entries.size() < stat_id) {
|
||||
r_ret = Ref<StatDataEntry>();
|
||||
r_ret = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -128,16 +169,52 @@ void StatData::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
int property_usange = PROPERTY_USAGE_DEFAULT;
|
||||
|
||||
for (int i = 0; i < ESS::get_instance()->stat_get_count(); ++i) {
|
||||
p_list->push_back(PropertyInfo(Variant::OBJECT, "stat/" + ESS::get_instance()->stat_get_property_name(i), PROPERTY_HINT_RESOURCE_TYPE, "StatDataEntry", property_usange));
|
||||
p_list->push_back(PropertyInfo(Variant::REAL, "stat/" + ESS::get_instance()->stat_get_property_name(i), PROPERTY_HINT_NONE, "", property_usange));
|
||||
}
|
||||
}
|
||||
|
||||
void StatData::_validate_property(PropertyInfo &property) const {
|
||||
String prop = property.name;
|
||||
if (prop.begins_with("ModStat_")) {
|
||||
int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int();
|
||||
if (frame >= _mod_stat_count) {
|
||||
property.usage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (prop.ends_with("stat_id")) {
|
||||
property.hint_string = ESS::get_instance()->stat_get_string();
|
||||
} else if (prop.ends_with("target_stat_id")) {
|
||||
property.hint_string = ESS::get_instance()->stat_get_string();
|
||||
}
|
||||
}
|
||||
|
||||
void StatData::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_stat_data", "index"), &StatData::get_stat_data);
|
||||
ClassDB::bind_method(D_METHOD("set_stat_data", "index", "entry"), &StatData::set_stat_data);
|
||||
ClassDB::bind_method(D_METHOD("get_base", "index"), &StatData::get_base);
|
||||
ClassDB::bind_method(D_METHOD("set_base", "index", "entry"), &StatData::set_base);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_level_stat_data"), &StatData::get_level_stat_data);
|
||||
ClassDB::bind_method(D_METHOD("set_level_stat_data", "value"), &StatData::set_level_stat_data);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "level_stat_data", PROPERTY_HINT_RESOURCE_TYPE, "LevelStatData"), "set_level_stat_data", "get_level_stat_data");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("has_mod_stats"), &StatData::has_mod_stats);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_count"), &StatData::get_mod_stat_count);
|
||||
ClassDB::bind_method(D_METHOD("set_mod_stat_count", "value"), &StatData::set_mod_stat_count);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "mod_stat_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_MOD_STATS), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_mod_stat_count", "get_mod_stat_count");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_target_stat_id", "index"), &StatData::get_target_stat_id);
|
||||
ClassDB::bind_method(D_METHOD("set_target_stat_id", "index", "value"), &StatData::set_target_stat_id);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_id", "index"), &StatData::get_mod_stat_id);
|
||||
ClassDB::bind_method(D_METHOD("set_mod_stat_id", "index", "value"), &StatData::set_mod_stat_id);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_multiplier", "index"), &StatData::get_mod_stat_multiplier);
|
||||
ClassDB::bind_method(D_METHOD("set_mod_stat_multiplier", "index", "value"), &StatData::set_mod_stat_multiplier);
|
||||
|
||||
for (int i = 0; i < MAX_MOD_STATS; i++) {
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::INT, "ModStat_" + itos(i) + "/target_stat_id", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_target_stat_id", "get_target_stat_id", i);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::INT, "ModStat_" + itos(i) + "/stat_id", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_id", "get_mod_stat_id", i);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "ModStat_" + itos(i) + "/multiplier", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_multiplier", "get_mod_stat_multiplier", i);
|
||||
}
|
||||
}
|
||||
|
@ -27,19 +27,41 @@ SOFTWARE.
|
||||
#include "scene/resources/curve.h"
|
||||
|
||||
#include "level_stat_data.h"
|
||||
#include "stat_data_entry.h"
|
||||
|
||||
class StatData : public Resource {
|
||||
GDCLASS(StatData, Resource);
|
||||
|
||||
public:
|
||||
Ref<StatDataEntry> get_stat_data(int index);
|
||||
void set_stat_data(int index, Ref<StatDataEntry> entry);
|
||||
struct ModStat {
|
||||
int target_stat_id;
|
||||
int stat_id;
|
||||
float multiplier;
|
||||
};
|
||||
|
||||
enum {
|
||||
MAX_MOD_STATS = 8,
|
||||
};
|
||||
|
||||
public:
|
||||
float get_base(int index);
|
||||
void set_base(int index, float entry);
|
||||
|
||||
Ref<LevelStatData> get_level_stat_data();
|
||||
void set_level_stat_data(Ref<LevelStatData> value);
|
||||
|
||||
float get_stat_for_stat(int index);
|
||||
bool has_mod_stats();
|
||||
|
||||
int get_mod_stat_count();
|
||||
void set_mod_stat_count(int value);
|
||||
|
||||
int get_target_stat_id(int index);
|
||||
void set_target_stat_id(int index, int value);
|
||||
|
||||
int get_mod_stat_id(int index);
|
||||
void set_mod_stat_id(int index, int value);
|
||||
|
||||
float get_mod_stat_multiplier(int index);
|
||||
void set_mod_stat_multiplier(int index, float value);
|
||||
|
||||
StatData();
|
||||
~StatData();
|
||||
@ -48,12 +70,16 @@ protected:
|
||||
bool _set(const StringName &p_name, const Variant &p_value);
|
||||
bool _get(const StringName &p_name, Variant &r_ret) const;
|
||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||
void _validate_property(PropertyInfo &property) const;
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
Vector<Ref<StatDataEntry> > _entries;
|
||||
Vector<float> _entries;
|
||||
|
||||
Ref<LevelStatData> _level_stat_data;
|
||||
|
||||
int _mod_stat_count;
|
||||
ModStat _mod_stats[MAX_MOD_STATS];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -1,121 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "stat_data_entry.h"
|
||||
|
||||
#include "core/version.h"
|
||||
|
||||
#include "../../singletons/ess.h"
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
#define REAL FLOAT
|
||||
#endif
|
||||
|
||||
float StatDataEntry::get_base() {
|
||||
return _base;
|
||||
}
|
||||
void StatDataEntry::set_base(float value) {
|
||||
_base = value;
|
||||
}
|
||||
|
||||
bool StatDataEntry::has_mod_stats() {
|
||||
return _mod_stat_count > 0;
|
||||
}
|
||||
|
||||
int StatDataEntry::get_mod_stat_count() {
|
||||
return _mod_stat_count;
|
||||
}
|
||||
void StatDataEntry::set_mod_stat_count(int value) {
|
||||
_mod_stat_count = value;
|
||||
}
|
||||
|
||||
int StatDataEntry::get_mod_stat_id(int index) {
|
||||
ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, 0);
|
||||
|
||||
return _mod_stats[index].stat_id;
|
||||
}
|
||||
void StatDataEntry::set_mod_stat_id(int index, int value) {
|
||||
ERR_FAIL_INDEX(index, MAX_MOD_STATS);
|
||||
|
||||
_mod_stats[index].stat_id = value;
|
||||
}
|
||||
|
||||
float StatDataEntry::get_mod_stat_multiplier(int index) {
|
||||
ERR_FAIL_INDEX_V(index, MAX_MOD_STATS, 1);
|
||||
|
||||
return _mod_stats[index].multiplier;
|
||||
}
|
||||
void StatDataEntry::set_mod_stat_multiplier(int index, float value) {
|
||||
ERR_FAIL_INDEX(index, 1);
|
||||
|
||||
_mod_stats[index].multiplier = value;
|
||||
}
|
||||
|
||||
StatDataEntry::StatDataEntry() {
|
||||
_base = 0;
|
||||
_mod_stat_count = 0;
|
||||
|
||||
for (int i = 0; i < MAX_MOD_STATS; ++i) {
|
||||
_mod_stats[i].stat_id = 0;
|
||||
_mod_stats[i].multiplier = 0;
|
||||
}
|
||||
}
|
||||
|
||||
StatDataEntry::~StatDataEntry() {
|
||||
}
|
||||
|
||||
void StatDataEntry::_validate_property(PropertyInfo &property) const {
|
||||
String prop = property.name;
|
||||
if (prop.begins_with("ModStat_")) {
|
||||
int frame = prop.get_slicec('/', 0).get_slicec('_', 1).to_int();
|
||||
if (frame >= _mod_stat_count) {
|
||||
property.usage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (prop.ends_with("stat_id")) {
|
||||
property.hint_string = ESS::get_instance()->stat_get_string();
|
||||
}
|
||||
}
|
||||
|
||||
void StatDataEntry::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_base"), &StatDataEntry::get_base);
|
||||
ClassDB::bind_method(D_METHOD("set_base", "value"), &StatDataEntry::set_base);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "base"), "set_base", "get_base");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("has_mod_stats"), &StatDataEntry::has_mod_stats);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_count"), &StatDataEntry::get_mod_stat_count);
|
||||
ClassDB::bind_method(D_METHOD("set_mod_stat_count", "value"), &StatDataEntry::set_mod_stat_count);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "mod_stat_count", PROPERTY_HINT_RANGE, "0," + itos(MAX_MOD_STATS), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), "set_mod_stat_count", "get_mod_stat_count");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_id", "index"), &StatDataEntry::get_mod_stat_id);
|
||||
ClassDB::bind_method(D_METHOD("set_mod_stat_id", "index", "value"), &StatDataEntry::set_mod_stat_id);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_mod_stat_multiplier", "index"), &StatDataEntry::get_mod_stat_multiplier);
|
||||
ClassDB::bind_method(D_METHOD("set_mod_stat_multiplier", "index", "value"), &StatDataEntry::set_mod_stat_multiplier);
|
||||
|
||||
for (int i = 0; i < MAX_MOD_STATS; i++) {
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::INT, "ModStat_" + itos(i) + "/stat_id", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_id", "get_mod_stat_id", i);
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "ModStat_" + itos(i) + "/multiplier", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_mod_stat_multiplier", "get_mod_stat_multiplier", i);
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef STAT_DATA_ENTRY_H
|
||||
#define STAT_DATA_ENTRY_H
|
||||
|
||||
#include "core/resource.h"
|
||||
#include "scene/resources/curve.h"
|
||||
|
||||
#include "level_stat_data.h"
|
||||
|
||||
class StatDataEntry : public Resource {
|
||||
GDCLASS(StatDataEntry, Resource);
|
||||
|
||||
public:
|
||||
float get_base();
|
||||
void set_base(float value);
|
||||
|
||||
bool has_mod_stats();
|
||||
|
||||
int get_mod_stat_count();
|
||||
void set_mod_stat_count(int value);
|
||||
|
||||
int get_mod_stat_id(int index);
|
||||
void set_mod_stat_id(int index, int value);
|
||||
|
||||
float get_mod_stat_multiplier(int index);
|
||||
void set_mod_stat_multiplier(int index, float value);
|
||||
|
||||
StatDataEntry();
|
||||
~StatDataEntry();
|
||||
|
||||
protected:
|
||||
void _validate_property(PropertyInfo &property) const;
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
struct ModStat {
|
||||
int stat_id;
|
||||
float multiplier;
|
||||
};
|
||||
|
||||
enum {
|
||||
MAX_MOD_STATS = 3,
|
||||
};
|
||||
|
||||
private:
|
||||
float _base;
|
||||
|
||||
int _mod_stat_count;
|
||||
ModStat _mod_stats[MAX_MOD_STATS];
|
||||
};
|
||||
|
||||
#endif
|
@ -68,7 +68,6 @@ SOFTWARE.
|
||||
#include "entities/stats/level_stat_data.h"
|
||||
#include "entities/stats/simple_level_stat_data.h"
|
||||
#include "entities/stats/stat_data.h"
|
||||
#include "entities/stats/stat_data_entry.h"
|
||||
|
||||
#include "inventory/bag.h"
|
||||
//#include "inventory/inventory.h"
|
||||
@ -195,7 +194,6 @@ void register_entity_spell_system_types() {
|
||||
//entity data
|
||||
ClassDB::register_class<EntityEnums>();
|
||||
|
||||
ClassDB::register_class<StatDataEntry>();
|
||||
ClassDB::register_class<StatData>();
|
||||
|
||||
ClassDB::register_class<LevelStatData>();
|
||||
|
Loading…
Reference in New Issue
Block a user