From e6848b27a0692f04d444773dfa8241212c49ff8b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 11 Nov 2025 17:25:38 +0100 Subject: [PATCH] Refactor `FightTable` to use `WinningTeam` enum for `win` column and adjust related logic. Signed-off-by: Chaoscaot --- CommonCore/SQL/src/de/steamwar/sql/Fight.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/Fight.kt b/CommonCore/SQL/src/de/steamwar/sql/Fight.kt index 7d609d09..d64d7583 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Fight.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/Fight.kt @@ -42,7 +42,7 @@ object FightTable : IntIdTable("Fight", "FightId") { val redLeader = reference("RedLeader", SteamwarUserTable) val blueSchem = optReference("BlueSchem", SchematicNodeTable, onDelete = ReferenceOption.SET_NULL) val redSchem = optReference("RedSchem", SchematicNodeTable, onDelete = ReferenceOption.SET_NULL) - val win = integer("Win") + val win = enumeration("Win", Fight.WinningTeam::class) val winCondition = varchar("WinCondition", 100) val replayAvailable = bool("ReplayAvailable") } @@ -74,7 +74,7 @@ class Fight(id: EntityID) : IntEntity(id) { it[FightTable.redLeader] = EntityID(redleader, SteamwarUserTable) it[FightTable.blueSchem] = blueschem?.let { EntityID(it, SchematicNodeTable) } it[FightTable.redSchem] = redschem?.let { EntityID(it, SchematicNodeTable) } - it[FightTable.win] = win + it[FightTable.win] = WinningTeam.entries[win] it[FightTable.winCondition] = wincondition }.value } @@ -111,7 +111,9 @@ class Fight(id: EntityID) : IntEntity(id) { val redLeader by lazy { useDb { SteamwarUser[redLeaderId] } } val blueSchem by FightTable.blueSchem val redSchem by FightTable.redSchem - val win by FightTable.win + val winner by FightTable.win + val win: Int + get() = winner.ordinal val winCondition by FightTable.winCondition val replayAvailable by FightTable.replayAvailable @@ -153,4 +155,8 @@ class Fight(id: EntityID) : IntEntity(id) { bluePlayers = blue redPlayers = red } + + enum class WinningTeam { + NONE, BLUE, RED; + } } \ No newline at end of file