Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
mcagabe19 committed Oct 2, 2024
2 parents 8468b44 + 6fb8760 commit b85b009
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 38 deletions.
2 changes: 1 addition & 1 deletion gitVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.1
0.8.2
2 changes: 1 addition & 1 deletion source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Main extends Sprite
public static var stage3D:AwayStage;
#end

public static final PSYCH_ONLINE_VERSION:String = "0.8.1";
public static final PSYCH_ONLINE_VERSION:String = "0.8.2";
public static final CLIENT_PROTOCOL:Float = 4;
public static final GIT_COMMIT:String = online.Macros.getGitCommitHash();

Expand Down
21 changes: 19 additions & 2 deletions source/objects/SustainSplash.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ class SustainSplash extends FlxSprite {
public static var frameRate:Int;
public var strumNote:StrumNote;

public static var defaultNoteHoldSplash(default, never):String = 'noteSplashes/holdSplashes/holdSplash';

public function new():Void {
super();
frames = Paths.getSparrowAtlas('noteSplashes/holdSplashes/holdSplash');

var skin:String = defaultNoteHoldSplash + getSplashSkinPostfix();
frames = Paths.getSparrowAtlas(skin);
if (frames == null) {
skin = defaultNoteHoldSplash;
frames = Paths.getSparrowAtlas(skin);
}

animation.addByPrefix('hold', 'hold', 24, true);
animation.addByPrefix('end', 'end', 24, false);
animation.play('hold', true, false, 0);
Expand Down Expand Up @@ -52,7 +61,7 @@ class SustainSplash extends FlxSprite {
offset.set(PlayState.isPixelStage ? 112.5 : 106.25, 100);

new FlxTimer().start(timeThingy, (idk:FlxTimer) -> {
if (tailEnd.mustPress && !(daNote.isSustainNote ? daNote.parent.noteSplashData.disabled : daNote.noteSplashData.disabled) && ClientPrefs.data.splashAlpha != 0) {
if (PlayState.isPlayerNote(tailEnd) && !(daNote.isSustainNote ? daNote.parent.noteSplashData.disabled : daNote.noteSplashData.disabled) && ClientPrefs.data.splashAlpha != 0) {
alpha = ClientPrefs.data.splashAlpha - (1 - strumNote.alpha);
animation.play('end', true, false, 0);
animation.curAnim.looped = false;
Expand All @@ -68,4 +77,12 @@ class SustainSplash extends FlxSprite {

}

public static function getSplashSkinPostfix()
{
var skin:String = '';
if(ClientPrefs.data.splashSkin != ClientPrefs.defaultData.splashSkin)
skin = '-' + ClientPrefs.data.splashSkin.trim().toLowerCase().replace(' ', '_');
return skin;
}

}
55 changes: 42 additions & 13 deletions source/online/GameClient.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package online;

import flixel.FlxState;
import online.net.Auth;
import online.net.FunkinNetwork;
import states.OutdatedState;
Expand Down Expand Up @@ -108,10 +109,10 @@ class GameClient {
}

GameClient.room.onLeave += () -> {
trace("Left!");
if (room?.roomId != null) {
trace("Left from room: " + room.roomId);
}
if (room?.roomId != null)
trace("Left/Kicked from room: " + room.roomId);
else
trace("Left/Kicked from unknown room!");

if (client == null) {
leaveRoom();
Expand All @@ -137,14 +138,20 @@ class GameClient {
//}
}

public static function reconnect(?nextTry:Bool = false) {
public static function reconnect() {
if (reconnecting)
return;

reconnecting = true;
Sys.println("reconnecting with token: " + room.reconnectionToken);

trace("Reconnecting with Token: " + room.reconnectionToken);
Alert.alert("Reconnecting...");

try {
GameClient.room.teardown();
GameClient.room.leave(false);
}
catch (exc) {}

Thread.run(() -> {
client.reconnect(room.reconnectionToken, GameRoom, (err, newRoom) -> {
if (err != null) {
Expand All @@ -157,6 +164,8 @@ class GameClient {
}

_onJoin(err, newRoom, GameClient.isOwner, GameClient.address);
if (addListeners != null)
addListeners();
sendPending();
Waiter.put(() -> {
Alert.alert("Reconnected!");
Expand Down Expand Up @@ -205,18 +214,21 @@ class GameClient {
Waiter.put(() -> {
if (reason != null)
Alert.alert("Disconnected!", reason.trim() != "" ? reason : null);
Sys.println("leaving the room");
trace("Leaving the Room, Reason: " + reason);

FlxG.autoPause = ClientPrefs.data.autoPause;

FlxG.switchState(() -> new OnlineState());
FlxG.sound.play(Paths.sound('cancelMenu'));
FlxG.sound.playMusic(Paths.music('freakyMenu'));

if (GameClient.room?.connection != null) {
GameClient.room.leave(true);
GameClient.room.teardown();
}
try {
if (GameClient.room?.connection != null) {
GameClient.room.teardown();
GameClient.room.leave(true);
}
}
catch (exc) {}

GameClient.room = null;
GameClient.isOwner = false;
Expand All @@ -228,14 +240,31 @@ class GameClient {
}

public static function isConnected() {
return client != null;
return client != null || reconnecting;
}

public static function initStateListeners(state:FlxState, listenersCallback:Void->Void) {
addListenersState = state;
addListeners = listenersCallback;
}
private static var addListenersState:FlxState;
private static var addListeners(default, null):Void->Void;

private static var hasStateCallback:Bool = false;

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

if (!hasStateCallback) {
hasStateCallback = true;
FlxG.signals.postStateSwitch.add(() -> {
if (addListenersState != FlxG.state)
addListeners = null;
});
}

GameClient.room.onMessageHandlers.clear();

ChatBox.tryRegisterLogs();
Expand Down
11 changes: 8 additions & 3 deletions source/online/states/ResultsScreen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ class ResultsScreen extends MusicBeatState {

});

registerMessages();
addTouchPad('NONE', 'B_C_T');
}

function registerMessages() {
GameClient.initStateListeners(this, this.registerMessages);

if (GameClient.isConnected()) {
GameClient.send("status", "Viewing results");

Expand All @@ -295,9 +302,7 @@ class ResultsScreen extends MusicBeatState {
});
});
}

addTouchPad('NONE', 'B_C_T');
}
}

function flickerLoop() {
FlxFlicker.flicker(spotlight, 0.2, 0.05, true);
Expand Down
26 changes: 17 additions & 9 deletions source/online/states/RoomState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,41 @@ class RoomState extends MusicBeatState {

instance = this;

GameClient.room.onMessage("checkChart", function(message) {
registerMessages();

playMusic((GameClient.isOwner ? GameClient.room.state.player1 : GameClient.room.state.player2).hasSong);
(GameClient.isOwner ? GameClient.room.state.player1 : GameClient.room.state.player2).listen("hasSong", (value:Bool, prev) -> {
Waiter.put(() -> {
verifyDownloadMod(false, true);
playMusic(value);
});
});
}

GameClient.room.onMessage("checkStage", function(message) {
function registerMessages() {
GameClient.initStateListeners(this, this.registerMessages);

GameClient.room.onMessage("checkChart", function(message) {
Waiter.put(() -> {
checkStage();
verifyDownloadMod(false, true);
});
});

playMusic((GameClient.isOwner ? GameClient.room.state.player1 : GameClient.room.state.player2).hasSong);
(GameClient.isOwner ? GameClient.room.state.player1 : GameClient.room.state.player2).listen("hasSong", (value:Bool, prev) -> {
GameClient.room.onMessage("checkStage", function(message) {
Waiter.put(() -> {
playMusic(value);
checkStage();
});
});

GameClient.room.state.player1.listen("skinName", (value, prev) -> {
if (value == prev) return;
if (value == prev)
return;
Waiter.put(() -> {
loadCharacter(true, true);
});
});
GameClient.room.state.player2.listen("skinName", (value, prev) -> {
if (value == prev) return;
if (value == prev)
return;
Waiter.put(() -> {
loadCharacter(false, true);
});
Expand Down
19 changes: 10 additions & 9 deletions source/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2346,11 +2346,9 @@ class PlayState extends MusicBeatState
addHealth(2);
}

#if LOCAL
if (FlxG.keys.justPressed.F9 && GameClient.isConnected()) {
GameClient.room.leave(false);
if (FlxG.keys.justPressed.F11 && GameClient.isConnected()) {
GameClient.reconnect();
}
#end

if (controls.TAUNT && canInput()) {
getPlayer().playAnim('taunt', true);
Expand All @@ -2359,10 +2357,11 @@ class PlayState extends MusicBeatState
}

if (GameClient.isConnected()) {
//if player 2 left then go back to lobby
if (GameClient.room.state.player2.name == "") {
endSong();
}
//if player 2 left then go back to lobby // nvm, unreliable on reconnects
// if (!GameClient.reconnecting && GameClient.room.state.player2.name == "") {
// trace("No one is playing, leaving...");
// endSong();
// }

if (canStart && !isReady && (controls.mobileC && FlxG.mouse.justPressed || controls.ACCEPT) && canInput()) {
isReady = true;
Expand Down Expand Up @@ -4227,7 +4226,7 @@ class PlayState extends MusicBeatState
public function spawnHoldSplash(note:Note) {
var end:Note = note.isSustainNote ? note.parent.tail[note.parent.tail.length - 1] : note.tail[note.tail.length - 1];
var splash:SustainSplash = grpHoldSplashes.recycle(SustainSplash);
splash.setupSusSplash(strumLineNotes.members[note.noteData + (note.mustPress ? 4 : 0)], note, playbackRate);
splash.setupSusSplash(getPlayerStrums().members[note.noteData], note, playbackRate);
grpHoldSplashes.add(end.extraData['holdSplash'] = splash);
}

Expand Down Expand Up @@ -4893,6 +4892,8 @@ class PlayState extends MusicBeatState
}

function registerMessages() {
GameClient.initStateListeners(this, this.registerMessages);

if (!GameClient.isConnected())
return;

Expand Down

0 comments on commit b85b009

Please sign in to comment.