mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Merge pull request #2245 from IvanSavenko/platform_settings
Allow defining default values of settings per platform
This commit is contained in:
commit
56680e102d
@ -22,17 +22,10 @@
|
||||
|
||||
std::unique_ptr<ICursor> CursorHandler::createCursor()
|
||||
{
|
||||
if (settings["video"]["cursor"].String() == "auto")
|
||||
{
|
||||
#if defined(VCMI_MOBILE)
|
||||
if (settings["general"]["userRelativePointer"].Bool())
|
||||
return std::make_unique<CursorSoftware>();
|
||||
else
|
||||
return std::make_unique<CursorHardware>();
|
||||
#else
|
||||
return std::make_unique<CursorHardware>();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (settings["video"]["cursor"].String() == "hardware")
|
||||
return std::make_unique<CursorHardware>();
|
||||
|
@ -130,6 +130,8 @@
|
||||
"height" : { "type" : "number" },
|
||||
"scaling" : { "type" : "number" }
|
||||
},
|
||||
"defaultIOS" : {"width" : 800, "height" : 600, "scaling" : 200 },
|
||||
"defaultAndroid" : {"width" : 800, "height" : 600, "scaling" : 200 },
|
||||
"default" : {"width" : 800, "height" : 600, "scaling" : 100 }
|
||||
},
|
||||
"fullscreen" : {
|
||||
@ -142,8 +144,8 @@
|
||||
},
|
||||
"cursor" : {
|
||||
"type" : "string",
|
||||
"enum" : [ "auto", "hardware", "software" ],
|
||||
"default" : "auto"
|
||||
"enum" : [ "hardware", "software" ],
|
||||
"default" : "hardware"
|
||||
},
|
||||
"showIntro" : {
|
||||
"type" : "boolean",
|
||||
@ -213,6 +215,8 @@
|
||||
"borderScroll" :
|
||||
{
|
||||
"type" : "boolean",
|
||||
"defaultIOS" : false,
|
||||
"defaultAndroid" : false,
|
||||
"default" : true
|
||||
}
|
||||
}
|
||||
@ -461,7 +465,7 @@
|
||||
"type" : "object",
|
||||
"default" : {},
|
||||
"additionalProperties" : false,
|
||||
"required" : [ "setupCompleted", "repositoryURL", "enableInstalledMods", "extraResolutionsModPath", "autoCheckRepositories", "updateOnStartup", "updateConfigUrl", "lobbyUrl", "lobbyPort", "lobbyUsername", "connectionTimeout" ],
|
||||
"required" : [ "setupCompleted", "repositoryURL", "enableInstalledMods", "autoCheckRepositories", "updateOnStartup", "updateConfigUrl", "lobbyUrl", "lobbyPort", "lobbyUsername", "connectionTimeout" ],
|
||||
"properties" : {
|
||||
"repositoryURL" : {
|
||||
"type" : "array",
|
||||
@ -480,10 +484,6 @@
|
||||
"type" : "boolean",
|
||||
"default" : true
|
||||
},
|
||||
"extraResolutionsModPath" : {
|
||||
"type" : "string",
|
||||
"default" : "/vcmi-extras/Mods/extraResolutions/Content/config/resolutions.json"
|
||||
},
|
||||
"autoCheckRepositories" : {
|
||||
"type" : "boolean",
|
||||
"default" : true
|
||||
|
@ -38,7 +38,6 @@ QString resolutionToString(const QSize & resolution)
|
||||
|
||||
static const std::string cursorTypesList[] =
|
||||
{
|
||||
"auto",
|
||||
"hardware",
|
||||
"software"
|
||||
};
|
||||
|
@ -112,7 +112,7 @@
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>-107</y>
|
||||
<y>0</y>
|
||||
<width>620</width>
|
||||
<height>745</height>
|
||||
</rect>
|
||||
@ -547,11 +547,6 @@
|
||||
</item>
|
||||
<item row="14" column="1" colspan="3">
|
||||
<widget class="QComboBox" name="comboBoxCursorType">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Default</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Hardware</string>
|
||||
|
@ -1135,73 +1135,76 @@ Key reverseMapFirst(const Val & val, const std::map<Key, Val> & map)
|
||||
return "";
|
||||
}
|
||||
|
||||
void minimizeNode(JsonNode & node, const JsonNode & schema)
|
||||
static JsonNode getDefaultValue(const JsonNode & schema, std::string fieldName)
|
||||
{
|
||||
if (schema["type"].String() == "object")
|
||||
{
|
||||
const JsonNode & fieldProps = schema["properties"][fieldName];
|
||||
|
||||
#if defined(VCMI_IOS)
|
||||
if (!fieldProps["defaultIOS"].isNull())
|
||||
return fieldProps["defaultIOS"];
|
||||
#elif defined(VCMI_ANDROID)
|
||||
if (!fieldProps["defaultAndroid"].isNull())
|
||||
return fieldProps["defaultAndroid"];
|
||||
#elif !defined(VCMI_MOBILE)
|
||||
if (!fieldProps["defaultDesktop"].isNull())
|
||||
return fieldProps["defaultDesktop"];
|
||||
#endif
|
||||
return fieldProps["default"];
|
||||
}
|
||||
|
||||
static void eraseOptionalNodes(JsonNode & node, const JsonNode & schema)
|
||||
{
|
||||
assert(schema["type"].String() == "object");
|
||||
|
||||
std::set<std::string> foundEntries;
|
||||
|
||||
for(const auto & entry : schema["required"].Vector())
|
||||
foundEntries.insert(entry.String());
|
||||
|
||||
vstd::erase_if(node.Struct(), [&](const auto & node){
|
||||
return !vstd::contains(foundEntries, node.first);
|
||||
});
|
||||
}
|
||||
|
||||
static void minimizeNode(JsonNode & node, const JsonNode & schema)
|
||||
{
|
||||
if (schema["type"].String() != "object")
|
||||
return;
|
||||
|
||||
for(const auto & entry : schema["required"].Vector())
|
||||
{
|
||||
const std::string & name = entry.String();
|
||||
foundEntries.insert(name);
|
||||
|
||||
minimizeNode(node[name], schema["properties"][name]);
|
||||
|
||||
if (vstd::contains(node.Struct(), name) &&
|
||||
node[name] == schema["properties"][name]["default"])
|
||||
{
|
||||
if (vstd::contains(node.Struct(), name) && node[name] == getDefaultValue(schema, name))
|
||||
node.Struct().erase(name);
|
||||
}
|
||||
}
|
||||
|
||||
// erase all unhandled entries
|
||||
for (auto it = node.Struct().begin(); it != node.Struct().end();)
|
||||
{
|
||||
if (!vstd::contains(foundEntries, it->first))
|
||||
it = node.Struct().erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
}
|
||||
eraseOptionalNodes(node, schema);
|
||||
}
|
||||
|
||||
void JsonUtils::minimize(JsonNode & node, const std::string & schemaName)
|
||||
{
|
||||
minimizeNode(node, getSchema(schemaName));
|
||||
}
|
||||
|
||||
// FIXME: except for several lines function is identical to minimizeNode. Some way to reduce duplication?
|
||||
void maximizeNode(JsonNode & node, const JsonNode & schema)
|
||||
static void maximizeNode(JsonNode & node, const JsonNode & schema)
|
||||
{
|
||||
// "required" entry can only be found in object/struct
|
||||
if (schema["type"].String() == "object")
|
||||
{
|
||||
std::set<std::string> foundEntries;
|
||||
if (schema["type"].String() != "object")
|
||||
return;
|
||||
|
||||
// check all required entries that have default version
|
||||
for(const auto & entry : schema["required"].Vector())
|
||||
{
|
||||
const std::string & name = entry.String();
|
||||
foundEntries.insert(name);
|
||||
|
||||
if (node[name].isNull() &&
|
||||
!schema["properties"][name]["default"].isNull())
|
||||
{
|
||||
node[name] = schema["properties"][name]["default"];
|
||||
}
|
||||
if (node[name].isNull() && !getDefaultValue(schema, name).isNull())
|
||||
node[name] = getDefaultValue(schema, name);
|
||||
|
||||
maximizeNode(node[name], schema["properties"][name]);
|
||||
}
|
||||
|
||||
// erase all unhandled entries
|
||||
for (auto it = node.Struct().begin(); it != node.Struct().end();)
|
||||
{
|
||||
if (!vstd::contains(foundEntries, it->first))
|
||||
it = node.Struct().erase(it);
|
||||
else
|
||||
it++;
|
||||
}
|
||||
}
|
||||
eraseOptionalNodes(node, schema);
|
||||
}
|
||||
|
||||
void JsonUtils::minimize(JsonNode & node, const std::string & schemaName)
|
||||
{
|
||||
minimizeNode(node, getSchema(schemaName));
|
||||
}
|
||||
|
||||
void JsonUtils::maximize(JsonNode & node, const std::string & schemaName)
|
||||
|
Loading…
Reference in New Issue
Block a user