From d2ba6585c4ad51cd26e08bd0c09977c3d7f6b425 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 13 Apr 2025 20:43:48 +0200 Subject: [PATCH] Implemented ESSEntityWorldSpawner3DSingle. --- .../ess_entity_world_spawner_3d_single.cpp | 83 ++++++++++++++++++- .../ess_entity_world_spawner_3d_single.h | 16 +++- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/modules/entity_spell_system/world_spawners/ess_entity_world_spawner_3d_single.cpp b/modules/entity_spell_system/world_spawners/ess_entity_world_spawner_3d_single.cpp index 0be8c5d9d..31304bbbf 100644 --- a/modules/entity_spell_system/world_spawners/ess_entity_world_spawner_3d_single.cpp +++ b/modules/entity_spell_system/world_spawners/ess_entity_world_spawner_3d_single.cpp @@ -31,16 +31,97 @@ #include "ess_entity_world_spawner_3d_single.h" +#include "../data/species/entity_species_data.h" +#include "../data/species/species_instance.h" +#include "../entities/data/entity_data.h" +#include "../entity_enums.h" #include "../utility/entity_create_info.h" +#include "core/config/engine.h" + +#include "../singletons/ess.h" + +String ESSEntityWorldSpawner3DSingle::get_entity_name() const { + return _entity_name; +} +void ESSEntityWorldSpawner3DSingle::set_entity_name(const String &p_name) { + _entity_name = p_name; +} + +Ref ESSEntityWorldSpawner3DSingle::get_entity_data() const { + return _entity_data; +} +void ESSEntityWorldSpawner3DSingle::set_entity_data(const Ref &p_data) { + _entity_data = p_data; +} + +int ESSEntityWorldSpawner3DSingle::get_level() const { + return _level; +} +void ESSEntityWorldSpawner3DSingle::set_level(const int p_level) { + _level = p_level; +} + void ESSEntityWorldSpawner3DSingle::_spawn() { + if (Engine::get_singleton()->is_editor_hint()) { + return; + } + + if (!_entity_data.is_valid()) { + return; + } + + if (!is_inside_tree()) { + return; + } + + Ref info; + info.instance(); + + if (!_entity_name.empty()) { + info->set_entity_name(_entity_name); + } else { + info->set_entity_name(get_name()); + } + + info->set_entity_controller(EntityEnums::ENITIY_CONTROLLER_AI); + info->set_level(_level); + info->set_transform(get_global_transform()); + info->set_entity_data(_entity_data); + info->set_species_instance(_entity_data->get_species_instance()); + ESS::get_singleton()->request_entity_spawn_deferred(info); + + emit_on_entity_spawned(info); } ESSEntityWorldSpawner3DSingle::ESSEntityWorldSpawner3DSingle() { + _level = 1; } ESSEntityWorldSpawner3DSingle::~ESSEntityWorldSpawner3DSingle() { } -void ESSEntityWorldSpawner3DSingle::_bind_methods() { +void ESSEntityWorldSpawner3DSingle::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + spawn(); + break; + + default: + break; + } +} + +void ESSEntityWorldSpawner3DSingle::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_entity_name"), &ESSEntityWorldSpawner3DSingle::get_entity_name); + ClassDB::bind_method(D_METHOD("set_entity_name", "value"), &ESSEntityWorldSpawner3DSingle::set_entity_name); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "entity_name"), "set_entity_name", "get_entity_name"); + + ClassDB::bind_method(D_METHOD("get_entity_data"), &ESSEntityWorldSpawner3DSingle::get_entity_data); + ClassDB::bind_method(D_METHOD("set_entity_data", "value"), &ESSEntityWorldSpawner3DSingle::set_entity_data); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "entity_data", PROPERTY_HINT_RESOURCE_TYPE, "EntityData"), "set_entity_data", "get_entity_data"); + + ClassDB::bind_method(D_METHOD("get_level"), &ESSEntityWorldSpawner3DSingle::get_level); + ClassDB::bind_method(D_METHOD("set_level", "value"), &ESSEntityWorldSpawner3DSingle::set_level); + ADD_PROPERTY(PropertyInfo(Variant::INT, "level"), "set_level", "get_level"); } diff --git a/modules/entity_spell_system/world_spawners/ess_entity_world_spawner_3d_single.h b/modules/entity_spell_system/world_spawners/ess_entity_world_spawner_3d_single.h index a42ed6d3e..b04c5012d 100644 --- a/modules/entity_spell_system/world_spawners/ess_entity_world_spawner_3d_single.h +++ b/modules/entity_spell_system/world_spawners/ess_entity_world_spawner_3d_single.h @@ -34,19 +34,33 @@ #include "ess_entity_world_spawner_3d.h" -class EntityCreateInfo; +class EntityData; class ESSEntityWorldSpawner3DSingle : public ESSEntityWorldSpawner3D { GDCLASS(ESSEntityWorldSpawner3DSingle, ESSEntityWorldSpawner3D); public: + String get_entity_name() const; + void set_entity_name(const String &p_name); + + Ref get_entity_data() const; + void set_entity_data(const Ref &p_data); + + int get_level() const; + void set_level(const int p_level); + virtual void _spawn(); ESSEntityWorldSpawner3DSingle(); ~ESSEntityWorldSpawner3DSingle(); protected: + void _notification(int p_what); static void _bind_methods(); + + String _entity_name; + Ref _entity_data; + int _level; }; #endif