Skip to content

Commit

Permalink
Reload map option now checks connection status
Browse files Browse the repository at this point in the history
Trying to activate "Game reloads .map file on save" without a valid game
connection will now show an error dialog and keep the toggle unchecked.
  • Loading branch information
Matthew Mott committed Dec 29, 2020
1 parent efd7675 commit c8f62fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
16 changes: 11 additions & 5 deletions plugins/dm.gameconnection/GameConnection.cpp
Expand Up @@ -184,8 +184,9 @@ bool GameConnection::connect() {
return true;
}

void GameConnection::disconnect(bool force) {
setAutoReloadMapEnabled(false);
void GameConnection::disconnect(bool force)
{
_autoReloadMap = false;
setUpdateMapLevel(false, false);
setCameraSyncEnabled(false);
if (force) {
Expand Down Expand Up @@ -235,9 +236,9 @@ void GameConnection::initialiseModule(const IApplicationContext& ctx)
"GameConnectionToggleCameraSync",
[this](bool v) { return setCameraSyncEnabled(v); }
);
GlobalEventManager().addToggle(
GlobalEventManager().addAdvancedToggle(
"GameConnectionToggleAutoMapReload",
[this](bool v) { setAutoReloadMapEnabled(v); }
[this](bool v) { return setAutoReloadMapEnabled(v); }
);
GlobalEventManager().addToggle(
"GameConnectionToggleHotReload",
Expand Down Expand Up @@ -470,8 +471,13 @@ void GameConnection::onMapEvent(IMap::MapEvent ev) {
}
}

void GameConnection::setAutoReloadMapEnabled(bool enable) {
bool GameConnection::setAutoReloadMapEnabled(bool enable)
{
if (!connect())
return false;

_autoReloadMap = enable;
return true;
}

void GameConnection::setUpdateMapLevel(bool on, bool always) {
Expand Down
20 changes: 17 additions & 3 deletions plugins/dm.gameconnection/GameConnection.h
Expand Up @@ -38,7 +38,13 @@ class GameConnection :
//flush all async commands (e.g. camera update) and wait until everything finishes
void finish();

/// Enable dynamic sync of camera to game position
/**
* \brief
* Enable dynamic sync of camera to game position
*
* \return
* true on success, false if connection failed.
*/
bool setCameraSyncEnabled(bool enable);

/// Trigger one-off sync of game position back to Radiant camera
Expand All @@ -51,8 +57,16 @@ class GameConnection :

//ask TDM to reload .map file from disk
void reloadMap();
//when enabled, forces TDM to reload .map from disk automatically after every map save
void setAutoReloadMapEnabled(bool enable);

/**
* \brief
* Instruct TDM to reload .map from disk automatically after every map save
*
* \return
* true on success, false if the game connection failed.
*/
bool setAutoReloadMapEnabled(bool enable);

//implementation of "update map" level toggling
void setUpdateMapLevel(bool on, bool always);
//send map update to TDM right now
Expand Down

0 comments on commit c8f62fe

Please sign in to comment.