Use bool for Load, Save, Append result, true on success

The `Append` method was returning `0` on success while `Load` and `Save` were returning `1`.
Now all three methods use a `bool` as return value and return `true` on success.

The call `SortImages()` is moved inside the `Append` method, as it should always be called when appending succeeded.
This commit is contained in:
Robert Müller 2022-11-03 20:17:06 +01:00
parent d83cf0ac56
commit b0a21dab09
4 changed files with 27 additions and 30 deletions

View file

@ -13,8 +13,8 @@ public:
virtual void OnUpdate() = 0;
virtual void OnRender() = 0;
virtual bool HasUnsavedData() const = 0;
virtual int Load(const char *pFilename, int StorageType) = 0;
virtual int Save(const char *pFilename) = 0;
virtual bool Load(const char *pFilename, int StorageType) = 0;
virtual bool Save(const char *pFilename) = 0;
virtual void UpdateMentions() = 0;
virtual void ResetMentions() = 0;
};

View file

@ -779,10 +779,8 @@ void CEditor::CallbackOpenMap(const char *pFileName, int StorageType, void *pUse
void CEditor::CallbackAppendMap(const char *pFileName, int StorageType, void *pUser)
{
CEditor *pEditor = (CEditor *)pUser;
if(pEditor->Append(pFileName, StorageType))
if(!pEditor->Append(pFileName, StorageType))
pEditor->m_aFileName[0] = 0;
else
pEditor->SortImages();
pEditor->m_Dialog = DIALOG_NONE;
}

View file

@ -467,8 +467,8 @@ public:
void CreateDefault(IGraphics::CTextureHandle EntitiesTexture);
// io
int Save(class IStorage *pStorage, const char *pFilename);
int Load(class IStorage *pStorage, const char *pFilename, int StorageType);
bool Save(class IStorage *pStorage, const char *pFilename);
bool Load(class IStorage *pStorage, const char *pFilename, int StorageType);
// DDRace
@ -857,9 +857,9 @@ public:
void (*pfnFunc)(const char *pFilename, int StorageType, void *pUser), void *pUser);
void Reset(bool CreateDefault = true);
int Save(const char *pFilename) override;
int Load(const char *pFilename, int StorageType) override;
int Append(const char *pFilename, int StorageType);
bool Save(const char *pFilename) override;
bool Load(const char *pFilename, int StorageType) override;
bool Append(const char *pFilename, int StorageType);
void LoadCurrentMap();
void Render();

View file

@ -31,12 +31,12 @@ struct CSoundSource_DEPRECATED
int m_SoundEnvOffset;
};
int CEditor::Save(const char *pFilename)
bool CEditor::Save(const char *pFilename)
{
return m_Map.Save(Kernel()->RequestInterface<IStorage>(), pFilename);
}
int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
bool CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
{
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "saving to '%s'...", pFileName);
@ -46,7 +46,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
{
str_format(aBuf, sizeof(aBuf), "failed to open file '%s'...", pFileName);
m_pEditor->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "editor", aBuf);
return 0;
return false;
}
// save version
@ -394,14 +394,14 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
}
}
return 1;
return true;
}
int CEditor::Load(const char *pFileName, int StorageType)
bool CEditor::Load(const char *pFileName, int StorageType)
{
Reset();
int result = m_Map.Load(Kernel()->RequestInterface<IStorage>(), pFileName, StorageType);
if(result)
bool Result = m_Map.Load(Kernel()->RequestInterface<IStorage>(), pFileName, StorageType);
if(Result)
{
str_copy(m_aFileName, pFileName, 512);
SortImages();
@ -412,14 +412,14 @@ int CEditor::Load(const char *pFileName, int StorageType)
m_aFileName[0] = 0;
Reset();
}
return result;
return Result;
}
int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int StorageType)
bool CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int StorageType)
{
CDataFileReader DataFile;
if(!DataFile.Open(pStorage, pFileName, StorageType))
return 0;
return false;
Clean();
@ -427,7 +427,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
CMapItemVersion *pItemVersion = (CMapItemVersion *)DataFile.FindItem(MAPITEMTYPE_VERSION, 0);
if(!pItemVersion)
{
return 0;
return false;
}
else if(pItemVersion->m_Version == 1)
{
@ -1005,10 +1005,10 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
}
}
else
return 0;
return false;
m_Modified = false;
return 1;
return true;
}
static int gs_ModifyAddAmount = 0;
@ -1018,15 +1018,13 @@ static void ModifyAdd(int *pIndex)
*pIndex += gs_ModifyAddAmount;
}
int CEditor::Append(const char *pFileName, int StorageType)
bool CEditor::Append(const char *pFileName, int StorageType)
{
CEditorMap NewMap;
NewMap.m_pEditor = this;
int Err;
Err = NewMap.Load(Kernel()->RequestInterface<IStorage>(), pFileName, StorageType);
if(!Err)
return Err;
if(!NewMap.Load(Kernel()->RequestInterface<IStorage>(), pFileName, StorageType))
return false;
// modify indices
gs_ModifyAddAmount = m_Map.m_vpImages.size();
@ -1046,7 +1044,6 @@ int CEditor::Append(const char *pFileName, int StorageType)
NewMap.m_vpEnvelopes.clear();
// transfer groups
for(const auto &pGroup : NewMap.m_vpGroups)
{
if(pGroup == NewMap.m_pGameGroup)
@ -1059,6 +1056,8 @@ int CEditor::Append(const char *pFileName, int StorageType)
}
NewMap.m_vpGroups.clear();
SortImages();
// all done \o/
return 0;
return true;
}