Refactored how entity resources are set up.

This commit is contained in:
Relintai 2019-11-30 19:26:12 +01:00
parent dc5d1515e2
commit fe6b3224c8
9 changed files with 141 additions and 23 deletions

1
SCsub
View File

@ -80,6 +80,7 @@ module_env.add_source_files(env.modules_sources,"pipelines/spell_damage_info.cpp
module_env.add_source_files(env.modules_sources,"pipelines/spell_heal_info.cpp")
module_env.add_source_files(env.modules_sources,"entities/auras/aura_data.cpp")
module_env.add_source_files(env.modules_sources,"entities/entity.cpp")
module_env.add_source_files(env.modules_sources,"entities/resources/entity_resource_data.cpp")
module_env.add_source_files(env.modules_sources,"entities/resources/entity_resource.cpp")
module_env.add_source_files(env.modules_sources,"ui/unit_frame.cpp")

View File

@ -72,6 +72,51 @@ void EntityClassData::set_stat_data(Ref<StatData> value) {
_stat_data = value;
}
//// Entity Resources ////
int EntityClassData::get_num_entity_resources() {
if (_entity_resources.size() == 0 && _inherits.is_valid()) {
return _inherits->get_num_entity_resources();
}
return _entity_resources.size();
}
void EntityClassData::set_num_entity_resources(int value) {
_entity_resources.resize(value);
}
Ref<EntityResourceData> EntityClassData::get_entity_resource(int index) const {
if (_entity_resources.size() == 0 && _inherits.is_valid()) {
return _inherits->get_entity_resource(index);
}
ERR_FAIL_INDEX_V(index, _entity_resources.size(), Ref<EntityResourceData>());
return _entity_resources[index];
}
void EntityClassData::set_entity_resource(int index, Ref<EntityResourceData> entity_resource) {
ERR_FAIL_INDEX(index, _entity_resources.size());
_entity_resources.set(index, Ref<EntityResourceData>(entity_resource));
}
Vector<Variant> EntityClassData::get_entity_resources() {
Vector<Variant> r;
for (int i = 0; i < _entity_resources.size(); i++) {
r.push_back(_entity_resources[i].get_ref_ptr());
}
return r;
}
void EntityClassData::set_entity_resources(const Vector<Variant> &entity_resources) {
_entity_resources.clear();
for (int i = 0; i < entity_resources.size(); i++) {
Ref<EntityResourceData> entity_resource = Ref<EntityResourceData>(entity_resources[i]);
_entity_resources.push_back(entity_resource);
}
}
//// SPECS ////
int EntityClassData::get_num_specs() {
@ -313,10 +358,23 @@ Ref<EntityAI> EntityClassData::_get_ai_instance() {
//// SETUP ////
void EntityClassData::setup_resources(Entity *entity) {
if (_inherits.is_valid())
_inherits->setup_resources(entity);
if (has_method("_setup_resources"))
call("_setup_resources", entity);
else if (_inherits.is_valid())
_inherits->setup_resources(entity);
}
void EntityClassData::_setup_resources(Node *entity) {
Entity *ent = Object::cast_to<Entity>(entity);
for (int i = 0; i < _entity_resources.size(); ++i) {
Ref<EntityResourceData> res = _entity_resources.get(i);
if (res.is_valid()) {
ent->adds_resource(res->get_entity_resource_instance());
}
}
}
void EntityClassData::start_casting(int spell_id, Entity *caster, float spellScale) {
@ -1016,6 +1074,19 @@ void EntityClassData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_playstyle_type", "value"), &EntityClassData::set_playstyle_type);
ADD_PROPERTY(PropertyInfo(Variant::INT, "playstyle_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_PLAYSTYLE_TYPE), "set_playstyle_type", "get_playstyle_type");
//// Entity Resources ////
ClassDB::bind_method(D_METHOD("get_num_entity_resources"), &EntityClassData::get_num_entity_resources);
ClassDB::bind_method(D_METHOD("set_num_entity_resources", "value"), &EntityClassData::set_num_entity_resources);
ClassDB::bind_method(D_METHOD("get_entity_resource", "index"), &EntityClassData::get_entity_resource);
ClassDB::bind_method(D_METHOD("set_entity_resource", "index", "entity_resource"), &EntityClassData::set_entity_resource);
ClassDB::bind_method(D_METHOD("get_entity_resources"), &EntityClassData::get_entity_resources);
ClassDB::bind_method(D_METHOD("set_entity_resources", "entity_resources"), &EntityClassData::set_entity_resources);
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entity_resources", PROPERTY_HINT_NONE, "17/17:EntityResourceData", PROPERTY_USAGE_DEFAULT, "EntityResourceData"), "set_entity_resources", "get_entity_resources");
ClassDB::bind_method(D_METHOD("_setup_resources", "entity"), &EntityClassData::_setup_resources);
//// Specs ////
ClassDB::bind_method(D_METHOD("get_num_specs"), &EntityClassData::get_num_specs);
ClassDB::bind_method(D_METHOD("set_num_specs", "value"), &EntityClassData::set_num_specs);

View File

@ -17,6 +17,8 @@
#include "../../utility/category_cooldown.h"
#include "../../item_enums.h"
#include "../resources/entity_resource_data.h"
class Aura;
class Spell;
class Entity;
@ -54,6 +56,16 @@ public:
EntityEnums::EntityClassPlaystyleType get_playstyle_type();
void set_playstyle_type(EntityEnums::EntityClassPlaystyleType playstyle_type);
//Entity Resources
int get_num_entity_resources();
void set_num_entity_resources(int value);
Ref<EntityResourceData> get_entity_resource(int index) const;
void set_entity_resource(int index, Ref<EntityResourceData> entity_resources);
Vector<Variant> get_entity_resources();
void set_entity_resources(const Vector<Variant> &entity_resourcess);
//Specs
int get_num_specs();
void set_num_specs(int value);
@ -109,7 +121,7 @@ public:
//Setup
void setup_resources(Entity *entity);
//void _setup_resources(Entity *entity);
void _setup_resources(Node *entity);
//// Spell System ////
@ -230,9 +242,10 @@ private:
Ref<StatData> _stat_data;
Vector<Ref<EntityResource> > _entity_resources;
Vector<Ref<CharacterSpec> > _specs;
Vector<Ref<Spell> > _spells;
Vector<Ref<Spell> > _start_spells;
Vector<Ref<CharacterSpec> > _specs;
Vector<Ref<Aura> > _auras;
Vector<Ref<EntityAI> > _ais;
};

View File

@ -111,7 +111,6 @@ public:
//Setup
void setup_resources(Entity *entity);
//void _setup_resources(Entity *entity);
//// Interactions ////
bool cans_interact(Entity *entity);

View File

@ -0,0 +1,18 @@
#include "entity_resource_data.h"
Ref<EntityResource> EntityResourceData::get_entity_resource_instance() {
if (has_method("_get_entity_resource_instance")) {
return call("_get_entity_resource_instance");
}
return Ref<EntityResource>();
}
EntityResourceData::EntityResourceData() {
}
void EntityResourceData::_bind_methods() {
BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "res", PROPERTY_HINT_RESOURCE_TYPE, "EntityResource"), "_get_entity_resource_instance"));
ClassDB::bind_method(D_METHOD("get_entity_resource_instance"), &EntityResourceData::get_entity_resource_instance);
}

View File

@ -0,0 +1,21 @@
#ifndef ENTITY_RESOURCE_DATA_H
#define ENTITY_RESOURCE_DATA_H
#include "core/resource.h"
#include "scene/main/node.h"
#include "entity_resource.h"
class EntityResourceData : public Resource {
GDCLASS(EntityResourceData, Resource);
public:
Ref<EntityResource> get_entity_resource_instance();
EntityResourceData();
protected:
static void _bind_methods();
};
#endif

View File

@ -1,7 +1,5 @@
#include "entity_enums.h"
const String EntityEnums::BINDING_STRING_PLAYER_RESOURCE_TYPES = "None,Rage,Mana,Energy,Time Anomaly";
const String EntityEnums::BINDING_STRING_ENTITY_TYPES = "None,Creature,Totem,Idol,Humanoid,Mechanical,Beast,Dragonkin,Elemental,Ghost,Energy,Anomaly,Demon,Object";
const String EntityEnums::BINDING_STRING_ENTITY_CONTOLLER = "None,Player,AI";
const String EntityEnums::BINDING_STRING_ENTITY_FLAGS = "Untargetable,Hidden,Interactable,Hostile";
@ -15,16 +13,11 @@ const String EntityEnums::BINDING_STRING_ENTITY_PLAYSTYLE_TYPE = "Melee,Spell,Hy
const String EntityEnums::BINDING_STRING_ENTITY_GENDER = "Male,Female";
const String EntityEnums::BINDING_STRING_ENTITY_WINDOWS = "Loot,Container,Vendor";
const int EntityEnums::PLAYER_RESOURCE_TYPES_RAGE = 0;
const int EntityEnums::PLAYER_RESOURCE_TYPES_MANA = 1;
const int EntityEnums::PLAYER_RESOURCE_TYPES_ENERGY = 2;
const int EntityEnums::PLAYER_RESOURCE_TYPES_TIME_ANOMALY = 3;
void EntityEnums::_bind_methods() {
BIND_CONSTANT(PLAYER_RESOURCE_TYPES_RAGE);
BIND_CONSTANT(PLAYER_RESOURCE_TYPES_MANA);
BIND_CONSTANT(PLAYER_RESOURCE_TYPES_ENERGY);
BIND_CONSTANT(PLAYER_RESOURCE_TYPES_TIME_ANOMALY);
BIND_CONSTANT(ENTITY_RESOURCE_TYPES_MANA);
BIND_CONSTANT(ENTITY_RESOURCE_TYPES_RAGE);
BIND_CONSTANT(ENTITY_RESOURCE_TYPES_ENERGY);
BIND_CONSTANT(ENTITY_RESOURCE_TYPES_TIME_ANOMALY);
BIND_ENUM_CONSTANT(ENITIY_TYPE_NONE);
BIND_ENUM_CONSTANT(ENITIY_TYPE_CREATURE);

View File

@ -8,8 +8,6 @@ class EntityEnums : public Object {
GDCLASS(EntityEnums, Object);
public:
static const String BINDING_STRING_PLAYER_RESOURCE_TYPES;
static const String BINDING_STRING_ENTITY_TYPES;
static const String BINDING_STRING_ENTITY_CONTOLLER;
static const String BINDING_STRING_ENTITY_FLAGS;
@ -23,11 +21,6 @@ public:
static const String BINDING_STRING_ENTITY_GENDER;
static const String BINDING_STRING_ENTITY_WINDOWS;
static const int PLAYER_RESOURCE_TYPES_RAGE;
static const int PLAYER_RESOURCE_TYPES_MANA;
static const int PLAYER_RESOURCE_TYPES_ENERGY;
static const int PLAYER_RESOURCE_TYPES_TIME_ANOMALY;
enum EntityType {
ENITIY_TYPE_NONE,
ENITIY_TYPE_CREATURE,
@ -51,6 +44,13 @@ public:
ENITIY_CONTROLLER_AI
};
enum {
ENTITY_RESOURCE_TYPES_MANA = 0,
ENTITY_RESOURCE_TYPES_RAGE,
ENTITY_RESOURCE_TYPES_ENERGY,
ENTITY_RESOURCE_TYPES_TIME_ANOMALY,
};
enum EntityFlags {
ENITIY_FLAGS_NONE = 0,

View File

@ -60,6 +60,7 @@
#include "pipelines/spell_damage_info.h"
#include "pipelines/spell_heal_info.h"
#include "entities/resources/entity_resource_data.h"
#include "entities/resources/entity_resource.h"
#include "entities/auras/aura_data.h"
#include "entities/entity.h"
@ -185,6 +186,7 @@ void register_entity_spell_system_types() {
ClassDB::register_class<SpellHealInfo>();
ClassDB::register_class<AuraData>();
ClassDB::register_class<EntityResourceData>();
ClassDB::register_class<EntityResource>();
ClassDB::register_class<AuraTriggerData>();