From 752d65557f1bd9680760bcf70672273673048c6d Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Mon, 18 Mar 2024 01:31:28 -0400 Subject: [PATCH] [+] Unlock option database model --- .../samnyan/aqua/net/db/AquaGameOptions.kt | 35 +++++++++++++++++++ .../icu/samnyan/aqua/net/db/AquaNetUser.kt | 9 ++--- .../mariadb/V1000_4__aqua_game_options.sql | 18 ++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 src/main/java/icu/samnyan/aqua/net/db/AquaGameOptions.kt create mode 100644 src/main/resources/db/migration/mariadb/V1000_4__aqua_game_options.sql diff --git a/src/main/java/icu/samnyan/aqua/net/db/AquaGameOptions.kt b/src/main/java/icu/samnyan/aqua/net/db/AquaGameOptions.kt new file mode 100644 index 00000000..bba24c16 --- /dev/null +++ b/src/main/java/icu/samnyan/aqua/net/db/AquaGameOptions.kt @@ -0,0 +1,35 @@ +package icu.samnyan.aqua.net.db + +import com.fasterxml.jackson.annotation.JsonIgnore +import ext.SettingField +import jakarta.persistence.Entity +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id +import org.springframework.data.jpa.repository.JpaRepository + +@Entity +class AquaGameOptions( + @Id @JsonIgnore + @GeneratedValue(strategy = GenerationType.IDENTITY) + var id: Long = 0, + + @SettingField("Unlock All Music", + "Unlock all music and master difficulty in game") + val unlockMusic: Boolean = false, + + @SettingField("Unlock All Chara", + "Unlock all characters and partners in game") + val unlockChara: Boolean = false, + + @SettingField("Unlock All Collectables", + "Unlock all collectables (nameplate, title, icon, frame) in game. " + + "This setting is not relevant in chusan because in-game user box is disabled in chusan.") + val unlockCollectables: Boolean = false, + + @SettingField("Unlock All Tickets" , + "Unlock all map tickets (the game still limits which tickets can be used)") + val unlockTickets: Boolean = false, +) + +interface AquaGameOptionsRepository : JpaRepository \ No newline at end of file diff --git a/src/main/java/icu/samnyan/aqua/net/db/AquaNetUser.kt b/src/main/java/icu/samnyan/aqua/net/db/AquaNetUser.kt index c9f07221..e2ebde91 100644 --- a/src/main/java/icu/samnyan/aqua/net/db/AquaNetUser.kt +++ b/src/main/java/icu/samnyan/aqua/net/db/AquaNetUser.kt @@ -11,7 +11,6 @@ import icu.samnyan.aqua.sega.general.model.Card import jakarta.persistence.* import org.springframework.data.jpa.repository.JpaRepository import org.springframework.security.crypto.password.PasswordEncoder -import org.springframework.stereotype.Repository import org.springframework.stereotype.Service import java.io.Serializable import kotlin.jvm.optionals.getOrNull @@ -19,8 +18,7 @@ import kotlin.reflect.KFunction import kotlin.reflect.KMutableProperty import kotlin.reflect.full.functions -@Entity(name = "AquaNetUser") -@Table(name = "aqua_net_user") +@Entity class AquaNetUser( @JsonIgnore @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -75,6 +73,10 @@ class AquaNetUser( @JsonIgnore @OneToMany(mappedBy = "user", cascade = [CascadeType.ALL]) var keychipSessions: MutableList = mutableListOf(), + + @OneToOne(cascade = [CascadeType.ALL]) + @JoinColumn(name = "gameOptions", unique = true, nullable = true) + var gameOptions: AquaGameOptions? = null ) : Serializable { val computedName get() = displayName.ifEmpty { username } @@ -89,7 +91,6 @@ class AquaNetUser( ) } -@Repository("AquaNetUserRepository") interface AquaNetUserRepo : JpaRepository { fun findByAuId(auId: Long): AquaNetUser? fun findByEmailIgnoreCase(email: String): AquaNetUser? diff --git a/src/main/resources/db/migration/mariadb/V1000_4__aqua_game_options.sql b/src/main/resources/db/migration/mariadb/V1000_4__aqua_game_options.sql new file mode 100644 index 00000000..6a8bb1ac --- /dev/null +++ b/src/main/resources/db/migration/mariadb/V1000_4__aqua_game_options.sql @@ -0,0 +1,18 @@ +CREATE TABLE aqua_game_options +( + id BIGINT AUTO_INCREMENT NOT NULL, + unlock_music BIT(1) NOT NULL, + unlock_chara BIT(1) NOT NULL, + unlock_collectables BIT(1) NOT NULL, + unlock_tickets BIT(1) NOT NULL, + CONSTRAINT pk_aquagameoptions PRIMARY KEY (id) +); + +ALTER TABLE aqua_net_user + ADD game_options BIGINT NULL; + +ALTER TABLE aqua_net_user + ADD CONSTRAINT uc_aquanetuser_gameoptions UNIQUE (game_options); + +ALTER TABLE aqua_net_user + ADD CONSTRAINT FK_AQUANETUSER_ON_GAMEOPTIONS FOREIGN KEY (game_options) REFERENCES aqua_game_options (id); \ No newline at end of file