Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jun 26, 2024
1 parent 3f088fb commit b092c53
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 39 deletions.
20 changes: 0 additions & 20 deletions src/main/kotlin/org/polyfrost/crosshair/PolyCrosshair.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ package org.polyfrost.crosshair
import cc.polyfrost.oneconfig.config.core.ConfigUtils
import cc.polyfrost.oneconfig.events.EventManager
import cc.polyfrost.oneconfig.events.event.ShutdownEvent
import cc.polyfrost.oneconfig.events.event.Stage
import cc.polyfrost.oneconfig.events.event.TickEvent
import cc.polyfrost.oneconfig.libs.eventbus.Subscribe
import cc.polyfrost.oneconfig.libs.universal.UResolution
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.common.event.FMLInitializationEvent
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent
import org.polyfrost.crosshair.config.Drawer.loadImage
import org.polyfrost.crosshair.config.ModConfig
import org.polyfrost.crosshair.render.CrosshairRenderer
import org.polyfrost.crosshair.utils.toBufferedImage
import java.io.File

@Mod(
Expand All @@ -32,8 +27,6 @@ object PolyCrosshair {

val dir = File(path)

private var lastGuiScale = 1f

@Mod.EventHandler
fun onFMLInitialization(event: FMLInitializationEvent) {
clearCaches()
Expand All @@ -48,19 +41,6 @@ object PolyCrosshair {
CrosshairRenderer.updateVanilla()
}

@Subscribe
fun onTick(event: TickEvent) {
if (event.stage != Stage.END) return
if (UResolution.scaleFactor.toFloat() != lastGuiScale) {
lastGuiScale = UResolution.scaleFactor.toFloat()
toBufferedImage(ModConfig.newCurrentCrosshair.img)?.let { it ->
loadImage(it, false, ModConfig.newCurrentCrosshair)?.let {
CrosshairRenderer.updateTexture(it)
}
}
}
}

@Subscribe
fun onShutDown(e: ShutdownEvent) {
clearCaches()
Expand Down
5 changes: 0 additions & 5 deletions src/main/kotlin/org/polyfrost/crosshair/config/Drawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import cc.polyfrost.oneconfig.libs.universal.UKeyboard
import cc.polyfrost.oneconfig.renderer.scissor.ScissorHelper
import cc.polyfrost.oneconfig.utils.IOUtils
import cc.polyfrost.oneconfig.utils.InputHandler
import cc.polyfrost.oneconfig.utils.Notifications
import cc.polyfrost.oneconfig.utils.color.ColorPalette
import cc.polyfrost.oneconfig.utils.dsl.mc
import cc.polyfrost.oneconfig.utils.dsl.nanoVGHelper
import cc.polyfrost.oneconfig.utils.dsl.runAsync
import org.polyfrost.crosshair.PolyCrosshair
import org.polyfrost.crosshair.elements.ColorSelector
import org.polyfrost.crosshair.elements.PresetElement
import org.polyfrost.crosshair.render.CrosshairRenderer
Expand All @@ -32,9 +30,6 @@ import java.io.File
import javax.imageio.ImageIO
import kotlin.math.ceil


private fun notify(message: String) = Notifications.INSTANCE.send(PolyCrosshair.NAME, message)

object Drawer : BasicOption(null, null, "", "", "", "", 2) {

val pixels: Array<Pixel> = Array(1024) { Pixel(it) }
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/org/polyfrost/crosshair/config/ModConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import cc.polyfrost.oneconfig.config.annotations.*
import cc.polyfrost.oneconfig.config.core.*
import cc.polyfrost.oneconfig.config.data.*
import cc.polyfrost.oneconfig.config.elements.*
import cc.polyfrost.oneconfig.utils.Notifications
import club.sk1er.patcher.config.OldPatcherConfig
import org.polyfrost.crosshair.PolyCrosshair
import org.polyfrost.crosshair.utils.*
Expand Down Expand Up @@ -101,10 +100,9 @@ object ModConfig : Config(Mod(PolyCrosshair.NAME, ModType.HUD, "/${PolyCrosshair
renderConfig.didPatcherMigration = true
save()
if (didAnything) {
Notifications.INSTANCE.send("PolyCrosshair", "Migrated Patcher settings replaced by PolyCrosshair. Please check PolyCrosshair's settings to make sure they are correct.")
notify("Migrated Patcher settings replaced by PolyCrosshair. Please check PolyCrosshair's settings to make sure they are correct.")
}
} catch (_: ClassNotFoundException) {

}
}
}
Expand Down
12 changes: 1 addition & 11 deletions src/main/kotlin/org/polyfrost/crosshair/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import java.awt.Image
import java.awt.image.BufferedImage
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.util.*
import javax.imageio.ImageIO

private fun notify(message: String) = Notifications.INSTANCE.send(PolyCrosshair.NAME, message)
fun notify(message: String) = Notifications.INSTANCE.send(PolyCrosshair.NAME, message)

fun posToIndex(x: Int, y: Int): Int =
x + y * 32
Expand All @@ -30,15 +29,6 @@ fun export(image: BufferedImage?, name: String): String {
return path
}

@Throws(IOException::class)
fun resizeImage(originalImage: BufferedImage, targetWidth: Int, targetHeight: Int): BufferedImage {
val resizedImage = BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB)
val graphics2D = resizedImage.createGraphics()
graphics2D.drawImage(originalImage, 0, 0, targetWidth, targetHeight, null)
graphics2D.dispose()
return resizedImage
}

fun save(image: OneImage?) {
image ?: return
val base64 = toBase64(image.image)
Expand Down

0 comments on commit b092c53

Please sign in to comment.