Commit 7ede522d authored by Dennis Willers's avatar Dennis Willers
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading

info.toml

0 → 100644
+9 −0
Original line number Original line Diff line number Diff line
[meta]
name = "Voting"
author = "RoboTec13"
category = "Race"

version = "1.0"

[script]
imports = ["Icons.as", "Formatting.as"]

src/conf/settings.as

0 → 100644
+13 −0
Original line number Original line Diff line number Diff line
[Setting category="Window" name="Change Voting Position"]
bool Setting_View_Change_Position = false;

[Setting category="Window" name="Position X / Position Y"]
vec2 Setting_View_Voting_Pos = vec2(Setting_View_Width-Setting_View_Voting_Size.x, 42);
int Setting_View_Width = Draw::GetWidth();

[Setting category="Window" name="Width / Height"]
vec2 Setting_View_Voting_Size = vec2(138,84);

[Setting category="Chat" name="insert chat message after click on vote"]
bool Setting_Chat_Show_Voting = true;

src/conf/socket.as

0 → 100644
+57 −0
Original line number Original line Diff line number Diff line
Net::Socket@ sock;
bool sockIsConnected = false;
bool initSocketConnection()
{
	// Create a new socket.
	@sock = Net::Socket();

	if (!sock.Connect("willers.digital", 3201)) {
		// If it failed, there was some socket error. (This is not necessarily
		// a connection error!)
		print("Couldn't initiate socket connection.");
		return false;
	}

	// Wait until we are connected. This is indicated by whether we can write
	// to the socket.
	while (!sock.CanWrite()) {
		yield();
	}

	sockIsConnected = true;
	startnew(waitingForResponse);
	return true;
}

void waitingForResponse() {

	while (true) {
        string line;
        if (sock.ReadLine(line)) {
            auto js = Json::Parse(line);
            handleMessage(js);
        }
        yield();
    }
}

void requestSocketServer(const Json::Value &in js) {
	// Send raw data (as a string) to the server.
	if (!sock.WriteRaw(Json::Write(js))) {
		// If this fails, the socket might not be open. Something is wrong!
		print("Couldn't send data.");
		return;
	}
}

void handleMessage(const Json::Value &in js)
{
	if (Json::Write(js) != "null") {
		setVotingInformation(js);
	} 
}

void closeSocket() {
	sock.Close();
	sockIsConnected = false;
}

src/features/chat.as

0 → 100644
+57 −0
Original line number Original line Diff line number Diff line
string currentChatMessage = "";

void readLastChatMessage() {
    while(true) {
        if (getNetwork() !is null) {
            MwFastBuffer<wstring> chatHistory = getNetwork().ChatHistoryLines;
            if (chatHistory.get_Length() > 0) {
                string chatMessage = chatHistory[0];
                if (chatMessage != currentChatMessage && !hasVoteTimeout) {
                    currentChatMessage = chatMessage;
                    if (checkIfMessageIsByCurrentClient()) {
                        sendRequestIfMessageMatchForVoting();
                    }
                }
            }
            yield();
        }
    }
}

bool checkIfMessageIsByCurrentClient() {
    string user = currentChatMessage.SubStr(3,currentChatMessage.IndexOf('$>]')-3);
    if (user == getName()) {
        return true;
    }
    return false;
}

void sendRequestIfMessageMatchForVoting() {
    string message = currentChatMessage.SubStr(currentChatMessage.IndexOf('$>] ')+4);
    if (message == '+++') newSelectedVoteByChat(3, 100);
    if (message == '++') newSelectedVoteByChat(2, 80);
    if (message == '+') newSelectedVoteByChat(1, 60);
    if (message == '-') newSelectedVoteByChat(4, 40);
    if (message == '--') newSelectedVoteByChat(5, 20);
    if (message == '---') newSelectedVoteByChat(6, 0);
}

void printVote(int vote) {
    if (Setting_Chat_Show_Voting) {
        CGamePlaygroundInterface@ playgroundInterface = getPlaygroundInterface();
        playgroundInterface.ChatEntry = getVoteText(vote);
    }
}

string getVoteText(int vote) {
    string startText = "";
    switch(vote) {
        case 0: startText = "$F00   "; break;
        case 20: startText = "$F00  "; break;
        case 40: startText = "$F00 "; break;
        case 60: startText = "$0F0 "; break;
        case 80: startText = "$0F0  "; break;
        case 100: startText = "$0F0   "; break;
    }
    return startText;
}
 No newline at end of file

src/features/menu.as

0 → 100644
+17 −0
Original line number Original line Diff line number Diff line
void RenderMenu()
{
    if (UI::MenuItem("\\$ff0" + Icons::Star + "\\$z Voting", "", !hideme)) {
		hideme = !hideme;
	}
    // add menu items to go to the right Tutorial Steps
    /*if (UI::BeginMenu(ColoredString("$ff0" + Icons::Star + "$fff Voting"))) {
        if (UI::MenuItem(ColoredString("$f00" + Icons::PowerOff + "$fff Hide"))) hideme = !hideme;
        if (UI::MenuItem(ColoredString("$0f0" + Icons::Plus + Icons::Plus + Icons::Plus))) print("+++");
        if (UI::MenuItem(ColoredString("$0f0" + Icons::Plus + Icons::Plus))) print("++");
        if (UI::MenuItem(ColoredString("$0f0" + Icons::Plus))) print("+");
        if (UI::MenuItem(ColoredString("$f00" + Icons::Minus + Icons::Minus + Icons::Minus))) print("---");
        if (UI::MenuItem(ColoredString("$f00" + Icons::Minus + Icons::Minus))) print("--");
        if (UI::MenuItem(ColoredString("$f00" + Icons::Minus))) print("-");
        UI::EndMenu();
    }*/
}
 No newline at end of file
Loading