Skip to content

Commit

Permalink
A bunch of moves to make order
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunderblade73 committed Jan 6, 2025
1 parent 6f2d5c9 commit f90d105
Show file tree
Hide file tree
Showing 12 changed files with 517 additions and 478 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ object CollectionAPI {
fun isCollectionTier0(lore: List<String>) = lore.any { collectionTier0Pattern.matches(it) }
fun getCollectionCounter(internalName: NEUInternalName): Long? = collectionValue[internalName]

fun NEUInternalName.getMultipleMap() = CollectionAPI.findAllMultiples()[this] ?: mapOf(this to 1)

fun findAllMultiples(): Map<NEUInternalName, MutableMap<NEUInternalName, Int>> {
val entries = mutableMapOf<NEUInternalName, MutableMap<NEUInternalName, Int>>()
NEUItems.allInternalNames.values.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import at.hannibal2.skyhanni.features.garden.fortuneguide.FarmingItems
import at.hannibal2.skyhanni.features.garden.pests.PestProfitTracker
import at.hannibal2.skyhanni.features.garden.pests.VinylType
import at.hannibal2.skyhanni.features.garden.visitor.VisitorReward
import at.hannibal2.skyhanni.features.gui.ShTrack
import at.hannibal2.skyhanni.features.gui.shtrack.TrackingList
import at.hannibal2.skyhanni.features.inventory.chocolatefactory.ChocolateFactoryStrayTracker
import at.hannibal2.skyhanni.features.inventory.experimentationtable.ExperimentsProfitTracker
import at.hannibal2.skyhanni.features.inventory.wardrobe.WardrobeAPI.WardrobeData
Expand Down Expand Up @@ -838,5 +838,5 @@ class ProfileSpecificStorage {
}

@Expose
val tracking: ShTrack.TrackingList = ShTrack.TrackingList()
val tracking: TrackingList = TrackingList()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package at.hannibal2.skyhanni.features.gui.shtrack

import at.hannibal2.skyhanni.utils.CommandUtils
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.PrimitiveItemStack
import at.hannibal2.skyhanni.utils.renderables.Renderable

// TODO remove
@Deprecated("Not needed anymore")
class ItemGroupElement(
val group: CommandUtils.ItemGroup,
override var current: Long,
override val target: Long?,
override val includeSack: Boolean,
) : ItemTrackingInterface() {

override val name = group.name
override val saveName = group.name

override fun similarElement(other: TrackingElement<*>): Boolean {
if (other !is ItemGroupElement) return false
return other.group == this.group
}

override fun atRemove() {
for (item in group.items.keys) {
ShTrack.itemTrackers[item]?.remove(this)
}
}

override fun atAdd() {
for (item in group.items.keys) {
ShTrack.itemTrackers.compute(item) { _, v ->
v?.also { it.add(this) } ?: mutableListOf(this)
}
}
}

override fun internalUpdate(amount: Number) {
current += amount.toLong()
if (target != null && current >= target) {
handleDone("${group.name} §adone")
}
}

override fun generateLine() = listOf(
Renderable.itemStack(group.icon.getItemStack()),
Renderable.string(group.name),
Renderable.string(current.toString() + ((target?.let { " / $it" }).orEmpty())),
)

override fun itemChange(item: PrimitiveItemStack) {
val multiple = group.items[item.internalName] ?: throw IllegalStateException("You should not be here!")
update(item.amount * multiple)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package at.hannibal2.skyhanni.features.gui.shtrack

import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.PrimitiveItemStack
import at.hannibal2.skyhanni.utils.renderables.Renderable
import com.google.gson.JsonElement

class ItemTrackingElement(
val item: NEUInternalName,
override var current: Long,
override val target: Long?,
override val includeSack: Boolean,
) : ItemTrackingInterface() {

override val name get() = item.itemName
override val saveName = item.asString()

override fun similarElement(other: TrackingElement<*>): Boolean {
if (other !is ItemTrackingElement) return false
return other.item == this.item
}

override fun atRemove() {
ShTrack.itemTrackers[item]?.remove(this)
}

override fun atAdd() {
ShTrack.itemTrackers.compute(item) { _, v ->
v?.also { it.add(this) } ?: mutableListOf(this)
}
}

override fun internalUpdate(amount: Number) {
current += amount.toLong()
if (target != null && current >= target) {
handleDone("$name §adone")
}
}

override fun generateLine() = listOf(
Renderable.itemStack(item.getItemStack()),
Renderable.string(item.itemName),
Renderable.string(current.toString() + ((target?.let { " / $it" }).orEmpty())),
)

override fun itemChange(item: PrimitiveItemStack) {
update(item.amount)
}

companion object {
fun fromJson(read: Map<String, JsonElement>): ItemsStackElement = ItemsStackElement(
read["name"]!!.asString.toInternalName(),
read["current"]?.asLong ?: 0,
read["target"]?.asLong,
read["sack"]?.asBoolean ?: false,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package at.hannibal2.skyhanni.features.gui.shtrack

import at.hannibal2.skyhanni.utils.PrimitiveItemStack
import com.google.gson.stream.JsonWriter

abstract class ItemTrackingInterface() : TrackingElement<Long>() {

abstract fun itemChange(item: PrimitiveItemStack)

abstract val includeSack: Boolean

override fun toJson(out: JsonWriter) {
super.toJson(out)
out.name("sack").value(includeSack)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package at.hannibal2.skyhanni.features.gui.shtrack

import at.hannibal2.skyhanni.api.CollectionAPI.getMultipleMap
import at.hannibal2.skyhanni.utils.ItemUtils.itemName
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.NEUItems.getItemStack
import at.hannibal2.skyhanni.utils.PrimitiveItemStack
import at.hannibal2.skyhanni.utils.renderables.Renderable
import com.google.gson.JsonElement

class ItemsStackElement(
val main: NEUInternalName,
override var current: Long,
override val target: Long?,
override val includeSack: Boolean,
) : ItemTrackingInterface() {

override val name get() = main.itemName
override val saveName = main.asString()

val map = NEUItems.getPrimitiveMultiplier(main).internalName.getMultipleMap()

private val mappedCurrent get() = map[main]?.let { current.div(it) } ?: current

override fun similarElement(other: TrackingElement<*>): Boolean {
if (other !is ItemsStackElement) return false
return other.main == this.main
}

override fun atRemove() {
for (item in map.keys) {
ShTrack.itemTrackers[item]?.remove(this)
}
}

override fun atAdd() {
for (item in map.keys) {
ShTrack.itemTrackers.compute(item) { _, v ->
v?.also { it.add(this) } ?: mutableListOf(this)
}
}
}

override fun internalUpdate(amount: Number) {
current += amount.toLong()
if (target != null && mappedCurrent >= target) {
handleDone("$name §adone")
}
}

override fun generateLine() = listOf(
Renderable.itemStack(main.getItemStack()),
Renderable.string(main.itemName),

Renderable.string(mappedCurrent.toString() + ((target?.let { " / $it" }).orEmpty())),
)

override fun itemChange(item: PrimitiveItemStack) {
val multiple = map[item.internalName] ?: throw IllegalStateException("You should not be here!")
update(item.amount * multiple)
}

companion object {

fun fromJson(read: Map<String, JsonElement>): ItemsStackElement = ItemsStackElement(
read["name"]!!.asString.toInternalName(),
read["current"]?.asLong ?: 0,
read["target"]?.asLong,
read["sack"]?.asBoolean ?: false,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package at.hannibal2.skyhanni.features.gui.shtrack

import at.hannibal2.skyhanni.api.HotmAPI
import at.hannibal2.skyhanni.utils.renderables.Renderable
import com.google.gson.JsonElement

class PowderTrackingElement(val type: HotmAPI.PowderType, override var current: Long, override val target: Long?) :
TrackingElement<Long>() {

override val name = "${type.displayNameWithColor} Powder"
override val saveName = type.name

override fun internalUpdate(amount: Number) {
current += amount.toLong()
if (target != null && current >= target) {
handleDone("${type.displayName} §adone")
}
}

override fun generateLine() = listOf(
Renderable.itemStack(type.icon),
Renderable.string(type.displayName),
Renderable.string(current.toString() + ((target?.let { " / $it" }).orEmpty())),
)

override fun similarElement(other: TrackingElement<*>): Boolean {
if (other !is PowderTrackingElement) return false
return other.type == this.type
}

override fun atRemove() {
ShTrack.powderTracker.remove(this)
}

override fun atAdd() {
ShTrack.powderTracker.add(this)
}

companion object {
fun fromJson(read: Map<String, JsonElement>): PowderTrackingElement =
PowderTrackingElement(extractType(read), read["current"]?.asLong ?: 0, read["target"]?.asLong)

private fun extractType(read: Map<String, JsonElement>) = HotmAPI.PowderType.getValue(read["name"]!!.asString)!!
}

}
Loading

0 comments on commit f90d105

Please sign in to comment.