Refactor FightTable to use WinningTeam enum for win column and adjust related logic.

Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
2025-11-11 17:25:38 +01:00
parent 93d0011b46
commit e6848b27a0
+9 -3
View File
@@ -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<Int>) : 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<Int>) : 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<Int>) : IntEntity(id) {
bluePlayers = blue
redPlayers = red
}
enum class WinningTeam {
NONE, BLUE, RED;
}
}