api: add fallback values for hmd identification
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 31s

This commit is contained in:
Lee 2024-08-05 05:57:50 +01:00
parent 6cb86f843d
commit 54bdf532fe
2 changed files with 46 additions and 10 deletions

@ -9,37 +9,49 @@ import lombok.Getter;
@AllArgsConstructor
@Getter
public enum DeviceHeadset {
UNKNOWN("Unknown"),
UNKNOWN("Unknown", 0),
/**
* Oculus HMDs
*/
OCULUS_CV1("Rift"),
OCULUS_QUEST("Quest"),
OCULUS_QUEST_2("Quest 2"),
OCULUS_QUEST_3("Quest 3"),
OCULUS_RIFT_S("Rift S"),
OCULUS_CV1("Rift", 1),
OCULUS_QUEST("Quest", 32),
OCULUS_QUEST_2("Quest 2", -1),
OCULUS_QUEST_3("Quest 3", -1),
OCULUS_RIFT_S("Rift S", 16),
/**
* Windows Mixed Reality HMDs
* todo: find the new format name
*/
WINDOWS_MR("Windows Mixed Reality", 8),
/**
* HTC HMDs
*/
HTC_VIVE("Vive"),
HTC_VIVE("Vive", 2),
HTC_VIVE_COSMOS("Vive Cosmos", 128),
/**
* HP HMDs
*/
HP_REVERB("HP Reverb"),
HP_REVERB("HP Reverb", -1),
/**
* Valve HMDs
*/
VALVE_INDEX("Valve Index");
VALVE_INDEX("Valve Index", 64);
/**
* The name of the headset.
*/
private final String name;
/**
* The fallback value of the headset.
*/
private final int fallbackValue;
/**
* Gets a headset by its name.
*
@ -54,4 +66,19 @@ public enum DeviceHeadset {
}
return null;
}
/**
* Gets a headset by its fallback value.
*
* @param fallbackValue the fallback value of the headset
* @return the headset
*/
public static DeviceHeadset getByFallbackValue(int fallbackValue) {
for (DeviceHeadset deviceHeadset : values()) {
if (deviceHeadset.getFallbackValue() == fallbackValue) {
return deviceHeadset;
}
}
return null;
}
}

@ -199,6 +199,14 @@ public class ScoreService {
double pp = score.getPp() != 0 ? PlatformService.INSTANCE.getScoreSaberPlatform().getPp(leaderboard.getStars(), accuracy) : 0; // Recalculate the pp
String[] modifiers = !score.getModifiers().isEmpty() ? score.getModifiers().split(",") : new String[0];
DeviceHeadset deviceHmd;
boolean legacyDeviceInformation = score.getDeviceHmd() == null && score.getHmd() != 0;
if (!legacyDeviceInformation) { // Use the new format
deviceHmd = DeviceHeadset.getByName(score.getDeviceHmd());
} else { // Use the legacy format (only includes the HMD, missing controller information)
deviceHmd = DeviceHeadset.getByFallbackValue(score.getHmd());
}
ScoreSaberScore scoreSaberScore = new ScoreSaberScore(
counterService.getNext(CounterService.CounterType.SCORE),
user.getSteamId(),
@ -213,7 +221,7 @@ public class ScoreService {
score.getMissedNotes() == 0 ? null : score.getMissedNotes(), // no misses, set to null to save data
score.getBadCuts() == 0 ? null : score.getBadCuts(), // no bad cuts, set to null to save data
new DeviceInformation(
score.getDeviceHmd() == null ? DeviceHeadset.UNKNOWN : DeviceHeadset.getByName(score.getDeviceHmd()),
deviceHmd,
score.getDeviceControllerLeft() == null ? DeviceController.UNKNOWN : DeviceController.getByName(score.getDeviceControllerLeft()),
score.getDeviceControllerRight() == null ? DeviceController.UNKNOWN : DeviceController.getByName(score.getDeviceControllerRight())
),
@ -224,6 +232,7 @@ public class ScoreService {
);
this.saveScore(user, scoreSaberScore);
this.logScore(Platform.Platforms.SCORESABER, Leaderboard.getFromScoreSaberToken(leaderboard), scoreSaberScore, user);
log.info(" - Using legacy device information, headset found: {} (missing controller information)", deviceHmd);
}
/**