Skip to content

Commit

Permalink
World's most hacky gamejointext command implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Oct 20, 2023
1 parent 00a10e8 commit a854598
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 11 additions & 2 deletions core/src/mindustry/client/ClientLogic.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ class ClientLogic {
}
// Game join text after hh
if (settings.getString("gamejointext")?.isNotBlank() == true) {
Call.sendChatMessage(settings.getString("gamejointext"))
val input = settings.getString("gamejointext").split("(?<!\\\\);".toRegex()) // Hacky way to allow escaping the split
val out = StringBuilder()
Log.debug("The split input: $input")
input.forEach { // Try running each bit as a command, this code is terribly inefficient but should get the job done so I don't care
val clean = if (!it.endsWith("\\\\;")) it.removeSuffix(";") else it // FINISHME: Remove the \ before the ; if needed
Log.debug("Input part: '$it' ('$clean')")
val res = ChatFragment.handleClientCommand(clean, false)
if (res.type == CommandHandler.ResponseType.noCommand) out.append(clean) // If the command doesn't exist we pass the text through to the output, otherwise we don't pass it to the output. this is kind of hacky but i don't care.
}
Log.debug("Sent message: $out")
Call.sendChatMessage(out.toString())
}
}
}
Expand Down Expand Up @@ -125,7 +135,6 @@ class ClientLogic {
UnitType.hitboxAlpha = settings.getInt("hitboxopacity") / 100f

Autocomplete.autocompleters.add(BlockEmotes(), PlayerCompletion(), CommandCompletion())

Autocomplete.initialize()

Navigation.navigator.init()
Expand Down
6 changes: 5 additions & 1 deletion core/src/mindustry/ui/fragments/ChatFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,16 @@ private void sendMessage(){
}

public static CommandHandler.CommandResponse handleClientCommand(String message){
return handleClientCommand(message, true);
}

public static CommandHandler.CommandResponse handleClientCommand(String message, boolean send){
//check if it's a command
CommandHandler.CommandResponse response = ClientVars.clientCommandHandler.handleMessage(message, player);
if(response.type == CommandHandler.ResponseType.noCommand){ //no command to handle
String msg = Main.INSTANCE.sign(message);
Events.fire(new ClientChatEvent(message));
Call.sendChatMessage(msg);
if (send) Call.sendChatMessage(msg);
if (message.startsWith(netServer.clientCommands.getPrefix() + "sync")) { // /sync
ClientVars.syncing = true;
}
Expand Down

0 comments on commit a854598

Please sign in to comment.