Skip to content

Commit

Permalink
add option to ignore chroma events
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-hydrogen committed Feb 12, 2022
1 parent 1017a16 commit 94d9b97
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/main/java/com/ilm9001/nightclub/beatmap/BeatmapParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BeatmapParser {
* @return InfoData which includes bpm, artist, song folder and the beatmaps author.
* Returns null if no info.dat file can be found.
*/
public static @Nullable InfoData getInfoData(String folder) {
public static @Nullable InfoData getInfoData(String folder, boolean dontUseChroma) {
File dataFolder = Nightclub.DATA_FOLDER;
File infoFolder = new File(dataFolder + "/" + folder);
@SuppressWarnings("ConstantConditions") // compiler warns about "infoFolder.listFiles() might be null". please tell me how.
Expand Down Expand Up @@ -77,7 +77,7 @@ public class BeatmapParser {
secondaryColor = new Color(envColorLeft.get("r").getAsFloat(), envColorRight.get("g").getAsFloat(), envColorRight.get("b").getAsFloat());
isChroma = true;
}
if (requirements != null && !isChroma) {
if (requirements != null) {
isChroma = requirements.contains(new JsonPrimitive("Chroma"))
|| requirements.contains(new JsonPrimitive("Chroma Lighting Events"))
|| requirements.contains(new JsonPrimitive("Chroma Special Events"));
Expand All @@ -102,7 +102,7 @@ public class BeatmapParser {
.mapper(info.get("_levelAuthorName").getAsString())
.songSubName(info.get("_songSubName").getAsString())
.beatmapFileName(filename)
.isChroma(isChroma)
.isChroma(!dontUseChroma && isChroma)
.primaryColor(primaryColor)
.secondaryColor(secondaryColor)
.build();
Expand All @@ -113,11 +113,11 @@ public class BeatmapParser {
* @param name Folder where beatmap is (/name/ExpertPlus.dat/)
* @return List of LightEvent's in the beatmap file. Returns an empty list if info file can't be found
*/
public static @NotNull List<LightEvent> getEvents(String name) {
public static @NotNull List<LightEvent> getEvents(String name, boolean dontUseChroma) {
File dataFolder = Nightclub.DATA_FOLDER;
List<LightEvent> events = new ArrayList<>();
JsonArray eventArray;
InfoData info = BeatmapParser.getInfoData(name);
InfoData info = BeatmapParser.getInfoData(name, dontUseChroma);
if (info == null) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ public class BeatmapPlayer {
private ScheduledExecutorService executorService;
@Getter private boolean isPlaying;

public BeatmapPlayer(String name) {
this(name, false);
}
/**
* Constructor that defines a new Beatmap you can play from.
*
* @param name name of the folder the beatmap itself resides in (/name/ExpertPlus.dat)
*/
public BeatmapPlayer(String name) {
info = BeatmapParser.getInfoData(name);
events = BeatmapParser.getEvents(name);
public BeatmapPlayer(String name, boolean dontUseChroma) {
info = BeatmapParser.getInfoData(name, dontUseChroma);
events = BeatmapParser.getEvents(name, dontUseChroma);
this.name = name;
playTo = new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ public static void onPlay(CommandSender sender, String[] args) {
List<CommandError> errors = LightUniverseCommand.isUnloaded(args, 1);
errors.add(Util.getStringValuesFromArray(new File(Nightclub.getInstance().getDataFolder().getAbsolutePath()).listFiles(File::isDirectory))
.stream().noneMatch(beatmap -> args[0].equals(beatmap)) ? CommandError.INVALID_ARGUMENT : CommandError.VALID);
errors.add(args.length >= 2 && !(args[1].toLowerCase().contains("true") || args[1].toLowerCase().contains("false")) ? CommandError.INVALID_ARGUMENT : CommandError.VALID);
if (errors.stream().anyMatch(error -> error != CommandError.VALID)) {
sender.sendMessage(formatErrors(errors));
return;
}
player = new BeatmapPlayer(args[0]);
player = new BeatmapPlayer(args[0], args.length >= 2 && Boolean.parseBoolean(args[1]));
ArrayList<Player> playTo = new ArrayList<>(Bukkit.getOnlinePlayers());
InfoData info = player.play(playTo);
String playBackMessage = ChatColor.GOLD + "Now Playing: " + ChatColor.AQUA + info.getSongAuthorName() + " - " + info.getSongName() + " " + info.getSongSubName() + System.lineSeparator()
Expand Down

0 comments on commit 94d9b97

Please sign in to comment.