Rename property "tag" to "name" in tag definitions

This commit is contained in:
Timotej Lazar 2021-09-07 21:54:40 +02:00
parent ff63d29adb
commit 1eee2fc2b5
No known key found for this signature in database
GPG key ID: B6F38793D143456F
2 changed files with 13 additions and 9 deletions

View file

@ -80,11 +80,15 @@ void EventList::load(const QJsonObject& json)
{
const auto& jsonTags = json["tags"].toArray();
if (!jsonTags.isEmpty()) {
// Map tag name to definition and remember tag order.
tags = {};
tagsOrder.clear();
for (int i = 0; i < jsonTags.size(); i++) {
const auto name = jsonTags[i]["tag"].toString();
tags[name] = jsonTags[i].toObject();
const auto& tag = jsonTags[i].toObject();
// Compatibility with older tag definitions.
const auto& nameKey = tag.contains("name") ? "name" : "tag";
const auto name = tag[nameKey].toString();
tags[name] = tag;
tagsOrder.append(name);
}
emit tagsChanged();

View file

@ -1,6 +1,6 @@
[
{
"tag": "pass", "key": "p", "fields": [
"name": "pass", "key": "p", "fields": [
{ "name": "player", "type": "Text", "key": "p" },
{
"name": "type", "type": "Enum",
@ -14,7 +14,7 @@
]
},
{
"tag": "shot", "key": "s", "fields": [
"name": "shot", "key": "s", "fields": [
{ "name": "player", "type": "Text", "key": "p" },
{
"name": "outcome", "type": "Enum",
@ -29,28 +29,28 @@
]
},
{
"tag": "foul", "key": "f", "fields": [
"name": "foul", "key": "f", "fields": [
{ "name": "player", "type": "Text", "key": "p" },
{ "name": "opponent", "type": "Text", "key": "o" },
{ "name": "comment", "type": "TextArea", "key": "c" }
]
},
{
"tag": "offside", "key": "o", "fields": [
"name": "offside", "key": "o", "fields": [
{ "name": "player", "type": "Text", "key": "p" },
{ "name": "comment", "type": "TextArea", "key": "c" }
]
},
{
"tag": "assist", "key": "a", "fields": [
"name": "assist", "key": "a", "fields": [
{ "name": "player", "type": "Text", "key": "p" },
{ "name": "comment", "type": "TextArea", "key": "c" }
]
},
{
"tag": "offense", "key": "O", "fields": []
"name": "offense", "key": "O", "fields": []
},
{
"tag": "defense", "key": "D", "fields": []
"name": "defense", "key": "D", "fields": []
}
]