Compare commits
3 Commits
9b0620943d
...
46791002e4
Author | SHA1 | Date | |
---|---|---|---|
46791002e4 | |||
a09e2c389a | |||
ff7c473ecb |
@ -26,7 +26,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "fr.username404"
|
||||
version = "0.3.5"
|
||||
version = "0.3.6"
|
||||
val groupAndName = "${rootProject.group}.${rootProject.name.lowercase()}"
|
||||
|
||||
val javaVer: String = "21"
|
||||
|
@ -1,4 +1,4 @@
|
||||
architectury { common("fabric", "neoforge"); injectInjectables = false }
|
||||
architectury { common("fabric", "neoforge"); injectInjectables = true }
|
||||
dependencies {
|
||||
modImplementation("net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}")
|
||||
modImplementation("me.shedaniel.cloth:cloth-config:${rootProject.property("clothconfig_version")}") {
|
||||
|
@ -8,34 +8,30 @@ import com.typesafe.config.ConfigFactory.parseFile
|
||||
import com.typesafe.config.ConfigFactory.parseString
|
||||
import com.typesafe.config.ConfigRenderOptions
|
||||
import com.typesafe.config.ConfigValueFactory
|
||||
import dev.architectury.injectables.targets.ArchitecturyTarget
|
||||
import fr.username404.snowygui.ClickGui
|
||||
import fr.username404.snowygui.Snowy
|
||||
import fr.username404.snowygui.Snowy.Companion.MissingComponent
|
||||
import fr.username404.snowygui.gui.feature.shouldSave
|
||||
import fr.username404.snowygui.gui.feature.Category
|
||||
import fr.username404.snowygui.gui.feature.Macro
|
||||
import fr.username404.snowygui.gui.feature.shouldSave
|
||||
import io.github.config4k.extract
|
||||
import io.github.config4k.getValue
|
||||
import net.minecraft.client.Minecraft
|
||||
|
||||
import java.io.File
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlinx.coroutines.CoroutineStart
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import net.minecraft.network.chat.MutableComponent
|
||||
import net.minecraft.network.chat.contents.TranslatableContents
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.full.isSuperclassOf
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
object Configuration {
|
||||
@Deprecated("Use the getValue or setValue methods instead", level = DeprecationLevel.ERROR)
|
||||
@JvmStatic
|
||||
@ -54,7 +50,19 @@ object Configuration {
|
||||
}.toTypedArray()),
|
||||
)
|
||||
}
|
||||
private val configDirectory: String = (Minecraft.getInstance().gameDirectory.absolutePath + File.separator + "config").also { File(it).mkdir() }
|
||||
private val configDirectory: String =
|
||||
(if (ArchitecturyTarget.getCurrentTarget() == "fabric") {
|
||||
Class.forName("net.fabricmc.loader.api.FabricLoader").run {
|
||||
getMethod("getConfigDir").invoke(getMethod("getInstance").invoke(null))
|
||||
}
|
||||
} else {
|
||||
Class.forName("net.neoforged.fml.loading.FMLPaths")
|
||||
.getField("CONFIGDIR")
|
||||
.get(null)
|
||||
.let { enum ->
|
||||
enum.javaClass.getMethod("get").invoke(enum)
|
||||
}
|
||||
} as Path).absolutePathString()
|
||||
private val file: File = File(configDirectory + File.separator + "snowy.conf")
|
||||
private val obtained: Config = run {
|
||||
var result: Config = empty()
|
||||
@ -87,11 +95,7 @@ object Configuration {
|
||||
val enabledFeatures = mutableMapOf<String, Boolean>().apply {
|
||||
"enabledFeatures".let { obtained.run {
|
||||
if (hasPath(it)) {
|
||||
putAll(extract<Map<out String, Boolean>>(it).filterKeys { keyName -> ClickGui.clickBoxes.any {
|
||||
it.buttons.any { button ->
|
||||
button.info.shouldSave() && button.title == keyName
|
||||
}
|
||||
}})
|
||||
putAll(extract<Map<out String, Boolean>>(it))
|
||||
}
|
||||
} }
|
||||
}
|
||||
|
@ -17,25 +17,20 @@ sealed class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
|
||||
private fun addButtons(vararg buttons: ButtonImpl) {
|
||||
buttons.groupBy { impl ->
|
||||
ClickGui.clickBoxes.find { box ->
|
||||
with(impl) {
|
||||
box.isCategory(impl.info.parent)
|
||||
}
|
||||
}.entries.forEach { entry -> entry.run {
|
||||
key?.buttons?.clear()
|
||||
value.forEach { if (!it.isDisabled) {
|
||||
key?.buttons?.add(it.apply {
|
||||
if (info.shouldSave() && !info.parent.shouldHide) {
|
||||
Configuration.enabledFeatures[title]?.let { bool ->
|
||||
toggled = bool
|
||||
}
|
||||
}
|
||||
box.isCategory(info.parent)
|
||||
}
|
||||
}
|
||||
}.entries.forEach { entry ->
|
||||
with(entry) {
|
||||
key?.buttons?.clear()
|
||||
value.forEach {
|
||||
if (!it.isDisabled) {
|
||||
key?.buttons?.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
} }
|
||||
} }
|
||||
}
|
||||
@JvmStatic
|
||||
fun initButtons() = addButtons(
|
||||
|
@ -9,12 +9,13 @@ import net.arikia.dev.drpc.DiscordRPC as discord_rpc
|
||||
@ButtonInfo(Category.MISC)
|
||||
object DiscordRPC: ButtonImpl() {
|
||||
private val RPCHandlers: DiscordEventHandlers = DiscordEventHandlers.Builder().build()
|
||||
private val RichPresence: DiscordRichPresence.Builder = DiscordRichPresence
|
||||
private val RichPresence: Lazy<DiscordRichPresence.Builder> = lazy { DiscordRichPresence
|
||||
.Builder("Playing Minecraft ${Minecraft.getInstance().launchedVersion}")
|
||||
.setDetails("Launched with ${Minecraft.getInstance().versionType}")
|
||||
.setBigImage("icon", "SnowyGUI")
|
||||
}
|
||||
override fun execAction() {
|
||||
if (toggled) discord_rpc.discordUpdatePresence(RichPresence.build())
|
||||
if (toggled) discord_rpc.discordUpdatePresence(RichPresence.value.build())
|
||||
else discord_rpc.discordClearPresence()
|
||||
}
|
||||
init {
|
||||
|
Loading…
Reference in New Issue
Block a user