Skip to content

Commit

Permalink
Process and parse elements in the replay header (#148)
Browse files Browse the repository at this point in the history
* Parse the player options from Lua

* Add parsing of a mod

* Revert the name change on the Lua data type

* Read out the scenario information

* First batch of primary options

* Rename the options fields to make their purpose more clear

* Undo accidental changes

* Remove accidental replacements

* Rename the `toMap` function to improve our sanity
  • Loading branch information
Garanas authored May 26, 2024
1 parent 6e9ba4d commit 31b0945
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

/**
* Populated by the game mods field of the table that is passed to `CLobby:LaunchGame`
*
* @param location
* @param icon
* @param copyright
* @param name
* @param description
* @param author
* @param uid
* @param version
* @param url
* @param urlGithub
*/
public record GameMod(String location, String name, String description, String author, String uid, String version,
String url, String urlGithub) {
public record GameMod(String location, String icon, String copyright, String name, String description, String author,
String uid, Integer version, String url) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* Populated by the game options field of the table that is passed to `CLobby:LaunchGame`
*
* @param autoTeams
* @param teamLock
* @param teamSpawn
Expand All @@ -13,19 +14,20 @@
* @param revealedCivilians
* @param scoreEnabled
* @param unitCap
* @param unRated
* @param unRanked
* @param victory
*/
public record GameOptions(AutoTeams autoTeams, TeamLock teamLock, TeamSpawn teamSpawn, boolean allowObservers,
boolean cheatsEnabled, boolean prebuiltUnits, boolean revealedCivilians, boolean scoreEnabled,
int unitCap, boolean unRated, Victory victory) {
public record GameOptions(AutoTeams autoTeams, TeamLock teamLock, TeamSpawn teamSpawn, Boolean allowObservers,
Boolean cheatsEnabled, Boolean prebuiltUnits, Boolean revealedCivilians, Boolean scoreEnabled,
Integer unitCap, String unRanked, Victory victory) {

public enum AutoTeams {
NONE("none", "None"),
MANUAL("manual", "Manual"),
TOP_VS_BOTTOM("tvsb", "Top versus bottom"),
LEFT_VS_RIGHT("lvsr", "Left versus right"),
EVEN_VS_UNEVEN("pvsi", "Even versus uneven");
EVEN_VS_UNEVEN("pvsi", "Even versus uneven"),
UNKNOWN("unknown", "Unknown");

public final String readable;

Expand All @@ -37,17 +39,17 @@ public enum AutoTeams {
}

public static AutoTeams findByKey(String key) {
for (AutoTeams autoTeam : values()) {
if (autoTeam.key.equals(key)) {
return autoTeam;
for (AutoTeams value : values()) {
if (value.key.equals(key)) {
return value;
}
}
throw new IllegalArgumentException("Unknown key: " + key);
return AutoTeams.UNKNOWN;
}
}

public enum TeamLock {
LOCKED("locked", "Locked"), UNLOCKED("unlocked", "Unlocked");
LOCKED("locked", "Locked"), UNLOCKED("unlocked", "Unlocked"), UNKNOWN("unknown", "Unknown");;

public final String readable;

Expand All @@ -59,12 +61,13 @@ public enum TeamLock {
}

public static TeamLock findByKey(String key) {
for (TeamLock teamLock : values()) {
if (teamLock.key.equals(key)) {
return teamLock;
for (TeamLock value : values()) {
if (value.key.equals(key)) {
return value;
}
}
throw new IllegalArgumentException("Unknown key: " + key);

return TeamLock.UNKNOWN;
}
}

Expand All @@ -77,7 +80,8 @@ public enum TeamSpawn {
RANDOM_REVEAL("random_reveal", "Random and revealed"),
BALANCED_REVEAL("balanced_reveal", "Balanced and revealed"),
BALANCED_REVEAL_MIRRORED("balanced_reveal_mirrored", "Mirror balanced and revealed"),
BALANCED_FLEX_REVEAL("balanced_flex_reveal", "Flexible balanced and revealed");
BALANCED_FLEX_REVEAL("balanced_flex_reveal", "Flexible balanced and revealed"),
UNKNOWN("unknown", "Unknown");

public final String readable;

Expand All @@ -89,20 +93,22 @@ public enum TeamSpawn {
}

public static TeamSpawn findByKey(String key) {
for (TeamSpawn teamSpawn : values()) {
if (teamSpawn.key.equals(key)) {
return teamSpawn;
for (TeamSpawn value : values()) {
if (value.key.equals(key)) {
return value;
}
}
throw new IllegalArgumentException("Unknown key: " + key);

return TeamSpawn.UNKNOWN;
}
}

public enum Victory {
DEMORALIZATION("demoralization", "Assasination"),
DOMINATION("domination", "Supremacy"),
ERADICATION("eradication", "Annihilation"),
SANDBOX("sandbox", "Sandbox");
SANDBOX("sandbox", "Sandbox"),
UNKNOWN("unknown", "Unknown");

public final String readable;

Expand All @@ -114,13 +120,68 @@ public enum Victory {
}

public static Victory findByKey(String key) {
for (Victory victory : values()) {
if (victory.key.equals(key)) {
return victory;
for (Victory value : values()) {
if (value.key.equals(key)) {
return value;
}
}

return Victory.UNKNOWN;
}
}

public enum SharedArmy {
OFF("demoralization", "Assasination"),
UNION("domination", "Supremacy"),
COMMON("eradication", "Annihilation"),
UNKNOWN("unknown", "Unknown");

public final String readable;

private final String key;

SharedArmy(String key, String readable) {
this.key = key;
this.readable = readable;
}

public static SharedArmy findByKey(String key) {
for (SharedArmy value : values()) {
if (value.key.equals(key)) {
return value;
}
}
throw new IllegalArgumentException("Unknown key: " + key);

return SharedArmy.UNKNOWN;
}
}

public enum Share {
FULLSHARE("FullShare", "Full share"),
SHAREUNTILDEATH("ShareUntilDeath", "Share until death"),
PARTIALSHARE("PartialShare", "Partial share"),
TRAITORS("TransferToKiller", "Traitors"),
DEFECTORS("Defectors", "Defectors"),
DESERTION("CivilianDeserter", "Desert to civilians"),
UNKNOWN("unknown", "Unknown");

public final String readable;

private final String key;

Share(String key, String readable) {
this.key = key;
this.readable = readable;
}

public static Share findByKey(String key) {
for (Share value : values()) {
if (value.key.equals(key)) {
return value;
}
}

return Share.UNKNOWN;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.faforever.commons.replay.header;

import java.util.Map;

public record GameScenario(String mapPath, Integer mapVersion, String mapDescription, String mapScript, String mapSave,
String mapName, Integer mapSizeX, Integer mapSizeZ, Integer reclaimMassValue,
Integer reclaimEnergyValue, GameOptions gameOptions,
Map<String, String> modOptions) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* @param ratingDeviation
* @param clan
* @param isCivilian
* @param isReady
* @param isBadMap
* @param lobbyIndex
* @param armyName
* @param armyColor
Expand All @@ -20,11 +18,10 @@
* @param country
* @param team
* @param faction
* @param sourceId
*/
public record PlayerOptions(boolean isHuman, String aiPersonality, float ratingMean, float ratingDeviation, String clan,
boolean isCivilian, boolean isReady, boolean isBadMap, int lobbyIndex,
String armyName, String armyColor, String playerColor, String playerName,
int ratedGamesPlayed, String country,
int team, int faction, int sourceId) {
public record PlayerOptions(Boolean isHuman, String aiPersonality, Float ratingMean, Float ratingDeviation, String clan,
Boolean isCivilian, Integer lobbyIndex,
String armyName, Integer armyColor, Integer playerColor, String playerName,
Integer ratedGamesPlayed, String country,
Integer team, Integer faction) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public record ReplayHeader(String gameVersion, String replayVersion, String pathToScenario, boolean cheatsEnabled, int seed,
List<Source> sources,
List<GameMod> mods,
GameOptions gameOptions,
GameScenario scenario,
List<PlayerOptions> playerOptions
) {
}
Loading

0 comments on commit 31b0945

Please sign in to comment.