Skip to content

Commit

Permalink
using typed ref instead of string ID
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 6, 2023
1 parent 1eb63c9 commit 95ae354
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 182 deletions.
8 changes: 4 additions & 4 deletions main/src/net/liplum/welcome/Condition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ abstract class Condition(
this.register()
}

abstract fun canShow(tip: WelcomeTip): Boolean
abstract fun priority(tip: WelcomeTip): Int
abstract fun canShow(tip: WelcomeScene): Boolean
abstract fun priority(tip: WelcomeScene): Int

companion object {
val Default = object : Condition("Default") {
override fun canShow(tip: WelcomeTip): Boolean {
override fun canShow(tip: WelcomeScene): Boolean {
return false
}

override fun priority(tip: WelcomeTip) = Int.MIN_VALUE
override fun priority(tip: WelcomeScene) = Int.MIN_VALUE
}
}
}
16 changes: 8 additions & 8 deletions main/src/net/liplum/welcome/Conditions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ import opengal.experssion.ExpressionParser

object Conditions {
val ShowWelcome = object : Condition("ShowWelcome") {
override fun canShow(tip: WelcomeTip): Boolean {
override fun canShow(tip: WelcomeScene): Boolean {
return Settings.ShouldShowWelcome
}

override fun priority(tip: WelcomeTip) = 0
override fun priority(tip: WelcomeScene) = 0
}
val CheckUpdate = object : Condition("CheckUpdate") {
override fun canShow(tip: WelcomeTip): Boolean {
override fun canShow(tip: WelcomeScene): Boolean {
return !Vars.steam && Settings.ShowUpdate &&
Updater.requireUpdate &&
!Updater.latestVersion.equalsString(Settings.LastSkippedUpdate) &&
Updater.matchMinGameVersion
}

override fun priority(tip: WelcomeTip) = 10
override fun priority(tip: WelcomeScene) = 10
}
val SpecialDishes = object : Condition("SpecialDishes") {
override fun canShow(tip: WelcomeTip): Boolean {
override fun canShow(tip: WelcomeScene): Boolean {
return Settings.ShouldShowWelcome
}

override fun priority(tip: WelcomeTip) =
override fun priority(tip: WelcomeScene) =
if (Settings.ClickWelcomeTimes == 0) 5 else 0
}
val SettingsReq = object : Condition("SettingsReq") {
override fun canShow(tip: WelcomeTip): Boolean {
override fun canShow(tip: WelcomeScene): Boolean {
val data = tip.data
val exprRaw = data["CExpression"] as? String ?: ""
val expr = ExpressionParser.by(exprRaw).parse<Boolean>()
return expr.calculate(ExprSettingsWrapper)
}

override fun priority(tip: WelcomeTip) = 0
override fun priority(tip: WelcomeScene) = 0
}

object ExprSettingsWrapper : IExpressionReceiver {
Expand Down
45 changes: 0 additions & 45 deletions main/src/net/liplum/welcome/Scenes.kt

This file was deleted.

8 changes: 4 additions & 4 deletions main/src/net/liplum/welcome/Welcome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import plumy.dsl.sprite
@ClientOnly
object Welcome {
var bundle = ReferBundleWrapper.create()
private var version = Scenes.v5_1
private var version = WelcomeScenePacks.v5_1
fun genEntity() = Entity(bundle, version)
private var entity = genEntity()
private var showWelcome = false
Expand All @@ -49,7 +49,7 @@ object Welcome {

@JvmStatic
fun judgeWelcome() {
val allTips = version.scenes.map { Welcomes[it] }.distinct().toList()
val allTips = version.scenes.distinct().toList()
val tipsCanShow = allTips.filter { it.condition.canShow(it) }
val allCandidates = tipsCanShow.allMaxBy { it.condition.priority(it) }
if (allCandidates.isEmpty()) {
Expand Down Expand Up @@ -131,9 +131,9 @@ object Welcome {

class Entity(
val bundle: ReferBundleWrapper,
val info: WelcomeTipPack,
val info: WelcomeScenePack,
) {
var tip: WelcomeTip = WelcomeTip.Default
var tip: WelcomeScene = WelcomeScene.Default
operator fun get(key: String) =
bundle["$tip.$key"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.liplum.welcome

class WelcomeTip(
class WelcomeScene(
@JvmField var id: String = DefaultID,
@JvmField var conditionID: String = DefaultCondition,
@JvmField var templateID: String = DefaultTemplateID,
Expand All @@ -15,7 +15,7 @@ class WelcomeTip(
get() = ConditionRegistry[conditionID]

companion object {
val Default = WelcomeTip()
val Default = WelcomeScene()
const val DefaultID = "Default"
const val DefaultCondition = "ShowWelcome"
const val DefaultTemplateID = "Story"
Expand All @@ -24,27 +24,24 @@ class WelcomeTip(
}
}

class WelcomeTipPack(
var default: String = "Default",
var scenes: List<String> = emptyList(),
class WelcomeScenePack(
var default: WelcomeScene,
var scenes: List<WelcomeScene> = emptyList(),
) {
operator fun get(index: Int) =
operator fun get(index: Int): WelcomeScene =
if (index !in scenes.indices)
default
else
scenes[index]

fun indexOf(tipID: String): Int =
fun indexOf(tipID: WelcomeScene): Int =
scenes.indexOf(tipID)

val defaultIndex: Int
get() = indexOf(default)

fun inherit(
default: String? = null,
scenes: List<String> = emptyList(),
): WelcomeTipPack {
return WelcomeTipPack(
default: WelcomeScene? = null,
scenes: List<WelcomeScene> = emptyList(),
): WelcomeScenePack {
return WelcomeScenePack(
default = default ?: this.default,
scenes = this.scenes + scenes,
)
Expand Down
44 changes: 44 additions & 0 deletions main/src/net/liplum/welcome/WelcomeScenePacks.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package net.liplum.welcome

object WelcomeScenePacks {
val common = WelcomeScenePack(
default = Welcomes.default,
scenes = listOf(
Welcomes.updateECHO,
Welcomes.theShip,
Welcomes.echo,
Welcomes.newBrains,
Welcomes.discord,
Welcomes.adBlock,
Welcomes.`404NotFound`,
Welcomes.ohNo,
Welcomes.rateUs,
)
)
val v2 = WelcomeScenePack(
default = Welcomes.employmentVerification,
scenes = listOf(
Welcomes.employmentVerification,
)
)
val v3 = common.inherit(
default = Welcomes.researchProject,
scenes = listOf(
Welcomes.employmentVerification,
)
)
val v4 = common.inherit(
default = Welcomes.erekirDetected,
scenes = listOf(
Welcomes.erekirDetected,
Welcomes.setOutErekir,
)
)
val v4_1 = v4.inherit(
scenes = listOf(
Welcomes.cyberionForErekir,
)
)
val v5 = v4_1.inherit()
val v5_1 = v5.inherit()
}
Loading

0 comments on commit 95ae354

Please sign in to comment.