mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
use json format within the language index file
This commit is contained in:
parent
3048ebe3c5
commit
d39cdb9468
3
bam.lua
3
bam.lua
|
@ -201,6 +201,7 @@ function build(settings)
|
|||
-- build the small libraries
|
||||
wavpack = Compile(settings, Collect("src/engine/external/wavpack/*.c"))
|
||||
pnglite = Compile(settings, Collect("src/engine/external/pnglite/*.c"))
|
||||
jsonparser = Compile(settings, Collect("src/engine/external/json-parser/*.c"))
|
||||
|
||||
-- build game components
|
||||
engine_settings = settings:Copy()
|
||||
|
@ -261,7 +262,7 @@ function build(settings)
|
|||
|
||||
-- build client, server, version server and master server
|
||||
client_exe = Link(client_settings, "teeworlds", game_shared, game_client,
|
||||
engine, client, game_editor, zlib, pnglite, wavpack,
|
||||
engine, client, game_editor, zlib, pnglite, wavpack, jsonparser,
|
||||
client_link_other, client_osxlaunch)
|
||||
|
||||
server_exe = Link(server_settings, "teeworlds_srv", engine, server,
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 1de429e6c3de5a27f19affe0f86f3857d8c1af20
|
||||
Subproject commit 928f0f47c0ffb1f6fea9d13254da42c250a825af
|
|
@ -11,10 +11,10 @@
|
|||
#include <game/generated/client_data.h>
|
||||
|
||||
#include <game/client/gameclient.h>
|
||||
#include <game/client/localization.h>
|
||||
|
||||
#include <game/client/components/scoreboard.h>
|
||||
#include <game/client/components/sounds.h>
|
||||
#include <game/localization.h>
|
||||
|
||||
#include "menus.h"
|
||||
#include "chat.h"
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
#include <engine/friends.h>
|
||||
|
||||
#include <game/voting.h>
|
||||
#include <game/localization.h>
|
||||
#include <game/client/component.h>
|
||||
#include <game/client/localization.h>
|
||||
#include <game/client/ui.h>
|
||||
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#include <engine/graphics.h>
|
||||
#include <engine/storage.h>
|
||||
#include <engine/textrender.h>
|
||||
#include <engine/external/json-parser/json.h>
|
||||
#include <engine/shared/config.h>
|
||||
#include <engine/shared/linereader.h>
|
||||
|
||||
#include <game/generated/protocol.h>
|
||||
#include <game/generated/client_data.h>
|
||||
|
@ -477,62 +477,44 @@ public:
|
|||
|
||||
void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array<CLanguage> *pLanguages)
|
||||
{
|
||||
IOHANDLE File = pStorage->OpenFile("languages/index.txt", IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
// read file data into buffer
|
||||
IOHANDLE File = pStorage->OpenFile("languages/index.json", IOFLAG_READ, IStorage::TYPE_ALL);
|
||||
if(!File)
|
||||
{
|
||||
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "couldn't open index file");
|
||||
return;
|
||||
}
|
||||
|
||||
char aOrigin[128];
|
||||
char aReplacement[128];
|
||||
CLineReader LineReader;
|
||||
LineReader.Init(File);
|
||||
char *pLine;
|
||||
while((pLine = LineReader.Get()))
|
||||
{
|
||||
if(!str_length(pLine) || pLine[0] == '#') // skip empty lines and comments
|
||||
continue;
|
||||
|
||||
str_copy(aOrigin, pLine, sizeof(aOrigin));
|
||||
|
||||
pLine = LineReader.Get();
|
||||
if(!pLine)
|
||||
{
|
||||
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "unexpected end of index file");
|
||||
break;
|
||||
}
|
||||
|
||||
if(pLine[0] != '=' || pLine[1] != '=' || pLine[2] != ' ')
|
||||
{
|
||||
char aBuf[128];
|
||||
str_format(aBuf, sizeof(aBuf), "malform replacement for index '%s'", aOrigin);
|
||||
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf);
|
||||
(void)LineReader.Get();
|
||||
continue;
|
||||
}
|
||||
str_copy(aReplacement, pLine+3, sizeof(aReplacement));
|
||||
|
||||
pLine = LineReader.Get();
|
||||
if(!pLine)
|
||||
{
|
||||
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "unexpected end of index file");
|
||||
break;
|
||||
}
|
||||
|
||||
if(pLine[0] != '=' || pLine[1] != '=' || pLine[2] != ' ')
|
||||
{
|
||||
char aBuf[128];
|
||||
str_format(aBuf, sizeof(aBuf), "malform replacement for index '%s'", aOrigin);
|
||||
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", aBuf);
|
||||
continue;
|
||||
}
|
||||
|
||||
char aFileName[128];
|
||||
str_format(aFileName, sizeof(aFileName), "languages/%s.txt", aOrigin);
|
||||
pLanguages->add(CLanguage(aReplacement, aFileName, str_toint(pLine+3)));
|
||||
}
|
||||
int FileSize = (int)io_length(File);
|
||||
char *pFileData = (char *)mem_alloc(FileSize+1, 1);
|
||||
io_read(File, pFileData, FileSize);
|
||||
pFileData[FileSize] = 0;
|
||||
io_close(File);
|
||||
|
||||
// parse json data
|
||||
json_settings JsonSettings;
|
||||
mem_zero(&JsonSettings, sizeof(JsonSettings));
|
||||
char aError[256];
|
||||
json_value *pJsonData = json_parse_ex(&JsonSettings, pFileData, aError);
|
||||
if(pJsonData == 0)
|
||||
{
|
||||
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localizations", aError);
|
||||
return;
|
||||
}
|
||||
|
||||
// extract data
|
||||
const json_value &rStart = (*pJsonData)["language indices"];
|
||||
if(rStart.type == json_array)
|
||||
{
|
||||
for(int i = 0; i < rStart.u.array.length; ++i)
|
||||
{
|
||||
char aFileName[128];
|
||||
str_format(aFileName, sizeof(aFileName), "languages/%s.txt", (const char *)rStart[i]["file"]);
|
||||
pLanguages->add(CLanguage((const char *)rStart[i]["name"], aFileName, (long)rStart[i]["code"]));
|
||||
}
|
||||
}
|
||||
|
||||
// clean up
|
||||
json_value_free(pJsonData);
|
||||
}
|
||||
|
||||
void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header)
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
#include <game/generated/client_data.h>
|
||||
#include <game/generated/protocol.h>
|
||||
|
||||
#include <game/localization.h>
|
||||
#include <game/client/animstate.h>
|
||||
#include <game/client/gameclient.h>
|
||||
#include <game/client/localization.h>
|
||||
#include <game/client/render.h>
|
||||
#include <game/client/components/countryflags.h>
|
||||
#include <game/client/components/motd.h>
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#include <game/generated/protocol.h>
|
||||
#include <game/generated/client_data.h>
|
||||
|
||||
#include <game/localization.h>
|
||||
#include <game/version.h>
|
||||
#include "localization.h"
|
||||
#include "render.h"
|
||||
|
||||
#include "gameclient.h"
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
#include <engine/textrender.h>
|
||||
|
||||
#include <game/gamecore.h>
|
||||
#include <game/localization.h>
|
||||
#include <game/client/lineinput.h>
|
||||
#include <game/client/localization.h>
|
||||
#include <game/client/render.h>
|
||||
#include <game/client/ui.h>
|
||||
#include <game/generated/client_data.h>
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
|
||||
#include "editor.h"
|
||||
#include <game/generated/client_data.h>
|
||||
#include <game/client/localization.h>
|
||||
#include <game/client/render.h>
|
||||
#include <game/localization.h>
|
||||
|
||||
|
||||
CLayerQuads::CLayerQuads()
|
||||
{
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
#include <engine/textrender.h>
|
||||
|
||||
#include <game/generated/client_data.h>
|
||||
#include <game/client/localization.h>
|
||||
#include <game/client/render.h>
|
||||
#include "editor.h"
|
||||
|
||||
#include <game/localization.h>
|
||||
|
||||
CLayerTiles::CLayerTiles(int w, int h)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue