Skip to content

Instantly share code, notes, and snippets.

@aerouk
Created May 4, 2017 15:07
Show Gist options
  • Save aerouk/27aea8b7dd33890bc955209a9cfcd723 to your computer and use it in GitHub Desktop.
Save aerouk/27aea8b7dd33890bc955209a9cfcd723 to your computer and use it in GitHub Desktop.
[osu!] parse mods from bitwise mod value
public static final Map<String, Integer> osuMods = new LinkedHashMap<String, Integer>();
public OsuListener()
{
osuMods.put("NF", 1);
osuMods.put("EZ", 2);
osuMods.put("HD", 8);
osuMods.put("HR", 16);
osuMods.put("SD", 32);
osuMods.put("DT", 64);
osuMods.put("RL", 128);
osuMods.put("HT", 256);
osuMods.put("NC", 512);
osuMods.put("FL", 1024);
}
/**
* Parses the mods from the corresponding bitwise value.
*
* @param bitVal bitwise mod value
* @return corresponding mods enabled
*/
public String parseMods(String bitVal)
{
String mods = "";
int i = Integer.parseInt(bitVal);
ListIterator<Entry<String, Integer>> iter = new ArrayList<>(osuMods.entrySet()).listIterator(osuMods.size());
// go through list backwards for proper display order
while (iter.hasPrevious()) {
Entry<String, Integer> entry = iter.previous();
if (i >= entry.getValue()) {
i -= entry.getValue();
// handle repeated implied mods (e.g. NC implies DT)
if (entry.getKey().equals("NC")) {
i -= osuMods.get("DT");
}
mods = entry.getKey() + mods;
}
}
return mods;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment