forked from SteamWar/SteamWar
Add configurable particle slot model
Introduce parameters, particle types, designs and entries that build the existing particle elements, store each of the 7 particle slots in its own UserConfig key, and let LobbyPlayer select a slot next to the old enum particles. Slots 4-5 need a team, 6-7 the server team.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.lobby.particle.slot;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import de.steamwar.lobby.LobbySystem;
|
||||
import de.steamwar.lobby.particle.ParticleRequirement;
|
||||
import de.steamwar.sql.UserConfig;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
@UtilityClass
|
||||
public class ParticleSlots {
|
||||
|
||||
public final int COUNT = 7;
|
||||
private final String KEY_PREFIX = "lobby-particle-slot-";
|
||||
|
||||
// Slots 1-3 for everyone, 4-5 for team members, 6-7 for the server team
|
||||
public ParticleRequirement requirement(int index) {
|
||||
if (index < 3) return ParticleRequirement.NO_REQUIRMENT;
|
||||
if (index < 5) return ParticleRequirement.TEAM_MEMBER;
|
||||
return ParticleRequirement.SERVER_TEAM;
|
||||
}
|
||||
|
||||
public String defaultName(int index) {
|
||||
return "Slot " + (index + 1);
|
||||
}
|
||||
|
||||
public ParticleSlot load(int userId, int index) {
|
||||
String saved = UserConfig.getConfig(userId, key(index));
|
||||
if (saved == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return ParticleSlot.fromJson(JsonParser.parseString(saved).getAsJsonObject(), defaultName(index));
|
||||
} catch (RuntimeException e) {
|
||||
LobbySystem.getInstance().getLogger().log(Level.WARNING, "Could not load particle slot " + (index + 1) + " of user " + userId, e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void save(int userId, int index, ParticleSlot slot) {
|
||||
if (slot == null) {
|
||||
UserConfig.removePlayerConfig(userId, key(index));
|
||||
} else {
|
||||
UserConfig.updatePlayerConfig(userId, key(index), slot.toJson().toString());
|
||||
}
|
||||
}
|
||||
|
||||
private String key(int index) {
|
||||
if (index < 0 || index >= COUNT) {
|
||||
throw new IllegalArgumentException("Invalid particle slot " + index);
|
||||
}
|
||||
return KEY_PREFIX + (index + 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user