cleaned up category code

This commit is contained in:
Stachelbeere1248 2023-11-09 11:26:50 +01:00
parent 8e5d2881a3
commit a53195bedf
5 changed files with 46 additions and 52 deletions

View file

@ -2,8 +2,8 @@ package com.github.stachelbeere1248.zombiesutils;
import com.github.stachelbeere1248.zombiesutils.commands.CategoryCommand;
import com.github.stachelbeere1248.zombiesutils.commands.SlaCommand;
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.config.Hotkeys;
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.handlers.ChatHandler;
import com.github.stachelbeere1248.zombiesutils.handlers.TickHandler;
import com.github.stachelbeere1248.zombiesutils.render.RenderGameOverlayHandler;

View file

@ -10,6 +10,7 @@ public class ZombiesUtilsConfig {
public static Configuration config;
private static boolean slaToggle;
private static String chatMacro;
private static String defaultCategory;
public static void load() {
ZombiesUtils.getInstance().getLogger().debug("Loading config...");
config.load();
@ -26,7 +27,13 @@ public class ZombiesUtilsConfig {
Configuration.CATEGORY_GENERAL,
"T",
"The Text to be sent when pressing the chat-macro hotkey"
);
);
defaultCategory = config.getString(
"Default Category",
Configuration.CATEGORY_GENERAL,
"general",
"name of the category to be selected unless specified using /runCategory"
);
ZombiesUtils.getInstance().getLogger().debug("Saving Config...");
config.save();
@ -45,4 +52,7 @@ public class ZombiesUtilsConfig {
public static String getChatMacro() {
return chatMacro;
}
public static String getDefaultCategory() {
return defaultCategory;
}
}

View file

@ -4,27 +4,17 @@ import org.jetbrains.annotations.NotNull;
@SuppressWarnings("DuplicatedCode")
public class GameMode {
private static GameMode currentGameMode = null;
public static final GameMode DEAD_END_NORMAL = new GameMode(Map.DEAD_END), DEAD_END_HARD = new GameMode(Map.DEAD_END, Difficulty.HARD), DEAD_END_RIP = new GameMode(Map.DEAD_END, Difficulty.RIP);
public static final GameMode BAD_BLOOD_NORMAL = new GameMode(Map.BAD_BLOOD), BAD_BLOOD_HARD = new GameMode(Map.BAD_BLOOD, Difficulty.HARD), BAD_BLOOD_RIP = new GameMode(Map.BAD_BLOOD, Difficulty.RIP);
public static final GameMode ALIEN_ARCADIUM = new GameMode(Map.ALIEN_ARCADIUM);
public static GameMode currentGameMode = null;
private final Map map;
private final Difficulty difficulty;
private Difficulty difficulty;
private GameMode (@NotNull Map map, @NotNull Difficulty difficulty) {
this.map = map;
this.difficulty = difficulty;
}
private GameMode(@NotNull Map map) {
public GameMode(@NotNull Map map) {
this.map = map;
this.difficulty = Difficulty.NORMAL;
}
public static void create(@NotNull Map map) {
switch (map) {
case DEAD_END: currentGameMode = DEAD_END_NORMAL; break;
case BAD_BLOOD: currentGameMode = BAD_BLOOD_NORMAL; break;
case ALIEN_ARCADIUM: currentGameMode = ALIEN_ARCADIUM; break;
}
public GameMode(@NotNull Map map, @NotNull Difficulty difficulty) {
this.map = map;
this.difficulty = difficulty;
}
public Map getMap() {
return map;
@ -34,21 +24,11 @@ public class GameMode {
}
public void changeDifficulty(@NotNull Difficulty difficulty) {
switch (map) {
case DEAD_END: case BAD_BLOOD:
this.difficulty = difficulty;
break;
case ALIEN_ARCADIUM:
throw new RuntimeException("Achievement Get: Alien Arcadium Hard/RIP" + Map.ALIEN_ARCADIUM);
case DEAD_END:
switch (difficulty) {
case NORMAL: currentGameMode = DEAD_END_NORMAL; break;
case HARD: currentGameMode = DEAD_END_HARD; break;
case RIP: currentGameMode = DEAD_END_RIP; break;
}
break;
case BAD_BLOOD:
switch (difficulty) {
case NORMAL: currentGameMode = BAD_BLOOD_NORMAL; break;
case HARD: currentGameMode = BAD_BLOOD_HARD; break;
case RIP: currentGameMode = BAD_BLOOD_RIP; break;
} break;
}
}
public static GameMode getCurrentGameMode() {
@ -62,7 +42,7 @@ public class GameMode {
currentGameMode = null;
}
public boolean equals(@NotNull GameMode gameMode) {
return (this.getDifficulty() == gameMode.getDifficulty() && this.getMap() == gameMode.getMap());
public boolean is(Map map, Difficulty difficulty) {
return this.getDifficulty() == difficulty && this.getMap() == map;
}
}

View file

@ -34,7 +34,7 @@ public class Timer {
else throw new RuntimeException("invalid servernumber");
this.category = new Category();
GameMode.create(map);
GameMode.currentGameMode = new GameMode(map);
if (ZombiesUtilsConfig.isSlaToggled()) SLA.instance = new SLA(map);
}

View file

@ -1,45 +1,49 @@
package com.github.stachelbeere1248.zombiesutils.timer.recorder;
import com.github.stachelbeere1248.zombiesutils.config.ZombiesUtilsConfig;
import com.github.stachelbeere1248.zombiesutils.game.Difficulty;
import com.github.stachelbeere1248.zombiesutils.game.GameMode;
import com.github.stachelbeere1248.zombiesutils.game.Map;
import com.github.stachelbeere1248.zombiesutils.timer.Timer;
import org.jetbrains.annotations.NotNull;
import java.io.File;
public class Category {
private static String selectedCategory = "general"; // read from config ?
private static String selectedCategory = ZombiesUtilsConfig.getDefaultCategory();
public final TimesFile[] timesFiles = new TimesFile[7];
private final String name;
public Category() {
timesFiles[0] = new TimesFile(selectedCategory, GameMode.DEAD_END_NORMAL);
timesFiles[1] = new TimesFile(selectedCategory, GameMode.DEAD_END_HARD);
timesFiles[2] = new TimesFile(selectedCategory, GameMode.DEAD_END_RIP);
timesFiles[0] = new TimesFile(selectedCategory, new GameMode(Map.DEAD_END));
timesFiles[1] = new TimesFile(selectedCategory, new GameMode(Map.DEAD_END, Difficulty.HARD));
timesFiles[2] = new TimesFile(selectedCategory, new GameMode(Map.DEAD_END, Difficulty.RIP));
timesFiles[3] = new TimesFile(selectedCategory, GameMode.BAD_BLOOD_NORMAL);
timesFiles[4] = new TimesFile(selectedCategory, GameMode.BAD_BLOOD_HARD);
timesFiles[5] = new TimesFile(selectedCategory, GameMode.BAD_BLOOD_RIP);
timesFiles[3] = new TimesFile(selectedCategory, new GameMode(Map.BAD_BLOOD));
timesFiles[4] = new TimesFile(selectedCategory, new GameMode(Map.BAD_BLOOD, Difficulty.HARD));
timesFiles[5] = new TimesFile(selectedCategory, new GameMode(Map.BAD_BLOOD, Difficulty.RIP));
timesFiles[6] = new TimesFile(selectedCategory, GameMode.ALIEN_ARCADIUM);
timesFiles[6] = new TimesFile(selectedCategory, new GameMode(Map.ALIEN_ARCADIUM));
name = selectedCategory;
}
public TimesFile getByGameMode(@NotNull GameMode gameMode) {
if (gameMode.equals(GameMode.DEAD_END_NORMAL)) return timesFiles[0];
if (gameMode.equals(GameMode.DEAD_END_HARD)) return timesFiles[1];
if (gameMode.equals(GameMode.DEAD_END_RIP)) return timesFiles[2];
if (gameMode.equals(GameMode.BAD_BLOOD_NORMAL)) return timesFiles[3];
if (gameMode.equals(GameMode.BAD_BLOOD_HARD)) return timesFiles[4];
if (gameMode.equals(GameMode.BAD_BLOOD_RIP)) return timesFiles[5];
if (gameMode.equals(GameMode.ALIEN_ARCADIUM)) return timesFiles[6];
throw new IllegalStateException("Unexpected value: " + gameMode);
if (gameMode.is(Map.DEAD_END, Difficulty.NORMAL)) return timesFiles[0];
else if (gameMode.is(Map.BAD_BLOOD, Difficulty.NORMAL)) return timesFiles[3];
else if (gameMode.is(Map.ALIEN_ARCADIUM, Difficulty.NORMAL)) return timesFiles[6];
else if (gameMode.is(Map.DEAD_END, Difficulty.HARD)) return timesFiles[1];
else if (gameMode.is(Map.DEAD_END, Difficulty.RIP)) return timesFiles[2];
else if (gameMode.is(Map.BAD_BLOOD, Difficulty.HARD)) return timesFiles[4];
else if (gameMode.is(Map.BAD_BLOOD, Difficulty.RIP)) return timesFiles[5];
else throw new IllegalStateException("Unexpected value: " + gameMode);
}
public static void setSelectedCategory(String selectedCategory) {
Category.selectedCategory = selectedCategory;
if (!Timer.getInstance().isPresent()) return;
Timer.getInstance().get().category = new Category();
Timer.getInstance().ifPresent(timer -> timer.setCategory(new Category()));
}
public static String[] getCategories() {
File dir = new File("zombies");