Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend: Graph Editor #1454

Merged
merged 51 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
2536de8
added isKeyClicked
Thunderblade73 Apr 9, 2024
3717f1b
removed redundant delays
Thunderblade73 Apr 9, 2024
42aec8a
Merge branch 'key-clicked' into tool/graph
Thunderblade73 Apr 14, 2024
fc1ce24
f
Thunderblade73 Apr 14, 2024
74d9174
gson
Thunderblade73 Apr 14, 2024
a725135
fixes
Thunderblade73 Apr 15, 2024
1f3ae01
Merge branch 'beta' into tool/graph
Thunderblade73 Apr 16, 2024
0b6cb15
merge fix
Thunderblade73 Apr 17, 2024
aa5fc0e
Merge branch 'beta' into tool/graph
Thunderblade73 Apr 19, 2024
a6e7c4f
Merge branch 'beta' into tool/graph
Thunderblade73 Apr 24, 2024
8a48482
fix ConfigManager
Thunderblade73 Apr 24, 2024
bc2f69b
fix
Thunderblade73 Apr 25, 2024
c63bbc0
fixed indexOutOfBoundsException
Thunderblade73 Apr 25, 2024
385668f
Merge branch 'beta' into tool/graph
Thunderblade73 Apr 25, 2024
5a5c5f1
see through blocks toggle
Thunderblade73 Apr 26, 2024
448d621
fixed deadlock
Thunderblade73 May 1, 2024
f4983c5
round weight in export
Thunderblade73 May 1, 2024
f4397a9
Merge branch 'beta' into tool/graph
Thunderblade73 May 1, 2024
cf4f7c7
Merge branch 'beta' into tool/graph
Thunderblade73 May 5, 2024
1a18870
Merge branch 'beta' into tool/graph
Thunderblade73 May 7, 2024
0f735ba
Merge branch 'beta' into tool/graph
Thunderblade73 May 7, 2024
0e9d335
fixes
Thunderblade73 May 7, 2024
a273da3
added back the round
Thunderblade73 May 7, 2024
cb0ff4d
correct rounding
Thunderblade73 May 7, 2024
879738a
Merge branch 'refs/heads/beta' into tool/graph
Thunderblade73 May 11, 2024
88a156c
Merge branch 'refs/heads/beta' into tool/graph
Thunderblade73 May 11, 2024
272f8ec
fix clickable chat
Thunderblade73 May 15, 2024
de6ddd3
fix missing expose
Thunderblade73 May 24, 2024
f4f62c7
Merge branch 'refs/heads/beta' into fork/Thunderblade73/tool/graph
CalMWolfs Jun 1, 2024
adc9820
some tutorial
Thunderblade73 Jun 1, 2024
902aafc
changed default text key
Thunderblade73 Jun 1, 2024
82dd493
Merge branch 'refs/heads/beta' into tool/graph
Thunderblade73 Jun 1, 2024
d9ab4e7
Merge branch 'refs/heads/beta' into tool/graph
Thunderblade73 Jun 1, 2024
a993576
Merge branch 'beta' into tool/graph
CalMWolfs Jun 4, 2024
f7f6a4e
oops
CalMWolfs Jun 4, 2024
5c9c265
Merge branch 'refs/heads/beta' into fork/Thunderblade73/tool/graph
CalMWolfs Jun 6, 2024
d68dedc
fix merge
CalMWolfs Jun 6, 2024
575cbbc
Merge branch 'refs/heads/beta' into fork/tool/graph
hannibal002 Jun 9, 2024
9f8901d
code cleanup
hannibal002 Jun 9, 2024
bddd180
code cleanup
hannibal002 Jun 9, 2024
34b2992
code cleanup
hannibal002 Jun 9, 2024
1a994fc
fixes and typos
hannibal002 Jun 9, 2024
1e9f32c
extracted toJson
Thunderblade73 Jun 9, 2024
3152f4c
parkouring while in graph editor is dangerous!
Thunderblade73 Jun 9, 2024
05f3fea
extract buildDisplay into own function
hannibal002 Jun 9, 2024
d98d7b7
typo
hannibal002 Jun 9, 2024
e9432e5
better name rendering
Thunderblade73 Jun 9, 2024
2fc3804
added stats
Thunderblade73 Jun 9, 2024
c4c686d
fix place location being inaccurate
hannibal002 Jun 10, 2024
325fbec
fixed debug
hannibal002 Jun 10, 2024
eb69f7f
always show names of nodes close to you
hannibal002 Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import at.hannibal2.skyhanni.features.misc.visualwords.VisualWordGui
import at.hannibal2.skyhanni.features.rift.area.westvillage.VerminTracker
import at.hannibal2.skyhanni.features.slayer.SlayerProfitTracker
import at.hannibal2.skyhanni.test.DebugCommand
import at.hannibal2.skyhanni.test.GraphEditor
import at.hannibal2.skyhanni.test.PacketTest
import at.hannibal2.skyhanni.test.SkyHanniConfigSearchResetCommand
import at.hannibal2.skyhanni.test.SkyHanniDebugsAndTests
Expand Down Expand Up @@ -530,6 +531,10 @@ object Commands {
"shaddfoundburrowlocationsfromclipboard",
"Add all ever found burrow locations from clipboard"
) { AllBurrowsList.addFromClipboard() }
registerCommand(
"shgraph",
"Enables the graph editor"
) { GraphEditor.commandIn() }
registerCommand(
"shtoggleegglocationdebug",
"Shows Hoppity egg locations with their internal API names and status."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public class DevConfig {
@Category(name = "Minecraft Console", desc = "Minecraft Console Settings")
public MinecraftConsoleConfig minecraftConsoles = new MinecraftConsoleConfig();

@Expose
@Category(name = "Dev Tools", desc = "Tooling for devs")
public DevToolConfig devTool = new DevToolConfig();

@Expose
@Category(name = "Debug Mob", desc = "Every Debug related to the Mob System")
public DebugMobConfig mobDebug = new DebugMobConfig();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package at.hannibal2.skyhanni.config.features.dev;

import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class DevToolConfig {

@Expose
@ConfigOption(name = "Graph Tools", desc = "")
@Accordion
public GraphConfig graph = new GraphConfig();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package at.hannibal2.skyhanni.config.features.dev;

import at.hannibal2.skyhanni.config.core.config.Position;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind;
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import org.lwjgl.input.Keyboard;

public class GraphConfig {

@Expose
@ConfigOption(name = "Enabled", desc = "Enables the graphing tool.")
@ConfigEditorBoolean
public boolean enabled = false;

@Expose
@ConfigOption(name = "Place Key", desc = "Places a new node at the current position. If a node is active automatically connects." +
"Deletes a node if you are only 3 blocks away instead of placing a new one")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_F)
public int placeKey = Keyboard.KEY_F;

@Expose
@ConfigOption(name = "Select Key", desc = "Select the nearest node to be active. Double press to unselect.")
@ConfigEditorKeybind(defaultKey = -98) // Middle Mouse
public int selectKey = -98;

@Expose
@ConfigOption(name = "Connect Key", desc = "Connects the nearest node with the active node. If the nodes are already connected removes the connection.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_C)
public int connectKey = Keyboard.KEY_C;

@Expose
@ConfigOption(name = "Exit Key", desc = "Exit out of stuff. If nothing active disables the graph editor.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_HOME)
public int exitKey = Keyboard.KEY_HOME;

@Expose
@ConfigOption(name = "Edit Key", desc = "While holding the Key edit the position of the active node with the minecraft movement controls.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_TAB)
public int editKey = Keyboard.KEY_TAB;

@Expose
@ConfigOption(name = "Text Key", desc = "Starts text mode, which allows editing a name of a node.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_Y)
public int textKey = Keyboard.KEY_Y;

@Expose
@ConfigOption(name = "Test Dijkstra", desc = "On Keypress shows the shortest path between the nearest node and the active node.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_G)
public int dijkstraKey = Keyboard.KEY_G;

@Expose
@ConfigOption(name = "Save Key", desc = "Saves the current graph to the clipboard.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_O)
public int saveKey = Keyboard.KEY_O;

@Expose
@ConfigOption(name = "Load Key", desc = "Loads a graph from clipboard, if valid.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_I)
public int loadKey = Keyboard.KEY_I;

@Expose
@ConfigOption(name = "Clear Key", desc = "Clears the graph. Also saves the graph to the clipboard, just in case you miss clicked.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_P)
public int clearKey = Keyboard.KEY_P;

@Expose
@ConfigOption(name = "Vision Key", desc = "Toggles if the graph should render trough blocks.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_M)
public int throughBlocksKey = Keyboard.KEY_M;

@Expose
@ConfigOption(name = "Tutorial Key", desc = "Toggles the tutorial mode. In this mode you will get feedback for everything you do.")
@ConfigEditorKeybind(defaultKey = Keyboard.KEY_K)
public int tutorialKey = Keyboard.KEY_K;

@Expose
@ConfigLink(owner = GraphConfig.class, field = "enabled")
public Position infoDisplay = new Position(20, 20);
}
3 changes: 2 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.data.model

import at.hannibal2.skyhanni.utils.LorenzUtils.round
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.json.SkyHanniTypeAdapters.registerTypeAdapter
import at.hannibal2.skyhanni.utils.json.fromJson
Expand Down Expand Up @@ -48,7 +49,7 @@
out.beginObject()
it.neighbours.forEach { (node, weight) ->
val id = node.id.toString()
out.name(id).value(weight)
out.name(id).value(weight.round(2))

Check failure on line 52 in src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt

View workflow job for this annotation

GitHub Actions / Check Style

[ktlint] reported by reviewdog 🐶 Unexpected indentation (24) (should be 20) Raw Output: src/main/java/at/hannibal2/skyhanni/data/model/Graph.kt:52:1: error: Unexpected indentation (24) (should be 20) (standard:indent)
}
out.endObject()
out.endObject()
Expand Down
133 changes: 133 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/data/model/TextInput.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package at.hannibal2.skyhanni.data.model

import at.hannibal2.skyhanni.utils.KeyboardManager
import at.hannibal2.skyhanni.utils.KeyboardManager.isKeyClicked
import at.hannibal2.skyhanni.utils.OSUtils
import at.hannibal2.skyhanni.utils.StringUtils.insert
import kotlinx.coroutines.runBlocking
import net.minecraft.client.settings.KeyBinding
import org.lwjgl.input.Keyboard
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable

class TextInput {

var textBox: String = ""
private var carriage: Int? = null

fun editText() = textBox.let {
with(carriage) {
if (this == null) it
else it.insert(this, '|')
}
}.replace("§", "&&")

fun finalText() = textBox.replace("&&", "§")

fun makeActive() = Companion.activate(this)
fun disable() = Companion.disable()
fun handle() = Companion.handleTextInput()
fun clear() {
textBox = ""
carriage = null
}

companion object {
private var activeInstance: TextInput? = null

fun activate(instance: TextInput) {
activeInstance = instance
timeSinceKeyEvent = Keyboard.getEventNanoseconds()
}

fun disable() {
activeInstance = null
}

fun onMinecraftInput(keyBinding: KeyBinding, cir: CallbackInfoReturnable<Boolean>) {
if (activeInstance != null) {
cir.returnValue = false
return
}
}

private var timeSinceKeyEvent = 0L

private var carriage
get() = activeInstance?.carriage
set(value) {
activeInstance?.carriage = value
}

private var textBox
get() = activeInstance?.textBox ?: ""
set(value) {
activeInstance?.textBox = value
}

private fun handleTextInput() {
if (KeyboardManager.isCopyingKeysDown()) {
OSUtils.copyToClipboard(textBox)
return
}
if (KeyboardManager.isPastingKeysDown()) {
runBlocking {
textBox = OSUtils.readFromClipboard() ?: return@runBlocking
}
return
}
val tcarriage = carriage

if (Keyboard.KEY_LEFT.isKeyClicked()) {
carriage = tcarriage?.moveCarriageLeft() ?: (textBox.length - 1)
return
}
if (Keyboard.KEY_RIGHT.isKeyClicked()) {
carriage = when {
tcarriage == null -> null
(tcarriage >= textBox.length - 1) -> null
else -> moveCarriageRight(tcarriage)
}
return
}
if (Keyboard.KEY_DELETE.isKeyClicked()) { // Does not work for some reason
if (tcarriage != null) {
textBox.removeRange(tcarriage, tcarriage + 1)
} else {
textBox.dropLast(1)
}
return
}

if (timeSinceKeyEvent == Keyboard.getEventNanoseconds()) return
timeSinceKeyEvent = Keyboard.getEventNanoseconds()
val char = Keyboard.getEventCharacter()
textBox = when (char) {
Char(0) -> return
'\b' -> if (tcarriage != null) {
if (tcarriage == 0) {
textBox.substring(1)
} else {
carriage = tcarriage.minus(1)
textBox.removeRange(tcarriage - 1, tcarriage)
}
} else {
textBox.dropLast(1)
}

else -> if (tcarriage != null) {
carriage = tcarriage + 1
textBox.insert(tcarriage, char)
} else {
textBox + char
}
}
}

private fun moveCarriageRight(tcarriage: Int) = tcarriage + 1

private fun Int.moveCarriageLeft(): Int = when {
this > 0 -> this - 1
else -> 0
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.hannibal2.skyhanni.mixins.transformers;

import at.hannibal2.skyhanni.data.model.TextInput;
import at.hannibal2.skyhanni.features.garden.farming.GardenCustomKeybinds;
import at.hannibal2.skyhanni.test.GraphEditor;
import net.minecraft.client.settings.KeyBinding;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -18,5 +20,13 @@ private static void noOnTick(int keyCode, CallbackInfo ci) {
@Inject(method = "isKeyDown", at = @At("HEAD"), cancellable = true)
public void noIsKeyDown(CallbackInfoReturnable<Boolean> cir) {
GardenCustomKeybinds.isKeyDown((KeyBinding) (Object) this, cir);
TextInput.Companion.onMinecraftInput((KeyBinding) (Object) this, cir);
GraphEditor.INSTANCE.onMinecraftInput((KeyBinding) (Object) this, cir);
}

@Inject(method = "isPressed", at = @At("HEAD"), cancellable = true)
public void noIsPressed(CallbackInfoReturnable<Boolean> cir) {
TextInput.Companion.onMinecraftInput((KeyBinding) (Object) this, cir);
GraphEditor.INSTANCE.onMinecraftInput((KeyBinding) (Object) this, cir);
}
}
Loading
Loading