Now instance() will create the proper class instance, and also set up the script on it.

This commit is contained in:
Relintai 2020-07-22 01:59:53 +02:00
parent eed7f40e51
commit bc2ee7171a
10 changed files with 41 additions and 61 deletions

View File

@ -281,22 +281,18 @@ void Biome::set_voxel_surfaces(const Vector<Variant> &voxel_surfaces) {
#endif
Ref<Biome> Biome::instance(const int seed) {
if (has_method("_instance")) {
return call("_instance", seed, Ref<Biome>());
}
Ref<Biome> inst;
return Ref<Biome>();
}
inst = Ref<Biome>(Object::cast_to<Biome>(ClassDB::instance(get_class_name())));
ERR_FAIL_COND_V(!inst.is_valid(), inst);
Ref<Biome> Biome::_instance(const int seed, Ref<Biome> biome) {
Ref<Biome> inst = biome;
if (!inst.is_valid())
inst.instance();
if (inst->get_script().is_null() && !get_script().is_null())
if (!get_script().is_null())
inst->set_script(get_script());
return call("_instance", seed, inst);
}
Ref<Biome> Biome::_instance(const int seed, Ref<Biome> inst) {
inst->set_current_seed(seed);
inst->set_level_range(_level_range);

View File

@ -119,7 +119,7 @@ public:
#endif
Ref<Biome> instance(const int seed);
virtual Ref<Biome> _instance(const int seed, Ref<Biome> biome);
virtual Ref<Biome> _instance(const int seed, Ref<Biome> inst);
void setup();

View File

@ -463,22 +463,18 @@ void Dungeon::set_environment_datas(const Vector<Variant> &environment_datas) {
#endif
Ref<Dungeon> Dungeon::instance(const int seed) {
if (has_method("_instance")) {
return call("_instance", seed, Ref<Dungeon>());
}
Ref<Dungeon> inst;
return Ref<Dungeon>();
}
inst = Ref<Dungeon>(Object::cast_to<Dungeon>(ClassDB::instance(get_class_name())));
ERR_FAIL_COND_V(!inst.is_valid(), inst);
Ref<Dungeon> Dungeon::_instance(const int seed, Ref<Dungeon> dungeon) {
Ref<Dungeon> inst = dungeon;
if (!inst.is_valid())
inst.instance();
if (inst->get_script().is_null() && !get_script().is_null())
if (!get_script().is_null())
inst->set_script(get_script());
return call("_instance", seed, inst);
}
Ref<Dungeon> Dungeon::_instance(const int seed, Ref<Dungeon> inst) {
inst->set_current_seed(seed);
inst->set_level_range(_level_range);

View File

@ -187,7 +187,7 @@ public:
#endif
Ref<Dungeon> instance(const int seed);
virtual Ref<Dungeon> _instance(const int seed, Ref<Dungeon> dungeon);
virtual Ref<Dungeon> _instance(const int seed, Ref<Dungeon> inst);
void setup();

View File

@ -53,17 +53,13 @@ int DungeonCorridor::get_dungeon_room_count() const {
return _dungeon_rooms.size();
}
Ref<DungeonRoom> DungeonCorridor::_instance(const int seed, Ref<DungeonRoom> dungeon_room) {
Ref<DungeonCorridor> inst = dungeon_room;
if (!inst.is_valid())
inst.instance();
Ref<DungeonRoom> DungeonCorridor::_instance(const int seed, Ref<DungeonRoom> inst) {
DungeonRoom::_instance(seed, inst);
inst->set_max_connections(_max_connections);
Ref<DungeonCorridor> cinst = inst;
cinst->set_max_connections(_max_connections);
return inst;
return cinst;
}
DungeonCorridor::DungeonCorridor() {

View File

@ -40,7 +40,7 @@ public:
int get_dungeon_room_count() const;
Ref<DungeonRoom> _instance(const int seed, Ref<DungeonRoom> dungeon_room);
Ref<DungeonRoom> _instance(const int seed, Ref<DungeonRoom> inst);
DungeonCorridor();
~DungeonCorridor();

View File

@ -321,22 +321,18 @@ void DungeonRoom::set_entity_datas(const Vector<Variant> &entity_datas) {
#endif
Ref<DungeonRoom> DungeonRoom::instance(const int seed) {
if (has_method("_instance")) {
return call("_instance", seed, Ref<DungeonRoom>());
}
Ref<DungeonRoom> inst;
return Ref<DungeonRoom>();
}
inst = Ref<DungeonRoom>(Object::cast_to<DungeonRoom>(ClassDB::instance(get_class_name())));
ERR_FAIL_COND_V(!inst.is_valid(), inst);
Ref<DungeonRoom> DungeonRoom::_instance(const int seed, Ref<DungeonRoom> dungeon_room) {
Ref<DungeonRoom> inst = dungeon_room;
if (!inst.is_valid())
inst.instance();
if (inst->get_script().is_null() && !get_script().is_null())
if (!get_script().is_null())
inst->set_script(get_script());
return call("_instance", seed, inst);
}
Ref<DungeonRoom> DungeonRoom::_instance(const int seed, Ref<DungeonRoom> inst) {
inst->set_current_seed(seed);
inst->set_level_range(_level_range);

View File

@ -156,7 +156,7 @@ public:
#endif
Ref<DungeonRoom> instance(const int seed);
virtual Ref<DungeonRoom> _instance(const int seed, Ref<DungeonRoom> dungeon_room);
virtual Ref<DungeonRoom> _instance(const int seed, Ref<DungeonRoom> inst);
void setup();

View File

@ -226,22 +226,18 @@ void Planet::set_voxel_surfaces(const Vector<Variant> &voxel_surfaces) {
#endif
Ref<Planet> Planet::instance(const int seed) {
if (has_method("_instance")) {
return call("_instance", seed, Ref<Planet>());
}
Ref<Planet> inst;
return Ref<Planet>();
}
inst = Ref<Planet>(Object::cast_to<Planet>(ClassDB::instance(get_class_name())));
ERR_FAIL_COND_V(!inst.is_valid(), inst);
Ref<Planet> Planet::_instance(const int seed, Ref<Planet> planet) {
Ref<Planet> inst = planet;
if (!inst.is_valid())
inst.instance();
if (inst->get_script().is_null() && !get_script().is_null())
if (!get_script().is_null())
inst->set_script(get_script());
return call("_instance", seed, inst);
}
Ref<Planet> Planet::_instance(const int seed, Ref<Planet> inst) {
inst->set_id(_id);
inst->set_current_seed(seed);
inst->set_level_range(_level_range);

View File

@ -109,7 +109,7 @@ public:
#endif
Ref<Planet> instance(const int seed);
virtual Ref<Planet> _instance(const int seed, Ref<Planet> planet);
virtual Ref<Planet> _instance(const int seed, Ref<Planet> inst);
void setup();