Skip to content

Commit

Permalink
added gui
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunderblade73 committed Jan 18, 2024
1 parent b874ab0 commit 12f8e8f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<Pair<Duration, PlaySoundEvent>>()

val sounds = mutableListOf<PlaySoundEvent>()
private var isRecording = false

var enable = AtomicBoolean(true)
private val position get() = SkyHanniMod.feature.dev.debug.trackSoundLog

fun command(args: Array<String>) {
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")
}
}

0 comments on commit 12f8e8f

Please sign in to comment.