| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/templates/local_vector.h" |
| 34 |
#include "scene/main/node.h" |
| 35 |
#include "scene/resources/packed_scene.h" |
| 36 |
|
| 37 |
class MultiplayerSpawner : public Node { |
| 38 |
GDCLASS(MultiplayerSpawner, Node); |
| 39 |
|
| 40 |
public: |
| 41 |
enum { |
| 42 |
INVALID_ID = 0xFF, |
| 43 |
}; |
| 44 |
|
| 45 |
private: |
| 46 |
struct SpawnableScene { |
| 47 |
String path; |
| 48 |
Ref<PackedScene> cache; |
| 49 |
}; |
| 50 |
|
| 51 |
LocalVector<SpawnableScene> spawnable_scenes; |
| 52 |
|
| 53 |
HashSet<ResourceUID::ID> spawnable_ids; |
| 54 |
NodePath spawn_path; |
| 55 |
|
| 56 |
struct SpawnInfo { |
| 57 |
Variant args; |
| 58 |
int id = INVALID_ID; |
| 59 |
SpawnInfo(Variant p_args, int p_id) { |
| 60 |
id = p_id; |
| 61 |
args = p_args; |
| 62 |
} |
| 63 |
SpawnInfo() {} |
| 64 |
}; |
| 65 |
|
| 66 |
ObjectID spawn_node; |
| 67 |
HashMap<ObjectID, SpawnInfo> tracked_nodes; |
| 68 |
uint32_t spawn_limit = 0; |
| 69 |
Callable spawn_function; |
| 70 |
|
| 71 |
void _update_spawn_node(); |
| 72 |
void _track(Node *p_node, const Variant &p_argument, int p_scene_id = INVALID_ID); |
| 73 |
void _node_added(Node *p_node); |
| 74 |
void _node_exit(ObjectID p_id); |
| 75 |
void _spawn_notify(ObjectID p_id); |
| 76 |
|
| 77 |
Vector<String> _get_spawnable_scenes() const; |
| 78 |
void _set_spawnable_scenes(const Vector<String> &p_scenes); |
| 79 |
|
| 80 |
protected: |
| 81 |
static void _bind_methods(); |
| 82 |
void _notification(int p_what); |
| 83 |
|
| 84 |
#ifdef TOOLS_ENABLED |
| 85 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 86 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 87 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 88 |
#endif |
| 89 |
public: |
| 90 |
PackedStringArray get_configuration_warnings() const override; |
| 91 |
|
| 92 |
Node *get_spawn_node() const { |
| 93 |
return spawn_node.is_valid() ? ObjectDB::get_instance<Node>(spawn_node) : nullptr; |
| 94 |
} |
| 95 |
|
| 96 |
void add_spawnable_scene(const String &p_path); |
| 97 |
int get_spawnable_scene_count() const; |
| 98 |
String get_spawnable_scene(int p_idx) const; |
| 99 |
void clear_spawnable_scenes(); |
| 100 |
|
| 101 |
NodePath get_spawn_path() const; |
| 102 |
void set_spawn_path(const NodePath &p_path); |
| 103 |
uint32_t get_spawn_limit() const { return spawn_limit; } |
| 104 |
void set_spawn_limit(uint32_t p_limit) { spawn_limit = p_limit; } |
| 105 |
void set_spawn_function(Callable p_spawn_function) { spawn_function = p_spawn_function; } |
| 106 |
Callable get_spawn_function() const { return spawn_function; } |
| 107 |
|
| 108 |
const Variant get_spawn_argument(const ObjectID &p_id) const; |
| 109 |
int find_spawnable_scene_index_from_object(const ObjectID &p_id) const; |
| 110 |
int find_spawnable_scene_index_from_path(const String &p_path) const; |
| 111 |
Node *spawn(const Variant &p_data = Variant()); |
| 112 |
Node *instantiate_custom(const Variant &p_data); |
| 113 |
Node *instantiate_scene(int p_idx); |
| 114 |
|
| 115 |
MultiplayerSpawner() {} |
| 116 |
}; |