dont switch to editor if loading fails

This commit is contained in:
dobrykafe 2023-08-26 22:13:13 +02:00
parent 8957ae99bd
commit cb29ad2b4f
4 changed files with 13 additions and 11 deletions

View file

@ -3120,8 +3120,11 @@ void CClient::Run()
// handle pending map edits
if(m_aCmdEditMap[0])
{
g_Config.m_ClEditor = true;
m_pEditor->HandleMapDrop(m_aCmdEditMap, IStorage::TYPE_ALL_OR_ABSOLUTE);
int Result = m_pEditor->HandleMapDrop(m_aCmdEditMap, IStorage::TYPE_ALL_OR_ABSOLUTE);
if(Result)
g_Config.m_ClEditor = true;
else
dbg_msg("editor", "editing passed map file '%s' failed", m_aCmdEditMap);
m_aCmdEditMap[0] = 0;
}

View file

@ -15,7 +15,7 @@ public:
virtual void OnActivate() = 0;
virtual void OnWindowResize() = 0;
virtual bool HasUnsavedData() const = 0;
virtual void HandleMapDrop(const char *pFilename, int StorageType) = 0;
virtual bool HandleMapDrop(const char *pFilename, int StorageType) = 0;
virtual bool Load(const char *pFilename, int StorageType) = 0;
virtual bool Save(const char *pFilename) = 0;
virtual void UpdateMentions() = 0;

View file

@ -523,7 +523,7 @@ public:
// io
bool Save(const char *pFilename);
bool Load(const char *pFilename, int StorageType, const std::function<void(const char *pErrorMessage)> &ErrorHandler);
void HandleMapDrop(const char *pFilename, int StorageType);
bool HandleMapDrop(const char *pFilename, int StorageType);
void PerformSanityChecks(const std::function<void(const char *pErrorMessage)> &ErrorHandler);
// DDRace
@ -984,7 +984,7 @@ public:
void Reset(bool CreateDefault = true);
bool Save(const char *pFilename) override;
bool Load(const char *pFilename, int StorageType) override;
void HandleMapDrop(const char *pFilename, int StorageType) override;
bool HandleMapDrop(const char *pFilename, int StorageType) override;
bool Append(const char *pFilename, int StorageType);
void LoadCurrentMap();
void Render();

View file

@ -426,24 +426,23 @@ bool CEditorMap::Save(const char *pFileName)
return true;
}
void CEditor::HandleMapDrop(const char *pFileName, int StorageType)
bool CEditor::HandleMapDrop(const char *pFileName, int StorageType)
{
m_Map.HandleMapDrop(pFileName, IStorage::TYPE_ALL_OR_ABSOLUTE);
return m_Map.HandleMapDrop(pFileName, IStorage::TYPE_ALL_OR_ABSOLUTE);
}
void CEditorMap::HandleMapDrop(const char *pFileName, int StorageType)
bool CEditorMap::HandleMapDrop(const char *pFileName, int StorageType)
{
if(m_pEditor->HasUnsavedData())
{
str_copy(m_pEditor->m_aFileNamePending, pFileName);
m_pEditor->m_PopupEventType = CEditor::POPEVENT_LOADDROP;
m_pEditor->m_PopupEventActivated = true;
return true;
}
else
{
int Result = m_pEditor->Load(pFileName, IStorage::TYPE_ALL_OR_ABSOLUTE);
if(!Result)
dbg_msg("editor", "editing passed map file '%s' failed", pFileName);
return m_pEditor->Load(pFileName, IStorage::TYPE_ALL_OR_ABSOLUTE);
}
}