Skip to content

Commit

Permalink
Merge branch 'master' into ho-dev#1897
Browse files Browse the repository at this point in the history
  • Loading branch information
tychobrailleur authored Nov 19, 2023
2 parents 436c12f + 592890b commit e5c880e
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 164 deletions.
1 change: 1 addition & 0 deletions src/main/java/core/db/DBUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ void updateDB(int DBVersion) {
private void updateDBv800(int dbVersion) throws SQLException {
var playerTable = dbManager.getTable(SpielerTable.TABLENAME);
playerTable.tryAddColumn("LineupDisabled", "BOOLEAN");
playerTable.tryAddColumn("ContractDate", "VARCHAR(100)");
playerTable.tryChangeColumn("OwnerNotes", "VARCHAR(512)");
updateDBVersion(dbVersion, 800);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/core/db/SpielerTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ protected void initColumns() {
ColumnDescriptor.Builder.newInstance().setColumnName("MotherclubId").setGetter((p)->((Player)p).getOrDownloadMotherclubId()).setSetter((p, v)->((Player)p).setMotherClubId((Integer) v)).setType(Types.INTEGER).isNullable(true).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("MotherclubName").setGetter((p)->((Player)p).getOrDownloadMotherclubName()).setSetter((p, v)->((Player)p).setMotherClubName((String)v)).setType(Types.VARCHAR).isNullable(true).setLength(255).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("MatchesCurrentTeam").setGetter((p)->((Player)p).getMatchesCurrentTeam()).setSetter((p,v)->((Player)p).setMatchesCurrentTeam((Integer) v)).setType(Types.INTEGER).isNullable(true).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("LineupDisabled").setGetter((p)->((Player)p).isLineupDisabled()).setSetter((p,v)->((Player)p).setLineupDisabled((Boolean) v)).setType(Types.BOOLEAN).isNullable(true).build()
ColumnDescriptor.Builder.newInstance().setColumnName("LineupDisabled").setGetter((p)->((Player)p).isLineupDisabled()).setSetter((p,v)->((Player)p).setLineupDisabled((Boolean) v)).setType(Types.BOOLEAN).isNullable(true).build(),
ColumnDescriptor.Builder.newInstance().setColumnName("ContractDate").setGetter((p)->((Player)p).getContractDate()).setSetter((p,v)->((Player)p).setContractDate((String)v)).setType(Types.VARCHAR).isNullable(true).setLength(100).build()
};
}

Expand Down
19 changes: 9 additions & 10 deletions src/main/java/core/db/UserColumnsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,25 +72,24 @@ void insertDefault(HOTableModel model) {
void loadModel(HOTableModel model) {
int count = 0;
var userColumns = load(_UserColumn.class, model.getId() * 1000, model.getId() * 1000 + 999);
if (userColumns.size() > 0) { // user may not delete all columns
var dbcolumns = model.getColumns();
if (!userColumns.isEmpty()) { // user may not delete all columns
var modelColumns = model.getColumns();
if (model.userCanDisableColumns() && !DBManager.instance().isFirstStart()) {
for (var dbColumn : dbcolumns) {
dbColumn.setDisplay(false);
for (var modelColumn : modelColumns) {
modelColumn.setDisplay(!modelColumn.isEditable());
}
}
for (var userColumn : userColumns) {
var modelIndex = userColumn.getModelIndex();
if (modelIndex < dbcolumns.length) {
var dbColumn = dbcolumns[modelIndex];
dbColumn.setPreferredWidth(userColumn.getPreferredWidth());
dbColumn.setDisplay(true);
dbColumn.setIndex(userColumn.getIndex());
if (modelIndex < modelColumns.length) {
var modelColumn = modelColumns[modelIndex];
modelColumn.setPreferredWidth(userColumn.getPreferredWidth());
modelColumn.setDisplay(true);
modelColumn.setIndex(userColumn.getIndex());
count++;
}
}
}

if (count == 0) {
insertDefault(model);
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/core/file/hrf/HRFStringBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import module.training.Skills;
import module.youth.YouthPlayer;
import org.apache.commons.lang3.math.NumberUtils;

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

Expand Down Expand Up @@ -274,7 +273,7 @@ public void createLastLineUp(MatchLineupTeam matchLineupTeam, Map<String, String
appendKeyValue(lastLineupStringBuilder, "subst"+i+"playerIn", sub.getObjectPlayerID());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"playerOut", sub.getSubjectPlayerID());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"orderType", (int) sub.getOrderType().getId());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"matchMinuteCriteria", (int) sub.getMatchMinuteCriteria());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"matchMinuteCriteria", sub.getMatchMinuteCriteria());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"pos", (int) sub.getRoleId());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"behaviour", (int) sub.getBehaviour());
appendKeyValue(lastLineupStringBuilder, "subst"+i+"card", (int) sub.getRedCardCriteria().getId());
Expand Down Expand Up @@ -416,7 +415,7 @@ public void createPlayers(MatchLineupTeam matchLineupTeam, List<MyHashtable> pla
var firstName = ht.get("FirstName");
var lastName = ht.get("LastName");
var nickName = ht.get("NickName");
if (nickName.length() > 0) {
if (!nickName.isEmpty()) {
appendKeyValue(playersStringBuilder, "name", firstName + " '" + nickName + "' " + lastName);
} else {
appendKeyValue(playersStringBuilder, "name", firstName + " " + lastName);
Expand Down Expand Up @@ -462,7 +461,10 @@ public void createPlayers(MatchLineupTeam matchLineupTeam, List<MyHashtable> pla
appendKeyValue(playersStringBuilder, "AggressivenessLabel", PlayerAggressiveness.toString(Integer.parseInt(ht.get("Aggressiveness"))));

appendKeyValue(playersStringBuilder, "TrainerType", ht.get("TrainerType"));
appendKeyValue(playersStringBuilder, "TrainerSkill", ht.get("TrainerSkill"));
appendKeyValue(playersStringBuilder, "ContractDate", ht.get("ContractDate"));
appendKeyValue(playersStringBuilder, "Cost", ht.get("Cost"));
appendKeyValue(playersStringBuilder, "TrainerSkillLevel", ht.get("TrainerSkillLevel"));
appendKeyValue(playersStringBuilder, "TrainerStatus", ht.get("TrainerStatus"));

appendKeyValue(playersStringBuilder, "LastMatch_Date", ht.get("LastMatch_Date"));
appendKeyValue(playersStringBuilder, "LastMatch_Rating", ht.get("LastMatch_Rating"));
Expand Down Expand Up @@ -671,7 +673,7 @@ private static String getPlayerOrderForNextLineup(String position,

if (ret != null) {
ret = ret.trim();
if (!"null".equals(ret) && !"".equals(ret)) {
if (!"null".equals(ret) && !ret.isEmpty()) {
return ret.trim();
}
}
Expand Down
62 changes: 29 additions & 33 deletions src/main/java/core/file/xml/ConvertXml2Hrf.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import core.model.HOVerwaltung;
import core.model.match.*;
import core.model.player.PlayerAvatar;
import core.model.player.TrainerStatus;
import core.net.OnlineWorker;
import core.util.Helper;
import core.module.config.ModuleConfig;
Expand Down Expand Up @@ -62,9 +63,9 @@ private ConvertXml2Hrf() {
// user has only one single team
teamId = teamInfoList.get(0).getTeamId();
youthTeamId = teamInfoList.get(0).getYouthTeamId();
} else if (teamInfoList.size() >= 2){
} else if (teamInfoList.size() >= 2) {
// user has more than one team
if ( teamId <=0) {
if (teamId <= 0) {
// Select one of user's teams, if not done before
CursorToolkit.stopWaitCursor(HOMainFrame.instance().getRootPane());
TeamSelectionDialog selection = new TeamSelectionDialog(HOMainFrame.instance(), teamInfoList);
Expand All @@ -74,15 +75,14 @@ private ConvertXml2Hrf() {
}
teamId = selection.getSelectedTeam().getTeamId();
youthTeamId = selection.getSelectedTeam().getYouthTeamId();
}
else {
} else {
// team id is in DB and this is the first time we download youth team information
int finalTeamId = teamId;
var teaminfo = teamInfoList.stream()
.filter(x -> x.getTeamId() == finalTeamId)
.findAny()
.orElse(null);
if ( teaminfo != null){
if (teaminfo != null) {
youthTeamId = teaminfo.getYouthTeamId();
}
}
Expand Down Expand Up @@ -110,8 +110,8 @@ private ConvertXml2Hrf() {

// Currency fix
var lastPremierId = ModuleConfig.instance().getInteger("UsersPremierTeamId");
if ( lastPremierId != null && lastPremierId == usersPremierTeamId ){
//if (ModuleConfig.instance().containsKey("CurrencyRate")) {
if (lastPremierId != null && lastPremierId == usersPremierTeamId) {
//if (ModuleConfig.instance().containsKey("CurrencyRate")) {
worldDataMap.put("CurrencyRate", ModuleConfig.instance().getString("CurrencyRate"));
worldDataMap.put("CountryID", ModuleConfig.instance().getString("CountryId"));
} else {
Expand All @@ -126,29 +126,14 @@ private ConvertXml2Hrf() {

HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.players_information"), progressIncrement);
List<MyHashtable> playersData = new XMLPlayersParser().parsePlayersFromString(mc.downloadPlayers(teamId));
var trainerId = String.valueOf(teamdetailsDataMap.get("TrainerID"));
// If trainer is not in players data, download trainer info from player details
var found = false;
for ( var p : playersData){
if ( p.get("PlayerID").equals(trainerId)){
found=true;
break;
}
}
if ( !found){
var xml = MyConnector.instance().downloadPlayerDetails(trainerId);
var properties = new XMLPlayersParser().parsePlayerDetails(xml);
properties.put("LineupDisabled", "true");
playersData.add(properties);
}

// Download players' avatar
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.players_avatars"), progressIncrement);
List<PlayerAvatar> playersAvatar = XMLAvatarsParser.parseAvatarsFromString(mc.getAvatars(teamId));
ThemeManager.instance().generateAllPlayerAvatar(playersAvatar, 1);

List<MyHashtable> youthplayers=null;
if ( youthTeamId != null && youthTeamId > 0 ){
List<MyHashtable> youthplayers = null;
if (youthTeamId != null && youthTeamId > 0) {
youthplayers = new XMLPlayersParser().parseYouthPlayersFromString(mc.downloadYouthPlayers(youthTeamId));
}
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.economy"), progressIncrement);
Expand All @@ -159,6 +144,23 @@ private ConvertXml2Hrf() {

HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.staff"), progressIncrement);
List<MyHashtable> staffData = XMLStaffParser.parseStaffFromString(mc.getStaff(teamId));
var trainer = staffData.get(0);
var trainerId = String.valueOf(trainer.get("TrainerId"));
if (trainer.containsKey("TrainerId")) {
var trainerStatus = TrainerStatus.fromInt(Integer.parseInt(trainer.get("TrainerStatus")));
if (trainerStatus == TrainerStatus.PlayingTrainer){
for (var p : playersData) {
if (p.get("PlayerID").equals(trainerId)) {
p.putAll(trainer);
break;
}
}
}
else {
trainer.put("LineupDisabled", "true");
playersData.add(trainer);
}
}

int arenaId = 0;
try {
Expand All @@ -172,7 +174,7 @@ private ConvertXml2Hrf() {
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.match_orders"), progressIncrement);
List<MatchKurzInfo> matches = XMLMatchesParser
.parseMatchesFromString(mc.getMatches(Integer
.parseInt(teamdetailsDataMap.get("TeamID")),
.parseInt(teamdetailsDataMap.get("TeamID")),
false, true));

HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.match_info"), progressIncrement);
Expand Down Expand Up @@ -217,7 +219,7 @@ private ConvertXml2Hrf() {
hrfSgtringBuilder.createPlayers(matchLineupTeam, playersData);

// youth players
if ( youthplayers != null){
if (youthplayers != null) {
HOMainFrame.instance().setInformation(Helper.getTranslation("ls.update_status.create_youth_players"), progressIncrement);
hrfSgtringBuilder.appendYouthPlayers(youthplayers);
}
Expand All @@ -236,10 +238,4 @@ private ConvertXml2Hrf() {

return hrfSgtringBuilder.createHRF().toString();
}


// //////////////////////////////////////////////////////////////////////////////
// Helper
// //////////////////////////////////////////////////////////////////////////////

}
}
4 changes: 1 addition & 3 deletions src/main/java/core/file/xml/XMLEconomyParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import static core.net.MyConnector.VERSION_ECONOMY;


public class XMLEconomyParser {

Expand All @@ -26,7 +24,7 @@ public static Map<String, String> parseEconomyFromString(String inputStream) {
var fetchedDate = HODateTime.fromHT(mapEconomy.get("FetchedDate"));
var htWeek = fetchedDate.toHTWeek();
var season = htWeek.season;
if ((Float.parseFloat(VERSION_ECONOMY) >= 1.3f ) && (season >= 80)){
if (season >= 80){
var iSponsorBonusIncome = assessSponsorBonusIncome(mapEconomy, new String[]{"IncomeSpectators", "IncomeSponsors", "IncomeFinancial", "IncomeTemporary", "IncomeSoldPlayers",
"IncomeSoldPlayersCommission"}, "IncomeSum");
mapEconomy.put("IncomeSponsorsBonus", iSponsorBonusIncome.toString());
Expand Down
98 changes: 52 additions & 46 deletions src/main/java/core/file/xml/XMLStaffParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,58 @@
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import static core.file.xml.XMLManager.xmlValue2Hash;

public class XMLStaffParser {


/**
* Utility class - private constructor enforces noninstantiability.
*/
private XMLStaffParser() {
}


public static List<MyHashtable> parseStaffFromString(String inputStream) {
Document doc = null;
doc = XMLManager.parseString(inputStream);
return createList(doc);
}

private static List<MyHashtable> createList(Document doc) {

final List<MyHashtable> returnList = new ArrayList<MyHashtable>();
NodeList nodeList;
MyHashtable hash = null;
Element ele = null;
Element root = doc.getDocumentElement();

root = (Element) root.getElementsByTagName("StaffMembers").item(0);
nodeList = root.getElementsByTagName("Staff");

for (int i = 0; (nodeList != null) && (i < nodeList.getLength()); i++) {
hash = new MyHashtable();
root = (Element) nodeList.item(i);

ele = (Element) root.getElementsByTagName("Name").item(0);
hash.put("Name", (XMLManager.getFirstChildNodeValue(ele)));
ele = (Element) root.getElementsByTagName("StaffId").item(0);
hash.put("StaffId", (XMLManager.getFirstChildNodeValue(ele)));
ele = (Element) root.getElementsByTagName("StaffType").item(0);
hash.put("StaffType", (XMLManager.getFirstChildNodeValue(ele)));
ele = (Element) root.getElementsByTagName("StaffLevel").item(0);
hash.put("StaffLevel", (XMLManager.getFirstChildNodeValue(ele)));
ele = (Element) root.getElementsByTagName("Cost").item(0);
hash.put("Cost", (XMLManager.getFirstChildNodeValue(ele)));


returnList.add(hash);

}
return returnList;
}

/**
* Utility class - private constructor enforces noninstantiability.
*/
private XMLStaffParser() {
}


public static List<MyHashtable> parseStaffFromString(String inputStream) {
Document doc;
doc = XMLManager.parseString(inputStream);
return createList(doc);
}

private static List<MyHashtable> createList(Document doc) {

final List<MyHashtable> returnList = new ArrayList<>();
NodeList nodeList;
MyHashtable hash;
Element root = doc.getDocumentElement();
var trainer = (Element) root.getElementsByTagName("Trainer").item(0);
hash = new MyHashtable();
xmlValue2Hash(hash, trainer, "TrainerId");
xmlValue2Hash(hash, trainer, "Name");
xmlValue2Hash(hash, trainer, "Age");
xmlValue2Hash(hash, trainer, "AgeDays");
xmlValue2Hash(hash, trainer, "ContractDate");
xmlValue2Hash(hash, trainer, "Cost");
xmlValue2Hash(hash, trainer, "CountryID");
xmlValue2Hash(hash, trainer, "TrainerType");
xmlValue2Hash(hash, trainer, "Leadership");
xmlValue2Hash(hash, trainer, "TrainerSkillLevel");
xmlValue2Hash(hash, trainer, "TrainerStatus");
returnList.add(hash);

root = (Element) root.getElementsByTagName("StaffMembers").item(0);
nodeList = root.getElementsByTagName("Staff");
for (int i = 0; i < nodeList.getLength(); i++) {
hash = new MyHashtable();
root = (Element) nodeList.item(i);

xmlValue2Hash(hash, root, "Name");
xmlValue2Hash(hash, root, "StaffId");
xmlValue2Hash(hash, root, "StaffType");
xmlValue2Hash(hash, root, "StaffLevel");
xmlValue2Hash(hash, root, "Cost");
returnList.add(hash);
}
return returnList;
}
}
Loading

0 comments on commit e5c880e

Please sign in to comment.