feat: documentation updates

stripped
Sara 2024-05-30 15:42:53 +02:00
parent 67abbadbf1
commit 4ce27c38c6
3 changed files with 54 additions and 11 deletions

View File

@ -11,6 +11,7 @@ namespace utils {
* *
* Inheriting classes are intended to keep only data that is relevant for the duration of the current session/match. Use GameState instead if you want data to be saved between sessions. * Inheriting classes are intended to keep only data that is relevant for the duration of the current session/match. Use GameState instead if you want data to be saved between sessions.
* Will be destroyed when a level is loaded that does not match the same game mode class. * Will be destroyed when a level is loaded that does not match the same game mode class.
* The current active game mode can be gotten from the GameRoot3D singleton instance.
*/ */
class GameMode : public gd::Node { class GameMode : public gd::Node {
GDCLASS(GameMode, gd::Node); GDCLASS(GameMode, gd::Node);

View File

@ -44,6 +44,8 @@ void GameRoot3D::_enter_tree() { GDGAMEONLY();
void GameRoot3D::_ready() { GDGAMEONLY(); void GameRoot3D::_ready() { GDGAMEONLY();
this->load_level(this->first_boot_level); this->load_level(this->first_boot_level);
// TODO: try load save data from file.
this->game_state = this->game_state_prototype->duplicate(true);
} }
void GameRoot3D::_exit_tree() { GDGAMEONLY(); void GameRoot3D::_exit_tree() { GDGAMEONLY();
@ -250,6 +252,10 @@ gd::Ref<GameState> GameRoot3D::get_game_state_prototype() const {
return this->game_state_prototype; return this->game_state_prototype;
} }
gd::RandomNumberGenerator &GameRoot3D::get_rng() {
return this->rng;
}
void GameRoot3D::grab_singleton() { void GameRoot3D::grab_singleton() {
if(GameRoot3D::has_singleton()) { if(GameRoot3D::has_singleton()) {
this->set_process_mode(PROCESS_MODE_DISABLED); this->set_process_mode(PROCESS_MODE_DISABLED);

View File

@ -109,6 +109,7 @@ public:
gd::Ref<gd::PackedScene> get_first_boot_level() const; gd::Ref<gd::PackedScene> get_first_boot_level() const;
void set_game_state_prototype(gd::Ref<GameState> game_state); void set_game_state_prototype(gd::Ref<GameState> game_state);
gd::Ref<GameState> get_game_state_prototype() const; gd::Ref<GameState> get_game_state_prototype() const;
gd::RandomNumberGenerator &get_rng();
protected: protected:
//! Attempt to make 'this' the current singleton instance. //! Attempt to make 'this' the current singleton instance.
void grab_singleton(); void grab_singleton();
@ -127,22 +128,57 @@ protected:
static bool is_valid_level(gd::Ref<gd::PackedScene> &level); static bool is_valid_level(gd::Ref<gd::PackedScene> &level);
private: private:
static GameRoot3D *singleton_instance; static GameRoot3D *singleton_instance;
/*! Next available player ID.
uint32_t next_player_id{1}; //!< Next available player ID. Default is 1 because 0 is the "invalid" player id. *
gd::HashMap<uint32_t, gd::Pair<PlayerInput*, IPlayer*>> players{}; //!< all players by id by input device. * Default is 1 because 0 is the "invalid" player id.
*/
gd::RandomNumberGenerator rng{}; //!< Global random number generator. uint32_t next_player_id{1};
gd::HashMap<gd::StringName, Level3D*> levels{}; //!< all currently active levels identified by their resource paths. /*! All players by id by input device.
gd::Vector<SpawnPoint3D*> spawn_points{}; //!< all currently available spawn points. *
GameMode *game_mode{}; //!< current active gamemode. * `get_players()`
*/
gd::HashMap<uint32_t, gd::Pair<PlayerInput*, IPlayer*>> players{};
/*! Global random number generator.
*
* `&get_rng()`
*/
gd::RandomNumberGenerator rng{};
/*! All currently active levels.
*
* Each identified by their resource paths.
*
* `&get_levels()`
*/
gd::HashMap<gd::StringName, Level3D*> levels{};
/*! All currently available spawn points.
*/
gd::Vector<SpawnPoint3D*> spawn_points{};
/*! Current active gamemode.
*
* Replaced when a level is loaded that references a different game mode.
*
* `*get_game_mode()`
*/
GameMode *game_mode{};
/*! Active game state. /*! Active game state.
* *
* Will be assigned loaded save data, or game_state_prototype if no save data is found. * Will be assigned loaded save data, or game_state_prototype if no save data is found.
*
* `*get_game_mode()`
*/ */
gd::Ref<GameState> game_state{}; gd::Ref<GameState> game_state{};
/*! The level to boot into on startup.
gd::Ref<gd::PackedScene> first_boot_level{}; //!< The level to boot into on startup. *
gd::Ref<GameState> game_state_prototype{}; //!< The default game state data used for game_state if no save data is available. * `get_first_boot_level()` `set_first_boot_level(value)`
*/
gd::Ref<gd::PackedScene> first_boot_level{};
/*! The default game state data.
*
* Duplicated and assigned to game_state if no save data is available.
*
* `get_game_state_prototype()` `set_game_state_prototype(value)`
*/
gd::Ref<GameState> game_state_prototype{};
}; };
} }