Last active
April 26, 2019 04:45
-
-
Save ve3/172a3ac5b8c957dab8f9dbee5f33058b to your computer and use it in GitHub Desktop.
Kingdom Rush Origins format save data to readable achievements.
This file contains hidden or 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 | |
if (!is_file('filtered-savefile.php')) { | |
die('Unable to get filtered data, please run save-file.php first.'); | |
} | |
require 'filtered-savefile.php'; | |
// https://steamdb.info/app/816340/history/ | |
$string = "achievements/HARD_MODE/defaultvalue: 0 | |
achievements/HARD_MODE/description: Complete the Campaign in Veteran difficulty. | |
achievements/HARD_MODE/displayName: Supreme Defender | |
achievements/HARD_MODE/hidden: 0 | |
achievements/HARD_MODE/icon: a471516a41805961e260f89630d5bfa528633bd4.jpg | |
achievements/HARD_MODE/icongray: b4bbebb5446dfbc8d919c399658232fa8035c045.jpg | |
achievements/IMPOSSIBLE_MODE/defaultvalue: 0 | |
... | |
"; | |
$string = str_replace(["\r\n", "\r", "\n"], "\n", trim($string)); | |
$stringLines = explode("\n", $string); | |
$totalAchievementsLines = count($stringLines) / 6; | |
$achievementsArray = []; | |
echo 'total achievements: ' . $totalAchievementsLines . '<br>' . PHP_EOL; | |
if (is_array($stringLines)) { | |
$workingKey = ''; | |
foreach ($stringLines as $eachLine) { | |
if (empty(trim($eachLine))) { | |
continue; | |
} | |
preg_match('#\/(?P<key>.+)\/(?P<definename>.+):\s+(?P<definevalue>.+)#', $eachLine, $matches); | |
if (isset($matches['key']) && isset($matches['definename']) && isset($matches['definevalue'])) { | |
if ($workingKey === '') { | |
$workingKey = $matches['key']; | |
} | |
if (!isset($achievementsArray[$workingKey])) { | |
$achievementsArray[$workingKey] = []; | |
} elseif ($matches['definename'] === 'displayName') { | |
$achievementsArray[$workingKey]['name'] = $matches['definevalue']; | |
} elseif ($matches['definename'] === 'description') { | |
$achievementsArray[$workingKey]['desc'] = $matches['definevalue']; | |
} | |
if (isset($achievementsArray[$workingKey]['name']) && isset($achievementsArray[$workingKey]['desc'])) { | |
$workingKey = ''; | |
} | |
} | |
} | |
unset($workingKey); | |
} | |
$matchedAchievementsInSave = ''; | |
$matchedCount = 0; | |
if (is_array($savedata)) { | |
foreach ($savedata as $eachKey) { | |
if (array_key_exists($eachKey, $achievementsArray)) { | |
$matchedAchievementsInSave .= $eachKey . ' => '; | |
$matchedAchievementsInSave .= '<strong>' . $achievementsArray[$eachKey]['name'] . '</strong><br>' . PHP_EOL; | |
$matchedAchievementsInSave .= str_repeat(' ', 9) . PHP_EOL; | |
$matchedAchievementsInSave .= '<span style="color: #ccc; font-size: 0.95rem;">' . $achievementsArray[$eachKey]['desc'] . '</span>' . PHP_EOL; | |
$matchedAchievementsInSave .= '<br>' . PHP_EOL; | |
$matchedAchievementsInSave .= '<br>' . PHP_EOL; | |
unset($achievementsArray[$eachKey]); | |
$matchedCount++; | |
} | |
} | |
} | |
echo 'matched achievements in save file: ' . $matchedCount . '<br>' . PHP_EOL; | |
echo $matchedAchievementsInSave . PHP_EOL; | |
unset($matchedAchievementsInSave, $matchedCount); | |
echo '<hr>' . PHP_EOL; | |
echo 'achievements that don\'t have any counter: ' . count($achievementsArray) . '<br>' . PHP_EOL; | |
foreach ($achievementsArray as $key => $item) { | |
echo $key . ' => '; | |
echo '<strong>' . $item['name'] . '</strong><br>' . PHP_EOL; | |
echo str_repeat(' ', 9) . PHP_EOL; | |
echo '<span style="color: #ccc; font-size: 0.95rem;">' . $item['desc'] . '</span>' . PHP_EOL; | |
echo '<br>' . PHP_EOL; | |
echo '<br>' . PHP_EOL; | |
} | |
echo 'thanks to <a href="https://steamdb.info/app/816340/history/">https://steamdb.info/app/816340/history/</a><br>' . PHP_EOL; | |
echo 'see guide here <a href="https://steamcommunity.com/sharedfiles/filedetails/?id=1723581789">https://steamcommunity.com/sharedfiles/filedetails/?id=1723581789</a> |
This file contains hidden or 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 | |
$str = '["ARCANE_BURST"] = xxx; | |
["ART_OF_WAR"] = xxx; | |
["BEORNINGS"] = xxx; | |
...'; | |
$str = str_replace(["\r\n", "\r", "\n"], "\n", $str); | |
$exploded = explode("\n", $str); | |
$keynames = []; | |
if (is_array($exploded)) { | |
foreach ($exploded as $eachLine) { | |
preg_match('#([a-z_]+)#i', $eachLine, $matches); | |
if (isset($matches[1])) { | |
$keynames[] = $matches[1]; | |
} | |
} | |
} | |
echo '<pre>' . var_export($keynames, true) . '</pre>' . PHP_EOL; | |
file_put_contents('filtered-savefile.php', '<?php' . PHP_EOL . PHP_EOL . '$savedata = ' . var_export($keynames, true) . ';' . PHP_EOL . PHP_EOL); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment