summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/test
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2024-09-17 10:28:38 +0200
committerGitHub <noreply@github.com>2024-09-17 10:28:38 +0200
commit1dcc43a3f37591912f086299c298df4e0e471bd9 (patch)
tree1f1682f7ad74848a7569d0e237fb482f73cdf68a /src/main/java/at/hannibal2/skyhanni/test
parentd1bb73a6826b4c56694a47b5811980ec4cdc90af (diff)
downloadskyhanni-1dcc43a3f37591912f086299c298df4e0e471bd9.tar.gz
skyhanni-1dcc43a3f37591912f086299c298df4e0e471bd9.tar.bz2
skyhanni-1dcc43a3f37591912f086299c298df4e0e471bd9.zip
Improvement: More Graph Things (#2515)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/test')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt207
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/GraphNodeEditor.kt178
-rw-r--r--src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt1
3 files changed, 214 insertions, 172 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt
index 81a85283e..d4038162f 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/GraphEditor.kt
@@ -14,13 +14,12 @@ import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.ChatUtils
-import at.hannibal2.skyhanni.utils.CollectionUtils.addSearchString
-import at.hannibal2.skyhanni.utils.CollectionUtils.addString
import at.hannibal2.skyhanni.utils.ColorUtils
import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyHeld
import at.hannibal2.skyhanni.utils.LocationUtils
+import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer
import at.hannibal2.skyhanni.utils.LocationUtils.playerLocation
import at.hannibal2.skyhanni.utils.LorenzColor
import at.hannibal2.skyhanni.utils.LorenzUtils
@@ -30,37 +29,27 @@ import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.RenderUtils.draw3DLine_nea
import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText
import at.hannibal2.skyhanni.utils.RenderUtils.drawWaypointFilled
-import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
-import at.hannibal2.skyhanni.utils.SimpleTimeMark
-import at.hannibal2.skyhanni.utils.renderables.Renderable
-import at.hannibal2.skyhanni.utils.renderables.ScrollValue
-import at.hannibal2.skyhanni.utils.renderables.Searchable
-import at.hannibal2.skyhanni.utils.renderables.buildSearchableScrollable
-import at.hannibal2.skyhanni.utils.renderables.toSearchable
import kotlinx.coroutines.runBlocking
import net.minecraft.client.settings.KeyBinding
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable
import java.awt.Color
-import kotlin.math.sqrt
-import kotlin.time.Duration.Companion.milliseconds
-import kotlin.time.Duration.Companion.seconds
@SkyHanniModule
object GraphEditor {
- private val config get() = SkyHanniMod.feature.dev.devTool.graph
+ val config get() = SkyHanniMod.feature.dev.devTool.graph
- private fun isEnabled() = config != null && config.enabled
+ fun isEnabled() = config != null && config.enabled
private var id = 0
- private val nodes = mutableListOf<GraphingNode>()
+ val nodes = mutableListOf<GraphingNode>()
private val edges = mutableListOf<GraphingEdge>()
- private var activeNode: GraphingNode? = null
+ var activeNode: GraphingNode? = null
set(value) {
field = value
selectedEdge = findEdgeBetweenActiveAndClosed()
@@ -106,25 +95,25 @@ object GraphEditor {
private val edgeDijkstraColor = LorenzColor.DARK_BLUE.addOpacity(150)
private val edgeSelectedColor = LorenzColor.DARK_RED.addOpacity(150)
- private val scrollValue = ScrollValue()
- private val textInput = TextInput()
- private var nodesDisplay = emptyList<Searchable>()
- var lastUpdate = SimpleTimeMark.farPast()
-
@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onRender(event: LorenzRenderWorldEvent) {
if (!isEnabled()) return
nodes.forEach { event.drawNode(it) }
edges.forEach { event.drawEdge(it) }
- ghostPosition?.let {
- event.drawWaypointFilled(
- it,
- if (activeNode == null) Color.RED else Color.GRAY,
- seeThroughBlocks = seeThroughBlocks,
- minimumAlpha = 0.2f,
- inverseAlphaScale = true,
- )
- }
+ drawGhostPosition(event)
+ }
+
+ private fun drawGhostPosition(event: LorenzRenderWorldEvent) {
+ val ghostPosition = ghostPosition ?: return
+ if (ghostPosition.distanceToPlayer() >= config.maxNodeDistance) return
+
+ event.drawWaypointFilled(
+ ghostPosition,
+ if (activeNode == null) Color.RED else Color.GRAY,
+ seeThroughBlocks = seeThroughBlocks,
+ minimumAlpha = 0.2f,
+ inverseAlphaScale = true,
+ )
}
@SubscribeEvent
@@ -188,136 +177,6 @@ object GraphEditor {
dissolvePossible = edges.count { it.isInEdge(activeNode) } == 2
}
- @SubscribeEvent
- fun onGuiRender(event: GuiRenderEvent) {
- if (!isEnabled()) return
-
-
- config.namedNodesList.renderRenderables(
- buildList {
- val list = getNodeNames()
- val size = list.size
- addString("§eGraph Nodes: $size")
- val height = (size * 10).coerceAtMost(250)
- if (list.isNotEmpty()) {
- add(list.buildSearchableScrollable(height, textInput, scrollValue, velocity = 10.0))
- }
- },
- posLabel = "Graph Nodes List",
- )
- }
-
- private fun getNodeNames(): List<Searchable> {
- if (lastUpdate.passedSince() > 250.milliseconds) {
- updateNodeNames()
- }
- return nodesDisplay
- }
-
- private fun updateNodeNames() {
- lastUpdate = SimpleTimeMark.now()
- nodesDisplay = drawNodeNames()
- }
-
- private fun updateTagView(node: GraphingNode) {
- lastUpdate = SimpleTimeMark.now() + 60.seconds
- nodesDisplay = drawTagNames(node)
- }
-
- private fun drawTagNames(node: GraphingNode): List<Searchable> = buildList {
- addSearchString("§eChange tag for node '${node.name}§e'")
- addSearchString("")
-
- for (tag in GraphNodeTag.entries) {
- val state = if (tag in node.tags) "§aYES" else "§cNO"
- val name = state + " §r" + tag.displayName
- add(createTagName(name, tag, node))
- }
- addSearchString("")
- add(
- Renderable.clickAndHover(
- "§cGo Back!",
- tips = listOf("§eClick to go back to the node list!"),
- onClick = {
- updateNodeNames()
- },
- ).toSearchable(),
- )
- }
-
- private fun createTagName(
- name: String,
- tag: GraphNodeTag,
- node: GraphingNode,
- ) = Renderable.clickAndHover(
- name,
- tips = listOf(
- "Tag ${tag.name}",
- "§7${tag.description}",
- "",
- "§eClick to set tag for ${node.name} to ${tag.name}!",
- ),
- onClick = {
- if (tag in node.tags) {
- node.tags.remove(tag)
- } else {
- node.tags.add(tag)
- }
- updateTagView(node)
- },
- ).toSearchable(name)
-
- private fun drawNodeNames(): List<Searchable> = buildList {
- for ((node, distance: Double) in nodes.map { it to it.position.distanceSqToPlayer() }.sortedBy { it.second }) {
- val name = node.name?.takeIf { !it.isBlank() } ?: continue
- val color = if (node == activeNode) "§a" else "§7"
- val distanceFormat = sqrt(distance).toInt().addSeparators()
- val tagText = node.tags.let {
- if (it.isEmpty()) {
- " §cNo tag§r"
- } else {
- val text = node.tags.map { it.internalName }.joinToString(", ")
- " §f($text)"
- }
- }
-
- val text = "${color}Node §r$name$tagText §7[$distanceFormat]"
- add(createNodeTextLine(text, name, node))
- }
- }
-
- private fun MutableList<Searchable>.createNodeTextLine(
- text: String,
- name: String,
- node: GraphingNode,
- ): Searchable = Renderable.clickAndHover(
- text,
- tips = buildList {
- add("Node '$name'")
- add("")
-
- if (node.tags.isNotEmpty()) {
- add("Tags: ")
- for (tag in node.tags) {
- add(" §8- §r${tag.displayName}")
- }
- add("")
- }
-
- add("§eClick to select/deselect this node!")
- add("§eControl-Click to edit the tags for this node!")
-
- },
- onClick = {
- if (KeyboardManager.isModifierKeyDown()) {
- updateTagView(node)
- } else {
- activeNode = node
- updateNodeNames()
- }
- },
- ).toSearchable(name)
-
private fun feedBackInTutorial(text: String) {
if (inTutorialMode) {
ChatUtils.chat(text)
@@ -333,6 +192,7 @@ object GraphEditor {
}
private fun LorenzRenderWorldEvent.drawNode(node: GraphingNode) {
+ if (node.position.distanceToPlayer() > config.maxNodeDistance) return
this.drawWaypointFilled(
node.position,
node.getNodeColor(),
@@ -368,17 +228,20 @@ object GraphEditor {
)
}
- private fun LorenzRenderWorldEvent.drawEdge(edge: GraphingEdge) = this.draw3DLine_nea(
- edge.node1.position.add(0.5, 0.5, 0.5),
- edge.node2.position.add(0.5, 0.5, 0.5),
- when {
- selectedEdge == edge -> edgeSelectedColor
- edge in highlightedEdges -> edgeDijkstraColor
- else -> edgeColor
- },
- 7,
- !seeThroughBlocks,
- )
+ private fun LorenzRenderWorldEvent.drawEdge(edge: GraphingEdge) {
+ if (edge.node1.position.distanceToPlayer() > config.maxNodeDistance) return
+ this.draw3DLine_nea(
+ edge.node1.position.add(0.5, 0.5, 0.5),
+ edge.node2.position.add(0.5, 0.5, 0.5),
+ when {
+ selectedEdge == edge -> edgeSelectedColor
+ edge in highlightedEdges -> edgeDijkstraColor
+ else -> edgeColor
+ },
+ 7,
+ !seeThroughBlocks,
+ )
+ }
private fun GraphingNode.getNodeColor() = when (this) {
activeNode -> if (this == closedNode) ColorUtils.blendRGB(activeColor, closedColor, 0.5) else activeColor
@@ -723,7 +586,7 @@ object GraphEditor {
}
// The node object the graph editor is working with
-private class GraphingNode(
+class GraphingNode(
val id: Int,
var position: LorenzVec,
var name: String? = null,
diff --git a/src/main/java/at/hannibal2/skyhanni/test/GraphNodeEditor.kt b/src/main/java/at/hannibal2/skyhanni/test/GraphNodeEditor.kt
new file mode 100644
index 000000000..f541b16e3
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/test/GraphNodeEditor.kt
@@ -0,0 +1,178 @@
+package at.hannibal2.skyhanni.test
+
+import at.hannibal2.skyhanni.data.model.GraphNodeTag
+import at.hannibal2.skyhanni.data.model.TextInput
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
+import at.hannibal2.skyhanni.test.GraphEditor.distanceSqToPlayer
+import at.hannibal2.skyhanni.utils.CollectionUtils.addString
+import at.hannibal2.skyhanni.utils.KeyboardManager
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.NumberUtil.addSeparators
+import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.renderables.Renderable
+import at.hannibal2.skyhanni.utils.renderables.ScrollValue
+import at.hannibal2.skyhanni.utils.renderables.Searchable
+import at.hannibal2.skyhanni.utils.renderables.buildSearchableScrollable
+import at.hannibal2.skyhanni.utils.renderables.toSearchable
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.math.sqrt
+import kotlin.time.Duration.Companion.milliseconds
+import kotlin.time.Duration.Companion.seconds
+
+@SkyHanniModule
+object GraphNodeEditor {
+
+ private val scrollValueNodes = ScrollValue()
+ private val scrollValueTags = ScrollValue()
+ private val textInput = TextInput()
+ private var nodesDisplay = emptyList<Renderable>()
+ private var lastUpdate = SimpleTimeMark.farPast()
+
+ @SubscribeEvent
+ fun onGuiRender(event: GuiRenderEvent) {
+ if (!isEnabled()) return
+
+
+ config.namedNodesList.renderRenderables(
+ getNodeNames(),
+ posLabel = "Graph Nodes List",
+ )
+ }
+
+ private fun getNodeNames(): List<Renderable> {
+ if (lastUpdate.passedSince() > 250.milliseconds) {
+ updateNodeNames()
+ }
+ return nodesDisplay
+ }
+
+ private fun updateNodeNames() {
+ lastUpdate = SimpleTimeMark.now()
+ nodesDisplay = buildList {
+ val list = drawNodeNames()
+ val size = list.size
+ addString("§eGraph Nodes: $size")
+ val height = (size * 10).coerceAtMost(250)
+ if (list.isNotEmpty()) {
+ add(list.buildSearchableScrollable(height, textInput, scrollValueNodes, velocity = 10.0))
+ }
+ }
+ }
+
+ private fun updateTagView(node: GraphingNode) {
+ lastUpdate = SimpleTimeMark.now() + 60.seconds
+ nodesDisplay = buildList {
+ val list = drawTagNames(node)
+ val size = list.size
+ addString("§eGraph Nodes: $size")
+ val height = (size * 10).coerceAtMost(250)
+ if (list.isNotEmpty()) {
+ add(Renderable.scrollList(list, height, scrollValueTags, velocity = 10.0))
+ }
+ }
+ }
+
+ private fun drawTagNames(node: GraphingNode): List<Renderable> = buildList {
+ addString("§eChange tag for node '${node.name}§e'")
+ addString("")
+
+ for (tag in GraphNodeTag.entries.filter { it in node.tags || checkIsland(it) }) {
+ val state = if (tag in node.tags) "§aYES" else "§cNO"
+ val name = state + " §r" + tag.displayName
+ add(createTagName(name, tag, node))
+ }
+ addString("")
+ add(
+ Renderable.clickAndHover(
+ "§cGo Back!",
+ tips = listOf("§eClick to go back to the node list!"),
+ onClick = {
+ updateNodeNames()
+ },
+ ),
+ )
+ }
+
+ private fun checkIsland(tag: GraphNodeTag): Boolean = tag.onlyIsland?.let {
+ it == LorenzUtils.skyBlockIsland
+ } ?: true
+
+ private fun createTagName(
+ name: String,
+ tag: GraphNodeTag,
+ node: GraphingNode,
+ ) = Renderable.clickAndHover(
+ name,
+ tips = listOf(
+ "Tag ${tag.name}",
+ "§7${tag.description}",
+ "",
+ "§eClick to set tag for ${node.name} to ${tag.name}!",
+ ),
+ onClick = {
+ if (tag in node.tags) {
+ node.tags.remove(tag)
+ } else {
+ node.tags.add(tag)
+ }
+ updateTagView(node)
+ },
+ )
+
+ private fun drawNodeNames(): List<Searchable> = buildList {
+ for ((node, distance: Double) in GraphEditor.nodes.map { it to it.position.distanceSqToPlayer() }.sortedBy { it.second }) {
+ val name = node.name?.takeIf { !it.isBlank() } ?: continue
+ val color = if (node == GraphEditor.activeNode) "§a" else "§7"
+ val distanceFormat = sqrt(distance).toInt().addSeparators()
+ val tagText = node.tags.let { tags ->
+ if (tags.isEmpty()) {
+ " §cNo tag§r"
+ } else {
+ val text = node.tags.joinToString(", ") { it.internalName }
+ " §f($text)"
+ }
+ }
+
+ val text = "${color}Node §r$name$tagText §7[$distanceFormat]"
+ add(createNodeTextLine(text, name, node))
+ }
+ }
+
+ private fun createNodeTextLine(
+ text: String,
+ name: String,
+ node: GraphingNode,
+ ): Searchable = Renderable.clickAndHover(
+ text,
+ tips = buildList {
+ add("Node '$name'")
+ add("")
+
+ if (node.tags.isNotEmpty()) {
+ add("Tags: ")
+ for (tag in node.tags) {
+ add(" §8- §r${tag.displayName}")
+ }
+ add("")
+ }
+
+ add("§eClick to select/deselect this node!")
+ add("§eControl-Click to edit the tags for this node!")
+
+ },
+ onClick = {
+ if (KeyboardManager.isModifierKeyDown()) {
+ updateTagView(node)
+ } else {
+ GraphEditor.activeNode = node
+ updateNodeNames()
+ }
+ },
+ ).toSearchable(name)
+
+ fun isEnabled() = GraphEditor.isEnabled()
+ private val config get() = GraphEditor.config
+
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
index 9e95df881..5b7333189 100644
--- a/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
+++ b/src/main/java/at/hannibal2/skyhanni/test/SkyHanniDebugsAndTests.kt
@@ -116,6 +116,7 @@ object SkyHanniDebugsAndTests {
if (args.isEmpty()) {
testLocation = null
ChatUtils.chat("reset test waypoint")
+ IslandGraphs.stop()
}
val x = args[0].toDouble()