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()
|
std::unique_ptr<ICursor> CursorHandler::createCursor()
|
||||||
{
|
{
|
||||||
if (settings["video"]["cursor"].String() == "auto")
|
|
||||||
{
|
|
||||||
#if defined(VCMI_MOBILE)
|
#if defined(VCMI_MOBILE)
|
||||||
if (settings["general"]["userRelativePointer"].Bool())
|
if (settings["general"]["userRelativePointer"].Bool())
|
||||||
return std::make_unique<CursorSoftware>();
|
return std::make_unique<CursorSoftware>();
|
||||||
else
|
|
||||||
return std::make_unique<CursorHardware>();
|
|
||||||
#else
|
|
||||||
return std::make_unique<CursorHardware>();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
if (settings["video"]["cursor"].String() == "hardware")
|
if (settings["video"]["cursor"].String() == "hardware")
|
||||||
return std::make_unique<CursorHardware>();
|
return std::make_unique<CursorHardware>();
|
||||||
|
@ -130,6 +130,8 @@
|
|||||||
"height" : { "type" : "number" },
|
"height" : { "type" : "number" },
|
||||||
"scaling" : { "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 }
|
"default" : {"width" : 800, "height" : 600, "scaling" : 100 }
|
||||||
},
|
},
|
||||||
"fullscreen" : {
|
"fullscreen" : {
|
||||||
@ -142,8 +144,8 @@
|
|||||||
},
|
},
|
||||||
"cursor" : {
|
"cursor" : {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"enum" : [ "auto", "hardware", "software" ],
|
"enum" : [ "hardware", "software" ],
|
||||||
"default" : "auto"
|
"default" : "hardware"
|
||||||
},
|
},
|
||||||
"showIntro" : {
|
"showIntro" : {
|
||||||
"type" : "boolean",
|
"type" : "boolean",
|
||||||
@ -213,6 +215,8 @@
|
|||||||
"borderScroll" :
|
"borderScroll" :
|
||||||
{
|
{
|
||||||
"type" : "boolean",
|
"type" : "boolean",
|
||||||
|
"defaultIOS" : false,
|
||||||
|
"defaultAndroid" : false,
|
||||||
"default" : true
|
"default" : true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,7 +465,7 @@
|
|||||||
"type" : "object",
|
"type" : "object",
|
||||||
"default" : {},
|
"default" : {},
|
||||||
"additionalProperties" : false,
|
"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" : {
|
"properties" : {
|
||||||
"repositoryURL" : {
|
"repositoryURL" : {
|
||||||
"type" : "array",
|
"type" : "array",
|
||||||
@ -480,10 +484,6 @@
|
|||||||
"type" : "boolean",
|
"type" : "boolean",
|
||||||
"default" : true
|
"default" : true
|
||||||
},
|
},
|
||||||
"extraResolutionsModPath" : {
|
|
||||||
"type" : "string",
|
|
||||||
"default" : "/vcmi-extras/Mods/extraResolutions/Content/config/resolutions.json"
|
|
||||||
},
|
|
||||||
"autoCheckRepositories" : {
|
"autoCheckRepositories" : {
|
||||||
"type" : "boolean",
|
"type" : "boolean",
|
||||||
"default" : true
|
"default" : true
|
||||||
|
@ -38,7 +38,6 @@ QString resolutionToString(const QSize & resolution)
|
|||||||
|
|
||||||
static const std::string cursorTypesList[] =
|
static const std::string cursorTypesList[] =
|
||||||
{
|
{
|
||||||
"auto",
|
|
||||||
"hardware",
|
"hardware",
|
||||||
"software"
|
"software"
|
||||||
};
|
};
|
||||||
|
@ -112,7 +112,7 @@
|
|||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>-107</y>
|
<y>0</y>
|
||||||
<width>620</width>
|
<width>620</width>
|
||||||
<height>745</height>
|
<height>745</height>
|
||||||
</rect>
|
</rect>
|
||||||
@ -547,11 +547,6 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="14" column="1" colspan="3">
|
<item row="14" column="1" colspan="3">
|
||||||
<widget class="QComboBox" name="comboBoxCursorType">
|
<widget class="QComboBox" name="comboBoxCursorType">
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Default</string>
|
|
||||||
</property>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Hardware</string>
|
<string>Hardware</string>
|
||||||
|
@ -1135,73 +1135,76 @@ Key reverseMapFirst(const Val & val, const std::map<Key, Val> & map)
|
|||||||
return "";
|
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;
|
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())
|
for(const auto & entry : schema["required"].Vector())
|
||||||
{
|
{
|
||||||
const std::string & name = entry.String();
|
const std::string & name = entry.String();
|
||||||
foundEntries.insert(name);
|
|
||||||
|
|
||||||
minimizeNode(node[name], schema["properties"][name]);
|
minimizeNode(node[name], schema["properties"][name]);
|
||||||
|
|
||||||
if (vstd::contains(node.Struct(), name) &&
|
if (vstd::contains(node.Struct(), name) && node[name] == getDefaultValue(schema, name))
|
||||||
node[name] == schema["properties"][name]["default"])
|
|
||||||
{
|
|
||||||
node.Struct().erase(name);
|
node.Struct().erase(name);
|
||||||
}
|
}
|
||||||
}
|
eraseOptionalNodes(node, schema);
|
||||||
|
|
||||||
// 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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonUtils::minimize(JsonNode & node, const std::string & schemaName)
|
static void maximizeNode(JsonNode & node, const JsonNode & schema)
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
// "required" entry can only be found in object/struct
|
// "required" entry can only be found in object/struct
|
||||||
if (schema["type"].String() == "object")
|
if (schema["type"].String() != "object")
|
||||||
{
|
return;
|
||||||
std::set<std::string> foundEntries;
|
|
||||||
|
|
||||||
// check all required entries that have default version
|
// check all required entries that have default version
|
||||||
for(const auto & entry : schema["required"].Vector())
|
for(const auto & entry : schema["required"].Vector())
|
||||||
{
|
{
|
||||||
const std::string & name = entry.String();
|
const std::string & name = entry.String();
|
||||||
foundEntries.insert(name);
|
|
||||||
|
|
||||||
if (node[name].isNull() &&
|
if (node[name].isNull() && !getDefaultValue(schema, name).isNull())
|
||||||
!schema["properties"][name]["default"].isNull())
|
node[name] = getDefaultValue(schema, name);
|
||||||
{
|
|
||||||
node[name] = schema["properties"][name]["default"];
|
|
||||||
}
|
|
||||||
maximizeNode(node[name], schema["properties"][name]);
|
maximizeNode(node[name], schema["properties"][name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// erase all unhandled entries
|
eraseOptionalNodes(node, schema);
|
||||||
for (auto it = node.Struct().begin(); it != node.Struct().end();)
|
}
|
||||||
{
|
|
||||||
if (!vstd::contains(foundEntries, it->first))
|
void JsonUtils::minimize(JsonNode & node, const std::string & schemaName)
|
||||||
it = node.Struct().erase(it);
|
{
|
||||||
else
|
minimizeNode(node, getSchema(schemaName));
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonUtils::maximize(JsonNode & node, const std::string & schemaName)
|
void JsonUtils::maximize(JsonNode & node, const std::string & schemaName)
|
||||||
|
Loading…
Reference in New Issue
Block a user