-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f2d5c9
commit f90d105
Showing
12 changed files
with
517 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/at/hannibal2/skyhanni/features/gui/shtrack/ItemGroupElement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/at/hannibal2/skyhanni/features/gui/shtrack/ItemTrackingElement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/at/hannibal2/skyhanni/features/gui/shtrack/ItemTrackingInterface.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/at/hannibal2/skyhanni/features/gui/shtrack/ItemsStackElement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/at/hannibal2/skyhanni/features/gui/shtrack/PowderTrackingElement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)!! | ||
} | ||
|
||
} |
Oops, something went wrong.