From f361ac27e00ad3d0b9a854fd8e10643eda2cb116 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 13 Aug 2020 14:59:27 -0400 Subject: [PATCH] Optional custom displayed gamemode --- core/src/mindustry/game/Rules.java | 2 ++ core/src/mindustry/logic/LExecutor.java | 18 ------------------ core/src/mindustry/logic/LStatements.java | 2 +- core/src/mindustry/net/Host.java | 5 ++++- core/src/mindustry/net/NetworkIO.java | 10 +++++++--- core/src/mindustry/ui/dialogs/JoinDialog.java | 2 +- desktop/src/mindustry/desktop/steam/SNet.java | 3 ++- 7 files changed, 17 insertions(+), 25 deletions(-) diff --git a/core/src/mindustry/game/Rules.java b/core/src/mindustry/game/Rules.java index 83b0c67e6a..d3502845fc 100644 --- a/core/src/mindustry/game/Rules.java +++ b/core/src/mindustry/game/Rules.java @@ -92,6 +92,8 @@ public class Rules{ public Team defaultTeam = Team.sharded; /** team of the enemy in waves/sectors */ public Team waveTeam = Team.crux; + /** name of the custom mode that this ruleset describes, or null. */ + public @Nullable String modeName; /** special tags for additional info */ public StringMap tags = new StringMap(); diff --git a/core/src/mindustry/logic/LExecutor.java b/core/src/mindustry/logic/LExecutor.java index 1115904aea..dab3acb8ec 100644 --- a/core/src/mindustry/logic/LExecutor.java +++ b/core/src/mindustry/logic/LExecutor.java @@ -562,23 +562,5 @@ public class LExecutor{ } } - public static class GetBuildI implements LInstruction{ - public int dest; - public int x, y; - - public GetBuildI(int dest, int x, int y){ - this.dest = dest; - this.x = x; - this.y = y; - } - - GetBuildI(){} - - @Override - public void run(LExecutor exec){ - exec.setobj(dest, Vars.world.build(exec.numi(x), exec.numi(y))); - } - } - //endregion } diff --git a/core/src/mindustry/logic/LStatements.java b/core/src/mindustry/logic/LStatements.java index 42636cb505..d48fa42e6d 100644 --- a/core/src/mindustry/logic/LStatements.java +++ b/core/src/mindustry/logic/LStatements.java @@ -56,7 +56,7 @@ public class LStatements{ } } - @RegisterStatement("read") + @RegisterStatement("getlink") public static class GetLinkStatement extends LStatement{ public String output = "result", address = "0"; diff --git a/core/src/mindustry/net/Host.java b/core/src/mindustry/net/Host.java index c2319bc2b7..cc52f30b86 100644 --- a/core/src/mindustry/net/Host.java +++ b/core/src/mindustry/net/Host.java @@ -1,5 +1,6 @@ package mindustry.net; +import arc.util.ArcAnnotate.*; import mindustry.*; import mindustry.game.*; @@ -12,9 +13,10 @@ public class Host{ public final int version; public final String versionType; public final Gamemode mode; + public final @Nullable String modeName; public int ping, port = Vars.port; - public Host(String name, String address, String mapname, int wave, int players, int version, String versionType, Gamemode mode, int playerLimit, String description){ + public Host(String name, String address, String mapname, int wave, int players, int version, String versionType, Gamemode mode, int playerLimit, String description, String modeName){ this.name = name; this.address = address; this.players = players; @@ -25,5 +27,6 @@ public class Host{ this.playerLimit = playerLimit; this.mode = mode; this.description = description; + this.modeName = modeName; } } diff --git a/core/src/mindustry/net/NetworkIO.java b/core/src/mindustry/net/NetworkIO.java index f4b4d3a61f..7df5cd46bb 100644 --- a/core/src/mindustry/net/NetworkIO.java +++ b/core/src/mindustry/net/NetworkIO.java @@ -68,10 +68,10 @@ public class NetworkIO{ String description = headless && !Config.desc.string().equals("off") ? Config.desc.string() : ""; String map = state.map.name(); - ByteBuffer buffer = ByteBuffer.allocate(512); + ByteBuffer buffer = ByteBuffer.allocate(500); writeString(buffer, name, 100); - writeString(buffer, map); + writeString(buffer, map, 64); buffer.putInt(Core.settings.getInt("totalPlayers", Groups.player.size())); buffer.putInt(state.wave); @@ -82,6 +82,9 @@ public class NetworkIO{ buffer.putInt(netServer.admins.getPlayerLimit()); writeString(buffer, description, 100); + if(state.rules.modeName != null){ + writeString(buffer, state.rules.modeName, 50); + } return buffer; } @@ -95,8 +98,9 @@ public class NetworkIO{ Gamemode gamemode = Gamemode.all[buffer.get()]; int limit = buffer.getInt(); String description = readString(buffer); + String modeName = readString(buffer); - return new Host(host, hostAddress, map, wave, players, version, vertype, gamemode, limit, description); + return new Host(host, hostAddress, map, wave, players, version, vertype, gamemode, limit, description, modeName.isEmpty() ? null : modeName); } private static void writeString(ByteBuffer buffer, String string, int maxlen){ diff --git a/core/src/mindustry/ui/dialogs/JoinDialog.java b/core/src/mindustry/ui/dialogs/JoinDialog.java index e61caffffb..02fd664c91 100644 --- a/core/src/mindustry/ui/dialogs/JoinDialog.java +++ b/core/src/mindustry/ui/dialogs/JoinDialog.java @@ -230,7 +230,7 @@ public class JoinDialog extends BaseDialog{ } t.add("[lightgray]" + (Core.bundle.format("players" + (host.players == 1 && host.playerLimit <= 0 ? ".single" : ""), (host.players == 0 ? "[lightgray]" : "[accent]") + host.players + (host.playerLimit > 0 ? "[lightgray]/[accent]" + host.playerLimit : "")+ "[lightgray]"))).left(); t.row(); - t.add("[lightgray]" + Core.bundle.format("save.map", host.mapname) + "[lightgray] / " + host.mode.toString()).width(targetWidth() - 10f).left().get().setEllipsis(true); + t.add("[lightgray]" + Core.bundle.format("save.map", host.mapname) + "[lightgray] / " + (host.modeName == null ? host.mode.toString() : host.modeName)).width(targetWidth() - 10f).left().get().setEllipsis(true); }).expand().left().bottom().padLeft(12f).padBottom(8); } diff --git a/desktop/src/mindustry/desktop/steam/SNet.java b/desktop/src/mindustry/desktop/steam/SNet.java index ab12f0718e..2a038171f7 100644 --- a/desktop/src/mindustry/desktop/steam/SNet.java +++ b/desktop/src/mindustry/desktop/steam/SNet.java @@ -314,7 +314,8 @@ public class SNet implements SteamNetworkingCallback, SteamMatchmakingCallback, smat.getLobbyData(lobby, "versionType"), Gamemode.valueOf(smat.getLobbyData(lobby, "gamemode")), smat.getLobbyMemberLimit(lobby), - "" + "", + null ); hosts.add(out); }catch(Exception e){