Skip to content

Commit

Permalink
фиксы
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkness committed Jun 3, 2023
1 parent 0bba6b7 commit 4ef6dd5
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 134 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
project.version = json["version"]!!

val mindustryVersion = json["minGameVersion"]
val usefulHash = "256ab37b10"
val usefulHash = "d8a976ab4e"

compileOnly("com.github.anuken.arc:arc-core:v$mindustryVersion")
compileOnly("com.github.anuken.mindustryjitpack:core:v$mindustryVersion")
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/darkdustry/DarkdustryPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void init() {
netServer.admins.addChatFilter(Filters::chat);
netServer.invalidHandler = NetHandlers::invalidResponse;

maps.setMapProvider((mode, map) -> getAvailableMaps().random(map));
maps.setMapProvider((mode, map) -> availableMaps().random(map));

Timer.schedule(() -> Groups.player.each(player -> {
var data = Cache.get(player);
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/darkdustry/PluginVars.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import darkdustry.features.votes.*;
import mindustry.core.Version;

import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import static com.google.gson.FieldNamingPolicy.*;
import static mindustry.Vars.*;

Expand Down Expand Up @@ -46,7 +43,7 @@ public class PluginVars {
public static final int maxFillArea = 512;

/** Количество элементов на одной странице списка. */
public static final int maxPerPage = 8;
public static final int maxPerPage = 6;

/** Максимальное количество записей истории на один тайл. */
public static final int maxHistoryCapacity = 6;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/darkdustry/commands/ClientCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class ClientCommands {

public static void load() {
register("help", (args, player) -> MenuHandler.showHelpMenu(player));
register("help", PageIterator::commands);

register("discord", (args, player) -> Call.openURI(player.con, discordServerUrl));

Expand All @@ -33,7 +33,7 @@ public static void load() {

register("settings", (args, player) -> MenuHandler.showSettingsMenu(player));

register("players", (args, player) -> MenuHandler.showPlayersMenu(player));
register("players", PageIterator::players);

if (!config.hubIp.isEmpty())
register("hub", (args, player) -> net.pingHost(config.hubIp, config.hubPort, host -> Call.connect(player.con, host.address, host.port), error -> Bundle.send(player, "commands.hub.failed", error.getMessage())));
Expand Down Expand Up @@ -88,7 +88,7 @@ public static void load() {
vote.vote(player, 1);
});

register("maps", (args, player) -> MenuHandler.showMapsMenu(player));
register("maps", PageIterator::maps);
}

if (config.mode.useVnw()) {
Expand Down Expand Up @@ -121,7 +121,7 @@ public static void load() {
vote.vote(player, 1);
});

register("saves", (args, player) -> MenuHandler.showSavesMenu(player));
register("saves", PageIterator::saves);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/darkdustry/features/SchemeSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
public class SchemeSize {

/** Список игроков, использующих Scheme Size и их подписи. */
public static final IntMap<String> signatures = new IntMap<>();
public static final IntMap<String> subtitles = new IntMap<>();

public static void load() {
Events.on(PlayerJoin.class, event -> Call.clientPacketReliable(event.player.con, "SendMeSubtitle", null));
Events.on(PlayerLeave.class, event -> signatures.remove(event.player.id));
Events.on(PlayerLeave.class, event -> subtitles.remove(event.player.id));

netServer.addPacketHandler("MySubtitle", (player, text) -> {
signatures.put(player.id, text);
Call.clientPacketReliable("Subtitles", JsonIO.write(signatures));
subtitles.put(player.id, text);
Call.clientPacketReliable("Subtitles", JsonIO.write(subtitles));
});

netServer.addPacketHandler("fill", (player, text) -> {
Expand Down
96 changes: 15 additions & 81 deletions src/main/java/darkdustry/features/menus/MenuHandler.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package darkdustry.features.menus;

import arc.files.Fi;
import arc.func.*;
import arc.graphics.Color;
import arc.util.CommandHandler.Command;
import arc.struct.Seq;
import darkdustry.components.Cache;
import darkdustry.utils.*;
import darkdustry.utils.Admins;
import mindustry.content.Fx;
import mindustry.gen.*;
import mindustry.graphics.Pal;
import mindustry.maps.Map;
import useful.*;
import useful.State.StateKey;
import useful.menu.Menu;
Expand All @@ -30,6 +28,12 @@ public class MenuHandler {

// region menu

public static final ListMenu
listMenu = new ListMenu();

public static final ConfirmMenu
confirmMenu = new ConfirmMenu();

public static final Menu
statsMenu = new Menu(),
promotionMenu = new Menu(),
Expand All @@ -42,21 +46,6 @@ public class MenuHandler {
languagesMenu = new Menu(),
effectsMenu = new Menu();

public static final ConfirmMenu
confirmMenu = new ConfirmMenu();

public static final SelectDisplayMenu<Command>
helpMenu = new SelectDisplayMenu<>();

public static final SelectDisplayMenu<Player>
playersMenu = new SelectDisplayMenu<>();

public static final SelectDisplayMenu<Map>
mapsMenu = new SelectDisplayMenu<>();

public static final SelectDisplayMenu<Fi>
savesMenu = new SelectDisplayMenu<>();

// endregion
// region input

Expand All @@ -67,60 +56,17 @@ public class MenuHandler {
// endregion
// region keys

public static final StateKey<Long> DURATION = new StateKey<>();
public static final StateKey<Long> DURATION = new StateKey<>("duration");

public static final StateKey<Player> TARGET = new StateKey<>();
public static final StateKey<PlayerData> DATA = new StateKey<>();
public static final StateKey<Player> TARGET = new StateKey<>("target");
public static final StateKey<PlayerData> DATA = new StateKey<>("data");

// endregion
// region transforms

public static void load() {
// region menu

helpMenu.content(Utils::getAvailableCommands)
.button(command -> "/" + command.text)
.transform(menu -> {
menu.title("command.select.title");
menu.content("command.select.content");
}).display((menu, command) -> {
menu.title("command.info.title");
menu.content("command.info.content", command.text,
Bundle.get("commands." + command.text + ".params", menu.player),
Bundle.get("commands." + command.text + ".description", menu.player)
);
});

playersMenu.content(Groups.player)
.button(Player::coloredName)
.transform(menu -> {
menu.title("player.select.title");
menu.content("player.select.content");
}).display((menu, player) -> {
menu.title("player.info.title");
menu.content("player.info.content", player.coloredName(), player.id, player.locale);
});

mapsMenu.content(Utils::getAvailableMaps)
.button(Map::name)
.transform(menu -> {
menu.title("map.select.title");
menu.content("map.select.content");
}).display((menu, map) -> {
menu.title("map.info.title");
menu.content("map.info.content", map.name(), map.width, map.height, map.author(), map.description());
});

savesMenu.content(Utils::getAvailableSaves)
.button(Fi::name)
.transform(menu -> {
menu.title("save.select.title");
menu.content("save.select.content");
}).display((menu, save) -> {
menu.title("save.info.title");
menu.content("save.info.content", save.name(), formatDateTime(save.lastModified()));
});

statsMenu.transform(TARGET, DATA, (menu, target, data) -> {
menu.title("stats.title");
menu.content("stats.content", target.coloredName(), data.rank.name(menu.player), data.rank.description(menu.player), data.blocksPlaced, data.blocksBroken, data.gamesPlayed, data.wavesSurvived, data.attackWins, data.pvpWins, data.hexedWins, formatDuration(MINUTES.toMillis(data.playTime), menu.player));
Expand Down Expand Up @@ -260,6 +206,10 @@ public static void load() {
// endregion
// region show

public static <T> void showListMenu(Player player, int page, int pages, String title, Seq<T> values, Cons3<StringBuilder, Integer, T> cons) {
listMenu.show(player, page, pages, maxPerPage, title, values, cons);
}

public static void showConfirmMenu(Player player, String content, Runnable confirmed, Object... values) {
confirmMenu.show(player, "ui.title.confirm", content, confirmed, values);
}
Expand Down Expand Up @@ -292,22 +242,6 @@ public static void showSettingsMenu(Player player) {
settingsMenu.show(player);
}

public static void showHelpMenu(Player player) {
helpMenu.show(player);
}

public static void showPlayersMenu(Player player) {
playersMenu.show(player);
}

public static void showMapsMenu(Player player) {
mapsMenu.show(player);
}

public static void showSavesMenu(Player player) {
savesMenu.show(player);
}

// endregion
// region enums

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/darkdustry/listeners/Filters.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
import arc.util.Log;
import darkdustry.components.Translator;
import darkdustry.discord.Bot;
import darkdustry.features.history.*;
import mindustry.gen.Player;
import mindustry.net.Administration.PlayerAction;

import static darkdustry.PluginVars.*;
import static darkdustry.utils.Checks.*;
import static darkdustry.utils.Utils.*;
import static mindustry.Vars.*;
import static mindustry.net.Administration.ActionType.*;

public class Filters {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/darkdustry/listeners/NetHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static String invalidResponse(Player player, CommandResponse response) {
if (response.type == fewArguments)
return Bundle.format("commands.unknown.few-arguments", player, response.command.text, response.command.paramText);

var closest = getAvailableCommands(player)
var closest = availableCommands(player)
.map(command -> command.text)
.filter(command -> Strings.levenshtein(command, response.runCommand) < 3)
.min(command -> Strings.levenshtein(command, response.runCommand));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/darkdustry/utils/Checks.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public static boolean notFound(Player player, Team team) {
}

public static boolean notFound(Player player, UnitType type) {
return check(type == null || !isAvailable(type), player, "commands.unit-not-found", Icons.contentList(content.units().select(Utils::isAvailable)));
return check(type == null || !available(type), player, "commands.unit-not-found", Icons.contentList(content.units().select(Utils::available)));
}

public static boolean notFound(Player player, Block block) {
return check(block == null || !isAvailable(block), player, "commands.block-not-found");
return check(block == null || !available(block), player, "commands.block-not-found");
}

public static boolean notFound(Player player, Item item) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/darkdustry/utils/Find.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public static Block core(String name) {
}

public static Map map(String name) {
return findInSeq(name, getAvailableMaps(), map -> deepEquals(map.name(), name));
return findInSeq(name, availableMaps(), map -> deepEquals(map.name(), name));
}

public static Fi save(String name) {
return findInSeq(name, getAvailableSaves(), save -> deepEquals(save.nameWithoutExtension(), name));
return findInSeq(name, availableSaves(), save -> deepEquals(save.nameWithoutExtension(), name));
}

public static Gamemode mode(String name) {
Expand Down
44 changes: 41 additions & 3 deletions src/main/java/darkdustry/utils/PageIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import arc.func.*;
import arc.math.Mathf;
import arc.struct.Seq;
import arc.util.Strings;
import darkdustry.discord.MessageContext;
import mindustry.gen.Groups;
import darkdustry.features.menus.MenuHandler;
import mindustry.gen.*;
import useful.Bundle;

import static arc.util.Strings.*;
import static darkdustry.PluginVars.*;
Expand All @@ -15,6 +16,43 @@
// (C) xzxADIxzx, 2023 год
public class PageIterator {

// region client

public static void commands(String[] args, Player player) {
client(args, player, "help", availableCommands(player), (builder, index, command) -> {
var params = Bundle.get("commands." + command.text + ".params", command.paramText, player);
var description = Bundle.get("commands." + command.text + ".description", command.description, player);

builder.append(Bundle.format("commands.help.command", player, command.text, params, description));
});
}

public static void players(String[] args, Player player) {
client(args, player, "players", Groups.player.copy(new Seq<>()), (builder, index, p) ->
builder.append(Bundle.format("commands.players.player", player, p.coloredName(), p.admin ? "\uE82C" : "\uE872", p.id, p.locale)));
}

public static void maps(String[] args, Player player) {
client(args, player, "maps", availableMaps(), (builder, index, map) ->
builder.append(Bundle.format("commands.maps.map", player, index, map.name(), map.author(), map.width, map.height)));
}

public static void saves(String[] args, Player player) {
client(args, player, "saves", availableSaves(), (builder, index, save) ->
builder.append(Bundle.format("commands.saves.save", player, index, save.nameWithoutExtension(), formatDateTime(save.lastModified()))));
}

private static <T> void client(String[] args, Player player, String command, Seq<T> content, Cons3<StringBuilder, Integer, T> cons) {
int page = args.length > 0 ? parseInt(args[0]) : 1, pages = Math.max(1, Mathf.ceil(content.size / (float) maxPerPage));
if (page > pages || page < 1) {
Bundle.send(player, "commands.invalid-page", pages);
return;
}

MenuHandler.showListMenu(player, page, pages, "commands." + command + ".title", content, cons);
}

// endregion
// region discord

public static void players(String[] args, MessageContext context) {
Expand All @@ -34,7 +72,7 @@ public static void maps(String[] args, MessageContext context) {
"Maps in Playlist: @",
"Page @ / @",

getAvailableMaps(),
availableMaps(),

(map, index) -> format("**@.** @", index, stripColors(map.name())),
(map) -> format("Author: @\nSize: @x@", stripColors(map.author()), map.width, map.height)
Expand Down
Loading

0 comments on commit 4ef6dd5

Please sign in to comment.