/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
package de.steamwar.lobby.particle.gui;
import de.steamwar.lobby.LobbySystem;
import de.steamwar.lobby.particle.ParticleRequirement;
import de.steamwar.lobby.particle.UnlockContext;
import de.steamwar.lobby.particle.design.*;
import de.steamwar.lobby.particle.slot.ParticleEntry;
import de.steamwar.lobby.particle.slot.ParticleSlot;
import de.steamwar.lobby.particle.slot.ParticleSlots;
import de.steamwar.sql.SteamwarUser;
import lombok.experimental.UtilityClass;
import org.bukkit.entity.Player;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import static de.steamwar.lobby.particle.design.EntryParameters.*;
@UtilityClass
class ParticleGuiText {
String msg(String key, Player player, Object... params) {
return LobbySystem.getMessage().parse(key, player, params);
}
// Falls back to a readable form of the key for names without a translation
String name(String key, Player player) {
try {
return LobbySystem.getMessage().parse(key, player);
} catch (MissingResourceException e) {
return "§f" + prettify(key.replaceFirst("^PARTICLE_(TYPE_|DESIGN_|PARAM_)?", ""));
}
}
String prettify(String id) {
StringBuilder builder = new StringBuilder();
for (String word : id.toLowerCase(Locale.ROOT).split("_")) {
if (word.isEmpty()) continue;
if (!builder.isEmpty()) builder.append(' ');
builder.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1));
}
return builder.toString();
}
String designName(ParticleDesign design, Player player) {
return name(design.getNameKey(), player);
}
String particleName(ParticleType type, Player player) {
return name(type.getNameKey(), player);
}
String choiceName(ChoiceParameter parameter, E value, Player player) {
for (ChoiceParameter.Choice choice : parameter.getChoices()) {
if (choice.value() != value) continue;
if (value instanceof ParticleType type) return particleName(type, player);
return name("PARTICLE_CHOICE_" + parameter.getKey().toUpperCase(Locale.ROOT) + "_" + choice.id().toUpperCase(Locale.ROOT), player);
}
return String.valueOf(value);
}
String number(double value) {
return value == Math.rint(value) ? String.valueOf((long) value) : String.format(Locale.ROOT, "%.2f", value).replaceAll("0+$", "");
}
@SuppressWarnings("unchecked")
String valueText(Parameter> parameter, Object value, Player player) {
if (parameter instanceof DoubleParameter) return "§e" + number((Double) value);
if (parameter instanceof IntParameter) return "§e" + value;
if (parameter instanceof BooleanParameter) return msg((Boolean) value ? "PARTICLE_VALUE_YES" : "PARTICLE_VALUE_NO", player);
if (parameter instanceof ChoiceParameter> choice) return choiceName((ChoiceParameter