Skip to content

Commit

Permalink
0.2.1 cool
Browse files Browse the repository at this point in the history
  • Loading branch information
Snirozu committed Nov 20, 2023
1 parent 2b9ded7 commit c347196
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 20 deletions.
16 changes: 13 additions & 3 deletions source/online/GameClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class GameClient {
FlxG.autoPause = false;

GameClient.room = room;
clearOnMessage();
GameClient.isOwner = true;

GameClient.room.onError += (id:Int, e:String) -> {
Expand Down Expand Up @@ -78,6 +79,7 @@ class GameClient {
FlxG.autoPause = false;

GameClient.room = room;
clearOnMessage();
GameClient.isOwner = false;

GameClient.room.onError += (id:Int, e:String) -> {
Expand Down Expand Up @@ -127,6 +129,7 @@ class GameClient {
Sys.println("reconnected!");

GameClient.room = room;
clearOnMessage();

GameClient.room.onError += (id:Int, e:String) -> {
Sys.println("Room.onError: " + id + " - " + e);
Expand Down Expand Up @@ -175,12 +178,19 @@ class GameClient {
}

public static function isConnected() {
return client != null || reconnectTries > 0;
return client != null;
}

@:access(io.colyseus.Room.onMessageHandlers)
public static function clearOnMessage() {
if (GameClient.isConnected())
@:privateAccess GameClient.room.onMessageHandlers.clear();
if (GameClient.isConnected() && GameClient.room?.onMessageHandlers != null)
GameClient.room.onMessageHandlers.clear();

GameClient.room.onMessage("ping", function(message) {
Waiter.put(() -> {
GameClient.send("pong");
});
});
}

public static function send(type:Dynamic, ?message:Null<Dynamic>) {
Expand Down
3 changes: 3 additions & 0 deletions source/online/schema/Player.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ class Player extends Schema {

@:type("boolean")
public var hasEnded:Bool = false;

@:type("number")
public var ping:Dynamic = 0;
}
2 changes: 1 addition & 1 deletion source/online/states/FindRoom.hx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class RoomText extends FlxText {

public function new(room:RoomAvailable) {
code = room.roomId;
daText = "Code: " + code + " | Player: " + room.metadata.name;
daText = "Code: " + code + " | Player: " + room.metadata.name + " | " + room.metadata.ping + "ms";

super(0, 0, FlxG.width, daText);
setFormat("VCR OSD Mono", 30, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
Expand Down
7 changes: 7 additions & 0 deletions source/online/states/Lobby.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package online.states;

import lime.system.Clipboard;
import haxe.Json;
import states.MainMenuState;
import openfl.events.KeyboardEvent;
Expand Down Expand Up @@ -66,6 +67,8 @@ class Lobby extends MusicBeatState {
override function create() {
super.create();

DiscordClient.changePresence("In online lobby.", null, null, true);

daName = ClientPrefs.data.nickname;

var bg:FlxSprite = new FlxSprite().loadGraphic(Paths.image('menuDesat'));
Expand Down Expand Up @@ -224,6 +227,10 @@ class Lobby extends MusicBeatState {
newText = newText.toLowerCase();
}

if (key == 86 && e.ctrlKey) {
newText = Clipboard.text;
}

if (newText.length > 0) {
inputString += newText;
}
Expand Down
35 changes: 30 additions & 5 deletions source/online/states/Room.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package online.states;

import lime.system.Clipboard;
import online.schema.Player;
import backend.Rating;
import backend.WeekData;
Expand Down Expand Up @@ -28,6 +29,13 @@ class Room extends MusicBeatState {
public function new() {
super();

if (GameClient.room.state.isPrivate) {
DiscordClient.changePresence("In a online room.", "Private room.", null, true);
}
else {
DiscordClient.changePresence("In a online room.", "Public room: " + GameClient.room.roomId, null, true);
}

WeekData.reloadWeekFiles(false);
for (i in 0...WeekData.weeksList.length) {
WeekData.setDirectoryFromWeek(WeekData.weeksLoaded.get(WeekData.weeksList[i]));
Expand All @@ -43,11 +51,11 @@ class Room extends MusicBeatState {
add(bg);

player1Text = new FlxText(0, 50, 0, "PLAYER 1");
player1Text.setFormat("VCR OSD Mono", 30, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
player1Text.setFormat("VCR OSD Mono", 25, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(player1Text);

player2Text = new FlxText(0, 50, 0, "PLAYER 2");
player2Text.setFormat("VCR OSD Mono", 30, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
player2Text.setFormat("VCR OSD Mono", 25, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(player2Text);

roomCode = new FlxText(0, 0, FlxG.width, "????");
Expand All @@ -56,7 +64,7 @@ class Room extends MusicBeatState {
roomCode.screenCenter(X);
add(roomCode);

roomCodeTip = new FlxText(0, roomCode.y + roomCode.height + 5, FlxG.width, "(Press S to show your room code)");
roomCodeTip = new FlxText(0, roomCode.y + roomCode.height + 5, FlxG.width, "(Press S to show your room code, CTRL+C to copy)");
roomCodeTip.setFormat("VCR OSD Mono", 18, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
roomCodeTip.screenCenter(X);
add(roomCodeTip);
Expand Down Expand Up @@ -154,7 +162,18 @@ class Room extends MusicBeatState {
});
});

GameClient.room.state.listen("isPrivate", (value, prev) -> {
if (value) {
DiscordClient.changePresence("In a online room.", "Private room.", null, true);
}
else {
DiscordClient.changePresence("In a online room.", "Public room: " + GameClient.room.roomId, null, true);
}
});

updateTexts();

new FlxTimer().start();
}

override function update(elapsed) {
Expand Down Expand Up @@ -204,6 +223,10 @@ class Room extends MusicBeatState {
GameClient.send("anarchyMode");
}
}

if (FlxG.keys.pressed.CONTROL && FlxG.keys.justPressed.C) {
Clipboard.text = GameClient.room.roomId;
}
}

player1Text.x = FlxG.width / 2 - 200 - player1Text.width;
Expand Down Expand Up @@ -259,7 +282,8 @@ class Room extends MusicBeatState {
"Goods: " + GameClient.room.state.player1.goods + "\n" +
"Bads: " + GameClient.room.state.player1.bads + "\n" +
"Shits: " + GameClient.room.state.player1.shits + "\n" +
"Misses: " + GameClient.room.state.player1.misses;
"Misses: " + GameClient.room.state.player1.misses + "\n" +
"Ping: " + GameClient.room.state.player1.ping + "ms";

if (GameClient.room.state.player2 != null) {
player2Text.text = "PLAYER 2\n" +
Expand All @@ -271,7 +295,8 @@ class Room extends MusicBeatState {
"Goods: " + GameClient.room.state.player2.goods + "\n" +
"Bads: " + GameClient.room.state.player2.bads + "\n" +
"Shits: " + GameClient.room.state.player2.shits + "\n" +
"Misses: " + GameClient.room.state.player2.misses;
"Misses: " + GameClient.room.state.player2.misses + "\n" +
"Ping: " + GameClient.room.state.player2.ping + "ms";
}
else {
player2Text.text = "WAITING FOR OPPONENT...";
Expand Down
10 changes: 10 additions & 0 deletions source/states/FreeplayState.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package states;

import online.Alert;
import online.Waiter;
import haxe.crypto.Md5;
import online.states.Room;
Expand Down Expand Up @@ -179,6 +180,15 @@ class FreeplayState extends MusicBeatState
add(text);

updateTexts();

if (GameClient.isConnected()) {
GameClient.room.onMessage("log", function(message) {
Waiter.put(() -> {
Alert.alert("New message", message);
});
});
}

super.create();
}

Expand Down
2 changes: 1 addition & 1 deletion source/states/MainMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import options.OptionsState;

class MainMenuState extends MusicBeatState
{
public static var psychOnlineVersion:String = "0.2.5";
public static var psychOnlineVersion:String = "0.2.1";
public static var psychEngineVersion:String = '0.7.1h* (online)'; //This is also used for Discord RPC
public static var curSelected:Int = 0;

Expand Down
Loading

0 comments on commit c347196

Please sign in to comment.