Skip to content

Commit

Permalink
Drop generator support
Browse files Browse the repository at this point in the history
It was not maintainable.
  • Loading branch information
Fesaa committed Jul 27, 2024
1 parent 38e1485 commit 07f1a30
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean execute(String prefix, String[] arguments) {
}

boolean check = this.addon.getManager().getGameMapInfoManager()
.doGameMapLayout(mapName, false);
.doGameMapLayout(mapName);
if (!check) {
this.displayMessage(
Component.translatable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public class GameMapInfoSubConfig extends Config {
@SpriteSlot(x = 6, y = 2)
private final ConfigProperty<Boolean> buildLimit = new ConfigProperty<>(true);

@SwitchSetting
@SpriteSlot(y = 2, x = 1)
private final ConfigProperty<Boolean> genLayout = new ConfigProperty<>(true);

public ConfigProperty<Boolean> isEnabled() {
return this.enabled;
}
Expand All @@ -45,8 +41,4 @@ public ConfigProperty<Boolean> getBuildLimit() {
return this.buildLimit;
}

public ConfigProperty<Boolean> getGenLayout() {
return genLayout;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void onKeyEvent(KeyEvent keyEvent) {
&& GameMapAPI.getInstance().hasMaps(this.addon.getManager().getDivision())) {
if (keyEvent.state() == State.PRESS) {
this.addon.getManager().getGameMapInfoManager()
.doGameMapLayout(this.addon.getManager().getMapName(), true);
.doGameMapLayout(this.addon.getManager().getMapName());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public GameMapInfoManager(Cubepanion addon) {
this.gameMapInfoSubConfig = addon.configuration().getGameMapInfoSubConfig();
}

private void displayGameMapLayout(LoadedGameMap map, boolean genLayout) {
private void displayGameMapLayout(LoadedGameMap map) {
ChatExecutor chat = this.addon.labyAPI().minecraft().chatExecutor();

if (addon.getManager().getMapName().equals(map.getName())) {
Expand Down Expand Up @@ -50,27 +50,16 @@ private void displayGameMapLayout(LoadedGameMap map, boolean genLayout) {
.append(buildLimit);
}

if (genLayout) {
Component component = map.getGenLayoutComponent();
if (component != null) {
display = display
.append(Component.newline())
.append(this.addon.prefix())
.append(component);
}

}

chat.displayClientMessage(display.append(Component.newline()));
}

public boolean doGameMapLayout(String mapName, boolean keyBind) {
public boolean doGameMapLayout(String mapName) {
LoadedGameMap map = GameMapAPI.getInstance().getGameMapFromCache(this.addon.getManager().getDivision(), mapName);
GameMapInfoSubConfig config = this.addon.configuration().getGameMapInfoSubConfig();
if (map == null) {
return false;
}
this.displayGameMapLayout(map, config.getGenLayout().get() && !keyBind);
this.displayGameMapLayout(map);
return true;
}

Expand All @@ -84,7 +73,7 @@ public void doGameMapLayout() {
return;
}

this.displayGameMapLayout(map, false);
this.displayGameMapLayout(map);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import art.ameliah.laby.addons.cubepanion.core.utils.gamemaps.TriangleEggWarsMap;
import art.ameliah.laby.addons.cubepanion.core.utils.gamemaps.base.GenLayout;
import art.ameliah.laby.addons.cubepanion.core.utils.gamemaps.base.GenLayout.Location;
import art.ameliah.laby.addons.cubepanion.core.utils.gamemaps.base.GenLayout.MapGenerator;
import art.ameliah.laby.addons.cubepanion.core.utils.gamemaps.base.LoadedGameMap;
import art.ameliah.laby.addons.cubepanion.core.weave.ChestAPI.ChestLocation;
import art.ameliah.laby.addons.cubepanion.core.weave.GameMapAPI.GameMap;
import art.ameliah.laby.addons.cubepanion.core.weave.GameMapAPI.Generator;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
Expand Down Expand Up @@ -51,40 +49,26 @@ public class Utils {
}

public static @Nullable LoadedGameMap fromAPIMap(GameMap map) {
Generator[] gens = map.generators();
GenLayout layout = null;
// EggWars Map
if (gens != null) {
List<MapGenerator> mapGenerators = new ArrayList<>();
for (Generator gen : gens) {
MapGenerator mapGen = new MapGenerator(transformGen(gen.gen_type()),
transformLoc(gen.gen_location()), gen.level(), gen.count());
mapGenerators.add(mapGen);
}
layout = new GenLayout(mapGenerators);
}


CubeGame game = CubeGame.stringToGame(map.game());
if (game.equals(CubeGame.NONE)) {
return null;
}

switch (map.layout()) {
case "square" -> {
return new SquareGameMap(game, map.map_name(), map.team_size(), map.build_limit(), layout,
return new SquareGameMap(game, map.map_name(), map.team_size(), map.build_limit(),
twoDeepStringList(transformColours(map)));
}
case "cross" -> {
return new CrossGameMap(game, map.map_name(), map.team_size(), map.build_limit(), layout,
return new CrossGameMap(game, map.map_name(), map.team_size(), map.build_limit(),
oneDeepStringList(transformColours(map)));
}
case "doublecross" -> {
return new DoubleCrossGameMap(game, map.map_name(), map.team_size(), map.build_limit(), layout,
return new DoubleCrossGameMap(game, map.map_name(), map.team_size(), map.build_limit(),
twoDeepStringList(transformColours(map)));
}
case "triangle" -> {
return new TriangleEggWarsMap(game, map.map_name(), map.team_size(), map.build_limit(), layout,
return new TriangleEggWarsMap(game, map.map_name(), map.team_size(), map.build_limit(),
twoDeepStringList(transformColours(map)));
}
default -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ public class CrossGameMap extends LoadedGameMap {
private String teamRight = "";
private String teamBefore = "";

public CrossGameMap(CubeGame game, String mapName, int teamSize, int buildLimit, GenLayout genLayout,
List<String> teamColours) {
super(game, mapName, teamSize, buildLimit, genLayout);
public CrossGameMap(CubeGame game, String mapName, int teamSize, int buildLimit, List<String> teamColours) {
super(game, mapName, teamSize, buildLimit);
this.teamColours = teamColours;
this.setCurrentTeamColour(this.teamColours.get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public class DoubleCrossGameMap extends LoadedGameMap {
private String teamAcrossLeft = "";
private String teamAcrossRight = "";

public DoubleCrossGameMap(CubeGame game,String mapName, int teamSize, int buildLimit, GenLayout genLayout,
List<List<String>> teamColours) {
super(game, mapName, teamSize, buildLimit, genLayout);
public DoubleCrossGameMap(CubeGame game,String mapName, int teamSize, int buildLimit, List<List<String>> teamColours) {
super(game, mapName, teamSize, buildLimit);
this.teamColours = teamColours;
this.setCurrentTeamColour(this.teamColours.get(0).get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ public class SquareGameMap extends LoadedGameMap {
private String teamAcross = "";
private String teamAcrossSide = "";

public SquareGameMap(CubeGame game,String mapName, int teamSize, int buildLimit, GenLayout genLayout,
List<List<String>> teamColours) {
super(game, mapName, teamSize, buildLimit, genLayout);
public SquareGameMap(CubeGame game,String mapName, int teamSize, int buildLimit, List<List<String>> teamColours) {
super(game, mapName, teamSize, buildLimit);
this.teamColours = teamColours;
this.setCurrentTeamColour(this.teamColours.get(0).get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public class TriangleEggWarsMap extends LoadedGameMap {
String teamUpRight = "";
int triangleLocation = -1;

public TriangleEggWarsMap(CubeGame game,String mapName, int teamSize, int buildLimit, GenLayout genLayout,
List<List<String>> teamColours) {
super(game, mapName, teamSize, buildLimit, genLayout);
public TriangleEggWarsMap(CubeGame game,String mapName, int teamSize, int buildLimit, List<List<String>> teamColours) {
super(game, mapName, teamSize, buildLimit);
this.teamColours = teamColours;
this.setCurrentTeamColour(this.teamColours.getFirst().getFirst());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ public abstract class LoadedGameMap {
protected final String mapName;
protected final int teamSize;
protected final int buildLimit;
protected final @Nullable GenLayout genLayout;
protected String currentTeamColour = "";

public LoadedGameMap(CubeGame game, String mapName, int teamSize, int buildLimit, @Nullable GenLayout genLayout) {
public LoadedGameMap(CubeGame game, String mapName, int teamSize, int buildLimit) {
this.game = game;
this.mapName = mapName;
this.teamSize = teamSize;
this.buildLimit = buildLimit;
this.genLayout = genLayout;
}

protected static Component spaceMaker(int n) {
Expand All @@ -34,14 +32,6 @@ public int getBuildLimit() {
return buildLimit;
}

@Nullable
public Component getGenLayoutComponent() {
if (this.genLayout == null) {
return null;
}
return this.genLayout.getLayoutComponent();
}

public abstract Component getMapLayoutComponent();

public Component getBuildLimitMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,7 @@ public CompletableFuture<GameMap[]> getAllGameMaps() {
*/
public record GameMap(String game, String unique_name, String map_name, String layout, int team_size,
int build_limit,
String colours, Generator[] generators) {

}

/**
* Generator
*/
public record Generator(String unique_name, int ordering, String gen_type, String gen_location,
int level,
int count) {
String colours) {

}

Expand Down

0 comments on commit 07f1a30

Please sign in to comment.