Skip to content

Commit

Permalink
Add config shockers and options
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHeart committed Feb 24, 2024
1 parent 044f0f7 commit 865b141
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 41 deletions.
123 changes: 123 additions & 0 deletions src/main/kotlin/openshock/integrations/minecraft/ConfigGuiFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package openshock.integrations.minecraft

import com.terraformersmc.modmenu.api.ConfigScreenFactory
import dev.isxander.yacl3.api.ConfigCategory
import dev.isxander.yacl3.api.ListOption
import dev.isxander.yacl3.api.Option
import dev.isxander.yacl3.api.OptionDescription
import dev.isxander.yacl3.api.OptionGroup
import dev.isxander.yacl3.api.YetAnotherConfigLib
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder
import dev.isxander.yacl3.api.controller.StringControllerBuilder
import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController
import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.Text

object ConfigGuiFactory : ConfigScreenFactory<Screen> {

override fun create(parent: Screen): Screen {
val yacl =
YetAnotherConfigLib.create(ShockCraftConfig.HANDLER) { defaults: ShockCraftConfig, config: ShockCraftConfig, builder: YetAnotherConfigLib.Builder ->
createBuilder(
defaults,
config,
builder
)
}

return yacl.generateScreen(MinecraftClient.getInstance().currentScreen)
}

fun createBuilder(
defaults: ShockCraftConfig,
config: ShockCraftConfig,
builder: YetAnotherConfigLib.Builder
): YetAnotherConfigLib.Builder {
return builder
.title(Text.literal("OpenShock"))


.category(
ConfigCategory.createBuilder()
.name(Text.literal("ShockCraft - OpenShock Config"))

// Server group
.group(OptionGroup.createBuilder()
.name(Text.literal("Server"))
.description(OptionDescription.of(Text.literal("Server / OpenShock Backend Settings")))
.option(
Option.createBuilder<String>()
.name(Text.literal("API URL"))
.description(OptionDescription.of(Text.literal("The API base URL of the OpenShock Backend. For the official instance this is https://api.openshock.org")))
.controller { option: Option<String>? -> StringControllerBuilder.create(option) }
.binding(
defaults.apiBaseUrl,
{ config.apiBaseUrl },
{ newVal: String -> config.apiBaseUrl = newVal })
.build()
)
.option(
Option.createBuilder<String>()
.name(Text.literal("API Token"))
.description(OptionDescription.of(Text.literal("API Token generated on the web, needs shocker use permission")))
.controller { option: Option<String> -> StringControllerBuilder.create(option) }
.binding(
defaults.apiToken,
{ config.apiToken },
{ newVal: String -> config.apiToken = newVal })
.build()
).build()
)

// Shocker group
.group(OptionGroup.createBuilder()
.name(Text.literal("Shocking Options"))

.option(Option.createBuilder<Int>()
.name(Text.literal("Minimum Intensity"))
.controller { option: Option<Int> ->
IntegerSliderControllerBuilder.create(option)
.range(1, 100)
.step(1).formatValue { it -> Text.literal("$it minimum") }
}
.binding(
defaults.intensityMin,
{ config.intensityMin },
{ newVal: Int -> config.intensityMin = newVal })
.build()
)


.option(Option.createBuilder<Int>()
.name(Text.literal("Maximum Intensity"))
.controller { option: Option<Int> ->
IntegerSliderControllerBuilder.create(option)
.range(1, 100)
.step(1).formatValue { it -> Text.literal("$it maximum") }
}
.binding(
defaults.intensityMax,
{ config.intensityMax },
{ newVal: Int -> config.intensityMax = newVal })
.build()
)
.build()
)

.group(ListOption.createBuilder<String>()
.name(Text.literal("Shockers"))
.controller { option: Option<String> -> StringControllerBuilder.create(option) }
.binding(
defaults.shockers,
{ config.shockers },
{ newVal: List<String> -> config.shockers = newVal })
.initial("Put your Shocker ID here")
.build()
)

.build()
)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package openshock.integrations.minecraft
import com.terraformersmc.modmenu.api.ConfigScreenFactory
import com.terraformersmc.modmenu.api.ModMenuApi

class ModMenuEntry : ModMenuApi {
class ModMenuEntryPoint : ModMenuApi {
override fun getModConfigScreenFactory(): ConfigScreenFactory<*> {
return ModMenuEntryFactory
return ConfigGuiFactory
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ class ShockCraftConfig {
@SerialEntry(comment = "API Token generated on the web")
var apiToken: String = ""

@SerialEntry(comment = "Intensity Min")
var intensityMin: Int = 0;

@SerialEntry(comment = "Intensity Max")
var intensityMax: Int = 100;


@SerialEntry(comment = "Shockers to use")
var shockers: List<String> = ArrayList()

companion object {
var HANDLER: ConfigClassHandler<ShockCraftConfig> = ConfigClassHandler.createBuilder(ShockCraftConfig::class.java)
.id(Identifier("shockcraft", "config"))
.serializer { config: ConfigClassHandler<ShockCraftConfig?>? ->
GsonConfigSerializerBuilder.create(config)
.setPath(FabricLoader.getInstance().getConfigDir().resolve("ShockCraft.json5"))
.setPath(FabricLoader.getInstance().configDir.resolve("ShockCraft.json5"))
.appendGsonBuilder(GsonBuilder::setPrettyPrinting) // not needed, pretty print by default
.setJson5(true)
.build()
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"adapter": "kotlin"
}
],
"modmenu": [ "openshock.integrations.minecraft.ModMenuEntry" ]
"modmenu": [
"openshock.integrations.minecraft.ModMenuEntryPoint"
]
},
"mixins": [
"shockcraft.mixins.json"
Expand Down

0 comments on commit 865b141

Please sign in to comment.