Skip to content

Commit

Permalink
fixup! 568 Add campaign menu and mission selection screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ottml committed Nov 1, 2023
1 parent 40e52ca commit 0898bb9
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions libs/s25main/desktops/dskCampaignSelection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,51 +152,55 @@ void dskCampaignSelection::Msg_ButtonClick(unsigned ctrl_id)
void dskCampaignSelection::FillCampaignsTable()
{
const size_t numFaultyCampaignsPrior = brokenCampaignPaths_.size();
const bfs::path campaignPath = RTTRCONFIG.ExpandPath(s25::folders::campaigns);
static const std::array<std::string, 2> campaignFolders = {{s25::folders::campaignsBuiltin, s25::folders::campaignsUser}};

auto* table = GetCtrl<ctrlTable>(ID_Table);
for(const bfs::path& folder : ListDir(campaignPath, "", true))
for(auto& campaignFolder : campaignFolders)
{
if(helpers::contains(brokenCampaignPaths_, folder))
continue;

CampaignDescription desc;
CampaignDataLoader loader(desc, folder);
if(!loader.Load())
{
LOG.write(_("Failed to load campaign %1%.\n")) % folder;
brokenCampaignPaths_.insert(folder);
continue;
}

for(auto const& mapName : desc.mapNames)
const bfs::path campaignPath = RTTRCONFIG.ExpandPath(campaignFolder);
for(const bfs::path& folder : ListDir(campaignPath, "", true))
{
auto const mapPath = RTTRCONFIG.ExpandPath(desc.mapFolder) / mapName;
auto const luaFilepath = (RTTRCONFIG.ExpandPath(desc.luaFolder) / mapName).replace_extension("lua");
if(!bfs::exists(mapPath))
{
LOG.write(_("Campaign map %1% does not exist.\n")) % mapPath;
brokenCampaignPaths_.insert(folder);
if(helpers::contains(brokenCampaignPaths_, folder))
continue;
}
if(!bfs::exists(luaFilepath))

CampaignDescription desc;
CampaignDataLoader loader(desc, folder);
if(!loader.Load())
{
LOG.write(_("Campaign map lua file %1% does not exist.\n")) % luaFilepath;
LOG.write(_("Failed to load campaign %1%.\n")) % folder;
brokenCampaignPaths_.insert(folder);
continue;
}

libsiedler2::Archiv map;
if(int ec = libsiedler2::loader::LoadMAP(mapPath, map, true))
for(auto const& mapName : desc.mapNames)
{
LOG.write(_("Failed to load map %1%: %2%\n")) % mapPath % libsiedler2::getErrorString(ec);
brokenMapPaths_.insert(folder);
continue;
auto const mapPath = RTTRCONFIG.ExpandPath(desc.mapFolder) / mapName;
auto const luaFilepath = (RTTRCONFIG.ExpandPath(desc.luaFolder) / mapName).replace_extension("lua");
if(!bfs::exists(mapPath))
{
LOG.write(_("Campaign map %1% does not exist.\n")) % mapPath;
brokenCampaignPaths_.insert(folder);
continue;
}
if(!bfs::exists(luaFilepath))
{
LOG.write(_("Campaign map lua file %1% does not exist.\n")) % luaFilepath;
brokenCampaignPaths_.insert(folder);
continue;
}

libsiedler2::Archiv map;
if(int ec = libsiedler2::loader::LoadMAP(mapPath, map, true))
{
LOG.write(_("Failed to load map %1%: %2%\n")) % mapPath % libsiedler2::getErrorString(ec);
brokenMapPaths_.insert(folder);
continue;
}
}
}

table->AddRow({desc.name, desc.shortDescription, desc.author, std::to_string(desc.mapNames.size()),
_(desc.difficulty), folder.string()});
table->AddRow({desc.name, desc.shortDescription, desc.author, std::to_string(desc.mapNames.size()),
_(desc.difficulty), folder.string()});
}
}

if(brokenCampaignPaths_.size() > numFaultyCampaignsPrior)
Expand Down

0 comments on commit 0898bb9

Please sign in to comment.