Skip to content

Commit

Permalink
refactor: custom radio callsigns json object
Browse files Browse the repository at this point in the history
JSON element "custom" has been renamed to "custom_callsigns"
The value of this element was changed from array of objects
to a single object of indefinite amount of elements.
This object will hold two values:
1. the callsign, which can be a strict constant or a regex (element name)
2. the corresponding radio callsign (element value)

Example:
    "radio_callsigns": {
        "config": {
            "load_from_ese": false,
            "path_to_ese" : "..\\..\\"
        },
        "custom_callsigns": {
            "^HECC_CTR$": "Cairo Control Bandbox",
            "^HECC_(\\d+)(?:_)CTR$" : "Cairo Control ACC $0"
        }
    }
  • Loading branch information
Kirollos committed Nov 8, 2024
1 parent 28b6d59 commit b858ab9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
24 changes: 9 additions & 15 deletions DiscordEuroscope/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,17 @@ namespace DiscordEuroScope_Configuration
}
}

assert(RadioCallsignObj.HasMember("custom") && RadioCallsignObj["custom"].IsArray());
assert(RadioCallsignObj.HasMember("custom_callsigns") && RadioCallsignObj["custom_callsigns"].IsObject());
data.RadioCallsigns.clear();
for (auto& it : RadioCallsignObj["custom"].GetArray())
auto& obj = RadioCallsignObj["custom_callsigns"].GetObjectA();
for (auto& it : obj)
{
if (it.IsObject())
{
RadioCallsignElement_t element;
if (it.HasMember("callsign") && it["callsign"].IsString())
element.callsign = std::string(it["callsign"].GetString());
if (it.HasMember("frequency") && it["frequency"].IsString())
element.frequency = std::string(it["frequency"].GetString());
if (it.HasMember("rcallsign") && it["rcallsign"].IsString())
element.radio_callsign = std::string(it["rcallsign"].GetString());

element.icao = element.callsign.substr(0, element.callsign.find_first_of('_'));
data.RadioCallsigns.push_back(element);
}
RadioCallsignElement_t element;
assert(it.name.IsString() && it.value.IsString());
element.callsign = it.name.GetString();
element.radio_callsign = it.value.GetString();
element.icao = element.callsign.substr(0, element.callsign.find_first_of('_'));
data.RadioCallsigns.push_back(element);
}
}

Expand Down
14 changes: 4 additions & 10 deletions DiscordEuroscope/DefaultFileContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,10 @@
\"load_from_ese\": false,\r\
\"path_to_ese\" : \"..\\\\..\\\\\"\r\
},\r\
\"custom\" : [\r\
{\r\
\"callsign\": \"^HECC_CTR$\",\r\
\"rcallsign\" : \"Cairo Control Bandbox\"\r\
},\r\
{\r\
\"callsign\": \"^HECC_(\\\\d+)(?:_)CTR$\",\r\
\"rcallsign\" : \"Cairo Control ACC $0\"\r\
}\r\
]\r\
\"custom_callsigns\": {\r\
\"^HECC_CTR$\": \"Cairo Control Bandbox\",\r\
\"^HECC_(\\\\d+)(?:_)CTR$\" : \"Cairo Control ACC $0\"\r\
}\r\
}\r\
}\r\
")
17 changes: 17 additions & 0 deletions DiscordEuroscope/ESEHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
Copyright(C) 2023-2024 Kirollos Nashaat
This program is free software : you can redistribute it and /or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see < https://www.gnu.org/licenses/>.
*/

#include "stdafx.h"
#include "ESEHandler.h"
#include "ConfigData.h"
Expand Down

0 comments on commit b858ab9

Please sign in to comment.