forgot file and maybe min compatible php 5.5

This commit is contained in:
Nereziel
2024-02-03 16:43:50 +01:00
parent eb6cdfc98d
commit 8f0e8a0a63
3 changed files with 101 additions and 28 deletions

View File

@@ -11,20 +11,20 @@ class UtilsClass
*
* @return array An associative array containing skin data.
*/
public static function skinsFromJson(): array
public static function skinsFromJson()
{
$skins = [];
$skins = array();
$jsonFilePath = __DIR__ . "/../data/skins.json";
if (file_exists($jsonFilePath) && is_readable($jsonFilePath)) {
$json = json_decode(file_get_contents($jsonFilePath), true);
foreach ($json as $skin) {
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = [
$skins[(int) $skin['weapon_defindex']][(int) $skin['paint']] = array(
'weapon_name' => $skin['weapon_name'],
'paint_name' => $skin['paint_name'],
'image_url' => $skin['image'],
];
);
}
} else {
// Handle file not found or unreadable error
@@ -39,17 +39,17 @@ class UtilsClass
*
* @return array An associative array containing weapon data.
*/
public static function getWeaponsFromArray(): array
public static function getWeaponsFromArray()
{
$weapons = [];
$weapons = array();
$skinsData = self::skinsFromJson();
foreach ($skinsData as $key => $value) {
$weapons[$key] = [
$weapons[$key] = array(
'weapon_name' => $value[0]['weapon_name'],
'paint_name' => $value[0]['paint_name'],
'image_url' => $value[0]['image_url'],
];
);
}
return $weapons;
@@ -60,32 +60,32 @@ class UtilsClass
*
* @return array An associative array containing knife types data.
*/
public static function getKnifeTypes(): array
public static function getKnifeTypes()
{
$knifes = [];
$knifes = array();
$weaponsData = self::getWeaponsFromArray();
$allowedKnifeKeys = [
$allowedKnifeKeys = array(
500, 503, 505, 506, 507, 508, 509, 512, 514, 515,
516, 517, 518, 519, 520, 521, 522, 523, 525
];
);
foreach ($weaponsData as $key => $weapon) {
if (in_array($key, $allowedKnifeKeys)) {
$knifes[$key] = [
$knifes[$key] = array(
'weapon_name' => $weapon['weapon_name'],
'paint_name' => rtrim(explode("|", $weapon['paint_name'])[0]),
'image_url' => $weapon['image_url'],
];
);
}
}
// Add default knife
$knifes[0] = [
$knifes[0] = array(
'weapon_name' => "weapon_knife",
'paint_name' => "Default knife",
'image_url' => "https://raw.githubusercontent.com/Nereziel/cs2-WeaponPaints/main/website/img/skins/weapon_knife.png",
];
);
ksort($knifes);
return $knifes;
@@ -97,19 +97,18 @@ class UtilsClass
* @param array $temp An array containing the selected skins data.
* @return array An associative array containing selected skins data.
*/
public static function getSelectedSkins(array $temp): array
public static function getSelectedSkins($temp)
{
$selected = [];
$selected = array();
foreach ($temp as $weapon) {
$selected[$weapon['weapon']] = [
$selected[$weapon['weapon']] = array(
'weapon_paint_id' => $weapon['paint'],
'weapon_seed' => $weapon['seed'],
'weapon_wear' => $weapon['wear'],
];
);
}
return $selected;
}
}