feat: gameroot will now spawn players using spawn_at_position
parent
90d8d626a0
commit
d81ad91a88
|
@ -185,11 +185,17 @@ Level3D *GameRoot3D::load_level_at(Ref<PackedScene> level, Transform3D at) {
|
||||||
this->levels.insert(level->get_path(), instance);
|
this->levels.insert(level->get_path(), instance);
|
||||||
// store and add to tree at desired transform
|
// store and add to tree at desired transform
|
||||||
// if this is the first level containing a game mode currently active use it's gamemode as a prototype
|
// if this is the first level containing a game mode currently active use it's gamemode as a prototype
|
||||||
if(this->game_mode.is_null()) {
|
bool const switch_game_mode{this->game_mode.is_null()};
|
||||||
|
if(switch_game_mode) {
|
||||||
this->set_game_mode(instance->get_game_mode_prototype());
|
this->set_game_mode(instance->get_game_mode_prototype());
|
||||||
}
|
}
|
||||||
this->add_child(instance);
|
this->add_child(instance);
|
||||||
instance->set_global_transform(at);
|
instance->set_global_transform(at);
|
||||||
|
if(switch_game_mode) {
|
||||||
|
for(KeyValue<uint32_t, Pair<PlayerInput *, IPlayer *>> const &kvp : this->players) {
|
||||||
|
this->place_player_at_spawnpoint(kvp.value.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,6 +215,12 @@ void GameRoot3D::unregister_spawn_point(SpawnPoint3D *spawn_point) {
|
||||||
this->spawn_points.erase(spawn_point);
|
this->spawn_points.erase(spawn_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameRoot3D::place_player_at_spawnpoint(IPlayer *player) {
|
||||||
|
if(this->spawn_points.is_empty()) return;
|
||||||
|
SpawnPoint3D *spawn_point = *this->spawn_points.begin();
|
||||||
|
player->spawn_at_position(spawn_point->get_global_transform());
|
||||||
|
}
|
||||||
|
|
||||||
void GameRoot3D::set_first_boot_level(Ref<PackedScene> level) {
|
void GameRoot3D::set_first_boot_level(Ref<PackedScene> level) {
|
||||||
if(level.is_null() || !level.is_valid()) {
|
if(level.is_null() || !level.is_valid()) {
|
||||||
this->first_boot_level.unref();
|
this->first_boot_level.unref();
|
||||||
|
|
|
@ -78,6 +78,7 @@ public:
|
||||||
void register_spawn_point(SpawnPoint3D *spawn_point);
|
void register_spawn_point(SpawnPoint3D *spawn_point);
|
||||||
// remove a spawnpoint so it can't be used to spawn players
|
// remove a spawnpoint so it can't be used to spawn players
|
||||||
void unregister_spawn_point(SpawnPoint3D *spawn_point);
|
void unregister_spawn_point(SpawnPoint3D *spawn_point);
|
||||||
|
void place_player_at_spawnpoint(IPlayer *player);
|
||||||
|
|
||||||
// ----- getter / setters -----
|
// ----- getter / setters -----
|
||||||
void set_first_boot_level(Ref<PackedScene> level);
|
void set_first_boot_level(Ref<PackedScene> level);
|
||||||
|
|
Loading…
Reference in New Issue