Skip to content

Commit

Permalink
Cleanup [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Oct 28, 2024
1 parent d9b8304 commit fc2f52f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 40 deletions.
2 changes: 1 addition & 1 deletion core/src/mindustry/client/ClientLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class ClientLogic {
Events.on(GameOverEventClient::class.java) {
if (net.client()) {
// Afk players will start mining at the end of a game (kind of annoying but worth it)
if ((Navigation.currentlyFollowing as? BuildPath)?.mineItems == null && !CustomMode.tower_defense()) Navigation.follow(MinePath(args = "copper lead beryllium graphite", newGame = true))
if ((Navigation.currentlyFollowing as? BuildPath)?.mineItems == null && !CustomMode.defense()) Navigation.follow(MinePath(args = "copper lead beryllium graphite", newGame = true))

// Save maps on game over if the setting is enabled
if (settings.getBool("savemaponend")) control.saves.addSave(state.map.name())
Expand Down
73 changes: 34 additions & 39 deletions core/src/mindustry/client/utils/ServerUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@
package mindustry.client.utils

import arc.*
import arc.graphics.*
import arc.struct.*
import arc.util.*
import mindustry.Vars.*
import mindustry.client.*
import mindustry.client.ui.*
import mindustry.client.utils.*
import mindustry.client.utils.CustomMode.*
import mindustry.client.utils.Server.*
import mindustry.content.*
import mindustry.content.Blocks.*
import mindustry.content.UnitTypes.*
import mindustry.entities.*
import mindustry.entities.abilities.*
import mindustry.entities.bullet.*
import mindustry.game.EventType.*
import mindustry.gen.*
import mindustry.graphics.*
import mindustry.mod.*
import mindustry.net.Packets.*
import mindustry.ui.fragments.ChatFragment.*
import mindustry.world.blocks.defense.turrets.*
import java.lang.reflect.*
import kotlin.properties.*

Expand All @@ -45,8 +39,6 @@ enum class Server( // FINISHME: This is horrible. Why have I done this?
else super.run(*args)
}
}, votekickString = "Type[orange] /vote <y/n>[] to vote.") {
val tdAgree: Cmd = Cmd("/agree", 0)
val tdString: String = "Type [green]/agree[] to vote!"
override fun handleBan(p: Player) {
ui.showTextInput("@client.banreason.title", "@client.banreason.body", "Griefing.") { reason ->
val id = p.trace?.uuid ?: p.serverID
Expand All @@ -62,8 +54,9 @@ enum class Server( // FINISHME: This is horrible. Why have I done this?
override fun adminui() = player.admin || ClientVars.rank >= 5
override fun handleVoteButtons(msg: ChatMessage) {
super.handleVoteButtons(msg)
if (msg.sender == null && CustomMode.tower_defense() && tdString in msg.message) {
msg.addButton(tdAgree.str, tdAgree::invoke)
if (msg.sender == null && defense() && "Type [green]/agree[] to vote!" in msg.message) { // td upgrade voting
val agree = Cmd("/agree", 0)
msg.addButton(agree.str, agree::invoke)
}
}
},
Expand Down Expand Up @@ -137,7 +130,7 @@ enum class Server( // FINISHME: This is horrible. Why have I done this?
init {
Events.on(MenuReturnEvent::class.java) {
current = other
Log.debug("Returning to menu, server override cleared")
Log.debug("Returning to menu, server, mode override cleared")
}
}

Expand Down Expand Up @@ -181,43 +174,46 @@ enum class Server( // FINISHME: This is horrible. Why have I done this?
open fun blockEffect(fx: Effect, rot: Float): Boolean = false
}

enum class CustomMode {
enum class CustomMode(
val modeName: String? = null // Override the name of the mode
) {
none,
flood {
val ioFloodCompatRepo = "mindustry-antigrief/FloodCompat"

override fun enable() {
super.enable()
if (Server.io() && net.client()) {
val floodcompatMod: Mods.LoadedMod? = mods.list().find { it.getRepo()?.lowercase() == ioFloodCompatRepo.lowercase() }
flood.name
if (io() && net.client()) { // FINISHME: Load the mod at runtime
val floodcompatMod: Mods.LoadedMod? = mods.list().find { it.repo?.lowercase() == ioFloodCompatRepo.lowercase() }
Timer.schedule({
if (floodcompatMod === null) {
ui.chatfrag.addMsg(
"[accent]Floodcompat mod [scarlet]not[] found! Installing the [white]${ioFloodCompatRepo}[] mod is recommended for a better game experience." +
"\n[green]INSTALL")
.addButton("INSTALL") {
Toast(3f).add("Downloading mod")
ui.mods.githubImportMod(ioFloodCompatRepo, false, null, "") {
Toast(3f).add("Downloaded!")
val mod: Mods.LoadedMod = mods.list().find { it.getRepo()?.lowercase() == ioFloodCompatRepo.lowercase() } ?: return@githubImportMod
mods.setEnabled(mod, true)
ui.chatfrag.addMsg("[accent]Mod downloaded! Restart game to apply mod.\n[red]RESTART").addButton("RESTART") { restartGame() };
if (floodcompatMod === null) {
ui.chatfrag.addMsg(
"[accent]Floodcompat mod [scarlet]not[] found! Installing the [white]${ioFloodCompatRepo}[] mod is recommended for a better game experience." +
"\n[green]INSTALL")
.addButton("INSTALL") {
Toast(3f).add("Downloading mod")
ui.mods.githubImportMod(ioFloodCompatRepo, false, null, "") {
Toast(3f).add("Downloaded!")
val mod: Mods.LoadedMod = mods.list().find { it.repo?.lowercase() == ioFloodCompatRepo.lowercase() } ?: return@githubImportMod
mods.setEnabled(mod, true)
ui.chatfrag.addMsg("[accent]Mod downloaded! Restart game to apply mod.\n[red]RESTART").addButton("RESTART") { restartGame() };
}
}
} else if (!floodcompatMod.enabled()){
ui.chatfrag.addMsg(
"[accent]Floodcompat mod [scarlet]disabled[]! Enabling it is recommended for a better game experience." +
"\n[green]ENABLE (requires restart)")
.addButton("ENABLE (requires restart)") {
mods.setEnabled(floodcompatMod, true)
restartGame()
}
}
} else if (!floodcompatMod.enabled()){
ui.chatfrag.addMsg(
"[accent]Floodcompat mod [scarlet]disabled[]! Enabling it is recommended for a better game experience." +
"\n[green]ENABLE (requires restart)")
.addButton("ENABLE (requires restart)") {
mods.setEnabled(floodcompatMod, true)
restartGame()
}
}
}, 2f)
}
}
},
tower_defense;
defense(modeName = "tower defense");

companion object {
@JvmStatic var current by Delegates.observable(none) { _, oldValue, newValue ->
Expand All @@ -230,11 +226,10 @@ enum class CustomMode {
init {
Events.on(WorldLoadEvent::class.java) {
val modeName = if (!net.client() || ui.join.lastHost?.modeName?.isBlank() != false) state.rules.modeName?.lowercase() else ui.join.lastHost.modeName.lowercase()
current = entries.find { it.name == modeName?.replace(" ", "_") } ?: none
current = entries.find { (it.modeName ?: it.name) == modeName } ?: none // If modeName (or just the enum name if modeName is unspecified) matches, setup this mode
}

Events.on(MenuReturnEvent::class.java) {
Log.debug("Returning to menu")
current = none
}
}
Expand Down

0 comments on commit fc2f52f

Please sign in to comment.