Skip to content

Commit

Permalink
Revert GameWaitingLobby for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Dec 17, 2024
1 parent 2d1831c commit 0174f3c
Showing 1 changed file with 6 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ public static GameWaitingLobby addTo(GameActivity activity, WaitingLobbyConfig p
activity.listen(GamePlayerEvents.OFFER, lobby::offerPlayer);
activity.listen(GamePlayerEvents.ADD, lobby::onAddPlayer);
activity.listen(GamePlayerEvents.REMOVE, lobby::onRemovePlayer);
activity.listen(GamePlayerEvents.JOIN_MESSAGE, lobby::onJoinMessage);
activity.listen(GamePlayerEvents.LEAVE_MESSAGE, lobby::onLeaveMessage);
activity.listen(GameWaitingLobbyEvents.BUILD_UI_LAYOUT, lobby::onBuildUiLayout);

activity.listen(GameActivityEvents.STATE_UPDATE, lobby::updateState);
Expand All @@ -120,52 +118,6 @@ public static GameWaitingLobby addTo(GameActivity activity, WaitingLobbyConfig p
return lobby;
}

@Nullable
private Text onJoinMessage(ServerPlayerEntity player, Text currentText, Text defaultText) {
if (currentText == null || (this.playerConfig.thresholdPlayers() == 1 && this.playerConfig.minPlayers() == 1) || this.playerConfig.playerConfig().maxPlayers().isEmpty() || this.gameSpace.getPlayers().spectators().contains(player)) {
return currentText;
}
var count = this.gameSpace.getPlayers().participants().size();
var canStart = count >= this.playerConfig.minPlayers() && (this.isActiveFull(this.gameSpace.getPlayers().size()) || this.isReady(count));

if (canStart) {
return currentText;
}

var required = Math.max(Math.min(this.playerConfig.thresholdPlayers(),
this.gameSpace.getServer().getCurrentPlayerCount()
), this.playerConfig.minPlayers()) - count;

return Text.empty()
.append(currentText)
.append(" ")
.append(Text.translatable("text.plasmid.game.waiting_lobby.players_needed_to_start", required).formatted(Formatting.YELLOW));
}

@Nullable
private Text onLeaveMessage(ServerPlayerEntity player, Text currentText, Text defaultText) {
if (currentText == null || (this.playerConfig.thresholdPlayers() == 1 && this.playerConfig.minPlayers() == 1) || this.playerConfig.playerConfig().maxPlayers().isEmpty() || this.gameSpace.getPlayers().spectators().contains(player)) {
return currentText;
}

var count = this.gameSpace.getPlayers().participants().size() - 1;
var canStart = count >= this.playerConfig.minPlayers() && (this.isActiveFull(this.gameSpace.getPlayers().size() - 1) || this.isReady(count));


if (canStart) {
return currentText;
}

var required = Math.max(Math.min(this.playerConfig.thresholdPlayers(),
this.gameSpace.getServer().getCurrentPlayerCount()
), this.playerConfig.minPlayers()) - count;

return Text.empty()
.append(currentText)
.append(" ")
.append(Text.translatable("text.plasmid.game.waiting_lobby.players_needed_to_start", required).formatted(Formatting.YELLOW));
}

private GameSpaceState.Builder updateState(GameSpaceState.Builder builder) {
return builder.state(this.getTargetCountdownDuration() != -1 ? GameSpaceState.State.STARTING : GameSpaceState.State.WAITING);
}
Expand Down Expand Up @@ -288,9 +240,9 @@ private long getTargetCountdownDuration() {
}

if (this.gameSpace.getPlayers().participants().size() >= this.playerConfig.minPlayers()) {
if (this.isActiveFull(this.gameSpace.getPlayers().size())) {
if (this.isActiveFull()) {
return countdown.fullSeconds() * 20L;
} else if (this.isReady(this.gameSpace.getPlayers().participants().size())) {
} else if (this.isReady()) {
return countdown.readySeconds() * 20L;
}
}
Expand Down Expand Up @@ -365,22 +317,22 @@ private long getRemainingTicks(long time) {
return Math.max(this.countdownStart + this.countdownDuration - time, 0);
}

private boolean isReady(int count) {
return count >= this.playerConfig.thresholdPlayers();
private boolean isReady() {
return this.gameSpace.getPlayers().participants().size() >= this.playerConfig.thresholdPlayers();
}

private boolean isFull() {
return this.limiter.isFull();
}

private boolean isActiveFull(int count) {
private boolean isActiveFull() {
if (this.isFull()) {
return true;
}

// if all players on the server are in this lobby
var server = this.gameSpace.getServer();
if (count >= server.getCurrentPlayerCount()) {
if (this.gameSpace.getPlayers().size() >= server.getCurrentPlayerCount()) {
return true;
}

Expand Down

0 comments on commit 0174f3c

Please sign in to comment.