mirror of
https://github.com/Relintai/entity_spell_system.git
synced 2025-05-11 22:42:10 +02:00
Loot data container now uses the vector based bindings.
This commit is contained in:
parent
cd2022792b
commit
223276ef41
@ -1,36 +1,59 @@
|
|||||||
#include "loot_data_container.h"
|
#include "loot_data_container.h"
|
||||||
|
|
||||||
Ref<LootDataBase> LootDataContainter::get_entry(int index) const {
|
int LootDataContainter::get_num_entries() const {
|
||||||
ERR_FAIL_INDEX_V(index, MAX_ENTRIES, Ref<LootDataBase>(NULL));
|
return _entries.size();
|
||||||
|
}
|
||||||
|
|
||||||
return _entries[index];
|
Ref<LootDataBase> LootDataContainter::get_entry(int index) const {
|
||||||
|
ERR_FAIL_INDEX_V(index, _entries.size(), Ref<LootDataBase>(NULL));
|
||||||
|
|
||||||
|
return _entries.get(index);
|
||||||
}
|
}
|
||||||
void LootDataContainter::set_entry(const int index, const Ref<LootDataBase> ldb) {
|
void LootDataContainter::set_entry(const int index, const Ref<LootDataBase> ldb) {
|
||||||
ERR_FAIL_INDEX(index, MAX_ENTRIES);
|
ERR_FAIL_INDEX(index, _entries.size());
|
||||||
|
|
||||||
_entries[index] = ldb;
|
_entries.set(index, ldb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LootDataContainter::_get_loot(Array into) {
|
void LootDataContainter::_get_loot(Array into) {
|
||||||
for (int i = 0; i < MAX_ENTRIES; ++i) {
|
for (int i = 0; i < _entries.size(); ++i) {
|
||||||
if (_entries[i].is_valid()) {
|
if (_entries[i].is_valid()) {
|
||||||
_entries[i]->get_loot(into);
|
_entries.get(i)->get_loot(into);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector<Variant> LootDataContainter::get_entries() {
|
||||||
|
Vector<Variant> r;
|
||||||
|
for (int i = 0; i < _entries.size(); i++) {
|
||||||
|
r.push_back(_entries[i].get_ref_ptr());
|
||||||
|
}
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
void LootDataContainter::set_entries(const Vector<Variant> &entries) {
|
||||||
|
_entries.clear();
|
||||||
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
|
Ref<LootDataBase> entry = Ref<LootDataBase>(entries[i]);
|
||||||
|
|
||||||
|
_entries.push_back(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LootDataContainter::LootDataContainter() {
|
LootDataContainter::LootDataContainter() {
|
||||||
}
|
}
|
||||||
|
LootDataContainter::~LootDataContainter() {
|
||||||
|
_entries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
void LootDataContainter::_bind_methods() {
|
void LootDataContainter::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("_get_loot", "into"), &LootDataContainter::_get_loot);
|
ClassDB::bind_method(D_METHOD("_get_loot", "into"), &LootDataContainter::_get_loot);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("get_num_entries"), &LootDataContainter::get_num_entries);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_entry", "index"), &LootDataContainter::get_entry);
|
ClassDB::bind_method(D_METHOD("get_entry", "index"), &LootDataContainter::get_entry);
|
||||||
ClassDB::bind_method(D_METHOD("set_entry", "index", "ldb"), &LootDataContainter::set_entry);
|
ClassDB::bind_method(D_METHOD("set_entry", "index", "ldb"), &LootDataContainter::set_entry);
|
||||||
|
|
||||||
for (int i = 0; i < MAX_ENTRIES; ++i) {
|
ClassDB::bind_method(D_METHOD("get_entries"), &LootDataContainter::get_entries);
|
||||||
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "entry_" + itos(i), PROPERTY_HINT_RESOURCE_TYPE, "LootDataBase", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_INTERNAL), "set_entry", "get_entry", i);
|
ClassDB::bind_method(D_METHOD("set_entries", "auras"), &LootDataContainter::set_entries);
|
||||||
}
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "entries", PROPERTY_HINT_NONE, "17/17:LootDataBase", PROPERTY_USAGE_DEFAULT, "LootDataBase"), "set_entries", "get_entries");
|
||||||
|
|
||||||
BIND_CONSTANT(MAX_ENTRIES);
|
|
||||||
}
|
}
|
||||||
|
@ -2,27 +2,30 @@
|
|||||||
#define LOOT_DATA_CONTAINER_H
|
#define LOOT_DATA_CONTAINER_H
|
||||||
|
|
||||||
#include "loot_data_base.h"
|
#include "loot_data_base.h"
|
||||||
|
#include "core/vector.h"
|
||||||
|
|
||||||
class LootDataContainter : public LootDataBase {
|
class LootDataContainter : public LootDataBase {
|
||||||
GDCLASS(LootDataContainter, LootDataBase);
|
GDCLASS(LootDataContainter, LootDataBase);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
int get_num_entries() const;
|
||||||
|
|
||||||
Ref<LootDataBase> get_entry(const int index) const;
|
Ref<LootDataBase> get_entry(const int index) const;
|
||||||
void set_entry(const int index, const Ref<LootDataBase> ldb);
|
void set_entry(const int index, const Ref<LootDataBase> ldb);
|
||||||
|
|
||||||
void _get_loot(Array into);
|
void _get_loot(Array into);
|
||||||
|
|
||||||
LootDataContainter();
|
Vector<Variant> get_entries();
|
||||||
|
void set_entries(const Vector<Variant> &auras);
|
||||||
|
|
||||||
enum {
|
LootDataContainter();
|
||||||
MAX_ENTRIES = 6,
|
~LootDataContainter();
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ref<LootDataBase> _entries[MAX_ENTRIES];
|
Vector<Ref<LootDataBase> > _entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user