Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add warn if DUETSINGERP tag used not for duet song #56

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.nianna.karedi.problem;

import com.github.nianna.karedi.I18N;

public class DuetTagNotForDuetProblem extends TagProblem {

public DuetTagNotForDuetProblem(String key) {
super(Severity.WARNING, I18N.get("problem.tag.duet_not_for_duet.title", key), key);
}

}
10 changes: 10 additions & 0 deletions src/main/java/com/github/nianna/karedi/song/SongChecker.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.nianna.karedi.song;

import com.github.nianna.karedi.problem.DuetTagNotForDuetProblem;
import com.github.nianna.karedi.problem.InvalidMedleyBeatRangeProblem;
import com.github.nianna.karedi.problem.InvalidMedleyLengthProblem;
import com.github.nianna.karedi.problem.MedleyMissingProblem;
Expand Down Expand Up @@ -113,6 +114,15 @@ private void validateTagKey(String tagKey) {
.ifPresent(ignored -> combiner.add(new TagForNonexistentTrackProblem(tagKey)));
}

if (isADuetSingerTagForExistingTrackInNotDuetSong(tagKey)) {
combiner.add(new DuetTagNotForDuetProblem(tagKey));
}

}

private boolean isADuetSingerTagForExistingTrackInNotDuetSong(String tagKey) {
return TagKey.isKey(tagKey, TagKey.DUETSINGERP1) && song.getTrackCount() != 2
|| TagKey.isKey(tagKey, TagKey.DUETSINGERP2) && song.getTrackCount() > 2;
}

private void performAdditionalValueValidation(TagKey key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public final class MultiplayerTags {

private static final Pattern MULTIPLAYER_TAG_NAME_PATTERN = Pattern.compile("(DUETSINGERP|P)(\\d+)");
private static final Pattern TAG_KEY_PATTERN = Pattern.compile("DUETSINGERP([12])|P([1-9]\\d*)");

private MultiplayerTags() {
}
Expand All @@ -19,7 +19,7 @@ public static boolean isANameTag(Tag tag) {
}

public static boolean isANameTagKey(String tagKey) {
return MULTIPLAYER_TAG_NAME_PATTERN.matcher(tagKey).matches();
return TAG_KEY_PATTERN.matcher(tagKey).matches();
}

public static String getTagKeyForTrackNumber(int index, FormatSpecification formatSpecification) {
Expand All @@ -39,9 +39,10 @@ public static Optional<Integer> getTrackNumber(String tagKey) {
}

private static Optional<Integer> getPlayerNumber(String tagKey) {
Matcher matcher = MULTIPLAYER_TAG_NAME_PATTERN.matcher(tagKey);
Matcher matcher = TAG_KEY_PATTERN.matcher(tagKey);
if (matcher.find()) {
return Converter.toInteger(matcher.group(2));
String playerNumber = Optional.ofNullable(matcher.group(1)).orElseGet(() -> matcher.group(2));
return Converter.toInteger(playerNumber);
}
return Optional.empty();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ problem.tag.validation_fail.title=Tag validation failed
problem.tag.validation_fail.full_title=Tag validation failed #{0}
problem.tag.unsupported.title=Unsupported tag #{0}
problem.tag.nonexistent_track.title=Tag #{0} defines name for nonexistent track
problem.tag.duet_not_for_duet.title=Tag #{0} defined not for duet song
problem.tag.inconsistent.title=Tags #{0} and #{1} are inconsistent
problem.tag.inconsistent.description=These tags have the same meaning, remove one of them or use the same value
problem.uncommon_golden_bonus.title=Uncommon golden bonus
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_en_GB.properties
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ problem.tag.validation_fail.title=Tag validation failed
problem.tag.validation_fail.full_title=Tag validation failed #{0}
problem.tag.unsupported.title=Unsupported tag #{0}
problem.tag.nonexistent_track.title=Tag #{0} defines name for nonexistent track
problem.tag.duet_not_for_duet.title=Tag #{0} defined not for duet song
problem.tag.inconsistent.title=Tags #{0} and #{1} are inconsistent
problem.tag.inconsistent.description=These tags have the same meaning, remove one of them or use the same value
problem.uncommon_golden_bonus.title=Uncommon golden bonus
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_pl_PL.properties
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ problem.tag.inconsistent.title=Tagi #{0} i #{1} s\u0105 niesp
problem.tag.inconsistent.description=Te tagi maj\u0105 t\u0105 sam\u0105 funkcj\u0119, usu\u0144 jeden z nich lub ustaw t\u0105 sam\u0105 warto\u015B\u0107
problem.tag.unsupported.title=Niewspierany tag #{0}
problem.tag.nonexistent_track.title=Tag #{0} definiuje nazw\u0119 dla nieistniej\u0105cej \u015Bcie\u017Cki
problem.tag.duet_not_for_duet.title=Tag #{0} u\u017Cyty nie w duecie
problem.uncommon_golden_bonus.title=Niepoprawny bonus za z\u0142ote nuty
problem.uncommon_golden_bonus.full_title=Niepoprawny bonus za z\u0142ote nuty ({0, number} punktów)
problem.uncommon_golden_bonus.description=Z\u0142ote nuty powinny by\u0107 warte od {0, number, integer} do {1, number, integer} punktów
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
public class MultiplayerTagsTest {

@ParameterizedTest
@ValueSource(strings = {"DUETSINGERP1", "DUETSINGERP2", "P1", "P2", "P3"})
@ValueSource(strings = {"DUETSINGERP1", "DUETSINGERP2", "P1", "P20", "P9"})
public void recognizesValidNameTagKeys(String key) {
Tag tag = new Tag(key, "");
assertTrue(MultiplayerTags.isANameTag(tag));
}

@ParameterizedTest
@ValueSource(strings = {"DUETSINGERP0", "DUETSINGERP3", "P0", "P02"})
public void doesNotRecognizeInvalidNameTags(String key) {
Tag tag = new Tag(key, "");
assertFalse(MultiplayerTags.isANameTag(tag));
}

@Test
public void otherTagKeysAreNotRecognizedAsNameTags() {
Tag tag = new Tag("ARTIST", "");
Expand All @@ -30,10 +37,10 @@ public void otherTagKeysAreNotRecognizedAsNameTags() {

@Test
public void extractsCorrectTrackNumbersFromValidDuetSingerPTags() {
Tag tag = new Tag("DUETSINGERP3", "");
Tag tag = new Tag("DUETSINGERP2", "");
Optional<Integer> result = MultiplayerTags.getTrackNumber(tag);
assertTrue(result.isPresent());
assertEquals((Integer) 2, result.get());
assertEquals((Integer) 1, result.get());
}

@Test
Expand Down
Loading