Skip to content

Commit 75151e7

Browse files
xerufanarchuser
authored andcommitted
refactor: remove generics from ITeam
1 parent 61b9181 commit 75151e7

File tree

18 files changed

+51
-47
lines changed

18 files changed

+51
-47
lines changed

plugin/src/client/sc/plugin2020/AbstractClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void onRoomMessage(String roomId, Object data) {
8080
if(data instanceof MoveRequest) {
8181
this.handler.onRequestAction();
8282
} else if(data instanceof WelcomeMessage) {
83-
this.color = Team.valueOf(((WelcomeMessage) data).getPlayerColor());
83+
this.color = Team.valueOf(((WelcomeMessage)data).getColor());
8484
}
8585
this.roomId = roomId;
8686
}

plugin/src/client/sc/plugin2021/AbstractClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ abstract class AbstractClient @Throws(IOException::class) constructor(
7474
handler.onRequestAction()
7575
}
7676
if(data is WelcomeMessage) {
77-
team = Team.valueOf(data.playerColor.toUpperCase())
77+
team = Team.valueOf(data.color.toUpperCase())
7878
}
7979
roomID = roomId
8080
}

plugin/src/server/sc/plugin2021/Game.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Game(UUID: String = GamePlugin.PLUGIN_UUID): RoundBasedGameInstance<Player
3333

3434
override fun onPlayerJoined(): Player {
3535
val player = gameState.getPlayer(availableTeams.removeAt(0))
36-
?: throw NullPointerException("Too many players joined the game!")
36+
?: throw IllegalStateException("Too many players joined the game!")
3737

3838
players.add(player)
3939
playerMap[player.color as Team] = player

plugin/src/shared/sc/plugin2020/Board.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ data class Board(
104104
override fun hashCode(): Int =
105105
gameField.contentDeepHashCode()
106106

107-
fun getFieldsOwnedBy(owner: ITeam<*>): List<Field> = fields.filter { it.owner == owner }
107+
fun getFieldsOwnedBy(owner: ITeam): List<Field> = fields.filter { it.owner == owner }
108108

109109
companion object {
110110
private const val SHIFT = (Constants.BOARD_SIZE - 1) / 2

plugin/src/shared/sc/plugin2020/GameState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class GameState @JvmOverloads constructor(
7171
}
7272
}
7373

74-
override fun getPointsForPlayer(team: ITeam<*>): Int {
74+
override fun getPointsForPlayer(team: ITeam): Int {
7575
return GameRuleLogic.freeBeeNeighbours(this.board, team)
7676
}
7777

plugin/src/shared/sc/plugin2020/Piece.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import sc.api.plugins.ITeam
77
@XStreamAlias(value = "piece")
88
data class Piece(
99
@field:XStreamAsAttribute
10-
val owner: ITeam<*>,
10+
val owner: ITeam,
1111
@field: XStreamAsAttribute
1212
val type: PieceType)
1313

plugin/src/shared/sc/plugin2020/Team.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package sc.plugin2020
22

33
import sc.api.plugins.ITeam
44

5-
enum class Team(override val index: Int, val displayName: String): ITeam<Team> {
5+
enum class Team(override val index: Int, val displayName: String): ITeam {
66
RED(0, "Rot") {
77
val letter = name.first()
88

plugin/src/shared/sc/plugin2020/util/GameRuleLogic.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object GameRuleLogic {
2828

2929
/** @return the [Team] that has to make the next Move. */
3030
@JvmStatic
31-
fun getCurrentPlayerColor(gameState: GameState): ITeam<*> = gameState.currentTeam
31+
fun getCurrentPlayerColor(gameState: GameState): ITeam = gameState.currentTeam
3232

3333
/** Validates & executes the [move] on the [gameState]. */
3434
@JvmStatic
@@ -58,7 +58,7 @@ object GameRuleLogic {
5858

5959
/** @return number of free (empty & not obstructed) fields around the Bee - -1 if no Bee has been placed. */
6060
@JvmStatic
61-
fun freeBeeNeighbours(board: Board, color: ITeam<*>): Int =
61+
fun freeBeeNeighbours(board: Board, color: ITeam): Int =
6262
board.fields.find { it.pieces.contains(Piece(color, PieceType.BEE)) }
6363
?.let { getNeighbours(board, it) }?.count { field -> field.isEmpty }
6464
?: -1

plugin/src/shared/sc/plugin2021/Color.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import com.thoughtworks.xstream.annotations.XStreamAlias
44

55
@XStreamAlias(value = "color")
66
enum class Color(val team: Team) {
7-
BLUE (Team.ONE),
7+
BLUE(Team.ONE),
88
YELLOW(Team.TWO),
9-
RED (Team.ONE),
10-
GREEN (Team.TWO) { init {
11-
BLUE.next = YELLOW
12-
YELLOW.next = RED
13-
RED.next = GREEN
14-
GREEN.next = BLUE
15-
}};
9+
RED(Team.ONE),
10+
GREEN(Team.TWO);
1611

17-
lateinit var next: Color
18-
private set
12+
val next: Color
13+
get() = when (this) {
14+
BLUE -> YELLOW
15+
YELLOW -> RED
16+
RED -> GREEN
17+
GREEN -> BLUE
18+
}
1919

20-
operator fun unaryPlus(): FieldContent = when(this) {
21-
BLUE -> FieldContent.BLUE
20+
operator fun unaryPlus(): FieldContent = when (this) {
21+
BLUE -> FieldContent.BLUE
2222
YELLOW -> FieldContent.YELLOW
23-
RED -> FieldContent.RED
24-
GREEN -> FieldContent.GREEN
23+
RED -> FieldContent.RED
24+
GREEN -> FieldContent.GREEN
2525
}
2626
}

plugin/src/shared/sc/plugin2021/GameState.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ class GameState @JvmOverloads constructor(
4242
val lastMoveMono: MutableMap<Color, Boolean> = mutableMapOf()
4343

4444
override val currentTeam
45-
get() = currentColor.team
45+
get() = when(currentColor) {
46+
Color.BLUE, Color.RED -> Team.ONE
47+
Color.YELLOW, Color.GREEN -> Team.TWO
48+
}
49+
// get() = currentColor.team
4650

4751
override val currentPlayer
4852
get() = getPlayer(currentTeam)!!
@@ -102,7 +106,7 @@ class GameState @JvmOverloads constructor(
102106
}
103107
}
104108

105-
override fun getPointsForPlayer(team: ITeam<*>): Int =
109+
override fun getPointsForPlayer(team: ITeam): Int =
106110
(team as Team).colors.map { getPointsForColor(it) }.sum()
107111

108112
private fun getPointsForColor(color: Color): Int {

0 commit comments

Comments
 (0)