Skip to content

Commit

Permalink
Various code style related changes based on feedback by Sheikah
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas committed May 5, 2024
1 parent c5ef202 commit 1cad3f5
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,209 +9,182 @@ public sealed interface Event {
/**
* Created by the parser to indicate we do not support this event yet.
*/
record Unprocessed(Token token, String reason) implements Event { }
record Unprocessed(Token token, String reason) implements Event {
}

/**
* Created by the parser to indicate we made a mistake
*/
record ProcessingError(Token token, Exception exception) implements Event { }
record ProcessingError(Token token, Exception exception) implements Event {
}

/**
* Created by the engine to advance the tick.
*/
record Advance(int ticksToAdvance) implements Event { }
record Advance(int ticksToAdvance) implements Event {
}

/**
* Created by the engine to set the command source for the next tokens.
*/
record SetCommandSource(int playerIndex) implements Event { }
record SetCommandSource(int playerIndex) implements Event {
}

/**
* Created by the engine when a player leaves the game.
*/
record CommandSourceTerminated() implements Event { }
record CommandSourceTerminated() implements Event {
}

/**
* Created by the engine to check the state of the game
*/
record VerifyChecksum(String hash, int tick) implements Event { }
record VerifyChecksum(String hash, int tick) implements Event {
}

/**
* Created by the User global `SessionRequestPause` to request a pause
*/
record RequestPause() implements Event { }
record RequestPause() implements Event {
}

/**
* Created by the User global `SessionResume` to request a resume
*/
record RequestResume() implements Event { }
record RequestResume() implements Event {
}

/**
* Created by the console command `wld_SingleStep` while the game is paused
*/
record SingleStep() implements Event { }
record SingleStep() implements Event {
}

/**
* Created by the console command `CreateUnit`
*/
record CreateUnit(int playerIndex, String blueprintId, float px, float pz, float heading) implements Event { }
record CreateUnit(int playerIndex, String blueprintId, float px, float pz, float heading) implements Event {
}

/**
* Created by the console command `CreateProp`
*/
record CreateProp(String blueprintId, float px, float pz, float heading) implements Event { }
record CreateProp(String blueprintId, float px, float pz, float heading) implements Event {
}

/**
* Created by the console commands `DestroySelectedUnits` and `DestroySelectedUnits`
*/
record DestroyEntity(int entityId) implements Event { }
record DestroyEntity(int entityId) implements Event {
}

/**
* Created by the console command `TeleportSelectedUnits`
*/
record WarpEntity(int entityId, float px, float py, float pz) implements Event { }
record WarpEntity(int entityId, float px, float py, float pz) implements Event {
}

/**
* Created by the UserUnit function `ProcessInfo`
*/
record ProcessInfoPair(int entityId, String arg1, String arg2) implements Event { }

enum CommandTargetType {
NONE,
ENTITY,
POSITION
}

enum CommandType {
NONE("NONE"),
STOP("Stop"),
MOVE("Move"),
DIVE("Dive"),
FORM_MOVE("FormMove"),
BUILD_SILO_TACTICAL("BuildSiloTactical"),
BUILD_SILO_NUKE("BuildSiloNuke"),
BUILD_FACTORY("BuildFactory"),
BUILD_MOBILE("BuildMobile"),
BUILD_ASSIsT("BuildAssist"),
ATTACK("Attack"),
FORM_ATTACK("FormAttack"),
NUKE("Nuke"),
TACTICAL("Tactical"),
TELEPORT("Teleport"),
GUARD("Guard"),
PATROL("Patrol"),
FERRY("Ferry"),
FORM_PATROL("FormPatrol"),
RECLAIM("Reclaim"),
REPAIR("Repair"),
CAPTURE("Capture"),
TRANSPORT_LOAD_UNITS("TransportLoadUnits"),
TRANSPORT_REVERSE_LOAD_UNITS("TransportReverseLoadUnits"),
TRANSPORT_UNLOAD_UNITS("TransportUnloadUnits"),
TRANSPORT_UNLOAD_SPECIFIC_UNITS("TransportUnloadSpecificUnits"),
DETACH_FROM_TRANSPORT("DetachFromTransport"),
UPGRADE("Upgrade"),
SCRIPT("Script"),
ASSIST_COMMANDER("AssistCommander"),
KILL_SELF("KillSelf"),
DESTROY_SELF("DestroySelf"),
SACRIFICE("Sacrifice"),
PAUSE("Pause"),
OVER_CHARGE("OverCharge"),
AGGRESSIVE_MOVE("AggressiveMove"),
FORM_AGGRESSIVE_MOVE("FormAggressiveMove"),
ASSIST_MOVE("AssistMove"),
SPECIAL_ACTION("SpecialAction"),
DOCK("Dock");

private final String string;

CommandType(String string) {
this.string = string;
}
record ProcessInfoPair(int entityId, String arg1, String arg2) implements Event {
}

record CommandUnits (int count, List<Integer> unitIds) {}

record CommandFormation (int formationId, float orientation, float px, float py, float pz, float scale) {}

sealed interface CommandTarget {
record Entity (int unitId) implements CommandTarget { }
record Position (float px, float py, float pz) implements CommandTarget { }
}

/**
*
* @param commandId The command id to reference it later (to adjust or delete it, for example)
* @param commandtype The command type (move, attack - what else?)
* @param commandTarget
* @param commandFormation
* @param blueprintId
* @param parametersLua
*/
record CommandData (int commandId, CommandType commandtype, CommandTarget commandTarget, CommandFormation commandFormation, String blueprintId, LuaData parametersLua) {}

/**
* Created by the engine when the user creates a command by clicking
*/
record IssueCommand( CommandUnits commandUnits, CommandData commandData ) implements Event {


record IssueCommand(CommandUnits commandUnits, CommandData commandData) implements Event {
}

/**
* Created by the User global function `IssueBlueprintCommand`
*/
record IssueFactoryCommand(CommandUnits commandUnits, CommandData commandData) implements Event { }
record IssueFactoryCommand(CommandUnits commandUnits, CommandData commandData) implements Event {
}

/**
* Created by the User global function `IncreaseBuildCountInQueue`
*/
record IncreaseCommandCount(int commandId, int delta) implements Event { }
record IncreaseCommandCount(int commandId, int delta) implements Event {
}

/**
* Created by the user global function `DecreaseBuildCountInQueue`
*/
record DecreaseCommandCount(int commandId, int delta) implements Event { }
record DecreaseCommandCount(int commandId, int delta) implements Event {
}

/**
* Created by the engine when updating the target (entity or position) of a command
*/
record SetCommandTarget(int commandId, CommandTarget commandTarget) implements Event { }
record SetCommandTarget(int commandId, CommandTarget commandTarget) implements Event {
}

/**
* Created by the engine when transforming the command (move to patrol)
*/
record SetCommandType(int commandId, int targetId) implements Event { }
record SetCommandType(int commandId, int targetId) implements Event {
}

/**
* ??
*/
record SetCommandCells(int commandId, LuaData parametersLua, float px, float py, float pz) implements Event { }
record SetCommandCells(int commandId, LuaData parametersLua, float px, float py, float pz) implements Event {
}

/**
* Created by the User global function `DeleteCommand`
*/
record RemoveCommandFromQueue(int commandId, int unitId) implements Event { }
record RemoveCommandFromQueue(int commandId, int unitId) implements Event {
}

/**
* ??
*/
record DebugCommand() implements Event { }
record DebugCommand() implements Event {
}

/**
* Created by the User global function `ExecLuaInSim`
*/
record ExecuteLuaInSim(String luaCode) implements Event { }
record ExecuteLuaInSim(String luaCode) implements Event {
}

/**
* Created by the user global function `SimCallback`
*/
record LuaSimCallback(String func, LuaData parametersLua, CommandUnits commandUnits) implements Event { }
record LuaSimCallback(String func, LuaData parametersLua, CommandUnits commandUnits) implements Event {
}

/**
* Created by the User global function `SessionEndGame`
*/
record EndGame() implements Event { }
record EndGame() implements Event {
}

sealed interface CommandTarget {
record Entity(int unitId) implements CommandTarget {
}

record Position(float px, float py, float pz) implements CommandTarget {
}
}

record CommandUnits(int count, List<Integer> unitIds) {
}

record CommandFormation(int formationId, float orientation, float px, float py, float pz, float scale) {
}

/**
* @param commandId The command id to reference it later (to adjust or delete it, for example)
* @param commandType The command type (move, attack - what else?)
* @param commandTarget
* @param commandFormation
* @param blueprintId
* @param parametersLua
*/
record CommandData(int commandId, EventCommandType commandType, CommandTarget commandTarget,
CommandFormation commandFormation, String blueprintId, LuaData parametersLua) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.faforever.commons.replay.event;

public enum EventCommandType {
NONE("NONE"),
STOP("Stop"),
MOVE("Move"),
DIVE("Dive"),
FORM_MOVE("FormMove"),
BUILD_SILO_TACTICAL("BuildSiloTactical"),
BUILD_SILO_NUKE("BuildSiloNuke"),
BUILD_FACTORY("BuildFactory"),
BUILD_MOBILE("BuildMobile"),
BUILD_ASSIsT("BuildAssist"),
ATTACK("Attack"),
FORM_ATTACK("FormAttack"),
NUKE("Nuke"),
TACTICAL("Tactical"),
TELEPORT("Teleport"),
GUARD("Guard"),
PATROL("Patrol"),
FERRY("Ferry"),
FORM_PATROL("FormPatrol"),
RECLAIM("Reclaim"),
REPAIR("Repair"),
CAPTURE("Capture"),
TRANSPORT_LOAD_UNITS("TransportLoadUnits"),
TRANSPORT_REVERSE_LOAD_UNITS("TransportReverseLoadUnits"),
TRANSPORT_UNLOAD_UNITS("TransportUnloadUnits"),
TRANSPORT_UNLOAD_SPECIFIC_UNITS("TransportUnloadSpecificUnits"),
DETACH_FROM_TRANSPORT("DetachFromTransport"),
UPGRADE("Upgrade"),
SCRIPT("Script"),
ASSIST_COMMANDER("AssistCommander"),
KILL_SELF("KillSelf"),
DESTROY_SELF("DestroySelf"),
SACRIFICE("Sacrifice"),
PAUSE("Pause"),
OVER_CHARGE("OverCharge"),
AGGRESSIVE_MOVE("AggressiveMove"),
FORM_AGGRESSIVE_MOVE("FormAggressiveMove"),
ASSIST_MOVE("AssistMove"),
SPECIAL_ACTION("SpecialAction"),
DOCK("Dock");

private final String string;

EventCommandType(String string) {
this.string = string;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static Event.CommandFormation parseCommandFormation(LittleEndianDataInpu
}

private static Event.CommandTarget parseCommandTarget(LittleEndianDataInputStream stream) throws IOException {
Event.CommandTargetType target = Event.CommandTargetType.values()[stream.readByte()];
CommandTargetType target = CommandTargetType.values()[stream.readByte()];
switch (target) {
case ENTITY -> {
int entityId = stream.readInt();
Expand All @@ -89,7 +89,7 @@ private static Event.CommandTarget parseCommandTarget(LittleEndianDataInputStrea
private static Event.CommandData parseCommandData(LittleEndianDataInputStream stream) throws IOException {
int commandId = stream.readInt();
byte[] arg1 = stream.readNBytes(4);
Event.CommandType commandType = Event.CommandType.values()[stream.readByte()];
EventCommandType commandType = EventCommandType.values()[stream.readByte()];
byte[] arg2 = stream.readNBytes(4);

Event.CommandTarget commandTarget = parseCommandTarget(stream);
Expand Down Expand Up @@ -322,4 +322,10 @@ private static Event parseToken(Token token) throws IOException {
default -> new Event.Unprocessed(token, "Unknown");
};
}

private enum CommandTargetType {
NONE,
ENTITY,
POSITION
}
}

0 comments on commit 1cad3f5

Please sign in to comment.