Skip to content

Commit

Permalink
#5168: Ensure that up-to-date edit timings are written to automatic s…
Browse files Browse the repository at this point in the history
…aves.
  • Loading branch information
codereader committed Apr 19, 2020
1 parent 4489ccd commit 5cd0e30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 13 additions & 4 deletions radiant/map/EditingStopwatch.cpp
Expand Up @@ -43,6 +43,7 @@ const StringSet& EditingStopwatch::getDependencies() const
{
_dependencies.insert(MODULE_MAP);
_dependencies.insert(MODULE_MAPINFOFILEMANAGER);
_dependencies.insert(MODULE_MAPRESOURCEMANAGER);
_dependencies.insert(MODULE_UIMANAGER);
}

Expand All @@ -61,6 +62,10 @@ void EditingStopwatch::initialiseModule(const ApplicationContext& ctx)
std::make_shared<EditingStopwatchInfoFileModule>()
);

GlobalMapResourceManager().signal_onResourceExporting().connect(
sigc::mem_fun(this, &EditingStopwatch::onResourceExporting)
);

// Register the timer when the application has come up
GlobalRadiant().signal_radiantStarted().connect(
sigc::mem_fun(*this, &EditingStopwatch::onRadiantStartup));
Expand Down Expand Up @@ -130,7 +135,8 @@ void EditingStopwatch::onMapEvent(IMap::MapEvent ev)

// We start/stop during save operations
case IMap::MapSaving:
writeToMapProperties();
// the timing is not written to the map root node here,
// but in the separate resource-exporting event
stop();
break;
case IMap::MapSaved:
Expand All @@ -142,6 +148,11 @@ void EditingStopwatch::onMapEvent(IMap::MapEvent ev)
};
}

void EditingStopwatch::onResourceExporting(const scene::IMapRootNodePtr& root)
{
writeToMapProperties(root);
}

void EditingStopwatch::start()
{
if (_timer)
Expand Down Expand Up @@ -182,10 +193,8 @@ void EditingStopwatch::readFromMapProperties()
}
}

void EditingStopwatch::writeToMapProperties()
void EditingStopwatch::writeToMapProperties(const scene::IMapRootNodePtr& root)
{
auto root = GlobalMapModule().getRoot();

if (root)
{
root->setProperty(MAP_PROPERTY_KEY, string::to_string(getTotalSecondsEdited()));
Expand Down
3 changes: 2 additions & 1 deletion radiant/map/EditingStopwatch.h
Expand Up @@ -51,7 +51,8 @@ class EditingStopwatch :
void onRadiantStartup();
void onIntervalReached(wxTimerEvent& ev);
void readFromMapProperties();
void writeToMapProperties();
void writeToMapProperties(const scene::IMapRootNodePtr& root);
void onResourceExporting(const scene::IMapRootNodePtr& root);
};

}
Expand Down

0 comments on commit 5cd0e30

Please sign in to comment.