-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
316 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/resources/db/migration/V1.17.0__Create_break_preference_table.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
USE seichiassist; | ||
|
||
CREATE TABLE player_break_preference( | ||
uuid CHAR(36) NOT NULL, | ||
block_category ENUM('Chest', 'MadeFromNetherQuartz') NOT NULL, | ||
do_break BOOL NOT NULL DEFAULT TRUE, | ||
PRIMARY KEY(uuid, block_category), | ||
INDEX index_player_break_preference_on_uuid (uuid) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ub/unchama/seichiassist/subsystems/breakskilltargetconfig/BreakSkillTargetConfigAPI.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.unchama.seichiassist.subsystems.breakskilltargetconfig | ||
|
||
import cats.data.Kleisli | ||
import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.domain.BreakSkillTargetConfigKey | ||
|
||
trait BreakSkillTargetConfigAPI[F[_], Player] { | ||
|
||
/** | ||
* @return 破壊フラグをトグルする作用 | ||
*/ | ||
def toggleBreakSkillTargetConfig( | ||
configKey: BreakSkillTargetConfigKey | ||
): Kleisli[F, Player, Unit] | ||
|
||
/** | ||
* @return 現在の破壊フラグを取得する作用 | ||
*/ | ||
def breakSkillTargetConfig(player: Player, configKey: BreakSkillTargetConfigKey): F[Boolean] | ||
|
||
} | ||
|
||
object BreakSkillTargetConfigAPI { | ||
|
||
def apply[F[_], Player]( | ||
implicit ev: BreakSkillTargetConfigAPI[F, Player] | ||
): BreakSkillTargetConfigAPI[F, Player] = ev | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...main/scala/com/github/unchama/seichiassist/subsystems/breakskilltargetconfig/System.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.github.unchama.seichiassist.subsystems.breakskilltargetconfig | ||
|
||
import cats.data.Kleisli | ||
import cats.effect.{Sync, SyncEffect} | ||
import com.github.unchama.datarepository.bukkit.player.BukkitRepositoryControls | ||
import com.github.unchama.generic.ContextCoercion | ||
import com.github.unchama.seichiassist.meta.subsystem.Subsystem | ||
import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.application.repository.BreakSkillTargetConfigRepositoryDefinition | ||
import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.domain.{ | ||
BreakSkillTargetConfigKey, | ||
BreakSkillTargetConfigPersistence | ||
} | ||
import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.persistence.JdbcBreakSkillTargetConfigPersistence | ||
import org.bukkit.entity.Player | ||
|
||
trait System[F[_], Player] extends Subsystem[F] { | ||
val api: BreakSkillTargetConfigAPI[F, Player] | ||
} | ||
|
||
object System { | ||
|
||
import cats.implicits._ | ||
|
||
def wired[F[_]: Sync, G[_]: SyncEffect: ContextCoercion[*[_], F]]: G[System[F, Player]] = { | ||
implicit val breakSkillTargetConfigPersistence: BreakSkillTargetConfigPersistence[G] = | ||
new JdbcBreakSkillTargetConfigPersistence[G] | ||
|
||
for { | ||
breakSkillTargetConfigRepositoryControls <- BukkitRepositoryControls.createHandles( | ||
BreakSkillTargetConfigRepositoryDefinition.withContext[G, Player] | ||
) | ||
} yield { | ||
val breakSkillTargetConfigRepository = breakSkillTargetConfigRepositoryControls.repository | ||
|
||
new System[F, Player] { | ||
override val api: BreakSkillTargetConfigAPI[F, Player] = | ||
new BreakSkillTargetConfigAPI[F, Player] { | ||
override def toggleBreakSkillTargetConfig( | ||
configKey: BreakSkillTargetConfigKey | ||
): Kleisli[F, Player, Unit] = | ||
Kleisli { player => | ||
ContextCoercion( | ||
breakSkillTargetConfigRepository(player) | ||
.update(_.toggleBreakSkillTargetConfig(configKey)) | ||
) | ||
} | ||
|
||
override def breakSkillTargetConfig( | ||
player: Player, | ||
configKey: BreakSkillTargetConfigKey | ||
): F[Boolean] = | ||
ContextCoercion( | ||
breakSkillTargetConfigRepository(player) | ||
.get | ||
.map(_.breakSkillTargetConfig(configKey)) | ||
) | ||
} | ||
|
||
override val managedRepositoryControls: Seq[BukkitRepositoryControls[F, _]] = Seq( | ||
breakSkillTargetConfigRepositoryControls.coerceFinalizationContextTo[F] | ||
) | ||
} | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...skilltargetconfig/application/repository/BreakSkillTargetConfigRepositoryDefinition.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.application.repository | ||
|
||
import cats.effect.Sync | ||
import cats.effect.concurrent.Ref | ||
import com.github.unchama.datarepository.definitions.RefDictBackedRepositoryDefinition | ||
import com.github.unchama.datarepository.template.RepositoryDefinition | ||
import com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.domain.{ | ||
BreakSkillTargetConfig, | ||
BreakSkillTargetConfigPersistence | ||
} | ||
|
||
object BreakSkillTargetConfigRepositoryDefinition { | ||
|
||
def withContext[F[_]: Sync, Player]( | ||
implicit persistence: BreakSkillTargetConfigPersistence[F] | ||
): RepositoryDefinition[F, Player, Ref[F, BreakSkillTargetConfig]] = | ||
RefDictBackedRepositoryDefinition | ||
.usingUuidRefDict[F, Player, BreakSkillTargetConfig](persistence)( | ||
BreakSkillTargetConfig.initial | ||
) | ||
.toRefRepository | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...nchama/seichiassist/subsystems/breakskilltargetconfig/domain/BreakSkillTargetConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.github.unchama.seichiassist.subsystems.breakskilltargetconfig.domain | ||
|
||
case class BreakSkillTargetConfig(config: Map[BreakSkillTargetConfigKey, Boolean]) { | ||
|
||
/** | ||
* @return `configKey`の破壊フラグをトグルする | ||
*/ | ||
def toggleBreakSkillTargetConfig( | ||
configKey: BreakSkillTargetConfigKey | ||
): BreakSkillTargetConfig = | ||
this.copy(this.config + (configKey -> this.config.getOrElse(configKey, false))) | ||
|
||
/** | ||
* @return 現在の破壊フラグを取得する | ||
*/ | ||
def breakSkillTargetConfig(configKey: BreakSkillTargetConfigKey): Boolean = | ||
this.config.getOrElse(configKey, false) | ||
|
||
} | ||
|
||
object BreakSkillTargetConfig { | ||
|
||
/** | ||
* [[BreakSkillTargetConfig]]の初期値 | ||
*/ | ||
val initial: BreakSkillTargetConfig = BreakSkillTargetConfig(Map.empty) | ||
|
||
} |
Oops, something went wrong.