use json format within the language index file

This commit is contained in:
oy 2012-12-17 00:05:43 +01:00
parent 3048ebe3c5
commit d39cdb9468
12 changed files with 44 additions and 60 deletions

View file

@ -201,6 +201,7 @@ function build(settings)
-- build the small libraries -- build the small libraries
wavpack = Compile(settings, Collect("src/engine/external/wavpack/*.c")) wavpack = Compile(settings, Collect("src/engine/external/wavpack/*.c"))
pnglite = Compile(settings, Collect("src/engine/external/pnglite/*.c")) pnglite = Compile(settings, Collect("src/engine/external/pnglite/*.c"))
jsonparser = Compile(settings, Collect("src/engine/external/json-parser/*.c"))
-- build game components -- build game components
engine_settings = settings:Copy() engine_settings = settings:Copy()
@ -261,7 +262,7 @@ function build(settings)
-- build client, server, version server and master server -- build client, server, version server and master server
client_exe = Link(client_settings, "teeworlds", game_shared, game_client, 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) client_link_other, client_osxlaunch)
server_exe = Link(server_settings, "teeworlds_srv", engine, server, server_exe = Link(server_settings, "teeworlds_srv", engine, server,

@ -1 +1 @@
Subproject commit 1de429e6c3de5a27f19affe0f86f3857d8c1af20 Subproject commit 928f0f47c0ffb1f6fea9d13254da42c250a825af

View file

@ -11,10 +11,10 @@
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
#include <game/client/gameclient.h> #include <game/client/gameclient.h>
#include <game/client/localization.h>
#include <game/client/components/scoreboard.h> #include <game/client/components/scoreboard.h>
#include <game/client/components/sounds.h> #include <game/client/components/sounds.h>
#include <game/localization.h>
#include "menus.h" #include "menus.h"
#include "chat.h" #include "chat.h"

View file

@ -11,8 +11,8 @@
#include <engine/friends.h> #include <engine/friends.h>
#include <game/voting.h> #include <game/voting.h>
#include <game/localization.h>
#include <game/client/component.h> #include <game/client/component.h>
#include <game/client/localization.h>
#include <game/client/ui.h> #include <game/client/ui.h>

View file

@ -7,8 +7,8 @@
#include <engine/graphics.h> #include <engine/graphics.h>
#include <engine/storage.h> #include <engine/storage.h>
#include <engine/textrender.h> #include <engine/textrender.h>
#include <engine/external/json-parser/json.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/linereader.h>
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
@ -477,62 +477,44 @@ public:
void LoadLanguageIndexfile(IStorage *pStorage, IConsole *pConsole, sorted_array<CLanguage> *pLanguages) 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) if(!File)
{ {
pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "couldn't open index file"); pConsole->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "localization", "couldn't open index file");
return; return;
} }
int FileSize = (int)io_length(File);
char aOrigin[128]; char *pFileData = (char *)mem_alloc(FileSize+1, 1);
char aReplacement[128]; io_read(File, pFileData, FileSize);
CLineReader LineReader; pFileData[FileSize] = 0;
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)));
}
io_close(File); 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) void CMenus::RenderLanguageSelection(CUIRect MainView, bool Header)

View file

@ -8,9 +8,9 @@
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/localization.h>
#include <game/client/animstate.h> #include <game/client/animstate.h>
#include <game/client/gameclient.h> #include <game/client/gameclient.h>
#include <game/client/localization.h>
#include <game/client/render.h> #include <game/client/render.h>
#include <game/client/components/countryflags.h> #include <game/client/components/countryflags.h>
#include <game/client/components/motd.h> #include <game/client/components/motd.h>

View file

@ -16,8 +16,8 @@
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
#include <game/localization.h>
#include <game/version.h> #include <game/version.h>
#include "localization.h"
#include "render.h" #include "render.h"
#include "gameclient.h" #include "gameclient.h"

View file

@ -14,8 +14,8 @@
#include <engine/textrender.h> #include <engine/textrender.h>
#include <game/gamecore.h> #include <game/gamecore.h>
#include <game/localization.h>
#include <game/client/lineinput.h> #include <game/client/lineinput.h>
#include <game/client/localization.h>
#include <game/client/render.h> #include <game/client/render.h>
#include <game/client/ui.h> #include <game/client/ui.h>
#include <game/generated/client_data.h> #include <game/generated/client_data.h>

View file

@ -7,8 +7,9 @@
#include "editor.h" #include "editor.h"
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
#include <game/client/localization.h>
#include <game/client/render.h> #include <game/client/render.h>
#include <game/localization.h>
CLayerQuads::CLayerQuads() CLayerQuads::CLayerQuads()
{ {

View file

@ -7,10 +7,10 @@
#include <engine/textrender.h> #include <engine/textrender.h>
#include <game/generated/client_data.h> #include <game/generated/client_data.h>
#include <game/client/localization.h>
#include <game/client/render.h> #include <game/client/render.h>
#include "editor.h" #include "editor.h"
#include <game/localization.h>
CLayerTiles::CLayerTiles(int w, int h) CLayerTiles::CLayerTiles(int w, int h)
{ {