Skip to content

Commit

Permalink
First commit of Multi-Language Localization
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-Chara committed Mar 26, 2022
1 parent 62019e1 commit fcd26d0
Show file tree
Hide file tree
Showing 40 changed files with 3,103 additions and 42 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ the game, including new versions, custom maps and much more.

Originally written by Magnus Auvinen.

tw06mod-localization branch
---------------------------
Author: Necropotame, FlowerFell-Sans

Features:
- Localization System (In InfClass) (Necropotame)
- Chat command for Switch languages (FlowerFell-Sans)
- Json Example (FlowerFell-Sans)

tw06server branch
---------------------------
Author: necropotame, heinrich5991
Author: Necropotame, Heinrich5991

Features:
- Content related to client removed (necropotame)
Expand Down
73 changes: 70 additions & 3 deletions bam.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,36 @@ AddDependency(server_content_source, server_content_header)

nethash = CHash("src/game/generated/nethash.cpp", "src/engine/shared/protocol.h", "src/game/generated/protocol.h", "src/game/tuning.h", "src/game/gamecore.cpp", network_header)

icu_depends = {}
server_link_other = {}

if family == "windows" then
if platform == "win32" then
-- Add ICU because its a HAVE to
if config.compiler.driver == "cl" then
table.insert(icu_depends, CopyToDirectory(".", "other/icu/vc/lib32/icudt53.dll"))
table.insert(icu_depends, CopyToDirectory(".", "other/icu/vc/lib32/icuin53.dll"))
table.insert(icu_depends, CopyToDirectory(".", "other/icu/vc/lib32/icuuc53.dll"))
elseif config.compiler.driver == "gcc" then
table.insert(icu_depends, CopyToDirectory(".", "other/icu/gcc/lib32/icudt53.dll"))
table.insert(icu_depends, CopyToDirectory(".", "other/icu/gcc/lib32/icuin53.dll"))
table.insert(icu_depends, CopyToDirectory(".", "other/icu/gcc/lib32/icuuc53.dll"))
end
else
-- Add ICU because its a HAVE to
if config.compiler.driver == "cl" then
table.insert(icu_depends, CopyToDirectory(".", "other/icu/vc/lib64/icudt53.dll"))
table.insert(icu_depends, CopyToDirectory(".", "other/icu/vc/lib64/icuin53.dll"))
table.insert(icu_depends, CopyToDirectory(".", "other/icu/vc/lib64/icuuc53.dll"))
elseif config.compiler.driver == "gcc" then
table.insert(icu_depends, CopyToDirectory(".", "other/icu/gcc/lib64/icudt53.dll"))
table.insert(icu_depends, CopyToDirectory(".", "other/icu/gcc/lib64/icuin53.dll"))
table.insert(icu_depends, CopyToDirectory(".", "other/icu/gcc/lib64/icuuc53.dll"))
end
end
table.insert(server_sql_depends, CopyToDirectory(".", "other/mysql/vc2005libs/mysqlcppconn.dll"))
table.insert(server_sql_depends, CopyToDirectory(".", "other/mysql/vc2005libs/libmysql.dll"))

if config.compiler.driver == "cl" then
server_link_other = {ResCompile("other/icons/teeworlds_srv_cl.rc")}
elseif config.compiler.driver == "gcc" then
Expand Down Expand Up @@ -147,10 +174,22 @@ function build(settings)

if family == "unix" then
if platform == "macosx" then
settings.cc.flags_cxx:Add("-stdlib=libc++")
settings.cc.includes:Add("/usr/local/opt/icu4c/include")
settings.link.libs:Add("icui18n")
settings.link.libs:Add("icuuc")
settings.link.libs:Add("c++")
settings.link.libpath:Add("/usr/local/opt/icu4c/lib")
settings.link.frameworks:Add("Carbon")
settings.link.frameworks:Add("AppKit")
else
settings.link.libs:Add("pthread")
-- add ICU for linux
if ExecuteSilent("pkg-config icu-uc icu-i18n") == 0 then
end

settings.cc.flags:Add("`pkg-config --cflags icu-uc icu-i18n`")
settings.link.flags:Add("`pkg-config --libs icu-uc icu-i18n`")
end

if platform == "solaris" then
Expand All @@ -163,6 +202,10 @@ function build(settings)
settings.link.libs:Add("ws2_32")
settings.link.libs:Add("ole32")
settings.link.libs:Add("shell32")
settings.link.libs:Add("advapi32")

-- add ICU also here
settings.cc.includes:Add("other\\icu\\include")
end

-- compile zlib if needed
Expand All @@ -178,7 +221,8 @@ function build(settings)
end

-- build the small libraries

json = Compile(settings, "src/engine/external/json-parser/json.c")

-- build game components
engine_settings = settings:Copy()
server_settings = engine_settings:Copy()
Expand All @@ -188,10 +232,33 @@ function build(settings)
if platform == "macosx" then
launcher_settings.link.frameworks:Add("Cocoa")
end

elseif family == "windows" then
-- Add ICU because its a HAVE to
if platform == "win32" then
if config.compiler.driver == "cl" then
server_settings.link.libpath:Add("other/icu/vc/lib32")
elseif config.compiler.driver == "gcc" then
server_settings.link.libpath:Add("other/icu/gcc/lib32")
end
server_settings.link.libs:Add("icudt")
server_settings.link.libs:Add("icuin")
server_settings.link.libs:Add("icuuc")
else
if config.compiler.driver == "cl" then
server_settings.link.libpath:Add("other/icu/vc/lib64")
elseif config.compiler.driver == "gcc" then
server_settings.link.libpath:Add("other/icu/gcc/lib64")
end
server_settings.link.libs:Add("icudt")
server_settings.link.libs:Add("icuin")
server_settings.link.libs:Add("icuuc")
end
end

engine = Compile(engine_settings, Collect("src/engine/shared/*.cpp", "src/base/*.c"))
server = Compile(server_settings, Collect("src/engine/server/*.cpp"))
teeuniverses = Compile(server_settings, Collect("src/teeuniverses/*.cpp", "src/teeuniverses/components/*.cpp", "src/teeuniverses/system/*.cpp"))

game_shared = Compile(settings, Collect("src/game/*.cpp"), nethash, network_source)
game_server = Compile(settings, CollectRecursive("src/game/server/*.cpp"), server_content_source)
Expand All @@ -203,15 +270,15 @@ function build(settings)

-- build server
server_exe = Link(server_settings, "teeworlds_srv", engine, server,
game_shared, game_server, zlib, server_link_other)
game_shared, game_server, zlib, server_link_other, teeuniverses, json)

serverlaunch = {}
if platform == "macosx" then
serverlaunch = Link(launcher_settings, "serverlaunch", server_osxlaunch)
end

-- make targets
s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch)
s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch, icu_depends)

all = PseudoTarget(settings.config_name, c, s, v, m, t)
return all
Expand Down
Binary file added maps/ctf1.map
Binary file not shown.
Binary file added maps/ctf2.map
Binary file not shown.
Binary file added maps/ctf3.map
Binary file not shown.
Binary file added maps/ctf4.map
Binary file not shown.
Binary file added maps/ctf5.map
Binary file not shown.
Binary file added maps/ctf6.map
Binary file not shown.
Binary file added maps/ctf7.map
Binary file not shown.
Binary file added maps/dd1.map
Binary file not shown.
Binary file added maps/dm2.map
Binary file not shown.
Binary file added maps/dm6.map
Binary file not shown.
Binary file added maps/dm7.map
Binary file not shown.
Binary file added maps/dm8.map
Binary file not shown.
Binary file added maps/dm9.map
Binary file not shown.
12 changes: 12 additions & 0 deletions server_lang/cn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{"translation":
[
{
"key": "Language successfully switched to English",
"value": "语言成功切换为中文"
},
{
"key": "Available languages: {str:ListOfLanguage}",
"value": "可用语言: {str:ListOfLanguage}"
},
]
}
14 changes: 14 additions & 0 deletions server_lang/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"language indices":
[
{
"file": "en",
"name": "english"
},
{
"file": "cn",
"name": "Chinese",
"parent": "en"
}
]
}
36 changes: 35 additions & 1 deletion src/base/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define BASE_MATH_H

#include <stdlib.h>
#include <random>

template <typename T>
inline T clamp(T val, T min, T max)
Expand Down Expand Up @@ -33,6 +34,9 @@ inline T mix(const T a, const T b, TB amount)
return a + (b-a)*amount;
}

float random_float();
bool random_prob(float f);
int random_int(int Min, int Max);
inline float frandom() { return rand()/(float)(RAND_MAX); }

// float to fixed
Expand Down Expand Up @@ -65,6 +69,36 @@ const float pi = 3.1415926535897932384626433f;

template <typename T> inline T min(T a, T b) { return a<b?a:b; }
template <typename T> inline T max(T a, T b) { return a>b?a:b; }
template <typename T> inline T absolute(T a) { return a<T(0)?-a:a; }
template <typename T> inline T mt_absolute(T a) { return a<T(0)?-a:a; }

template<typename T>
constexpr inline T minimum(T a, T b)
{
return a < b ? a : b;
}

template<typename T>
constexpr inline T minimum(T a, T b, T c)
{
return minimum(minimum(a, b), c);
}

template<typename T>
constexpr inline T maximum(T a, T b)
{
return a > b ? a : b;
}

template<typename T>
constexpr inline T maximum(T a, T b, T c)
{
return maximum(maximum(a, b), c);
}

template<typename T>
constexpr inline T absolute(T a)
{
return a < T(0) ? -a : a;
}

#endif // BASE_MATH_H
23 changes: 23 additions & 0 deletions src/base/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -1870,6 +1870,29 @@ const char *str_utf8_skip_whitespaces(const char *str)
return str;
}

//TeeUniverses
void str_append_num(char *dst, const char *src, int dst_size, int num)
{
int s = strlen(dst);
int i = 0;
while(s < dst_size)
{
if(i>=num)
{
dst[s] = 0;
return;
}

dst[s] = src[i];
if(!src[i]) /* check for null termination */
return;
s++;
i++;
}

dst[dst_size-1] = 0; /* assure null termination */
}

static int str_utf8_isstart(char c)
{
if((c&0xC0) == 0x80) /* 10xxxxxx */
Expand Down
4 changes: 4 additions & 0 deletions src/base/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ int net_tcp_close(NETSOCKET sock);
*/
void str_append(char *dst, const char *src, int dst_size);

//TeeUniverses
void str_append_num(char *dst, const char *src, int dst_size, int num);


/*
Function: str_copy
Copies a string to another.
Expand Down
8 changes: 7 additions & 1 deletion src/base/tl/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class array : private ALLOCATOR
list = 0x0;
}

T& increment()
{
incsize();
set_size(size()+1);
return list[num_elements-1];
}

/*
Function: delete_all
Expand Down Expand Up @@ -242,7 +248,7 @@ class array : private ALLOCATOR
*/
void set_size(int new_size)
{
if(list_size < new_size)
if(list_size < new_size)
alloc(new_size);
num_elements = new_size;
}
Expand Down
10 changes: 7 additions & 3 deletions src/engine/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class IConsole : public IInterface
{
protected:
unsigned m_NumArgs;
int m_ClientID;
public:
IResult() { m_NumArgs = 0; }
virtual ~IResult() {}
Expand All @@ -43,6 +44,9 @@ class IConsole : public IInterface
virtual float GetFloat(unsigned Index) = 0;
virtual const char *GetString(unsigned Index) = 0;

void SetClientID(int ClientID) { m_ClientID = ClientID; }
int GetClientID() { return m_ClientID; }

int NumArguments() const { return m_NumArgs; }
};

Expand Down Expand Up @@ -80,10 +84,10 @@ class IConsole : public IInterface
virtual void StoreCommands(bool Store) = 0;

virtual bool LineIsValid(const char *pStr) = 0;
virtual void ExecuteLine(const char *Sptr) = 0;
virtual void ExecuteLineFlag(const char *Sptr, int FlasgMask) = 0;
virtual void ExecuteLine(const char *Sptr, int ClientID) = 0;
virtual void ExecuteLineFlag(const char *Sptr, int ClientID, int FlasgMask) = 0;
virtual void ExecuteLineClient(const char *pStr, int ClientID, int Level, int FlagMask) = 0;
virtual void ExecuteLineStroked(int Stroke, const char *pStr) = 0;
virtual void ExecuteLineStroked(int Stroke, const char *pStr, int ClientID) = 0;
virtual void ExecuteFile(const char *pFilename) = 0;

virtual int RegisterPrintCallback(int OutputLevel, FPrintCallback pfnPrintCallback, void *pUserData) = 0;
Expand Down
1 change: 1 addition & 0 deletions src/engine/external/json-parser/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unmarked version: 17.12.2012
Loading

0 comments on commit fcd26d0

Please sign in to comment.