forked from SteamWar/SteamWar
Refactor PersonalKitTable to use explicit ID column initialization and update create method to utilize insert operation.
Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
@@ -60,15 +60,17 @@ class InternalKit(id: EntityID<CompositeID>): CompositeEntity(id) {
|
||||
|
||||
@JvmStatic
|
||||
fun create(userId: Int, gamemode: String, kitName: String, rawInventory: String, rawArmor: String) = useDb {
|
||||
PersonalKitTable.insert {
|
||||
it[this.userId] = EntityID(userId, SteamwarUserTable)
|
||||
it[this.gamemode] = gamemode
|
||||
it[this.kitName] = kitName
|
||||
it[this.inventory] = rawInventory
|
||||
it[this.armor] = rawArmor
|
||||
it[this.inUse] = true
|
||||
new(
|
||||
CompositeID {
|
||||
it[PersonalKitTable.userId] = EntityID(userId, SteamwarUserTable)
|
||||
it[PersonalKitTable.gamemode] = gamemode
|
||||
it[PersonalKitTable.kitName] = kitName
|
||||
}
|
||||
) {
|
||||
this.inventory = rawInventory
|
||||
this.armor = rawArmor
|
||||
this.inUse = true
|
||||
}
|
||||
get(userId, gamemode, kitName)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -80,10 +82,15 @@ class InternalKit(id: EntityID<CompositeID>): CompositeEntity(id) {
|
||||
|
||||
var userID by PersonalKitTable.userId.transform({ EntityID(it, SteamwarUserTable) }, { it.value })
|
||||
private set
|
||||
var gamemode by PersonalKitTable.gamemode
|
||||
private set
|
||||
var name by PersonalKitTable.kitName
|
||||
private var gameMode by PersonalKitTable.gamemode
|
||||
val gamemode: String
|
||||
get() = gameMode.value
|
||||
|
||||
var kitName by PersonalKitTable.kitName
|
||||
private set
|
||||
val name: String
|
||||
get() = kitName.value
|
||||
|
||||
var rawInventory by PersonalKitTable.inventory
|
||||
private set
|
||||
var rawArmor by PersonalKitTable.armor
|
||||
@@ -99,7 +106,7 @@ class InternalKit(id: EntityID<CompositeID>): CompositeEntity(id) {
|
||||
set(value) = useDb { rawArmor = value }
|
||||
|
||||
fun setDefault() = useDb {
|
||||
find { PersonalKitTable.userId eq userID and (PersonalKitTable.gamemode eq gamemode) and (PersonalKitTable.inUse eq true) }
|
||||
find { PersonalKitTable.userId eq userID and (PersonalKitTable.gamemode eq gameMode) and (PersonalKitTable.inUse eq true) }
|
||||
.forEach { it.inUse = false }
|
||||
inUse = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user