Skip to content

Commit

Permalink
Refactoring, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ziggi committed Sep 19, 2016
1 parent 9291ced commit 4ac9d05
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ add_samp_plugin (${PROJECT_NAME}
src/sampfunctions.hpp
src/converter.cpp
src/converter.hpp
src/russifier.cpp
src/russifier.hpp
src/common.hpp
src/exports.def
)
2 changes: 0 additions & 2 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

logprintf_t logprintf;
std::list <AMX *> gAmxList;
std::map <int, Converter::Types> gPlayerTypesMap;
Converter::Types gDefaultType = Converter::Types::SanLtd;

amx_Function_t Samp::addr_GameTextForAll;
amx_Function_t Samp::addr_GameTextForPlayer;
Expand Down
31 changes: 15 additions & 16 deletions src/natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
#include "common.hpp"
#include "sampfunctions.hpp"
#include "converter.hpp"
#include "russifier.hpp"

extern logprintf_t logprintf;
extern std::map <int, Converter::Types> gPlayerTypesMap;
extern Converter::Types gDefaultType;

// native SetPlayerRussifierType(playerid, RussifierType:type);
cell AMX_NATIVE_CALL Natives::SetPlayerRussifierType(AMX *amx, cell *params)
Expand All @@ -31,7 +30,7 @@ cell AMX_NATIVE_CALL Natives::SetPlayerRussifierType(AMX *amx, cell *params)
return 0;
}

gPlayerTypesMap[playerid] = static_cast<Converter::Types>(type);
Russifier::SetPlayerType(playerid, type);
return 1;
}

Expand All @@ -46,21 +45,21 @@ cell AMX_NATIVE_CALL Natives::GetPlayerRussifierType(AMX *amx, cell *params)
return 0;
}

return gPlayerTypesMap[playerid];
return Russifier::GetPlayerType(playerid);
}

// native SetDefaultRussifierType(RussifierType:type);
cell AMX_NATIVE_CALL Natives::SetDefaultRussifierType(AMX *amx, cell *params)
{
CHECK_PARAMS(1, "SetDefaultRussifierType");

int type = static_cast<int>(params[2]);
int type = static_cast<int>(params[1]);

if (type < 0 || type >= Converter::TypesCount) {
return 0;
}

gDefaultType = static_cast<Converter::Types>(type);
Russifier::SetDefaultType(type);
return 1;
}

Expand All @@ -69,7 +68,7 @@ cell AMX_NATIVE_CALL Natives::GetDefaultRussifierType(AMX *amx, cell *params)
{
CHECK_PARAMS(0, "GetDefaultRussifierType");

return gDefaultType;
return Russifier::GetDefaultType();
}

// native GameTextForAll(const string[], time, style);
Expand All @@ -86,7 +85,7 @@ cell AMX_NATIVE_CALL Natives::GameTextForAll(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gDefaultType);
Converter::Process(string, Russifier::GetDefaultType());
return Samp::GameTextForAll(string.c_str(), time, style);
}

Expand All @@ -105,7 +104,7 @@ cell AMX_NATIVE_CALL Natives::GameTextForPlayer(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gPlayerTypesMap[playerid]);
Converter::Process(string, Russifier::GetPlayerType(playerid));
return Samp::GameTextForPlayer(playerid, string.c_str(), time, style);
}

Expand All @@ -123,7 +122,7 @@ cell AMX_NATIVE_CALL Natives::TextDrawCreate(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gDefaultType);
Converter::Process(string, Russifier::GetDefaultType());
return Samp::TextDrawCreate(x, y, string.c_str());
}

Expand All @@ -140,7 +139,7 @@ cell AMX_NATIVE_CALL Natives::TextDrawSetString(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gDefaultType);
Converter::Process(string, Russifier::GetDefaultType());
return Samp::TextDrawSetString(text, string.c_str());
}

Expand All @@ -159,7 +158,7 @@ cell AMX_NATIVE_CALL Natives::CreatePlayerTextDraw(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gPlayerTypesMap[playerid]);
Converter::Process(string, Russifier::GetPlayerType(playerid));
return Samp::CreatePlayerTextDraw(playerid, x, y, string.c_str());
}

Expand All @@ -177,7 +176,7 @@ cell AMX_NATIVE_CALL Natives::PlayerTextDrawSetString(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gPlayerTypesMap[playerid]);
Converter::Process(string, Russifier::GetPlayerType(playerid));
return Samp::PlayerTextDrawSetString(playerid, textid, string.c_str());
}

Expand All @@ -198,7 +197,7 @@ cell AMX_NATIVE_CALL Natives::CreateMenu(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gDefaultType);
Converter::Process(string, Russifier::GetDefaultType());
return Samp::CreateMenu(string.c_str(), columns, x, y, col1width, col2width);
}

Expand All @@ -216,7 +215,7 @@ cell AMX_NATIVE_CALL Natives::AddMenuItem(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gDefaultType);
Converter::Process(string, Russifier::GetDefaultType());
return Samp::AddMenuItem(menuid, column, string.c_str());
}

Expand All @@ -234,6 +233,6 @@ cell AMX_NATIVE_CALL Natives::SetMenuColumnHeader(AMX *amx, cell *params)
return 0;
}

Converter::Process(string, gDefaultType);
Converter::Process(string, Russifier::GetDefaultType());
return Samp::SetMenuColumnHeader(menuid, column, string.c_str());
}
42 changes: 42 additions & 0 deletions src/russifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
About: rustext player
Author: ziggi
*/

#include "russifier.hpp"

std::map <int, Converter::Types> Russifier::gPlayerTypesMap;
Converter::Types Russifier::gDefaultType;

void Russifier::SetPlayerType(int playerid, Converter::Types type)
{
gPlayerTypesMap[playerid] = type;
}

void Russifier::SetPlayerType(int playerid, int type)
{
gPlayerTypesMap[playerid] = static_cast<Converter::Types>(type);
}

Converter::Types Russifier::GetPlayerType(int playerid)
{
if (gPlayerTypesMap.find(playerid) == gPlayerTypesMap.end()) {
return gDefaultType;
}
return gPlayerTypesMap[playerid];
}

void Russifier::SetDefaultType(Converter::Types type)
{
gDefaultType = type;
}

void Russifier::SetDefaultType(int type)
{
gDefaultType = static_cast<Converter::Types>(type);
}

Converter::Types Russifier::GetDefaultType()
{
return gDefaultType;
}
28 changes: 28 additions & 0 deletions src/russifier.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
About: rustext russifier
Author: ziggi
*/

#ifndef RUSSIFIER_H
#define RUSSIFIER_H

#include <map>
#include "converter.hpp"

class Russifier
{
public:
static void SetPlayerType(int playerid, Converter::Types type);
static void SetPlayerType(int playerid, int type);
static Converter::Types GetPlayerType(int playerid);

static void SetDefaultType(Converter::Types type);
static void SetDefaultType(int type);
static Converter::Types GetDefaultType();

private:
static std::map <int, Converter::Types> gPlayerTypesMap;
static Converter::Types gDefaultType;
};

#endif

0 comments on commit 4ac9d05

Please sign in to comment.