mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-08-20 05:16:24 -04:00
Gamemode -> GameMode
This commit is contained in:
+11
-11
@@ -636,7 +636,7 @@ first in-game frame. Projection matrices match the renderer's WebGPU clip conven
|
||||
Camera operators allow overriding the main camera. When an operator callback returns true, its values replace the camera
|
||||
state for the current frame. Register and unregister using `register_camera_operator` / `unregister_camera_operator`.
|
||||
|
||||
### GamemodeService (`mods/svc/gamemode.h`)
|
||||
### GameModeService (`mods/svc/gamemode.h`)
|
||||
|
||||
Allows a mod to register a gamemode that allows the game to designate one form of gameplay (named a gamemode). This
|
||||
is intended to allow large mods that change large amounts of game logic (such as a randomizer) to have explicit control
|
||||
@@ -651,7 +651,7 @@ Note: for any gamemode wishing to use the vanilla set of savefiles, use `gczelda
|
||||
// An example that shows registering a gamemode with function hooks that are scoped to the gamemode being active
|
||||
IMPORT_SERVICE(LogService, svc_log);
|
||||
IMPORT_SERVICE(HookService, svc_hook);
|
||||
IMPORT_SERVICE(GamemodeService, svc_gamemode);
|
||||
IMPORT_SERVICE(GameModeService, svc_gamemode);
|
||||
|
||||
#define MY_GAMEMODE_ID "gamemodeid"
|
||||
|
||||
@@ -665,7 +665,7 @@ static HookAction myFunctionHook(ModContext *ctx, void *args, void *, void *) {
|
||||
|
||||
DEFINE_HOOK(fopAcM_createItem, CreateItem);
|
||||
|
||||
void onGamemodeActivated() {
|
||||
void onGameModeActivated() {
|
||||
// Setup the gamemode, Add any hooks that are gamemode specific
|
||||
// Overlay any files that are gamemode specific
|
||||
ModResult result = mods::hook_add_pre<CreateItem>(svc_hook, myFunctionHook);
|
||||
@@ -674,7 +674,7 @@ void onGamemodeActivated() {
|
||||
}
|
||||
}
|
||||
|
||||
void onGamemodeDeactivated() {
|
||||
void onGameModeDeactivated() {
|
||||
// Uninstall any hooks that are gamemode specific
|
||||
// Remove overlays to any files that are gamemode specific
|
||||
ModResult result = mods::hook_uninstall<CreateItem>();
|
||||
@@ -688,14 +688,14 @@ void onSaveLoaded() {
|
||||
}
|
||||
|
||||
// Register the gamemode when the mod is initialized
|
||||
const GamemodeDesc gamemodeDesc = {
|
||||
const GameModeDesc gamemodeDesc = {
|
||||
.gamemodeId = MY_GAMEMODE_ID,
|
||||
.fullName = "Gamemode Name",
|
||||
.fullName = "GameMode Name",
|
||||
// The save name should be something that other gamemodes will not try to use, so appending your name to it
|
||||
// is reccomended. Note: it is limited to 31 characters long
|
||||
.saveName = "my-unique-save_developer-name",
|
||||
.onActivatedFunction = onGamemodeActivated, // Called when the gamemode is selected on the prelaunch menu (or is launched)
|
||||
.onDeactivatedFunction = onGamemodeDeactivated, // Called when the gamemode is deselected on the prelaunch menu (or the mod is disabled)
|
||||
.onActivatedFunction = onGameModeActivated, // Called when the gamemode is selected on the prelaunch menu (or is launched)
|
||||
.onDeactivatedFunction = onGameModeDeactivated, // Called when the gamemode is deselected on the prelaunch menu (or the mod is disabled)
|
||||
.onPlayFunction = nullptr, // Called when "Play" is pressed on the prelaunch menu
|
||||
.onSaveLoadedFunction = onSaveLoaded, // Called when a save is loaded
|
||||
.onNewSaveFunction = nullptr, // Called after a new savefile is created
|
||||
@@ -710,7 +710,7 @@ Within the gamemode service, a gamemode can also request to load a UI for per-sa
|
||||
create a new file is pressed.
|
||||
|
||||
```cpp
|
||||
IMPORT_SERVICE(GamemodeService, svc_gamemode);
|
||||
IMPORT_SERVICE(GameModeService, svc_gamemode);
|
||||
IMPORT_SERVICE(UiService, svc_ui);
|
||||
|
||||
void onNewSaveSelect(bool *out_proceedToNameSelect, bool *out_returnToFileSelect) {
|
||||
@@ -753,9 +753,9 @@ void onNewSaveSelect(bool *out_proceedToNameSelect, bool *out_returnToFileSelect
|
||||
svc_ui->window_push(mod_ctx, &desc, &windowHandle);
|
||||
}
|
||||
|
||||
const GamemodeDesc gamemodeDesc = {
|
||||
const GameModeDesc gamemodeDesc = {
|
||||
.gamemodeId = "my-gamemode-id",
|
||||
.fullName = "My Gamemode",
|
||||
.fullName = "My GameMode",
|
||||
.saveName = "my-gamemode-save",
|
||||
.onNewSaveSelectFunction = onNewSaveSelect,
|
||||
};
|
||||
|
||||
@@ -740,9 +740,9 @@ public:
|
||||
#endif
|
||||
#ifdef TARGET_PC
|
||||
dDlst_FileSelFade_c mFadeDlst;
|
||||
bool mGamemodeSaveStartBuildUi = true;
|
||||
bool mGamemodeProceedToNameSelect = false;
|
||||
bool mGamemodeReturnToFileSelect = false;
|
||||
bool mGameModeSaveStartBuildUi = true;
|
||||
bool mGameModeProceedToNameSelect = false;
|
||||
bool mGameModeReturnToFileSelect = false;
|
||||
#endif
|
||||
|
||||
#if PLATFORM_WII || PLATFORM_SHIELD
|
||||
|
||||
@@ -21,20 +21,20 @@ typedef struct {
|
||||
// completed
|
||||
void (*onGameResetFunction)(); // Called when the game is reset
|
||||
void (*onTickFunction)(); // Called on every tick
|
||||
} GamemodeDesc;
|
||||
} GameModeDesc;
|
||||
|
||||
typedef struct GamemodeService {
|
||||
typedef struct GameModeService {
|
||||
ServiceHeader header;
|
||||
ModResult (*register_gamemode)(ModContext* ctx, const GamemodeDesc* desc);
|
||||
ModResult (*unregister_gamemode)(ModContext* ctx, const char* id);
|
||||
ModResult (*register_game_mode)(ModContext* ctx, const GameModeDesc* desc);
|
||||
ModResult (*unregister_game_mode)(ModContext* ctx, const char* id);
|
||||
ModResult (*is_active)(ModContext* ctx, const char* gamemodeId, bool* out_active);
|
||||
} GamemodeService;
|
||||
} GameModeService;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include "mods/service.hpp"
|
||||
|
||||
template <>
|
||||
struct mods::ServiceTraits<GamemodeService> {
|
||||
struct mods::ServiceTraits<GameModeService> {
|
||||
static constexpr const char* id = GAMEMODE_SERVICE_ID;
|
||||
static constexpr uint16_t major_version = GAMEMODE_SERVICE_MAJOR;
|
||||
static constexpr uint16_t minor_version = GAMEMODE_SERVICE_MINOR;
|
||||
|
||||
+14
-14
@@ -1315,21 +1315,21 @@ void dFile_select_c::selectDataNameMove() {
|
||||
bool isModoruTxtDisp = modoruTxtDispAnm();
|
||||
|
||||
#ifdef TARGET_PC
|
||||
const dusk::gamemode::Gamemode* gamemode = dusk::gamemode::getGamemodeManager().getCurrentGamemode();
|
||||
const dusk::gamemode::GameMode* gamemode = dusk::gamemode::getGameModeManager().getCurrentGameMode();
|
||||
if (gamemode) {
|
||||
if (isHeaderTxtChange == true && isFileRecScale == true && isModoruTxtDisp == true) {
|
||||
if (mGamemodeSaveStartBuildUi) {
|
||||
gamemode->invokeOnNewSaveSelectFunction(&mGamemodeProceedToNameSelect, &mGamemodeReturnToFileSelect);
|
||||
mGamemodeSaveStartBuildUi = false;
|
||||
if (mGameModeSaveStartBuildUi) {
|
||||
gamemode->invokeOnNewSaveSelectFunction(&mGameModeProceedToNameSelect, &mGameModeReturnToFileSelect);
|
||||
mGameModeSaveStartBuildUi = false;
|
||||
}
|
||||
if (mGamemodeReturnToFileSelect) {
|
||||
if (mGameModeReturnToFileSelect) {
|
||||
backToDataSelectMove();
|
||||
mGamemodeSaveStartBuildUi = true;
|
||||
mGamemodeProceedToNameSelect = false;
|
||||
mGamemodeReturnToFileSelect = false;
|
||||
mGameModeSaveStartBuildUi = true;
|
||||
mGameModeProceedToNameSelect = false;
|
||||
mGameModeReturnToFileSelect = false;
|
||||
return;
|
||||
}
|
||||
if (!mGamemodeProceedToNameSelect) {
|
||||
if (!mGameModeProceedToNameSelect) {
|
||||
return;
|
||||
}
|
||||
}else {
|
||||
@@ -1344,9 +1344,9 @@ void dFile_select_c::selectDataNameMove() {
|
||||
isModoruTxtDisp == true)
|
||||
{
|
||||
#ifdef TARGET_PC
|
||||
mGamemodeSaveStartBuildUi = true;
|
||||
mGamemodeProceedToNameSelect = false;
|
||||
mGamemodeReturnToFileSelect = false;
|
||||
mGameModeSaveStartBuildUi = true;
|
||||
mGameModeProceedToNameSelect = false;
|
||||
mGameModeReturnToFileSelect = false;
|
||||
#endif
|
||||
mDataSelProc = DATASELPROC_NAME_INPUT_WAIT;
|
||||
}
|
||||
@@ -1430,7 +1430,7 @@ void dFile_select_c::menuSelectStart() {
|
||||
#if TARGET_PC
|
||||
dusk::mods::svc::save_slot_loaded(mSelectNum, &mSaveData[mSelectNum]);
|
||||
|
||||
const dusk::gamemode::Gamemode* gamemode = dusk::gamemode::getGamemodeManager().getCurrentGamemode();
|
||||
const dusk::gamemode::GameMode* gamemode = dusk::gamemode::getGameModeManager().getCurrentGameMode();
|
||||
if (gamemode) {
|
||||
gamemode->invokeOnSaveLoadedFunction();
|
||||
}
|
||||
@@ -1787,7 +1787,7 @@ void dFile_select_c::nameInput2() {
|
||||
mIsSelectEnd = true;
|
||||
#if TARGET_PC
|
||||
dusk::mods::svc::save_slot_new(mSelectNum);
|
||||
const dusk::gamemode::Gamemode* gamemode = dusk::gamemode::getGamemodeManager().getCurrentGamemode();
|
||||
const dusk::gamemode::GameMode* gamemode = dusk::gamemode::getGameModeManager().getCurrentGameMode();
|
||||
if (gamemode) {
|
||||
gamemode->invokeOnNewSaveFunction();
|
||||
gamemode->invokeOnSaveLoadedFunction();
|
||||
|
||||
+1
-1
@@ -809,7 +809,7 @@ void dScnLogo_c::nextSceneChange() {
|
||||
if (status == 1) {
|
||||
dusk::mods::svc::save_slot_loaded(
|
||||
saveSlot, buf + saveSlot * SAVEDATA_SIZE);
|
||||
const dusk::gamemode::Gamemode* gamemode = dusk::gamemode::getGamemodeManager().getCurrentGamemode();
|
||||
const dusk::gamemode::GameMode* gamemode = dusk::gamemode::getGameModeManager().getCurrentGameMode();
|
||||
if (gamemode) {
|
||||
gamemode->invokeOnSaveLoadedFunction();
|
||||
}
|
||||
|
||||
@@ -1305,8 +1305,8 @@ void AchievementSystem::processEntry(Entry& e) {
|
||||
|
||||
void AchievementSystem::tick() {
|
||||
// Until we implement an AchievementService, achievements will be unavailible in custom gamemodes
|
||||
if (dusk::gamemode::getGamemodeManager().isCurrentGamemode(dusk::gamemode::kVanillaGamemodeId) == false
|
||||
&& dusk::gamemode::getGamemodeManager().isCurrentGamemode(dusk::speedrun::kSpeedrunGamemodeId) == false) {
|
||||
if (dusk::gamemode::getGameModeManager().isCurrentGameMode(dusk::gamemode::kVanillaGameModeId) == false
|
||||
&& dusk::gamemode::getGameModeManager().isCurrentGameMode(dusk::speedrun::kSpeedrunGameModeId) == false) {
|
||||
m_signals.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
+37
-37
@@ -7,85 +7,85 @@
|
||||
|
||||
namespace dusk::gamemode {
|
||||
|
||||
GamemodeManager g_GamemodeManager;
|
||||
GameModeManager g_GameModeManager;
|
||||
|
||||
aurora::Module DuskGamemodeLog("dusk::gamemode");
|
||||
aurora::Module DuskGameModeLog("dusk::gamemode");
|
||||
|
||||
GamemodeManager::GamemodeManager() {
|
||||
registerGamemode(Gamemode(kVanillaGamemodeId,"Vanilla","gczelda2"));
|
||||
mCurrentGamemodeId = kVanillaGamemodeId;
|
||||
GameModeManager::GameModeManager() {
|
||||
registerGameMode(GameMode(kVanillaGameModeId,"Vanilla","gczelda2"));
|
||||
mCurrentGameModeId = kVanillaGameModeId;
|
||||
}
|
||||
|
||||
void GamemodeManager::setGamemodeToPrevious() {
|
||||
void GameModeManager::setGameModeToPrevious() {
|
||||
// Gets the value from the settings of the last played gamemode id and sets that to the current gamemode (if registered)
|
||||
GamemodeId id = dusk::getSettings().game.lastSelectedGamemodeId;
|
||||
if (mRegisteredGamemodes.find(id) == mRegisteredGamemodes.end()) {
|
||||
setCurrentGamemode(kVanillaGamemodeId);
|
||||
GameModeId id = dusk::getSettings().game.lastSelectedGameModeId;
|
||||
if (mRegisteredGameModes.find(id) == mRegisteredGameModes.end()) {
|
||||
setCurrentGameMode(kVanillaGameModeId);
|
||||
return;
|
||||
}
|
||||
setCurrentGamemode(id);
|
||||
setCurrentGameMode(id);
|
||||
}
|
||||
|
||||
void GamemodeManager::registerGamemode(const Gamemode& gamemode) {
|
||||
void GameModeManager::registerGameMode(const GameMode& gamemode) {
|
||||
if (gamemode.getId().empty()) {
|
||||
DuskGamemodeLog.fatal("No gamemode id specified in GamemodeManager::registerGamemode!");
|
||||
DuskGameModeLog.fatal("No gamemode id specified in GameModeManager::registerGameMode!");
|
||||
}
|
||||
if (gamemode.getSaveName().empty()) {
|
||||
DuskGamemodeLog.fatal("No save name provided for gamemode {}", gamemode.getId());
|
||||
DuskGameModeLog.fatal("No save name provided for gamemode {}", gamemode.getId());
|
||||
}
|
||||
if (gamemode.getFullName().empty()) {
|
||||
DuskGamemodeLog.fatal("No Name Specified for gamemode {}", gamemode.getId());
|
||||
DuskGameModeLog.fatal("No Name Specified for gamemode {}", gamemode.getId());
|
||||
}
|
||||
|
||||
if (mRegisteredGamemodes.find(gamemode.getId()) != mRegisteredGamemodes.end()) {
|
||||
DuskGamemodeLog.warn("Attempting to register gamemode {} when it is already registered!", gamemode.getId());
|
||||
if (mRegisteredGameModes.find(gamemode.getId()) != mRegisteredGameModes.end()) {
|
||||
DuskGameModeLog.warn("Attempting to register gamemode {} when it is already registered!", gamemode.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
mRegisteredGamemodes.emplace(gamemode.getId(),gamemode);
|
||||
mRegisteredGameModes.emplace(gamemode.getId(),gamemode);
|
||||
dusk::ui::Prelaunch::rebuild_menu_buttons();
|
||||
}
|
||||
|
||||
void GamemodeManager::unregisterGamemode(const GamemodeId& gamemodeId) {
|
||||
const auto& it = mRegisteredGamemodes.find(gamemodeId);
|
||||
if (it == mRegisteredGamemodes.end()) {
|
||||
DuskGamemodeLog.warn(
|
||||
void GameModeManager::unregisterGameMode(const GameModeId& gamemodeId) {
|
||||
const auto& it = mRegisteredGameModes.find(gamemodeId);
|
||||
if (it == mRegisteredGameModes.end()) {
|
||||
DuskGameModeLog.warn(
|
||||
"Attempting to unregister gamemode of id {} that isn't registered!", gamemodeId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mCurrentGamemodeId == gamemodeId) {
|
||||
if (mCurrentGameModeId == gamemodeId) {
|
||||
// We need to be careful if we are unregistering a running gamemode, the easiest way is just
|
||||
// to reset the game back to title as vanilla;
|
||||
ui::prelaunch_state().showPrelaunchOnReset = true;
|
||||
JUTGamePad::C3ButtonReset::sResetSwitchPushing = true;
|
||||
setCurrentGamemode(kVanillaGamemodeId);
|
||||
setCurrentGameMode(kVanillaGameModeId);
|
||||
}
|
||||
mRegisteredGamemodes.erase(it);
|
||||
mRegisteredGameModes.erase(it);
|
||||
dusk::ui::Prelaunch::rebuild_menu_buttons();
|
||||
}
|
||||
|
||||
void GamemodeManager::setCurrentGamemode(const GamemodeId& id) {
|
||||
if (mCurrentGamemodeId == id) {
|
||||
void GameModeManager::setCurrentGameMode(const GameModeId& id) {
|
||||
if (mCurrentGameModeId == id) {
|
||||
return;
|
||||
}
|
||||
const Gamemode* currentGamemode = getCurrentGamemode();
|
||||
if (currentGamemode) {
|
||||
currentGamemode->invokeOnDeactivatedFunction();
|
||||
const GameMode* currentGameMode = getCurrentGameMode();
|
||||
if (currentGameMode) {
|
||||
currentGameMode->invokeOnDeactivatedFunction();
|
||||
}
|
||||
if (mRegisteredGamemodes.find(id) == mRegisteredGamemodes.end()) {
|
||||
DuskGamemodeLog.warn("Attempting to set current game mode to {} when it hasn't been registered!", id);
|
||||
if (mRegisteredGameModes.find(id) == mRegisteredGameModes.end()) {
|
||||
DuskGameModeLog.warn("Attempting to set current game mode to {} when it hasn't been registered!", id);
|
||||
}
|
||||
|
||||
mCurrentGamemodeId = id;
|
||||
dusk::getSettings().game.lastSelectedGamemodeId.setValue(id);
|
||||
mCurrentGameModeId = id;
|
||||
dusk::getSettings().game.lastSelectedGameModeId.setValue(id);
|
||||
dusk::config::save();
|
||||
|
||||
currentGamemode = getCurrentGamemode();
|
||||
if (currentGamemode) {
|
||||
currentGameMode = getCurrentGameMode();
|
||||
if (currentGameMode) {
|
||||
// Set the loaded save file to our gamemode's save name
|
||||
mDoMemCd_SetFileName(currentGamemode->mSaveName);
|
||||
currentGamemode->invokeOnActivatedFunction();
|
||||
mDoMemCd_SetFileName(currentGameMode->mSaveName);
|
||||
currentGameMode->invokeOnActivatedFunction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-23
@@ -4,23 +4,23 @@
|
||||
#include "d/d_file_select.h"
|
||||
|
||||
namespace dusk::gamemode {
|
||||
using GamemodeId = std::string;
|
||||
using GameModeId = std::string;
|
||||
|
||||
constexpr const char* kVanillaGamemodeId = "vanilla";
|
||||
constexpr const char* kVanillaGameModeId = "vanilla";
|
||||
|
||||
// This class holds the definition for the gamemode and various function pointers to call
|
||||
class Gamemode {
|
||||
class GameMode {
|
||||
public:
|
||||
Gamemode(const GamemodeId& id, const std::string& fullName, const std::string& saveName) {
|
||||
GameMode(const GameModeId& id, const std::string& fullName, const std::string& saveName) {
|
||||
mId = id;
|
||||
mFullName = fullName;
|
||||
mSaveName = saveName;
|
||||
}
|
||||
const GamemodeId& getId() const { return mId; }
|
||||
const GameModeId& getId() const { return mId; }
|
||||
const std::string& getFullName() const { return mFullName; }
|
||||
const std::string& getSaveName() const { return mSaveName; }
|
||||
|
||||
GamemodeId mId;
|
||||
GameModeId mId;
|
||||
std::string mFullName;
|
||||
std::string mSaveName;
|
||||
|
||||
@@ -84,37 +84,37 @@ public:
|
||||
std::function<void()> mOnTickFunction;
|
||||
};
|
||||
|
||||
class GamemodeManager {
|
||||
class GameModeManager {
|
||||
public:
|
||||
GamemodeManager();
|
||||
void registerGamemode(const Gamemode& gamemode);
|
||||
void unregisterGamemode(const GamemodeId& gamemodeId);
|
||||
GameModeManager();
|
||||
void registerGameMode(const GameMode& gamemode);
|
||||
void unregisterGameMode(const GameModeId& gamemodeId);
|
||||
|
||||
const Gamemode* getCurrentGamemode() const {
|
||||
const auto& it = mRegisteredGamemodes.find(mCurrentGamemodeId);
|
||||
return it != mRegisteredGamemodes.end() ? &it->second : &mRegisteredGamemodes.at(kVanillaGamemodeId);
|
||||
const GameMode* getCurrentGameMode() const {
|
||||
const auto& it = mRegisteredGameModes.find(mCurrentGameModeId);
|
||||
return it != mRegisteredGameModes.end() ? &it->second : &mRegisteredGameModes.at(kVanillaGameModeId);
|
||||
}
|
||||
bool isCurrentGamemode(const GamemodeId& id) const {
|
||||
const Gamemode* gamemode = getCurrentGamemode();
|
||||
bool isCurrentGameMode(const GameModeId& id) const {
|
||||
const GameMode* gamemode = getCurrentGameMode();
|
||||
if (gamemode && gamemode->getId() == id) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void setCurrentGamemode(const GamemodeId& id);
|
||||
void setGamemodeToPrevious();
|
||||
void setCurrentGameMode(const GameModeId& id);
|
||||
void setGameModeToPrevious();
|
||||
|
||||
std::map<GamemodeId, Gamemode>& getRegisteredGamemodes() { return mRegisteredGamemodes; }
|
||||
std::map<GameModeId, GameMode>& getRegisteredGameModes() { return mRegisteredGameModes; }
|
||||
|
||||
private:
|
||||
GamemodeId mCurrentGamemodeId;
|
||||
std::map<GamemodeId, Gamemode> mRegisteredGamemodes;
|
||||
GameModeId mCurrentGameModeId;
|
||||
std::map<GameModeId, GameMode> mRegisteredGameModes;
|
||||
};
|
||||
|
||||
extern GamemodeManager g_GamemodeManager;
|
||||
extern GameModeManager g_GameModeManager;
|
||||
|
||||
inline GamemodeManager& getGamemodeManager() {
|
||||
return g_GamemodeManager;
|
||||
inline GameModeManager& getGameModeManager() {
|
||||
return g_GameModeManager;
|
||||
}
|
||||
|
||||
}; // namespace dusk::gamemode
|
||||
|
||||
@@ -32,7 +32,7 @@ void gamemode_remove_mod(LoadedMod& mod) {
|
||||
const auto it = s_gamemodesRegisteredToMods.find(mod.metadata.id);
|
||||
if (it != s_gamemodesRegisteredToMods.end()) {
|
||||
for (const auto& id : it->second) {
|
||||
dusk::gamemode::getGamemodeManager().unregisterGamemode(id);
|
||||
dusk::gamemode::getGameModeManager().unregisterGameMode(id);
|
||||
}
|
||||
s_gamemodesRegisteredToMods.erase(it);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ void gamemode_remove_mod(LoadedMod& mod) {
|
||||
} // namespace
|
||||
|
||||
|
||||
ModResult register_gamemode(ModContext* ctx, const GamemodeDesc* desc) {
|
||||
ModResult register_gamemode(ModContext* ctx, const GameModeDesc* desc) {
|
||||
std::string id;
|
||||
if (!desc->gamemodeId) {
|
||||
Log.error("Attempted to register a gamemode with a null id!");
|
||||
@@ -71,7 +71,7 @@ ModResult register_gamemode(ModContext* ctx, const GamemodeDesc* desc) {
|
||||
saveName = "gczelda2";
|
||||
}
|
||||
|
||||
dusk::gamemode::Gamemode gamemode(id, fullName, saveName);
|
||||
dusk::gamemode::GameMode gamemode(id, fullName, saveName);
|
||||
|
||||
if (desc->onActivatedFunction) {
|
||||
gamemode.mOnActivatedFunction = desc->onActivatedFunction;
|
||||
@@ -98,12 +98,12 @@ ModResult register_gamemode(ModContext* ctx, const GamemodeDesc* desc) {
|
||||
gamemode.mOnTickFunction = desc->onTickFunction;
|
||||
}
|
||||
|
||||
dusk::gamemode::getGamemodeManager().registerGamemode(gamemode);
|
||||
dusk::gamemode::getGameModeManager().registerGameMode(gamemode);
|
||||
|
||||
const auto it = s_gamemodesRegisteredToMods.find(ctx->mod->metadata.id);
|
||||
if (it == s_gamemodesRegisteredToMods.end()) {
|
||||
std::vector<std::string> registeredGamemodes = {id};
|
||||
s_gamemodesRegisteredToMods.emplace(ctx->mod->metadata.id, registeredGamemodes);
|
||||
std::vector<std::string> registeredGameModes = {id};
|
||||
s_gamemodesRegisteredToMods.emplace(ctx->mod->metadata.id, registeredGameModes);
|
||||
}else {
|
||||
it->second.push_back(id);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ ModResult register_gamemode(ModContext* ctx, const GamemodeDesc* desc) {
|
||||
|
||||
ModResult unregister_gamemode(ModContext* ctx, const char* id) {
|
||||
std::string fullId = get_mod_gamemode_id(ctx,id);
|
||||
dusk::gamemode::getGamemodeManager().unregisterGamemode(fullId);
|
||||
dusk::gamemode::getGameModeManager().unregisterGameMode(fullId);
|
||||
|
||||
// Remove the gamemode from the service registered gamemodes map
|
||||
auto it = s_gamemodesRegisteredToMods.find(ctx->mod->metadata.id);
|
||||
@@ -124,7 +124,7 @@ ModResult unregister_gamemode(ModContext* ctx, const char* id) {
|
||||
}
|
||||
|
||||
ModResult is_active(ModContext* ctx, const char* gamemodeId, bool* out_active) {
|
||||
*out_active = dusk::gamemode::getGamemodeManager().isCurrentGamemode(get_mod_gamemode_id(ctx,gamemodeId));
|
||||
*out_active = dusk::gamemode::getGameModeManager().isCurrentGameMode(get_mod_gamemode_id(ctx,gamemodeId));
|
||||
return MOD_OK;
|
||||
}
|
||||
|
||||
@@ -133,10 +133,10 @@ ModResult is_active(ModContext* ctx, const char* gamemodeId, bool* out_active) {
|
||||
namespace dusk::mods::svc {
|
||||
namespace {
|
||||
|
||||
constexpr GamemodeService s_gamemodeService{
|
||||
.header = SERVICE_HEADER(GamemodeService, GAMEMODE_SERVICE_MAJOR, GAMEMODE_SERVICE_MINOR),
|
||||
.register_gamemode = gamemode_impl::register_gamemode,
|
||||
.unregister_gamemode = gamemode_impl::unregister_gamemode,
|
||||
constexpr GameModeService s_gamemodeService{
|
||||
.header = SERVICE_HEADER(GameModeService, GAMEMODE_SERVICE_MAJOR, GAMEMODE_SERVICE_MINOR),
|
||||
.register_game_mode = gamemode_impl::register_gamemode,
|
||||
.unregister_game_mode = gamemode_impl::unregister_gamemode,
|
||||
.is_active = gamemode_impl::is_active
|
||||
};
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ UserSettings g_userSettings = {
|
||||
.removeQuestMapMarkers {"game.removeQuestMapMarkers", false},
|
||||
.showInputViewer {"game.showInputViewer", false},
|
||||
.showInputViewerGyro {"game.showInputViewerGyro", false},
|
||||
.lastSelectedGamemodeId {"game.lastSelectedGamemodeId", gamemode::kVanillaGamemodeId}
|
||||
.lastSelectedGameModeId {"game.lastSelectedGameModeId", gamemode::kVanillaGameModeId}
|
||||
},
|
||||
|
||||
.backend = {
|
||||
@@ -308,7 +308,7 @@ void registerSettings() {
|
||||
Register(g_userSettings.game.removeQuestMapMarkers);
|
||||
Register(g_userSettings.game.showInputViewer);
|
||||
Register(g_userSettings.game.showInputViewerGyro);
|
||||
Register(g_userSettings.game.lastSelectedGamemodeId);
|
||||
Register(g_userSettings.game.lastSelectedGameModeId);
|
||||
Register(g_userSettings.game.fastSpinner);
|
||||
Register(g_userSettings.game.infiniteHearts);
|
||||
Register(g_userSettings.game.infiniteArrows);
|
||||
|
||||
+1
-1
@@ -286,7 +286,7 @@ struct UserSettings {
|
||||
ConfigVar<bool> showInputViewer;
|
||||
ConfigVar<bool> showInputViewerGyro;
|
||||
|
||||
ConfigVar<std::string> lastSelectedGamemodeId;
|
||||
ConfigVar<std::string> lastSelectedGameModeId;
|
||||
} game;
|
||||
|
||||
struct {
|
||||
|
||||
@@ -21,18 +21,18 @@ static void onSpeedrunModeDeactive() {
|
||||
}
|
||||
}
|
||||
|
||||
void registerSpeedrunGamemode() {
|
||||
dusk::gamemode::Gamemode speedrunGamemode(kSpeedrunGamemodeId,"Speedrun","gczelda2-speedrun");
|
||||
speedrunGamemode.mOnSaveLoadedFunction = dusk::speedrun::start;
|
||||
speedrunGamemode.mOnActivatedFunction = onSpeedrunModeActive;
|
||||
speedrunGamemode.mOnDeactivatedFunction = onSpeedrunModeDeactive;
|
||||
speedrunGamemode.mOnTickFunction = dusk::speedrun::onGameFrame;
|
||||
void registerSpeedrunGameMode() {
|
||||
dusk::gamemode::GameMode speedrunGameMode(kSpeedrunGameModeId,"Speedrun","gczelda2-speedrun");
|
||||
speedrunGameMode.mOnSaveLoadedFunction = dusk::speedrun::start;
|
||||
speedrunGameMode.mOnActivatedFunction = onSpeedrunModeActive;
|
||||
speedrunGameMode.mOnDeactivatedFunction = onSpeedrunModeDeactive;
|
||||
speedrunGameMode.mOnTickFunction = dusk::speedrun::onGameFrame;
|
||||
|
||||
dusk::gamemode::getGamemodeManager().registerGamemode(speedrunGamemode);
|
||||
dusk::gamemode::getGameModeManager().registerGameMode(speedrunGameMode);
|
||||
}
|
||||
|
||||
void unregisterSpeedrunGamemode() {
|
||||
dusk::gamemode::getGamemodeManager().unregisterGamemode(kSpeedrunGamemodeId);
|
||||
void unregisterSpeedrunGameMode() {
|
||||
dusk::gamemode::getGameModeManager().unregisterGameMode(kSpeedrunGameModeId);
|
||||
}
|
||||
|
||||
void resetForSpeedrunMode() {
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace dusk::speedrun {
|
||||
|
||||
constexpr const char* kSpeedrunGamemodeId = "vanilla_speedrun";
|
||||
constexpr const char* kSpeedrunGameModeId = "vanilla_speedrun";
|
||||
|
||||
struct SpeedrunInfo {
|
||||
|
||||
@@ -47,13 +47,13 @@ struct SpeedrunInfo {
|
||||
|
||||
extern SpeedrunInfo g_speedrunInfo;
|
||||
|
||||
void registerSpeedrunGamemode();
|
||||
void unregisterSpeedrunGamemode();
|
||||
void registerSpeedrunGameMode();
|
||||
void unregisterSpeedrunGameMode();
|
||||
void resetForSpeedrunMode();
|
||||
void restoreFromSpeedrunMode();
|
||||
|
||||
inline bool isActive() {
|
||||
return dusk::gamemode::getGamemodeManager().isCurrentGamemode(kSpeedrunGamemodeId);
|
||||
return dusk::gamemode::getGameModeManager().isCurrentGameMode(kSpeedrunGameModeId);
|
||||
}
|
||||
|
||||
} // namespace dusk
|
||||
|
||||
@@ -64,8 +64,8 @@ MenuBar::MenuBar()
|
||||
}
|
||||
|
||||
// Only allow us to access achievements if we are playing on a gamemode that uses them
|
||||
if (dusk::gamemode::getGamemodeManager().isCurrentGamemode(dusk::gamemode::kVanillaGamemodeId)
|
||||
|| dusk::gamemode::getGamemodeManager().isCurrentGamemode(dusk::speedrun::kSpeedrunGamemodeId)) {
|
||||
if (dusk::gamemode::getGameModeManager().isCurrentGameMode(dusk::gamemode::kVanillaGameModeId)
|
||||
|| dusk::gamemode::getGameModeManager().isCurrentGameMode(dusk::speedrun::kSpeedrunGameModeId)) {
|
||||
mTabBar->add_tab("Achievements", [this] { push(std::make_unique<AchievementsWindow>()); });
|
||||
}
|
||||
mTabBar->add_tab("Mods", [this] { push(std::make_unique<ModsWindow>()); });
|
||||
@@ -100,7 +100,7 @@ MenuBar::MenuBar()
|
||||
return;
|
||||
}
|
||||
dismiss(modal);
|
||||
if (gamemode::getGamemodeManager().getRegisteredGamemodes().size() > 1) {
|
||||
if (gamemode::getGameModeManager().getRegisteredGameModes().size() > 1) {
|
||||
// If we have gamemodes registered, show pre-launch on a menubar reset
|
||||
prelaunch_state().showPrelaunchOnReset = true;
|
||||
Document::hide(true);
|
||||
|
||||
+12
-12
@@ -766,10 +766,10 @@ static std::string get_playbutton_text() {
|
||||
return "Select Disc Image";
|
||||
}
|
||||
std::string playText;
|
||||
const dusk::gamemode::Gamemode* currentGameMode =
|
||||
dusk::gamemode::getGamemodeManager().getCurrentGamemode();
|
||||
const dusk::gamemode::GameMode* currentGameMode =
|
||||
dusk::gamemode::getGameModeManager().getCurrentGameMode();
|
||||
if (currentGameMode != nullptr) {
|
||||
return currentGameMode->getId() == dusk::gamemode::kVanillaGamemodeId ? "Play" :
|
||||
return currentGameMode->getId() == dusk::gamemode::kVanillaGameModeId ? "Play" :
|
||||
"Play " + currentGameMode->getFullName();
|
||||
}
|
||||
return "Play";
|
||||
@@ -821,7 +821,7 @@ Prelaunch::Prelaunch() : Document(kDocumentSource, false, DocumentScope::Prelaun
|
||||
void Prelaunch::build_menu_buttons() {
|
||||
if (auto* menuList = mDocument->GetElementById("menu-list")) {
|
||||
// Set the gamemode to the last used before showing the play button
|
||||
dusk::gamemode::getGamemodeManager().setGamemodeToPrevious();
|
||||
dusk::gamemode::getGameModeManager().setGameModeToPrevious();
|
||||
|
||||
mMenuButtons.push_back(std::make_unique<Button>(menuList, get_playbutton_text()));
|
||||
mMenuButtons.back()->on_pressed([this] {
|
||||
@@ -846,8 +846,8 @@ void Prelaunch::build_menu_buttons() {
|
||||
}
|
||||
|
||||
prelaunch_state().firstLaunch = false;
|
||||
const dusk::gamemode::Gamemode* gamemode =
|
||||
dusk::gamemode::getGamemodeManager().getCurrentGamemode();
|
||||
const dusk::gamemode::GameMode* gamemode =
|
||||
dusk::gamemode::getGameModeManager().getCurrentGameMode();
|
||||
if (gamemode) {
|
||||
gamemode->invokeOnPlayFunction();
|
||||
}
|
||||
@@ -873,28 +873,28 @@ void Prelaunch::build_menu_buttons() {
|
||||
|
||||
// If we have more gamemodes registered than the default vanilla, show the gamemode
|
||||
// selection
|
||||
if (dusk::gamemode::getGamemodeManager().getRegisteredGamemodes().size() > 1) {
|
||||
mMenuButtons.push_back(std::make_unique<Button>(menuList, "Select Gamemode"));
|
||||
if (dusk::gamemode::getGameModeManager().getRegisteredGameModes().size() > 1) {
|
||||
mMenuButtons.push_back(std::make_unique<Button>(menuList, "Select GameMode"));
|
||||
mMenuButtons.back()->on_pressed([this] {
|
||||
std::vector<ModalAction> gamemodeActions;
|
||||
gamemodeActions.push_back(dusk::ui::ModalAction{
|
||||
.label = "Vanilla", .onPressed = [this](dusk::ui::Modal& modal) {
|
||||
mDoAud_seStartMenu(kSoundClick);
|
||||
dusk::gamemode::getGamemodeManager().setCurrentGamemode(dusk::gamemode::kVanillaGamemodeId);
|
||||
dusk::gamemode::getGameModeManager().setCurrentGameMode(dusk::gamemode::kVanillaGameModeId);
|
||||
modal.pop();
|
||||
update();
|
||||
}});
|
||||
for (const auto& [id, gamemode] :
|
||||
dusk::gamemode::getGamemodeManager().getRegisteredGamemodes())
|
||||
dusk::gamemode::getGameModeManager().getRegisteredGameModes())
|
||||
{
|
||||
if (id == dusk::gamemode::kVanillaGamemodeId) {
|
||||
if (id == dusk::gamemode::kVanillaGameModeId) {
|
||||
// Force vanilla to the top
|
||||
continue;
|
||||
}
|
||||
gamemodeActions.push_back(dusk::ui::ModalAction{.label = gamemode.getFullName(),
|
||||
.onPressed = [this, id](dusk::ui::Modal& modal) {
|
||||
mDoAud_seStartMenu(kSoundClick);
|
||||
dusk::gamemode::getGamemodeManager().setCurrentGamemode(id);
|
||||
dusk::gamemode::getGameModeManager().setCurrentGameMode(id);
|
||||
modal.pop();
|
||||
update();
|
||||
}});
|
||||
|
||||
@@ -1239,12 +1239,12 @@ SettingsWindow::SettingsWindow(bool prelaunch) : mPrelaunch(prelaunch) {
|
||||
.onChange =
|
||||
[this](bool enabled) {
|
||||
if (enabled) {
|
||||
dusk::speedrun::registerSpeedrunGamemode();
|
||||
dusk::speedrun::registerSpeedrunGameMode();
|
||||
} else {
|
||||
if (dusk::speedrun::isActive()) {
|
||||
pop();
|
||||
}
|
||||
dusk::speedrun::unregisterSpeedrunGamemode();
|
||||
dusk::speedrun::unregisterSpeedrunGameMode();
|
||||
}
|
||||
MenuBar::rebuild();
|
||||
},
|
||||
|
||||
@@ -846,7 +846,7 @@ void fapGm_Execute() {
|
||||
|
||||
cCt_Counter(0);
|
||||
#ifdef TARGET_PC
|
||||
const dusk::gamemode::Gamemode* gamemode = dusk::gamemode::getGamemodeManager().getCurrentGamemode();
|
||||
const dusk::gamemode::GameMode* gamemode = dusk::gamemode::getGameModeManager().getCurrentGameMode();
|
||||
if (gamemode) {
|
||||
gamemode->invokeOnTickFunction();
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ void checkDiskCallback(s32 result, DVDCommandBlock* block) {
|
||||
|
||||
void mDoRst_resetCallBack(int port, void*) {
|
||||
#ifdef TARGET_PC
|
||||
const dusk::gamemode::Gamemode* gamemode = dusk::gamemode::getGamemodeManager().getCurrentGamemode();
|
||||
const dusk::gamemode::GameMode* gamemode = dusk::gamemode::getGameModeManager().getCurrentGameMode();
|
||||
if (gamemode) {
|
||||
gamemode->invokeOnGameResetFunction();
|
||||
}
|
||||
|
||||
@@ -922,7 +922,7 @@ int game_main(int argc, char* argv[]) {
|
||||
// Apply after aurora_initialize: speedrun mode mutates cvars whose change callbacks push
|
||||
// values into aurora.
|
||||
if (dusk::getSettings().game.speedrunMode) {
|
||||
dusk::speedrun::registerSpeedrunGamemode();
|
||||
dusk::speedrun::registerSpeedrunGameMode();
|
||||
}
|
||||
|
||||
if (parsed_arg_options.contains("mods") &&
|
||||
@@ -938,7 +938,7 @@ int game_main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
if (skipPreLaunchUI == true) {
|
||||
if (dusk::gamemode::getGamemodeManager().getRegisteredGamemodes().size() > 1 && dusk::getSettings().backend.skipPreLaunchUI.getValue()) {
|
||||
if (dusk::gamemode::getGameModeManager().getRegisteredGameModes().size() > 1 && dusk::getSettings().backend.skipPreLaunchUI.getValue()) {
|
||||
// Force pre-launch if we have registered gamemodes that we need to choose from
|
||||
dusk::ui::push_document(std::make_unique<dusk::ui::Prelaunch>(), true);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user