Skip to content

Commit

Permalink
Add Include command to automapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Marmare314 committed Jul 24, 2024
1 parent a84a53c commit b9cb2d2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
29 changes: 25 additions & 4 deletions src/game/editor/auto_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ CAutoMapper::CAutoMapper(CEditor *pEditor)
Init(pEditor);
}

void CAutoMapper::Load(const char *pTileName)
void CAutoMapper::Load(const char *pTileName, bool Include)
{
char aPath[IO_MAX_PATH_LENGTH];
str_format(aPath, sizeof(aPath), "editor/automap/%s.rules", pTileName);
CLineReader LineReader;
if(!LineReader.OpenFile(Storage()->OpenFile(aPath, IOFLAG_READ, IStorage::TYPE_ALL)))
{
char aBuf[IO_MAX_PATH_LENGTH + 32];
str_format(aBuf, sizeof(aBuf), "failed to load %s", aPath);
if(Include)
str_format(aBuf, sizeof(aBuf), "failed to include %s", aPath);
else
str_format(aBuf, sizeof(aBuf), "failed to load %s", aPath);
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf);
return;
}
Expand Down Expand Up @@ -331,6 +334,20 @@ void CAutoMapper::Load(const char *pTileName)
{
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;
}
}
}

Expand Down Expand Up @@ -383,10 +400,14 @@ void CAutoMapper::Load(const char *pTileName)
}

char aBuf[IO_MAX_PATH_LENGTH + 16];
str_format(aBuf, sizeof(aBuf), "loaded %s", aPath);
if(Include)
str_format(aBuf, sizeof(aBuf), "included %s", aPath);
else
str_format(aBuf, sizeof(aBuf), "loaded %s", aPath);
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "editor/automap", aBuf);

m_FileLoaded = true;
if(!Include)
m_FileLoaded = true;
}

const char *CAutoMapper::GetConfigName(int Index)
Expand Down
2 changes: 1 addition & 1 deletion src/game/editor/auto_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CAutoMapper : public CEditorComponent
public:
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 Proceed(class CLayerTiles *pLayer, int ConfigId, int Seed = 0, int SeedOffsetX = 0, int SeedOffsetY = 0);

Expand Down

0 comments on commit b9cb2d2

Please sign in to comment.