Skip to content

Commit

Permalink
Improvement: Show time until upgrade (#1654)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs authored May 2, 2024
1 parent 4e2e5a7 commit df8b39c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {

val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 44
const val CONFIG_VERSION = 45
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public class ChocolateFactoryConfig {
ChocolateFactoryStat.MULTIPLIER,
ChocolateFactoryStat.BARN,
ChocolateFactoryStat.TIME_TOWER,
ChocolateFactoryStat.LEADERBOARD_POS
ChocolateFactoryStat.LEADERBOARD_POS,
ChocolateFactoryStat.TIME_TO_BEST_UPGRADE
));

@Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public static class ChocolateFactoryStorage {
@Expose
public long bestUpgradeAvailableAt = 0;

@Expose
public long bestUpgradeCost = 0;

@Expose
public long lastDataSave = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ object ChocolateFactoryDataLoader {

val bestUpgrade = notMaxed.minByOrNull { it.effectiveCost ?: Double.MAX_VALUE }
profileStorage.bestUpgradeAvailableAt = bestUpgrade?.canAffordAt?.toMillis() ?: 0
profileStorage.bestUpgradeCost = bestUpgrade?.price ?: 0
ChocolateFactoryAPI.bestPossibleSlot = bestUpgrade?.getValidUpgradeIndex() ?: -1

val bestUpgradeLevel = bestUpgrade?.level ?: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.renderables.Renderable
import com.google.gson.JsonElement
import com.google.gson.JsonPrimitive
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

Expand Down Expand Up @@ -61,9 +62,11 @@ object ChocolateFactoryStats {
var chocolateUntilPrestige = "§6${chocolateUntilPrestigeCalculation.addSeparators()}"

if (chocolateUntilPrestigeCalculation <= 0) {
chocolateUntilPrestige = "§aPrestige Avaliable"
chocolateUntilPrestige = "§aPrestige Available"
}

val upgradeAvailableAt = ChocolateAmount.CURRENT.formattedTimeUntilGoal(profileStorage.bestUpgradeCost)

val map = buildMap {
put(ChocolateFactoryStat.HEADER, "§6§lChocolate Factory Stats")

Expand All @@ -84,6 +87,7 @@ object ChocolateFactoryStats {
put(ChocolateFactoryStat.EMPTY, "")
put(ChocolateFactoryStat.EMPTY_2, "")
put(ChocolateFactoryStat.EMPTY_3, "")
put(ChocolateFactoryStat.EMPTY_4, "")

put(ChocolateFactoryStat.TIME_TOWER, "§eTime Tower: §6$timeTowerInfo")
put(ChocolateFactoryStat.TIME_TO_PRESTIGE, "§eTime To Prestige: $prestigeEstimate")
Expand All @@ -95,6 +99,7 @@ object ChocolateFactoryStats {
ChocolateFactoryStat.CHOCOLATE_UNTIL_PRESTIGE,
"§eChocolate To Prestige: $chocolateUntilPrestige"
)
put(ChocolateFactoryStat.TIME_TO_BEST_UPGRADE, "§eBest Upgrade: $upgradeAvailableAt")
}
val text = config.statsDisplayList.filter { it.shouldDisplay() }.mapNotNull { map[it] }

Expand All @@ -117,13 +122,17 @@ object ChocolateFactoryStats {
@SubscribeEvent
fun onConfigFix(event: ConfigUpdaterMigrator.ConfigFixEvent) {
event.transform(42, "event.chocolateFactory.statsDisplayList") { element ->
val jsonArray = element.asJsonArray

jsonArray.add(JsonPrimitive("TIME_TOWER"))
jsonArray.add(JsonPrimitive("TIME_TO_PRESTIGE"))

jsonArray
addToDisplayList(element, "TIME_TOWER", "TIME_TO_PRESTIGE")
}
event.transform(45, "inventory.chocolateFactory.statsDisplayList") { element ->
addToDisplayList(element, "TIME_TO_BEST_UPGRADE")
}
}

private fun addToDisplayList(element: JsonElement, vararg toAdd: String): JsonElement {
val jsonArray = element.asJsonArray
toAdd.forEach { jsonArray.add(JsonPrimitive(it)) }
return jsonArray
}

enum class ChocolateFactoryStat(private val display: String, val shouldDisplay: () -> Boolean = { true }) {
Expand All @@ -141,10 +150,12 @@ object ChocolateFactoryStats {
EMPTY(""),
EMPTY_2(""),
EMPTY_3(""),
EMPTY_4(""),
TIME_TOWER("§eTime Tower: §62/3 Charges", { ChocolateFactoryTimeTowerManager.currentCharges() != -1 }),
TIME_TO_PRESTIGE("§eTime To Prestige: §61d 13h 59m 4s", { ChocolateFactoryAPI.currentPrestige != 5 }),
TIME_TO_PRESTIGE("§eTime To Prestige: §b1d 13h 59m 4s", { ChocolateFactoryAPI.currentPrestige != 5 }),
RAW_PER_SECOND("§eRaw Per Second: §62,136"),
CHOCOLATE_UNTIL_PRESTIGE("§eChocolate To Prestige: §65,851", { ChocolateFactoryAPI.currentPrestige != 5 }),
TIME_TO_BEST_UPGRADE("§eBest Upgrade: §b 59m 4s"),
;

override fun toString(): String {
Expand Down

0 comments on commit df8b39c

Please sign in to comment.