From 12f8e8fb16a2f0f400d7a958772ca933f68684c0 Mon Sep 17 00:00:00 2001 From: Thunderblade73 Date: Thu, 18 Jan 2024 19:44:19 +0100 Subject: [PATCH] added gui --- .../config/features/dev/DebugConfig.java | 4 ++ .../test/command/TrackSoundsCommand.kt | 42 ++++++++++++++----- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java index 7aba8033b178..492f509feb07 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DebugConfig.java @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni.config.features.dev; +import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean; import io.github.moulberry.moulconfig.annotations.ConfigEditorKeybind; @@ -96,4 +97,7 @@ public class DebugConfig { @ConfigOption(name = "Bypass Advanced Tab List", desc = "The Advaced Player Tab list is disabled whie pressing this hotkey.") @ConfigEditorKeybind(defaultKey = Keyboard.KEY_NONE) public int bypassAdvancedPlayerTabList = Keyboard.KEY_NONE; + + @Expose + public Position trackSoundLog = new Position(0, 0); } diff --git a/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt b/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt index bd9539b097e4..758a66603edf 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/command/TrackSoundsCommand.kt @@ -1,46 +1,68 @@ package at.hannibal2.skyhanni.test.command - +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.PlaySoundEvent import at.hannibal2.skyhanni.utils.DelayedRun import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.OSUtils +import at.hannibal2.skyhanni.utils.RenderUtils.renderRenderables import at.hannibal2.skyhanni.utils.SimpleTimeMark +import at.hannibal2.skyhanni.utils.renderables.Renderable import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import java.util.concurrent.atomic.AtomicBoolean +import java.util.concurrent.ConcurrentLinkedDeque +import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds object TrackSoundsCommand { - var cutOfTime: SimpleTimeMark = SimpleTimeMark.farPast() + private var cutOfTime: SimpleTimeMark = SimpleTimeMark.farPast() + private var startTime: SimpleTimeMark = SimpleTimeMark.farPast() + + private val sounds = ConcurrentLinkedDeque>() - val sounds = mutableListOf() + private var isRecording = false - var enable = AtomicBoolean(true) + private val position get() = SkyHanniMod.feature.dev.debug.trackSoundLog fun command(args: Array) { - if (!enable.get()) { + if (isRecording) { LorenzUtils.chat("Still tracking sounds, wait for the other tracking to complete before starting a new one") return } - enable.set(false) + isRecording = true sounds.clear() val duration = args.firstOrNull()?.toInt()?.seconds ?: 5.0.seconds LorenzUtils.chat("Now started tracking sounds for ${duration.inWholeSeconds} Seconds") + startTime = SimpleTimeMark.now() cutOfTime = SimpleTimeMark.future(duration) + // The function must run after cutOfTime has passed to ensure thread safety DelayedRun.runDelayed(duration + 0.1.seconds) { - val string = sounds.joinToString("\n") { it.toString() } + val string = sounds.reversed().joinToString("\n") { "Time: ${it.first.inWholeMilliseconds} ${it.second}" } val counter = sounds.size OSUtils.copyToClipboard(string) LorenzUtils.chat("$counter sounds copied into the clipboard!") - enable.set(true) + sounds.clear() + isRecording = false } } @SubscribeEvent fun onSoundEvent(event: PlaySoundEvent) { if (cutOfTime.isInPast()) return + if (event.soundName == "game.player.hurt" && event.pitch == 0f && event.volume == 0f) return // remove random useless sound + if (event.soundName == "") return // sound with empty name aren't useful event.distanceToPlayer // Need to call to initialize Lazy - sounds.add(event) + sounds.addFirst(startTime.passedSince() to event) + } + + @SubscribeEvent + fun onRender(event: GuiRenderEvent.GuiOverlayRenderEvent) { + if (cutOfTime.isInPast()) return + val list = sounds.takeWhile { startTime.passedSince() - it.first < 3.0.seconds } + .take(10).reversed().map { + Renderable.string("ยง6" + it.second.soundName + " p:" + it.second.pitch + " v:" + it.second.volume) + } + position.renderRenderables(list, posLabel = "Track sound log") } }