Skip to content

Commit

Permalink
qtscript: Add new events eventGameLoaded, eventGameSaving, and eventG…
Browse files Browse the repository at this point in the history
…ameSaved. You

will usually not need to heed these events. They are for special purposes.
  • Loading branch information
perim committed Nov 5, 2012
1 parent 58ed9a7 commit c7cabf1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/game.cpp
Expand Up @@ -2498,7 +2498,7 @@ bool loadGame(const char *pGameToLoad, bool keepObjects, bool freeMem, bool User
//put any widgets back on for the missions
resetMissionWidgets();

debug( LOG_NEVER, "loadGame: done\n" );
debug(LOG_NEVER, "Done loading");

return true;

Expand Down Expand Up @@ -2527,6 +2527,8 @@ bool saveGame(char *aFileName, GAME_TYPE saveType)
DROID *psDroid, *psNext;
char CurrentFileName[PATH_MAX] = {'\0'};

triggerEvent(TRIGGER_GAME_SAVING);

ASSERT_OR_RETURN(false, aFileName && strlen(aFileName) > 4, "Bad savegame filename");
sstrcpy(CurrentFileName, aFileName);
debug(LOG_WZ, "saveGame: %s", CurrentFileName);
Expand Down Expand Up @@ -2806,6 +2808,7 @@ bool saveGame(char *aFileName, GAME_TYPE saveType)
CurrentFileName[fileExtension-1] = '\0';

/* Start the game clock */
triggerEvent(TRIGGER_GAME_SAVED);
gameTimeStart();
return true;

Expand Down
3 changes: 2 additions & 1 deletion src/levels.cpp
Expand Up @@ -51,6 +51,7 @@
#include "effects.h"
#include "main.h"
#include "multiint.h"
#include "qtscript.h"

extern int lev_get_lineno(void);
extern char* lev_get_text(void);
Expand Down Expand Up @@ -1065,7 +1066,7 @@ bool levLoadData(char const *name, Sha256 const *hash, char *pSaveName, GAME_TYP
ssprintf(buf, "Current Level/map is %s", psCurrLevel->pName);
addDumpInfo(buf);
}

triggerEvent(TRIGGER_GAME_LOADED);

return true;
}
15 changes: 15 additions & 0 deletions src/qtscript.cpp
Expand Up @@ -583,6 +583,12 @@ bool loadScriptStates(const char *filename)
//__ An event that is run when the mission timer has run out.
//__ \subsection{eventVideoDone()}
//__ An event that is run when a video show stopped playing.
//__ \subsection{eventGameLoaded()}
//__ An event that is run when game is loaded from a saved game. There is usually no need to use this event.
//__ \subsection{eventGameSaving()}
//__ An event that is run before game is saved. There is usually no need to use this event.
//__ \subsection{eventGameSaved()}
//__ An event that is run after game is saved. There is usually no need to use this event.
bool triggerEvent(SCRIPT_TRIGGER_TYPE trigger)
{
for (int i = 0; i < scripts.size(); ++i)
Expand Down Expand Up @@ -610,6 +616,15 @@ bool triggerEvent(SCRIPT_TRIGGER_TYPE trigger)
case TRIGGER_VIDEO_QUIT:
callFunction(engine, "eventVideoDone", QScriptValueList());
break;
case TRIGGER_GAME_LOADED:
callFunction(engine, "eventGameLoaded", QScriptValueList());
break;
case TRIGGER_GAME_SAVING:
callFunction(engine, "eventGameSaving", QScriptValueList());
break;
case TRIGGER_GAME_SAVED:
callFunction(engine, "eventGameSaved", QScriptValueList());
break;
}
}
return true;
Expand Down
5 changes: 4 additions & 1 deletion src/qtscript.h
Expand Up @@ -34,7 +34,10 @@ enum SCRIPT_TRIGGER_TYPE
TRIGGER_LAUNCH_TRANSPORTER,
TRIGGER_REINFORCEMENTS_ARRIVED,
TRIGGER_VIDEO_QUIT,
TRIGGER_MISSION_TIMEOUT
TRIGGER_MISSION_TIMEOUT,
TRIGGER_GAME_LOADED,
TRIGGER_GAME_SAVING,
TRIGGER_GAME_SAVED
};

// ----------------------------------------------
Expand Down

0 comments on commit c7cabf1

Please sign in to comment.