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 #endif
Ref<Biome> Biome::instance(const int seed) { Ref<Biome> Biome::instance(const int seed) {
if (has_method("_instance")) { Ref<Biome> inst;
return call("_instance", seed, Ref<Biome>());
}
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) { if (!get_script().is_null())
Ref<Biome> inst = biome;
if (!inst.is_valid())
inst.instance();
if (inst->get_script().is_null() && !get_script().is_null())
inst->set_script(get_script()); 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_current_seed(seed);
inst->set_level_range(_level_range); inst->set_level_range(_level_range);

View File

@ -119,7 +119,7 @@ public:
#endif #endif
Ref<Biome> instance(const int seed); 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(); void setup();

View File

@ -463,22 +463,18 @@ void Dungeon::set_environment_datas(const Vector<Variant> &environment_datas) {
#endif #endif
Ref<Dungeon> Dungeon::instance(const int seed) { Ref<Dungeon> Dungeon::instance(const int seed) {
if (has_method("_instance")) { Ref<Dungeon> inst;
return call("_instance", seed, Ref<Dungeon>());
}
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) { if (!get_script().is_null())
Ref<Dungeon> inst = dungeon;
if (!inst.is_valid())
inst.instance();
if (inst->get_script().is_null() && !get_script().is_null())
inst->set_script(get_script()); 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_current_seed(seed);
inst->set_level_range(_level_range); inst->set_level_range(_level_range);

View File

@ -187,7 +187,7 @@ public:
#endif #endif
Ref<Dungeon> instance(const int seed); 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(); void setup();

View File

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

View File

@ -40,7 +40,7 @@ public:
int get_dungeon_room_count() const; 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();
~DungeonCorridor(); ~DungeonCorridor();

View File

@ -321,22 +321,18 @@ void DungeonRoom::set_entity_datas(const Vector<Variant> &entity_datas) {
#endif #endif
Ref<DungeonRoom> DungeonRoom::instance(const int seed) { Ref<DungeonRoom> DungeonRoom::instance(const int seed) {
if (has_method("_instance")) { Ref<DungeonRoom> inst;
return call("_instance", seed, Ref<DungeonRoom>());
}
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) { if (!get_script().is_null())
Ref<DungeonRoom> inst = dungeon_room;
if (!inst.is_valid())
inst.instance();
if (inst->get_script().is_null() && !get_script().is_null())
inst->set_script(get_script()); 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_current_seed(seed);
inst->set_level_range(_level_range); inst->set_level_range(_level_range);

View File

@ -156,7 +156,7 @@ public:
#endif #endif
Ref<DungeonRoom> instance(const int seed); 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(); void setup();

View File

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

View File

@ -109,7 +109,7 @@ public:
#endif #endif
Ref<Planet> instance(const int seed); 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(); void setup();