diff --git a/main/src/net/liplum/welcome/Condition.kt b/main/src/net/liplum/welcome/Condition.kt index deb6386b..c5651409 100644 --- a/main/src/net/liplum/welcome/Condition.kt +++ b/main/src/net/liplum/welcome/Condition.kt @@ -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 } } } \ No newline at end of file diff --git a/main/src/net/liplum/welcome/Conditions.kt b/main/src/net/liplum/welcome/Conditions.kt index cb99c779..29588721 100644 --- a/main/src/net/liplum/welcome/Conditions.kt +++ b/main/src/net/liplum/welcome/Conditions.kt @@ -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() return expr.calculate(ExprSettingsWrapper) } - override fun priority(tip: WelcomeTip) = 0 + override fun priority(tip: WelcomeScene) = 0 } object ExprSettingsWrapper : IExpressionReceiver { diff --git a/main/src/net/liplum/welcome/Scenes.kt b/main/src/net/liplum/welcome/Scenes.kt deleted file mode 100644 index fd97ef2d..00000000 --- a/main/src/net/liplum/welcome/Scenes.kt +++ /dev/null @@ -1,45 +0,0 @@ -package net.liplum.welcome - -object Scenes { - val common = WelcomeTipPack( - scenes = listOf( - "UpdateECHO", - "TheSHIP", - "ECHO", - "NewBrains", - "Discord", - "AdBlock", - "404NotFound", - "OhNo", - "RateUs", - "SetOutErekir", - "CyberionForErekir" - ) - ) - val v2 = WelcomeTipPack( - default = "EmploymentVerification", - scenes = listOf( - "EmploymentVerification" - ) - ) - val v3 = common.inherit( - default = "ResearchProject", - scenes = listOf( - "EmploymentVerification" - ) - ) - val v4 = common.inherit( - default = "ErekirDetected", - scenes = listOf( - "ErekirDetected", - "SetOutErekir" - ) - ) - val v4_1 = v4.inherit( - scenes = listOf( - "CyberionForErekir" - ) - ) - val v5 = v4_1.inherit() - val v5_1 = v5.inherit() -} \ No newline at end of file diff --git a/main/src/net/liplum/welcome/Welcome.kt b/main/src/net/liplum/welcome/Welcome.kt index 8aa01a0e..68449566 100644 --- a/main/src/net/liplum/welcome/Welcome.kt +++ b/main/src/net/liplum/welcome/Welcome.kt @@ -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 @@ -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()) { @@ -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"] diff --git a/main/src/net/liplum/welcome/WelcomeTip.kt b/main/src/net/liplum/welcome/WelcomeScene.kt similarity index 71% rename from main/src/net/liplum/welcome/WelcomeTip.kt rename to main/src/net/liplum/welcome/WelcomeScene.kt index 9ee06325..c246b3c3 100644 --- a/main/src/net/liplum/welcome/WelcomeTip.kt +++ b/main/src/net/liplum/welcome/WelcomeScene.kt @@ -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, @@ -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" @@ -24,27 +24,24 @@ class WelcomeTip( } } -class WelcomeTipPack( - var default: String = "Default", - var scenes: List = emptyList(), +class WelcomeScenePack( + var default: WelcomeScene, + var scenes: List = 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 = emptyList(), - ): WelcomeTipPack { - return WelcomeTipPack( + default: WelcomeScene? = null, + scenes: List = emptyList(), + ): WelcomeScenePack { + return WelcomeScenePack( default = default ?: this.default, scenes = this.scenes + scenes, ) diff --git a/main/src/net/liplum/welcome/WelcomeScenePacks.kt b/main/src/net/liplum/welcome/WelcomeScenePacks.kt new file mode 100644 index 00000000..00758188 --- /dev/null +++ b/main/src/net/liplum/welcome/WelcomeScenePacks.kt @@ -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() +} \ No newline at end of file diff --git a/main/src/net/liplum/welcome/Welcomes.kt b/main/src/net/liplum/welcome/Welcomes.kt index c13e0ec7..28f0f910 100644 --- a/main/src/net/liplum/welcome/Welcomes.kt +++ b/main/src/net/liplum/welcome/Welcomes.kt @@ -1,127 +1,141 @@ package net.liplum.welcome object Welcomes { - val tips = listOf( - WelcomeTip( - id = "Default", - templateID = "Story", - ), - WelcomeTip( - id = "EmploymentVerification", - templateID = "SpecialDishes", - ), - WelcomeTip( - id = "Discord", - templateID = "DoAction", - data = mapOf( - "YesAction" to "OpenLink", - "Link" to "@link", - ), - iconPath = "discord", - chance = 750, - ), - WelcomeTip( - id = "UpdateECHO", - templateID = "Update", - data = mapOf( - "ActionA" to "UpdateCyberIO", - "ActionC" to "@SkipThisUpdate", - ), - iconPath = "update-icon", - conditionID = "CheckUpdate", - ), - WelcomeTip( - id = "ResearchProject", - iconPath = "welcome-holo-project", - conditionID = "SpecialDishes", - ), - WelcomeTip( - id = "TheSHIP", - ), - WelcomeTip( - id = "ECHO", - ), - WelcomeTip( - id = "NewBrains", - iconPath = "heimdall", + val default = WelcomeScene( + id = "Default", + templateID = "Story", + ) + val employmentVerification = WelcomeScene( + id = "EmploymentVerification", + templateID = "SpecialDishes", + ) + val discord = WelcomeScene( + id = "Discord", + templateID = "DoAction", + data = mapOf( + "YesAction" to "OpenLink", + "Link" to "@link", ), - WelcomeTip( - id = "AdBlock", - templateID = "DoAction", - iconPath = "ad-block", - data = mapOf( - "NoAction" to "StopReceiveWelcome", - ), - chance = 300, + iconPath = "discord", + chance = 750, + ) + val updateECHO = WelcomeScene( + id = "UpdateECHO", + templateID = "Update", + data = mapOf( + "ActionA" to "UpdateCyberIO", + "ActionC" to "@SkipThisUpdate", ), - WelcomeTip( - id = "404NotFound", - templateID = "PlainText", - iconPath = "ad-block", - conditionID = "SettingsReq", - data = mapOf( - "FontSize" to 1.2, - "ShowPoliteWelcome" to false, - "CExpression" to "@ClickWelcomeTimes > 5 && @ShouldShowWelcome", - ), - chance = 200, + iconPath = "update-icon", + conditionID = "CheckUpdate", + ) + val researchProject = WelcomeScene( + id = "ResearchProject", + iconPath = "welcome-holo-project", + conditionID = "SpecialDishes", + ) + val theShip = WelcomeScene( + id = "TheSHIP", + ) + val echo = WelcomeScene( + id = "ECHO", + ) + val newBrains = WelcomeScene( + id = "NewBrains", + iconPath = "heimdall", + ) + val adBlock = WelcomeScene( + id = "AdBlock", + templateID = "DoAction", + iconPath = "ad-block", + data = mapOf( + "NoAction" to "StopReceiveWelcome", ), - WelcomeTip( - id = "OhNo", - iconPath = "@error", - data = mapOf( - "ShowPoliteWelcome" to false, - ), - chance = 200, + chance = 300, + ) + val `404NotFound` = WelcomeScene( + id = "404NotFound", + templateID = "PlainText", + iconPath = "ad-block", + conditionID = "SettingsReq", + data = mapOf( + "FontSize" to 1.2, + "ShowPoliteWelcome" to false, + "CExpression" to "@ClickWelcomeTimes > 5 && @ShouldShowWelcome", ), - WelcomeTip( - id = "RateUs", - templateID = "RateStar", - iconPath = "@error", - data = mapOf( - "StarNumber" to 5, - "InactiveStarIconPath" to "star-inactive", - "ActiveStarIconPath" to "star", - "StarSize" to 60.0, - ), - chance = 200, + chance = 200, + ) + val ohNo = WelcomeScene( + id = "OhNo", + iconPath = "@error", + data = mapOf( + "ShowPoliteWelcome" to false, ), - WelcomeTip( - id = "ErekirDetected", - iconPath = "spec-erekir", - conditionID = "SpecialDishes", + chance = 200, + ) + val rateUs = WelcomeScene( + id = "RateUs", + templateID = "RateStar", + iconPath = "@error", + data = mapOf( + "StarNumber" to 5, + "InactiveStarIconPath" to "star-inactive", + "ActiveStarIconPath" to "star", + "StarSize" to 60.0, ), - WelcomeTip( - id = "SetOutErekir", - templateID = "DoAction", - conditionID = "SettingsReq", - iconPath = "spec-erekir", - data = mapOf( - "ShowPoliteWelcome" to true, - "CExpression" to "@ContentSpecific == vanilla && @ShouldShowWelcome", - "YesAction" to "Navigation", - "Locator" to "/CyberIO/ContentSpecific", - ), + chance = 200, + ) + val erekirDetected = WelcomeScene( + id = "ErekirDetected", + iconPath = "spec-erekir", + conditionID = "SpecialDishes", + ) + val setOutErekir = WelcomeScene( + id = "SetOutErekir", + templateID = "DoAction", + conditionID = "SettingsReq", + iconPath = "spec-erekir", + data = mapOf( + "ShowPoliteWelcome" to true, + "CExpression" to "@ContentSpecific == vanilla && @ShouldShowWelcome", + "YesAction" to "Navigation", + "Locator" to "/CyberIO/ContentSpecific", ), - WelcomeTip( - id = "CyberionForErekir", - conditionID = "SettingsReq", - iconPath = "cyberion-for-erekir", - data = mapOf( - "ShowPoliteWelcome" to true, - "CExpression" to "@ContentSpecific == erekir && @ShouldShowWelcome", - ), + ) + val cyberionForErekir = WelcomeScene( + id = "CyberionForErekir", + conditionID = "SettingsReq", + iconPath = "cyberion-for-erekir", + data = mapOf( + "ShowPoliteWelcome" to true, + "CExpression" to "@ContentSpecific == erekir && @ShouldShowWelcome", ), ) + val tips = listOf( + default, + employmentVerification, + discord, + updateECHO, + researchProject, + theShip, + echo, + newBrains, + adBlock, + `404NotFound`, + ohNo, + rateUs, + erekirDetected, + setOutErekir, + cyberionForErekir, + ) val id2Tips = tips.associateBy { it.id } - } -operator fun Welcomes.get(id: String) = id2Tips[id] ?: WelcomeTip.Default -inline fun Welcomes.find(filter: (WelcomeTip) -> Boolean): WelcomeTip? { +operator fun Welcomes.get(id: String) = id2Tips[id] ?: WelcomeScene.Default +inline fun Welcomes.find(filter: (WelcomeScene) -> Boolean): WelcomeScene? { return id2Tips.values.find(filter) } -inline fun Welcomes.findAll(filter: (WelcomeTip) -> Boolean): List { +inline fun Welcomes.findAll(filter: (WelcomeScene) -> Boolean): List { return id2Tips.values.filter(filter) } \ No newline at end of file