Last active
July 22, 2019 13:46
-
-
Save hakasenyang/07bd86e3b5eda65c314cc910893ff35a to your computer and use it in GitHub Desktop.
PHP - osu! Gamemode Converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 게임모드 변환 함수 | |
* 레퍼런스 참조는 아래 주석. | |
* https://github.com/ppy/osu-api/wiki | |
* enum Mods | |
* { | |
* None = 0, | |
* NoFail = 1, | |
* Easy = 2, | |
* TouchDevice = 4, | |
* Hidden = 8, | |
* HardRock = 16, | |
* SuddenDeath = 32, | |
* DoubleTime = 64, | |
* Relax = 128, | |
* HalfTime = 256, | |
* Nightcore = 512, // Only set along with DoubleTime. i.e: NC only gives 576 | |
* Flashlight = 1024, | |
* Autoplay = 2048, | |
* SpunOut = 4096, | |
* Relax2 = 8192, // Autopilot | |
* Perfect = 16384, // Only set along with SuddenDeath. i.e: PF only gives 16416 | |
* Key4 = 32768, | |
* Key5 = 65536, | |
* Key6 = 131072, | |
* Key7 = 262144, | |
* Key8 = 524288, | |
* FadeIn = 1048576, | |
* Random = 2097152, | |
* Cinema = 4194304, | |
* Target = 8388608, | |
* Key9 = 16777216, | |
* KeyCoop = 33554432, | |
* Key1 = 67108864, | |
* Key3 = 134217728, | |
* Key2 = 268435456, | |
* ScoreV2 = 536870912, | |
* LastMod = 1073741824, | |
* KeyMod = Key1 | Key2 | Key3 | Key4 | Key5 | Key6 | Key7 | Key8 | Key9 | KeyCoop, | |
* FreeModAllowed = NoFail | Easy | Hidden | HardRock | SuddenDeath | Flashlight | FadeIn | Relax | Relax2 | SpunOut | KeyMod, | |
* ScoreIncreaseMods = Hidden | HardRock | DoubleTime | Flashlight | FadeIn | |
* } | |
*/ | |
/** | |
* gamemode_to_str :: gamemode 값을 String 으로 반환 | |
* @param int $gamemode 모드 값 (mysql 에서 나온 값) 입력 | |
* @return string 데이터 출력 (osu!, Taiko, CTB, osu!mania, Unknown) | |
*/ | |
function gamemode_to_str($gamemode) { | |
switch ($gamemode) { | |
case 0: | |
return 'osu!'; | |
case 1: | |
return 'Taiko'; | |
case 2: | |
return 'CTB'; | |
case 3: | |
return 'osu!mania'; | |
default: | |
return 'Unknown'; | |
} | |
} | |
/** | |
* mode_to_str :: mode 값을 String 으로 반환 | |
* @param int $mode 모드 값 (mysql 에서 나온 값) 입력 | |
* @return string 데이터 출력 (+ DT, RX, FL, SO) | |
*/ | |
function mode_to_str($mode) { | |
$mods = [ | |
'NF' => 0x1, // NoFail | |
'EZ' => 0x2, // Easy | |
'TD' => 0x4, // TouchDevice | |
'HD' => 0x8, // Hidden | |
'HR' => 0x10, // HardRock | |
'SD' => 0x20, // SuddenDeath | |
'DT' => 0x40, // DoubleTime | |
'RX' => 0x80, // Relax | |
'HF' => 0x100, // HalfTime | |
'NC' => 0x200, // Nightcore | |
'FL' => 0x400, // Flashlight | |
'Auto' => 0x800, // Auto | |
'SO' => 0x1000, // SpunOut | |
'AP' => 0x2000, // Autopilot | |
'PF' => 0x4000, // Perfect | |
'K4' => 0x8000, // Key4 | |
'K5' => 0x10000, // Key5 | |
'K6' => 0x20000, // Key6 | |
'K7' => 0x40000, // Key7 | |
'K8' => 0x80000, // Key8 | |
'FadeIn' => 0x100000, // FadeIn | |
'Random' => 0x200000, // Random | |
'Cinema' => 0x400000, // Cinema | |
'Target' => 0x800000, // Target?? | |
'K9' => 0x1000000, // Key9 | |
'KC' => 0x2000000, // KeyCoop | |
'K1' => 0x4000000, // Key1 | |
'K3' => 0x8000000, // Key3 | |
'K2' => 0x10000000, // Key2 | |
'ScoreV2' => 0x20000000, // ScoreV2 | |
'Lastmod' => 0x40000000 // LastMod | |
]; | |
// SD, PF, DT, NC 값 (위에 이름 바꿀 경우를 대비해서 hard-coding) | |
$specialmod = [ | |
/* SD, PF, DT, NC */ | |
0x20, 0x4000, 0x40, 0x200 | |
]; | |
// SD + PF = PF 통합하기 | |
if ($mode & $specialmod[0] && $mode & $specialmod[1]) $mode = $mode - $specialmod[0]; | |
// DT + NC = NC 통합하기 | |
if ($mode & $specialmod[2] && $mode & $specialmod[3]) $mode = $mode - $specialmod[2]; | |
foreach($mods as $name => $value) { | |
if ($mode & $value) $ret .= $name . ', '; | |
} | |
// 마지막 2글자 빼기. | |
if (strlen($ret) > 0) | |
return substr($ret, 0, -2); | |
else | |
return NULL; | |
} | |
// 예제 | |
echo mode_to_str(18046); // EZ, TD, HD, HR, NC, FL, PF | |
echo PHP_EOL; | |
echo gamemode_to_str(1); // Taiko | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment