From 5d36393643a91f5af8f5b8cb80125e1a384e989b Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 8 Nov 2025 22:44:22 +0100 Subject: [PATCH] Refactor `EventRelation`, `EventGroup`, and `EventFight` classes: ensure database operations are enclosed in `useDb`, add default values for group points, and override `delete` methods. Update Gradle build script to include `lombok` dependencies. Signed-off-by: Chaoscaot --- CommonCore/SQL/src/de/steamwar/sql/EventFight.kt | 6 +++++- CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt | 8 +++++--- CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt | 8 ++++++-- buildSrc/src/steamwar.kotlin.gradle | 7 +++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventFight.kt b/CommonCore/SQL/src/de/steamwar/sql/EventFight.kt index d658b347..ff41e24f 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventFight.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/EventFight.kt @@ -150,7 +150,7 @@ class EventFight(id: EntityID) : IntEntity(id), Comparable { var spielmodus by EventFightTable.gamemode var map by EventFightTable.map var groupId by EventFightTable.groupId - val group by lazy { Optional.ofNullable(groupId).map { EventGroup[it] } } + val group by lazy { useDb { Optional.ofNullable(groupId).map { EventGroup[it] } } } var spectatePort by EventFightTable.spectatePort private var fightStat by EventFightTable.fight.transform({ it?.let { EntityID(it, EventFightTable) } }, { it?.value }) var fight: Int? @@ -191,4 +191,8 @@ class EventFight(id: EntityID) : IntEntity(id), Comparable { this@EventFight.teamRed = teamRed this@EventFight.spectatePort = spectatePort } + + override fun delete() = useDb { + super.delete() + } } \ No newline at end of file diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt index a8a87094..7da29538 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/EventGroup.kt @@ -31,9 +31,9 @@ object EventGroupTable : IntIdTable("EventGroup", "Id") { val event = reference("EventID", EventTable) val name = varchar("Name", 64) val type = enumeration("Type", EventGroup.EventGroupType::class) - val pointsPerWin = integer("PointsPerWin") - val pointsPerLoss = integer("PointsPerLoss") - val pointsPerDraw = integer("PointsPerDraw") + val pointsPerWin = integer("PointsPerWin").default(3) + val pointsPerLoss = integer("PointsPerLoss").default(0) + val pointsPerDraw = integer("PointsPerDraw").default(1) } class EventGroup(id: EntityID) : IntEntity(id) { @@ -144,6 +144,8 @@ class EventGroup(id: EntityID) : IntEntity(id) { this@EventGroup.pointsPerDraw = pointsPerDraw } + override fun delete() = useDb { super.delete() } + enum class EventGroupType { GROUP_STAGE, ELIMINATION_STAGE diff --git a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt index e02119ed..6847adfd 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/EventRelation.kt @@ -89,7 +89,7 @@ class EventRelation(id: EntityID) : IntEntity(id) { fromId = value!! } val fromFight: EventFight? - get() = fromFightId?.let { EventFight[it] } + get() = fromFightId?.let { useDb { EventFight[it] } } var fromGroupId: Int? get() = if (fromType == FromType.GROUP) fromId else null set(value) = useDb { @@ -97,7 +97,7 @@ class EventRelation(id: EntityID) : IntEntity(id) { fromId = value!! } val fromGroup: EventGroup? - get() = fromGroupId?.let { EventGroup[it] } + get() = fromGroupId?.let { useDb { EventGroup[it] } } var fromPlace by EventRelationTable.fromPlace private set @@ -136,6 +136,10 @@ class EventRelation(id: EntityID) : IntEntity(id) { return true } + override fun delete() = useDb { + super.delete() + } + enum class FightTeam { BLUE, RED } diff --git a/buildSrc/src/steamwar.kotlin.gradle b/buildSrc/src/steamwar.kotlin.gradle index e1a633c5..f672713d 100644 --- a/buildSrc/src/steamwar.kotlin.gradle +++ b/buildSrc/src/steamwar.kotlin.gradle @@ -64,4 +64,11 @@ sourceSets { exclude("**/*.java", "**/*.kt") } } +} + +dependencies { + annotationProcessor libs.lombok + compileOnly libs.lombok + testCompileOnly libs.lombok + testAnnotationProcessor libs.lombok } \ No newline at end of file