Allow Gamemodes to interrupt flow on file creation

This commit is contained in:
jdflyer
2026-08-07 18:46:52 -07:00
parent ce6850acd3
commit 8be95d3aa3
6 changed files with 115 additions and 12 deletions
+9
View File
@@ -1,6 +1,7 @@
#pragma once
#include <functional>
#include <map>
#include "d/d_file_select.h"
namespace dusk::gamemode {
using GamemodeId = std::string;
@@ -50,6 +51,13 @@ public:
mOnNewSaveFunction();
}
}
bool invokeOnNewSaveSelectFunction(dFile_select_c* fileSelect) const {
if (mOnNewSaveSelectFunction) {
return mOnNewSaveSelectFunction(fileSelect);
}
return true;
}
void invokeOnGameResetFunction() const {
if (mOnGameResetFunction) {
@@ -68,6 +76,7 @@ public:
std::function<void()> mOnPlayFunction;
std::function<void()> mOnSaveLoadedFunction;
std::function<void()> mOnNewSaveFunction;
std::function<bool(dFile_select_c* fileSelect)> mOnNewSaveSelectFunction;
std::function<void()> mOnGameResetFunction;
std::function<void()> mOnTickFunction;
};
+6 -9
View File
@@ -65,16 +65,10 @@ ModResult register_gamemode(ModContext* ctx, const GamemodeDesc* desc) {
}
}
std::string saveName;
if (!desc->saveName) {
Log.warn("Attempted to register gamemode {} with a null save name! Defaulting to: (gczelda2)",id);
std::string saveName = desc->saveName;
if (saveName.empty()) {
Log.warn("Attempted to register gamemode {} with an empty save name! Defaulting to: (gczelda2)",id);
saveName = "gczelda2";
}else{
saveName = desc->saveName;
if (saveName.empty()) {
Log.warn("Attempted to register gamemode {} with an empty save name! Defaulting to: (gczelda2)",id);
saveName = "gczelda2";
}
}
dusk::gamemode::Gamemode gamemode(id, fullName, saveName);
@@ -94,6 +88,9 @@ ModResult register_gamemode(ModContext* ctx, const GamemodeDesc* desc) {
if (desc->onNewSaveFunction) {
gamemode.mOnNewSaveFunction = desc->onNewSaveFunction;
}
if (desc->onNewSaveSelectFunction) {
gamemode.mOnNewSaveSelectFunction = desc->onNewSaveSelectFunction;
}
if (desc->onGameResetFunction) {
gamemode.mOnGameResetFunction = desc->onGameResetFunction;
}