Skip to content

Commit

Permalink
Merge pull request #2146 from GiganticMinecraft/develop
Browse files Browse the repository at this point in the history
バージョン 84 リリース
  • Loading branch information
Lucky3028 authored Jul 2, 2023
2 parents c31ee87 + 7ac3d9c commit 0812312
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/create_new_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- name: Extract branch name
id: job
run: echo "::set-output name=value::$(echo ${GITHUB_REF#refs/heads/})"
run: echo "value=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT

bump_version:
runs-on: ubuntu-20.04
Expand All @@ -34,7 +34,7 @@ jobs:
update_version_to () {
echo "置換先のバージョン: $1"
echo "::set-output name=new_version::$1"
echo "new_version=$1" >> $GITHUB_OUTPUT
sed -i -e "s/ThisBuild \/ version := \"[0-9]\+\"/ThisBuild \/ version := \"$1\"/g" build.sbt
}
Expand All @@ -43,7 +43,7 @@ jobs:
exit 1
fi
echo "::set-output name=old_version::$(get_defined_versions)"
echo "old_version=$(get_defined_versions)" >> $GITHUB_OUTPUT
update_version_to $(get_defined_versions | xargs expr 1 +)
# 本来であればActionsに権限を増やしたりbranch protection ruleに例外を設けるなどしてpushを許したいが、
Expand Down
9 changes: 7 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import java.io._
ThisBuild / scalaVersion := "2.13.11"
// ThisBuild / version はGitHub Actionsによって取得/自動更新される。
// 次の行は ThisBuild / version := "(\d*)" の形式でなければならない。
ThisBuild / version := "83"
ThisBuild / version := "84"
ThisBuild / organization := "click.seichi"
ThisBuild / description := "ギガンティック☆整地鯖の独自要素を司るプラグイン"

// Scalafixが要求するため、semanticdbは有効化する
ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision
ThisBuild / scalafixScalaBinaryVersion :=
CrossVersion.binaryScalaVersion(scalaVersion.value)

// endregion

Expand Down Expand Up @@ -68,6 +70,9 @@ val providedDependencies = Seq(
"org.typelevel" %% "simulacrum" % "1.0.1"
).map(_ % "provided")

val scalafixCoreDep =
"ch.epfl.scala" %% "scalafix-core" % _root_.scalafix.sbt.BuildInfo.scalafixVersion % ScalafixConfig

val testDependencies = Seq(
"org.scalamock" %% "scalamock" % "5.2.0",
"org.scalatest" %% "scalatest" % "3.2.16",
Expand Down Expand Up @@ -189,7 +194,7 @@ Compile / PB.targets := Seq(scalapb.gen() -> (Compile / sourceManaged).value / "
lazy val root = (project in file(".")).settings(
name := "SeichiAssist",
assembly / assemblyOutputPath := baseDirectory.value / "target" / "build" / "SeichiAssist.jar",
libraryDependencies := providedDependencies ++ testDependencies ++ dependenciesToEmbed,
libraryDependencies := (providedDependencies :+ scalafixCoreDep) ++ testDependencies ++ dependenciesToEmbed,
excludeDependencies := Seq(ExclusionRule(organization = "org.bukkit", name = "bukkit")),
unmanagedBase := baseDirectory.value / "localDependencies",
scalacOptions ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ object System {
prizes.filterNot(_.id == gachaPrizeId)
}
_ <- _gachaPersistence.deleteMineStackGachaObject(gachaPrizeId)
_ <- _gachaPersistence.removeGachaPrize(gachaPrizeId)
} yield ()

override def addGachaPrize(gachaPrize: GachaPrizeByGachaPrizeId): F[Unit] = for {
Expand Down Expand Up @@ -133,11 +134,18 @@ object System {
override def createGachaEvent(gachaEvent: GachaEvent): F[Unit] = {
for {
_ <- _gachaEventPersistence.createGachaEvent(gachaEvent)
prizes <- allGachaPrizesListReference.get
defaultGachaPrizes = prizes
currentAllGachaPrizes <- allGachaPrizesListReference.get
maxId = currentAllGachaPrizes.map(_.id.id).max
eventGachaPrizes = currentAllGachaPrizes
.filter(_.gachaEventName.isEmpty)
.map(_.copy(gachaEventName = Some(gachaEvent.eventName)))
_ <- replace(defaultGachaPrizes ++ prizes)
.map(gachaPrize =>
gachaPrize.copy(
gachaEventName = Some(gachaEvent.eventName),
id = GachaPrizeId(maxId + gachaPrize.id.id)
)
)
_ <- replace(eventGachaPrizes ++ currentAllGachaPrizes)
_ <- _gachaPersistence.addGachaPrizes(eventGachaPrizes)
} yield ()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ trait GachaPrizeListPersistence[F[_], ItemStack] {
*/
def addGachaPrize(gachaPrize: GachaPrize[ItemStack]): F[Unit]

/**
* @return 複数のガチャアイテムを追加する作用
*/
def addGachaPrizes(gachaPrizes: Vector[GachaPrize[ItemStack]]): F[Unit]

/**
* @return ガチャアイテムを削除する作用
*/
def removeGachaPrize(gachaPrizeId: GachaPrizeId): F[Unit]

/**
* @return ガチャリストを更新する作用
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ case class GachaEvent(eventName: GachaEventName, startDate: LocalDate, endDate:
*/
def isHolding: Boolean = {
val now = LocalDate.now()
val isAfterStartDateOrFirstDay = now.equals(startDate) || now.isAfter(startDate)
val isBeforeEndDateOrEndDay = now.equals(endDate) || now.isBefore(endDate)

now.isAfter(startDate) && now.isBefore(endDate)
isAfterStartDateOrFirstDay && isBeforeEndDateOrEndDay
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ class JdbcGachaPrizeListPersistence[F[_]: Sync, ItemStack: Cloneable](
override def list: F[Vector[GachaPrize[ItemStack]]] = {
Sync[F].delay {
DB.readOnly { implicit session =>
sql"""SELECT gachadata.id, gachadata.probability, gachadata.itemstack, gacha_events.event_name FROM gachadata
| LEFT OUTER JOIN gacha_events ON gachadata.event_id = gacha_events.id
| UNION
| SELECT gachadata.id, gachadata.probability, gachadata.itemstack, gacha_events.event_name FROM gachadata
| RIGHT OUTER JOIN gacha_events ON gachadata.event_id = gacha_events.id"""
sql"SELECT gachadata.id AS gacha_prize_id, probability, itemstack, event_name FROM gachadata LEFT OUTER JOIN gacha_events ON gachadata.event_id = gacha_events.id"
.stripMargin
.map { rs =>
val probability = rs.double("probability")
Expand All @@ -34,7 +30,7 @@ class JdbcGachaPrizeListPersistence[F[_]: Sync, ItemStack: Cloneable](
itemStack,
GachaProbability(probability),
probability < 0.1,
GachaPrizeId(rs.int("id")),
GachaPrizeId(rs.int("gacha_prize_id")),
rs.stringOpt("event_name").map(GachaEventName)
)
}
Expand All @@ -56,11 +52,46 @@ class JdbcGachaPrizeListPersistence[F[_]: Sync, ItemStack: Cloneable](
.apply()
}

sql"INSERT INTO gachadata VALUES (${gachaPrize.id.id}, ${gachaPrize.probability.value}, ${serializeAndDeserialize
.serialize(gachaPrize.itemStack)}, $eventId)".execute().apply()
sql"INSERT INTO gachadata (id, probability, itemstack, event_id) VALUES (${gachaPrize.id.id}, ${gachaPrize
.probability
.value}, ${serializeAndDeserialize.serialize(gachaPrize.itemStack)}, $eventId)"
.execute()
.apply()
}
}

override def removeGachaPrize(gachaPrizeId: GachaPrizeId): F[Unit] = Sync[F].delay {
DB.localTx { implicit session =>
sql"DELETE FROM gachadata WHERE id = ${gachaPrizeId.id}".execute().apply()
}
}

override def addGachaPrizes(gachaPrizes: Vector[GachaPrize[ItemStack]]): F[Unit] =
Sync[F].delay {
DB.localTx { implicit session =>
// ここでは一つのイベントのアイテムのみが複数指定されることを想定しているので、1つ目のイベントで決め打ちする
val eventId = gachaPrizes.head.gachaEventName.flatMap { eventName =>
sql"SELECT id FROM gacha_events WHERE event_name = ${eventName.name}"
.map(_.int("id"))
.single()
.apply()
}

val batchParams = gachaPrizes.map { gachaPrize =>
Seq(
gachaPrize.id.id,
gachaPrize.probability.value,
serializeAndDeserialize.serialize(gachaPrize.itemStack),
eventId
)
}

sql"INSERT INTO gachadata (id, probability, itemstack, event_id) VALUES (?, ?, ?, ?)"
.batch(batchParams: _*)
.apply[List]()
}
}

override def set(gachaPrizesList: Vector[GachaPrize[ItemStack]]): F[Unit] = {
Sync[F].delay {
DB.localTx { implicit session =>
Expand All @@ -73,7 +104,7 @@ class JdbcGachaPrizeListPersistence[F[_]: Sync, ItemStack: Cloneable](
gachaPrize.gachaEventName.map(_.name)
)
}
sql"insert into gachadata values (?,?,?,?)".batch(batchParams).apply[List]()
sql"insert into gachadata values (?,?,?,?)".batch(batchParams: _*).apply[List]()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package fix

import scalafix.v1._

import scala.meta._

/**
* Lints on string interpolation where its variable part contains `case class` without `toString`.
*/
// noinspection ScalaUnusedSymbol; referred from scalafix implicitly
// NOTE: see AST on https://xuwei-k.github.io/scalameta-ast/ or https://astexplorer.net
class WarnUnoverriddenImplicitToStringCallsOnCaseClass extends SemanticRule("WarnUnoverriddenImplicitToStringCallsOnCaseClass") {
override def fix(implicit doc: SemanticDocument): Patch = {
val s = doc.tree.collect {
// string interpolation in standard library
case Term.Interpolate((prefix, _, args)) =>
if (prefix.value != "s") {
return Patch.empty
}

Patch.fromIterable(
args.collect { arg =>
val tp = arg.symbol
val info = tp.info.get
// does `tp` point to some `case class`?
val isCaseClass = info.isCase && info.isClass

// lazily evaluated since most classes are not `case class`
lazy val isToStringOverriden = info.overriddenSymbols.exists(overridenMethodSym => overridenMethodSym.value == "toString" && {
overridenMethodSym.info.get.signature match {
// def toString[](): <return type> の形の override を見つけたい。
// もし toString() の return type が String のサブタイプにならないような型であれば
// scalafix が走る前にコンパイルが落ちるので、ここで改めて return type が
// String のサブタイプであるかは考慮する必要はない
case MethodSignature(List(), List(), _) => true
case _ => false
}
})

if (!isCaseClass || isToStringOverriden) {
return Patch.empty
}

Patch.lint(new Diagnostic {
override def message: String = "Case class value shouldn't be interpolated, use `toString` " +
"if you wish to interpolate the String representation into the string"

// points to arg
override def position: _root_.scala.meta.Position = arg.pos
})
}
)
case _ => Patch.empty
}

Patch.fromIterable(s)
}
}

0 comments on commit 0812312

Please sign in to comment.