-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathCampaignDescription.cpp
More file actions
63 lines (54 loc) · 2.69 KB
/
Copy pathCampaignDescription.cpp
File metadata and controls
63 lines (54 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (C) 2005 - 2024 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later
#include "CampaignDescription.h"
#include "RttrConfig.h"
#include "helpers/format.hpp"
#include "lua/CheckedLuaTable.h"
#include "lua/LuaHelpers.h"
#include "mygettext/mygettext.h"
CampaignDescription::CampaignDescription(const boost::filesystem::path& campaignPath, const kaguya::LuaRef& table)
{
CheckedLuaTable luaData(table);
uid = luaData.getOrDefault("uid", decltype(uid){""});
luaData.getOrThrow(version, "version");
luaData.getOrThrow(author, "author");
luaData.getOrThrow(name, "name");
luaData.getOrThrow(shortDescription, "shortDescription");
luaData.getOrThrow(longDescription, "longDescription");
image = luaData.getOptional<std::string>("image");
if(image && image->empty())
image = std::nullopt;
luaData.getOrThrow(maxHumanPlayers, "maxHumanPlayers");
if(maxHumanPlayers != 1)
throw std::invalid_argument(helpers::format(_("Invalid maximum human player count: %1%"), maxHumanPlayers));
luaData.getOrThrow(difficulty, "difficulty");
if(difficulty != gettext_noop("easy") && difficulty != gettext_noop("medium") && difficulty != gettext_noop("hard"))
throw std::invalid_argument(helpers::format(_("Invalid difficulty: %1%"), difficulty));
auto resolveFolder = [campaignPath](const std::string& folder) {
const boost::filesystem::path tmpPath = folder;
// If it is only a filename or empty use path relative to campaign folder
if(!tmpPath.has_parent_path())
return campaignPath / tmpPath;
// Otherwise it must be a valid path inside the game files
lua::validatePath(folder);
return RTTRCONFIG.ExpandPath(folder);
};
const auto mapFolder = luaData.getOrDefault("mapFolder", std::string{});
mapFolder_ = resolveFolder(mapFolder);
// Default lua folder to map folder, i.e. LUA files are side by side with the maps
luaFolder_ = resolveFolder(luaData.getOrDefault("luaFolder", mapFolder));
mapNames_ = luaData.getOrDefault("maps", std::vector<std::string>());
// enable chapters 1 and 2 (like in the Roman campaign and the FANpaign) unless specified otherwise
chaptersEnabled = luaData.getOrDefault<decltype(chaptersEnabled)>("chaptersEnabled", {0, 1});
selectionMapData = luaData.getOptional<SelectionMapInputData>("selectionMap");
luaData.checkUnused();
}
boost::filesystem::path CampaignDescription::getLuaFilePath(const size_t idx) const
{
return (luaFolder_ / getMapName(idx)).replace_extension("lua");
}
boost::filesystem::path CampaignDescription::getMapFilePath(const size_t idx) const
{
return mapFolder_ / getMapName(idx);
}