Skip to content

Commit

Permalink
Put fields before methods in TwoPlayerGame
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Dec 3, 2024
1 parent 64b6948 commit af2ab3d
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ public class TwoPlayerGame<T, S extends Screen> {
public static final TwoPlayerGame<TicTacToeCommand.TicTacToeGame, TicTacToeCommand.TicTacToeGameScreen> TIC_TAC_TOE_GAME_TYPE = register(new TwoPlayerGame<>("commands.ctictactoe.name", "ctictactoe", ResourceLocation.fromNamespaceAndPath("clientcommands", "tictactoe"), (opponent, firstPlayer) -> new TicTacToeCommand.TicTacToeGame(opponent, firstPlayer ? TicTacToeCommand.TicTacToeGame.Mark.CROSS : TicTacToeCommand.TicTacToeGame.Mark.NOUGHT), TicTacToeCommand.TicTacToeGameScreen::new));
public static final TwoPlayerGame<ConnectFourCommand.ConnectFourGame, ConnectFourCommand.ConnectFourGameScreen > CONNECT_FOUR_GAME_TYPE = register(new TwoPlayerGame<>("commands.cconnectfour.name", "cconnectfour", ResourceLocation.fromNamespaceAndPath("clientcommands", "connectfour"), (opponent, firstPlayer) -> new ConnectFourCommand.ConnectFourGame(opponent, firstPlayer ? ConnectFourCommand.Piece.RED : ConnectFourCommand.Piece.YELLOW), ConnectFourCommand.ConnectFourGameScreen::new));

private final Component translation;
private final String command;
private final ResourceLocation id;
private final Set<UUID> pendingInvites;
private final Map<UUID, T> activeGames;
private final GameFactory<T> gameFactory;
private final ScreenFactory<T, S> screenFactory;

TwoPlayerGame(@Translatable String translationKey, String command, ResourceLocation id, GameFactory<T> gameFactory, ScreenFactory<T, S> screenFactory) {
this.translation = Component.translatable(translationKey);
this.command = command;
this.id = id;
this.pendingInvites = Collections.newSetFromMap(CacheBuilder.newBuilder().expireAfterWrite(Duration.ofMinutes(5)).<UUID, Boolean>build().asMap());
this.activeGames = CacheBuilder.newBuilder().expireAfterWrite(Duration.ofMinutes(15)).<UUID, T>build().asMap();
this.gameFactory = gameFactory;
this.screenFactory = screenFactory;
}

private static <T, S extends Screen> TwoPlayerGame<T, S> register(TwoPlayerGame<T, S> instance) {
TYPE_BY_NAME.put(instance.id, instance);
return instance;
Expand All @@ -73,24 +91,6 @@ public static void onPlayerLeave(UUID opponentUUID) {
});
}

private final Component translation;
private final String command;
private final ResourceLocation id;
private final Set<UUID> pendingInvites;
private final Map<UUID, T> activeGames;
private final GameFactory<T> gameFactory;
private final ScreenFactory<T, S> screenFactory;

TwoPlayerGame(@Translatable String translationKey, String command, ResourceLocation id, GameFactory<T> gameFactory, ScreenFactory<T, S> screenFactory) {
this.translation = Component.translatable(translationKey);
this.command = command;
this.id = id;
this.pendingInvites = Collections.newSetFromMap(CacheBuilder.newBuilder().expireAfterWrite(Duration.ofMinutes(5)).<UUID, Boolean>build().asMap());
this.activeGames = CacheBuilder.newBuilder().expireAfterWrite(Duration.ofMinutes(15)).<UUID, T>build().asMap();
this.gameFactory = gameFactory;
this.screenFactory = screenFactory;
}

public Component translate() {
return this.translation;
}
Expand Down

0 comments on commit af2ab3d

Please sign in to comment.