Add Include command to automapper

This commit is contained in:
marmare314 2024-07-24 17:50:13 +02:00
parent a84a53c5fe
commit b9cb2d2e00
2 changed files with 26 additions and 5 deletions

View file

@ -45,7 +45,7 @@ CAutoMapper::CAutoMapper(CEditor *pEditor)
Init(pEditor); Init(pEditor);
} }
void CAutoMapper::Load(const char *pTileName) void CAutoMapper::Load(const char *pTileName, bool Include)
{ {
char aPath[IO_MAX_PATH_LENGTH]; char aPath[IO_MAX_PATH_LENGTH];
str_format(aPath, sizeof(aPath), "editor/automap/%s.rules", pTileName); str_format(aPath, sizeof(aPath), "editor/automap/%s.rules", pTileName);
@ -53,6 +53,9 @@ void CAutoMapper::Load(const char *pTileName)
if(!LineReader.OpenFile(Storage()->OpenFile(aPath, IOFLAG_READ, IStorage::TYPE_ALL))) if(!LineReader.OpenFile(Storage()->OpenFile(aPath, IOFLAG_READ, IStorage::TYPE_ALL)))
{ {
char aBuf[IO_MAX_PATH_LENGTH + 32]; char aBuf[IO_MAX_PATH_LENGTH + 32];
if(Include)
str_format(aBuf, sizeof(aBuf), "failed to include %s", aPath);
else
str_format(aBuf, sizeof(aBuf), "failed to load %s", aPath); str_format(aBuf, sizeof(aBuf), "failed to load %s", aPath);
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf);
return; return;
@ -331,6 +334,20 @@ void CAutoMapper::Load(const char *pTileName)
{ {
pCurrentRun->m_AutomapCopy = false; pCurrentRun->m_AutomapCopy = false;
} }
else if(str_startswith(pLine, "Include "))
{
pLine += str_length("Include ");
char aName[512];
str_copy(aName, pLine, minimum<int>(sizeof(aName), str_length(pLine) + 1));
if(str_comp(aName, pTileName) != 0)
Load(aName, true);
pCurrentConf = nullptr;
pCurrentRun = nullptr;
pCurrentIndex = nullptr;
}
} }
} }
@ -383,9 +400,13 @@ void CAutoMapper::Load(const char *pTileName)
} }
char aBuf[IO_MAX_PATH_LENGTH + 16]; char aBuf[IO_MAX_PATH_LENGTH + 16];
if(Include)
str_format(aBuf, sizeof(aBuf), "included %s", aPath);
else
str_format(aBuf, sizeof(aBuf), "loaded %s", aPath); str_format(aBuf, sizeof(aBuf), "loaded %s", aPath);
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf);
if(!Include)
m_FileLoaded = true; m_FileLoaded = true;
} }

View file

@ -59,7 +59,7 @@ class CAutoMapper : public CEditorComponent
public: public:
explicit CAutoMapper(CEditor *pEditor); explicit CAutoMapper(CEditor *pEditor);
void Load(const char *pTileName); void Load(const char *pTileName, bool Include = false);
void ProceedLocalized(class CLayerTiles *pLayer, int ConfigId, int Seed = 0, int X = 0, int Y = 0, int Width = -1, int Height = -1); void ProceedLocalized(class CLayerTiles *pLayer, int ConfigId, int Seed = 0, int X = 0, int Y = 0, int Width = -1, int Height = -1);
void Proceed(class CLayerTiles *pLayer, int ConfigId, int Seed = 0, int SeedOffsetX = 0, int SeedOffsetY = 0); void Proceed(class CLayerTiles *pLayer, int ConfigId, int Seed = 0, int SeedOffsetX = 0, int SeedOffsetY = 0);