Skip to content

Commit

Permalink
migrate welcome list from json to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed Dec 6, 2023
1 parent 60e7a1e commit 5d80bf7
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 188 deletions.
2 changes: 0 additions & 2 deletions main/src/net/liplum/CioMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import net.liplum.script.NpcSystem
import net.liplum.update.Updater
import net.liplum.welcome.FirstLoaded
import net.liplum.welcome.Welcome
import net.liplum.welcome.WelcomeList
import plumy.core.ClientOnly
import plumy.core.HeadlessOnly
import java.io.File
Expand Down Expand Up @@ -129,7 +128,6 @@ class CioMod : Mod() {
Core.app.post {
CioShaderLoader.init()
safeCall {
WelcomeList.loadList()
Welcome.load()
}
DebugOnly {
Expand Down
9 changes: 5 additions & 4 deletions main/src/net/liplum/ui/CioUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ import net.liplum.common.util.getF
import net.liplum.common.util.randomExcept
import net.liplum.event.CioInitEvent
import net.liplum.function.MapCleaner
import net.liplum.utils.IsLocal
import net.liplum.utils.safeCall
import net.liplum.ui.settings.*
import net.liplum.ui.settings.AnySetting.Companion.addAny
import net.liplum.ui.settings.CheckSettingX.Companion.addCheckPref
import net.liplum.ui.settings.SliderSettingX.Companion.addSliderSettingX
import net.liplum.update.Updater
import net.liplum.utils.IsLocal
import net.liplum.utils.safeCall
import net.liplum.welcome.Conditions
import net.liplum.welcome.Welcome
import net.liplum.welcome.WelcomeList
import net.liplum.welcome.Welcomes
import net.liplum.welcome.findAll
import plumy.core.ClientOnly
import plumy.core.NonSteamOnly
import plumy.dsl.bundle
Expand Down Expand Up @@ -166,7 +167,7 @@ object CioUI {
Updater.accessJob?.join()
if (!failed) {
if (Updater.requireUpdate) {
val updateTips = WelcomeList.findAll { tip ->
val updateTips = Welcomes.findAll { tip ->
tip.condition == Conditions.CheckUpdate
}
if (updateTips.isEmpty()) {
Expand Down
6 changes: 3 additions & 3 deletions main/src/net/liplum/welcome/Welcome.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import mindustry.game.EventType.Trigger
import mindustry.io.JsonIO
import net.liplum.CioMod
import net.liplum.Meta
import net.liplum.Var
import net.liplum.Settings.CioVersion
import net.liplum.Settings.ClickWelcomeTimes
import net.liplum.Settings.LastWelcomeID
import net.liplum.Settings.ShouldShowWelcome
import net.liplum.Settings.ShowUpdate
import net.liplum.Var
import net.liplum.annotations.Only
import net.liplum.annotations.SubscribeEvent
import net.liplum.blocks.tmtrainer.RandomName
Expand Down Expand Up @@ -52,7 +52,7 @@ object Welcome {
}
@JvmStatic
fun judgeWelcome() {
val allTips = info.scenes.map { WelcomeList[it] }.distinct().toList()
val allTips = info.scenes.map { Welcomes[it] }.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 @@ -198,7 +198,7 @@ object Welcome {

companion object {
fun Entity.showTipByID(id: String): Entity {
tip = WelcomeList[id]
tip = Welcomes[id]
showTip()
return this
}
Expand Down
69 changes: 0 additions & 69 deletions main/src/net/liplum/welcome/WelcomeList.kt

This file was deleted.

25 changes: 25 additions & 0 deletions main/src/net/liplum/welcome/WelcomeTip.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.liplum.welcome

class WelcomeTip(
@JvmField var id: String = DefaultID,
@JvmField var conditionID: String = DefaultCondition,
@JvmField var templateID: String = DefaultTemplateID,
@JvmField var iconPath: String = DefaultIconPath,
@JvmField var chance: Int = DefaultChance,
@JvmField var data: Map<String, Any?> = emptyMap(),
) {
override fun toString() = id
val template: WelcomeTemplate
get() = TemplateRegistry[templateID]
val condition: Condition
get() = ConditionRegistry[conditionID]

companion object {
val Default = WelcomeTip()
const val DefaultID = "Default"
const val DefaultCondition = "ShowWelcome"
const val DefaultTemplateID = "Story"
const val DefaultChance = 1000
const val DefaultIconPath = "icon"
}
}
127 changes: 127 additions & 0 deletions main/src/net/liplum/welcome/Welcomes.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
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",
),
WelcomeTip(
id = "AdBlock",
templateID = "DoAction",
iconPath = "ad-block",
data = mapOf(
"NoAction" to "StopReceiveWelcome",
),
chance = 300,
),
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,
),
WelcomeTip(
id = "OhNo",
iconPath = "@error",
data = mapOf(
"ShowPoliteWelcome" to false,
),
chance = 200,
),
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,
),
WelcomeTip(
id = "ErekirDetected",
iconPath = "spec-erekir",
conditionID = "SpecialDishes",
),
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",
),
),
WelcomeTip(
id = "CyberionForErekir",
conditionID = "SettingsReq",
iconPath = "cyberion-for-erekir",
data = mapOf(
"ShowPoliteWelcome" to true,
"CExpression" to "@ContentSpecific == erekir && @ShouldShowWelcome",
),
),
)
val id2Tips = tips.associateBy { it.id }

}

operator fun Welcomes.get(id: String) = id2Tips[id] ?: WelcomeTip.Default
inline fun Welcomes.find(filter: (WelcomeTip) -> Boolean): WelcomeTip? {
return id2Tips.values.find(filter)
}

inline fun Welcomes.findAll(filter: (WelcomeTip) -> Boolean): List<WelcomeTip> {
return id2Tips.values.filter(filter)
}
Loading

0 comments on commit 5d80bf7

Please sign in to comment.