[WIP] Outfits TOML + XML

Deprecate old Outfits & Mounts functions
This commit is contained in:
slawkens
2026-02-26 18:39:08 +01:00
parent f738448f2e
commit 8a5823a69c
7 changed files with 177 additions and 58 deletions

View File

@@ -0,0 +1,24 @@
<?php
namespace MyAAC\Server;
use MyAAC\Cache\Cache;
class Outfits
{
public static function get()
{
return Cache::remember('outfits', 10 * 60, function () {
if (file_exists(config('server_path') . 'config/outfits.toml')) {
$outfits = new TOML\Outfits();
}
else {
$outfits = new XML\Outfits();
}
$outfits->load();
return $outfits->getOutfits();
});
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace MyAAC\Server\TOML;
use Devium\Toml\Toml;
class Outfits
{
private array $outfits = [];
const FILE = 'config/outfits.toml';
public function load(): void
{
$file = config('server_path') . self::FILE;
if(!@file_exists($file)) {
return;
}
$toml = file_get_contents($file);
$outfits = Toml::decode($toml, asArray: true);
foreach ($outfits as $outfit)
{
$this->outfits[] = [
'id' => $outfit['id'],
'sex' => ($outfit['sex'] == 'male' ? SEX_MALE : SEX_FEMALE),
'name' => $outfit['name'],
'premium' => $outfit['premium'] ?? false,
'locked' => $outfit['locked'] ?? false,
'enabled' => $outfit['enabled'] ?? true,
];
}
}
public function getOutfits(): array {
return $this->outfits;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace MyAAC\Server\XML;
class Outfits
{
private array $outfits = [];
const FILE = 'XML/outfits.xml';
public function load(): void
{
$file = config('data_path') . self::FILE;
if(!@file_exists($file)) {
return;
}
$xml = new \DOMDocument;
$xml->load($file);
foreach ($xml->getElementsByTagName('outfit') as $outfit) {
$this->outfits[] = $this->parseOutfitNode($outfit);
}
}
private function parseOutfitNode($node): array
{
$looktype = (int)$node->getAttribute('looktype');
$type = (int)$node->getAttribute('type');
$name = $node->getAttribute('name');
$premium = getBoolean($node->getAttribute('premium'));
$locked = !getBoolean($node->getAttribute('unlocked'));
$enabled = getBoolean($node->getAttribute('enabled'));
return [
'id' => $looktype,
'sex' => ($type === 1 ? SEX_MALE : SEX_FEMALE),
'name' => $name,
'premium' => $premium,
'locked' => $locked,
'enabled' => $enabled,
];
}
public function getOutfits(): array {
return $this->outfits;
}
}