diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 150d920..fd24bbb 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -46,5 +46,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/minchat-client/build.gradle.kts b/minchat-client/build.gradle.kts
index 06806cf..d2cee92 100644
--- a/minchat-client/build.gradle.kts
+++ b/minchat-client/build.gradle.kts
@@ -1,4 +1,5 @@
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.OutputStream
import java.security.MessageDigest
import java.util.*
@@ -12,6 +13,13 @@ val jarName = "minchat-client"
val mindustryVersion: String by rootProject
val ktorVersion: String by rootProject
+val spritesFolder = File("$projectDir/assets/sprites")
+val generatedCodeFolder = File("$buildDir/generated/")
+
+sourceSets.main {
+ kotlin.srcDir(generatedCodeFolder)
+}
+
dependencies {
implementation(project(":minchat-common"))
implementation(project(":minchat-rest"))
@@ -198,10 +206,59 @@ task("release") {
}
}
+val generateResources by tasks.registering {
+ val outputFile = generatedCodeFolder.resolve("R.kt")
+
+ inputs.dir(spritesFolder)
+ outputs.file(outputFile)
+
+ doLast {
+ val sprites = spritesFolder.walkTopDown()
+ .filter { it.isFile }
+ .filter { it.extension == "png" }
+ .map { it.nameWithoutExtension }
+ .map { name ->
+ // Trasnform kebab-case and snake_case into camelCase
+ buildString {
+ var isCapital = false
+ name.forEach {
+ if (it == '-' || it == '_' || it == ' ') {
+ isCapital = true
+ } else {
+ append(if (isCapital) it.uppercase() else it.lowercase())
+ isCapital = false
+ }
+ }
+ } to "minchat-$name"
+ }
+
+ val result = """
+ |package io.minchat.client
+ |
+ |import arc.Core
+ |import arc.scene.style.TextureRegionDrawable
+ |
+ |object R {
+ | ${sprites.joinToString("\n|\t") {
+ "val ${it.first} by lazy { Core.atlas.find(\"${it.second}\", \"error\").let(::TextureRegionDrawable) }"
+ }}
+ |}
+ """.trimMargin()
+
+ outputFile.writeText(result)
+ }
+}
+
+tasks.withType {
+ dependsOn(generateResources)
+}
+
tasks.jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
archiveFileName.set("${jarName}.jar")
+ dependsOn(generateResources)
+
from(rootDir) {
include("mod.hjson")
include("icon.png")
diff --git a/minchat-client/src/main/kotlin/io/minchat/client/Minchat.kt b/minchat-client/src/main/kotlin/io/minchat/client/Minchat.kt
index 49f8dc6..e7140ea 100644
--- a/minchat-client/src/main/kotlin/io/minchat/client/Minchat.kt
+++ b/minchat-client/src/main/kotlin/io/minchat/client/Minchat.kt
@@ -1,5 +1,6 @@
package io.minchat.client
+import arc.Core
import arc.Events
import arc.scene.ui.Label
import com.github.mnemotechnician.mkui.delegates.setting
@@ -10,6 +11,7 @@ import com.github.mnemotechnician.mkui.extensions.runUi
import io.minchat.client.config.*
import io.minchat.client.misc.*
import io.minchat.client.plugin.MinchatPluginHandler
+import io.minchat.client.ui.*
import io.minchat.client.ui.chat.ChatFragment
import io.minchat.client.ui.managers.GuiChatButtonManager
import io.minchat.common.MINCHAT_VERSION
@@ -23,6 +25,7 @@ import mindustry.mod.Mod
import mindustry.ui.Styles
import java.time.ZoneId
import java.time.format.DateTimeFormatter
+import io.minchat.client.R
private var minchatInstance: MinchatMod? = null
/** The only instance of this mod. */
@@ -94,7 +97,7 @@ class MinchatMod : Mod(), CoroutineScope {
}
Events.on(EventType.ClientLoadEvent::class.java) {
- Vars.ui.menufrag.addButton("MinChat", Icon.terminal) {
+ Vars.ui.menufrag.addButton("MinChat", R.chat) {
showChatDialog()
}
@@ -131,7 +134,7 @@ class MinchatMod : Mod(), CoroutineScope {
}.marginBottom(60f).row()
check("don't show again") {
- dontShowInfoAgain = true
+ dontShowInfoAgain = it
}.row()
}.show()
}