Skip to content

Commit

Permalink
[FEATURE]: #2140: Add ArenaInfoPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
sgcr committed Sep 3, 2024
1 parent a5c1d3d commit 56baf8a
Show file tree
Hide file tree
Showing 33 changed files with 1,445 additions and 414 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ plugins {
id "com.github.breadmoirai.github-release" version "2.5.2"
id "com.install4j.gradle" version "9.0.6"
id "org.barfuin.gradle.taskinfo" version "2.1.0"
id "io.freefair.lombok" version "8.10"
}
apply plugin: de.jansauer.poeditor.POEditorPlugin

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/core/db/DBUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ private void updateDBv900(int dbVersion) throws SQLException {
var playerTable = dbManager.getTable(SpielerTable.TABLENAME);
playerTable.tryAddColumn("SubForm", "FLOAT DEFAULT 0");

var arenaTable = dbManager.getTable(StadionTable.TABLENAME);
arenaTable.tryAddColumn("REBUILT_DATE", "TIMESTAMP");
arenaTable.tryAddColumn("EXPANSION_DATE", "TIMESTAMP");

updateDBVersion(dbVersion, 900);
}

Expand Down
31 changes: 18 additions & 13 deletions src/main/java/core/db/StadionTable.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package core.db;

import core.training.TrainingPerWeek;
import core.util.HODateTime;
import tool.arenasizer.Stadium;
import java.sql.Types;
import java.util.Optional;

final class StadionTable extends AbstractTable {
static final String TABLENAME = "STADION";
Expand All @@ -13,19 +16,21 @@ final class StadionTable extends AbstractTable {
@Override
protected void initColumns() {
columns = new ColumnDescriptor[]{
ColumnDescriptor.Builder.newInstance().setColumnName("HRF_ID").setGetter((p) -> ((Stadium) p).getHrfId()).setSetter((p, v) -> ((Stadium) p).setHrfId((int) v)).setType(Types.INTEGER).isNullable(false).isPrimaryKey(true).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("StadionName").setGetter((p) -> ((Stadium) p).getStadienname()).setSetter((p, v) -> ((Stadium) p).setStadienname((String) v)).setType(Types.VARCHAR).setLength(127).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AnzSteh").setGetter((p) -> ((Stadium) p).getStehplaetze()).setSetter((p, v) -> ((Stadium) p).setStehplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AnzSitz").setGetter((p) -> ((Stadium) p).getSitzplaetze()).setSetter((p, v) -> ((Stadium) p).setSitzplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AnzDach").setGetter((p) -> ((Stadium) p).getUeberdachteSitzplaetze()).setSetter((p, v) -> ((Stadium) p).setUeberdachteSitzplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AnzLogen").setGetter((p) -> ((Stadium) p).getLogen()).setSetter((p, v) -> ((Stadium) p).setLogen((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauSteh").setGetter((p) -> ((Stadium) p).getAusbauStehplaetze()).setSetter((p, v) -> ((Stadium) p).setAusbauStehplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauSitz").setGetter((p) -> ((Stadium) p).getAusbauSitzplaetze()).setSetter((p, v) -> ((Stadium) p).setAusbauSitzplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauDach").setGetter((p) -> ((Stadium) p).getAusbauUeberdachteSitzplaetze()).setSetter((p, v) -> ((Stadium) p).setAusbauUeberdachteSitzplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauLogen").setGetter((p) -> ((Stadium) p).getAusbauLogen()).setSetter((p, v) -> ((Stadium) p).setAusbauLogen((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("Ausbau").setGetter((p) -> ((Stadium) p).isAusbau()).setSetter((p, v) -> ((Stadium) p).setAusbau(0 != (int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauKosten").setGetter((p) -> ((Stadium) p).getAusbauKosten()).setSetter((p, v) -> ((Stadium) p).setAusbauKosten((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("ArenaID").setGetter((p) -> ((Stadium) p).getArenaId()).setSetter((p, v) -> ((Stadium) p).setArenaId((int) v)).setType(Types.INTEGER).isNullable(false).build()
ColumnDescriptor.Builder.newInstance().setColumnName("HRF_ID").setGetter(p -> ((Stadium) p).getHrfId()).setSetter((p, v) -> ((Stadium) p).setHrfId((int) v)).setType(Types.INTEGER).isNullable(false).isPrimaryKey(true).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("StadionName").setGetter(p -> ((Stadium) p).getStadienname()).setSetter((p, v) -> ((Stadium) p).setStadienname((String) v)).setType(Types.VARCHAR).setLength(127).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AnzSteh").setGetter(p -> ((Stadium) p).getStehplaetze()).setSetter((p, v) -> ((Stadium) p).setStehplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AnzSitz").setGetter(p -> ((Stadium) p).getSitzplaetze()).setSetter((p, v) -> ((Stadium) p).setSitzplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AnzDach").setGetter(p -> ((Stadium) p).getUeberdachteSitzplaetze()).setSetter((p, v) -> ((Stadium) p).setUeberdachteSitzplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AnzLogen").setGetter(p -> ((Stadium) p).getLogen()).setSetter((p, v) -> ((Stadium) p).setLogen((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauSteh").setGetter(p -> ((Stadium) p).getAusbauStehplaetze()).setSetter((p, v) -> ((Stadium) p).setAusbauStehplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauSitz").setGetter(p -> ((Stadium) p).getAusbauSitzplaetze()).setSetter((p, v) -> ((Stadium) p).setAusbauSitzplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauDach").setGetter(p -> ((Stadium) p).getAusbauUeberdachteSitzplaetze()).setSetter((p, v) -> ((Stadium) p).setAusbauUeberdachteSitzplaetze((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauLogen").setGetter(p -> ((Stadium) p).getAusbauLogen()).setSetter((p, v) -> ((Stadium) p).setAusbauLogen((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("Ausbau").setGetter(p -> ((Stadium) p).isAusbau()).setSetter((p, v) -> ((Stadium) p).setAusbau(0 != (int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("AusbauKosten").setGetter(p -> ((Stadium) p).getAusbauKosten()).setSetter((p, v) -> ((Stadium) p).setAusbauKosten((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("ArenaID").setGetter(p -> ((Stadium) p).getArenaId()).setSetter((p, v) -> ((Stadium) p).setArenaId((int) v)).setType(Types.INTEGER).isNullable(false).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("REBUILT_DATE").setGetter(p -> HODateTime.toDbTimestamp(((Stadium) p).getRebuiltDate())).setSetter((p, v) -> ((Stadium) p).setRebuiltDate((HODateTime) v)).setType(Types.TIMESTAMP).isNullable(true).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("EXPANSION_DATE").setGetter(p -> HODateTime.toDbTimestamp(((Stadium) p).getExpansionDate())).setSetter((p, v) -> ((Stadium) p).setExpansionDate((HODateTime) v)).setType(Types.TIMESTAMP).isNullable(true).build()
};
}

Expand Down
44 changes: 39 additions & 5 deletions src/main/java/core/file/hrf/HRFStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,26 @@
import core.model.match.MatchTeamAttitude;
import core.model.match.StyleOfPlay;
import core.model.player.IMatchRoleID;
import core.util.HODateTime;
import core.util.HOLogger;
import core.util.StringUtils;
import hattrickdata.Arena;
import hattrickdata.Capacity;
import hattrickdata.ExpandedCapacity;
import module.lineup.substitution.model.Substitution;
import module.youth.YouthPlayer;
import org.apache.commons.lang3.math.NumberUtils;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.apache.commons.lang3.StringUtils.EMPTY;

public class HRFStringBuilder {

private static final String HO_DATE_TIME_NOT_SET = EMPTY;

private StringBuilder basicsStringBuilder;
private StringBuilder clubStringBuilder;
private StringBuilder economyStringBuilder;
Expand Down Expand Up @@ -60,10 +71,11 @@ private void appendKeyValue(StringBuilder s, String key, Integer value){
private void appendKeyValue(StringBuilder s, String key, Double value){
s.append(key).append("=").append(value!=null?value:"").append("\n");
}
private void appendKeyValue(StringBuilder s, String key, boolean value){
s.append(key).append("=").append(value?"1":"0").append("\n");
}

/**
* Create the arena data.
*/
// TODO: fix the overload solution with 'Arena'
public void createArena(Map<String, String> arenaDataMap) {
arenaStringBuilder = new StringBuilder("[arena]\n");
appendKeyValue(arenaStringBuilder, "arenaname", arenaDataMap.get("ArenaName"));
Expand All @@ -79,8 +91,30 @@ public void createArena(Map<String, String> arenaDataMap) {
appendKeyValue(arenaStringBuilder, "expandingVIP", arenaDataMap.get("ExVIP"));
appendKeyValue(arenaStringBuilder, "expandingSseatTotal", arenaDataMap.get("ExTotal"));
appendKeyValue(arenaStringBuilder, "isExpanding", arenaDataMap.get("isExpanding"));
// Achtung bei keiner Erweiterung = 0!
appendKeyValue(arenaStringBuilder, "ExpansionDate", arenaDataMap.get("ExpansionDate"));
appendKeyValue(arenaStringBuilder, "RebuiltDate", Optional.ofNullable(arenaDataMap.get("RebuiltDate")).orElse(HO_DATE_TIME_NOT_SET));
appendKeyValue(arenaStringBuilder, "ExpansionDate", Optional.ofNullable(arenaDataMap.get("ExpansionDate")).orElse(HO_DATE_TIME_NOT_SET));
}

/**
* Create the arena data.
*/
public void createArena(Arena arena) {
arenaStringBuilder = new StringBuilder("[arena]\n");
appendKeyValue(arenaStringBuilder, "arenaname", arena.getName());
appendKeyValue(arenaStringBuilder, "arenaid", arena.getId());
appendKeyValue(arenaStringBuilder, "antalStaplats", arena.getCurrentCapacity().getTerraces());
appendKeyValue(arenaStringBuilder, "antalSitt", arena.getCurrentCapacity().getBasic());
appendKeyValue(arenaStringBuilder, "antalTak", arena.getCurrentCapacity().getRoof());
appendKeyValue(arenaStringBuilder, "antalVIP", arena.getCurrentCapacity().getVip());
appendKeyValue(arenaStringBuilder, "seatTotal", arena.getCurrentCapacity().getTotal());
appendKeyValue(arenaStringBuilder, "expandingStaplats", arena.getExpandedCapacity().map(Capacity::getTerraces).orElse(0));
appendKeyValue(arenaStringBuilder, "expandingSitt", arena.getExpandedCapacity().map(Capacity::getBasic).orElse(0));
appendKeyValue(arenaStringBuilder, "expandingTak", arena.getExpandedCapacity().map(Capacity::getRoof).orElse(0));
appendKeyValue(arenaStringBuilder, "expandingVIP", arena.getExpandedCapacity().map(Capacity::getVip).orElse(0));
appendKeyValue(arenaStringBuilder, "expandingSseatTotal", arena.getExpandedCapacity().map(Capacity::getTotal).orElse(0));
appendKeyValue(arenaStringBuilder, "isExpanding", arena.getExpandedCapacity().isPresent());
appendKeyValue(arenaStringBuilder, "RebuiltDate", arena.getCurrentCapacity().getRebuiltDate().map(HODateTime::toHT).orElse(HO_DATE_TIME_NOT_SET));
appendKeyValue(arenaStringBuilder, "ExpansionDate", arena.getExpandedCapacity().map(ExpandedCapacity::getExpansionDate).map(HODateTime::toHT).orElse(HO_DATE_TIME_NOT_SET));
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/core/file/xml/ConvertXml2Hrf.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import core.util.Helper;
import core.module.config.ModuleConfig;
import core.net.MyConnector;
import hattrickdata.Arena;
import module.transfer.PlayerTransfer;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
Expand Down Expand Up @@ -185,7 +186,7 @@ private ConvertXml2Hrf() {
} catch (Exception ignored) {

}
Map<String, String> arenaDataMap = XMLArenaParser.parseArenaFromString(mc.downloadArena(arenaId));
Arena arena = XMLArenaParser.parseArenaFromString(mc.downloadArena(arenaId)).getRight();

// MatchOrder
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.match_orders"), progressIncrement);
Expand Down Expand Up @@ -229,7 +230,7 @@ private ConvertXml2Hrf() {

// Arena
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.create_arena"), progressIncrement);
hrfSgtringBuilder.createArena(arenaDataMap);
hrfSgtringBuilder.createArena(arena);

// players
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.create_players"), progressIncrement);
Expand Down
Loading

0 comments on commit 56baf8a

Please sign in to comment.