mirror of
https://github.com/slawkens/myaac.git
synced 2026-03-16 16:03:31 +01:00
[WIP] Outfits TOML + XML
Deprecate old Outfits & Mounts functions
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
use MyAAC\Forum;
|
use MyAAC\Forum;
|
||||||
use MyAAC\Models\Player;
|
use MyAAC\Models\Player;
|
||||||
|
use MyAAC\Server\Outfits;
|
||||||
use MyAAC\Server\XML\Vocations;
|
use MyAAC\Server\XML\Vocations;
|
||||||
|
|
||||||
defined('MYAAC') or die('Direct access not allowed!');
|
defined('MYAAC') or die('Direct access not allowed!');
|
||||||
@@ -659,14 +660,14 @@ else if (isset($_REQUEST['search'])) {
|
|||||||
<div class="col-12 col-sm-12 col-lg-6">
|
<div class="col-12 col-sm-12 col-lg-6">
|
||||||
<label for="look_type" class="control-label">Type:</label>
|
<label for="look_type" class="control-label">Type:</label>
|
||||||
<?php
|
<?php
|
||||||
$outfitlist = null;
|
$outfits = Outfits::get();
|
||||||
$outfitlist = Outfits_loadfromXML();
|
if ($outfits) { ?>
|
||||||
if ($outfitlist) { ?>
|
|
||||||
<select name="look_type" id="look_type" class="form-control custom-select">
|
<select name="look_type" id="look_type" class="form-control custom-select">
|
||||||
<?php
|
<?php
|
||||||
foreach ($outfitlist as $_id => $outfit) {
|
foreach ($outfits as $outfit) {
|
||||||
if ($outfit['enabled'] == 'yes') ;
|
if ($outfit['enabled']) {
|
||||||
echo '<option value=' . $outfit['id'] . ($outfit['id'] == $player->getLookType() ? ' selected' : '') . '>' . $outfit['name'] . ' - ' . ($outfit['type'] == 1 ? 'Male' : 'Female') . '</option>';
|
echo '<option value=' . $outfit['id'] . ($outfit['id'] == $player->getLookType() ? ' selected' : '') . '>' . $outfit['name'] . ' - ' . ($outfit['sex'] == SEX_MALE ? 'Male' : 'Female') . '</option>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -74,3 +74,57 @@ function fieldExist($field, $table)
|
|||||||
global $db;
|
global $db;
|
||||||
return $db->hasColumn($table, $field);
|
return $db->hasColumn($table, $field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Outfits_loadfromXML(): ?array
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
$file_path = $config['data_path'] . 'XML/outfits.xml';
|
||||||
|
if (!file_exists($file_path)) { return null; }
|
||||||
|
|
||||||
|
$xml = new DOMDocument;
|
||||||
|
$xml->load($file_path);
|
||||||
|
|
||||||
|
$outfits = null;
|
||||||
|
foreach ($xml->getElementsByTagName('outfit') as $outfit) {
|
||||||
|
$outfits[] = Outfit_parseNode($outfit);
|
||||||
|
}
|
||||||
|
return $outfits;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Outfit_parseNode($node): array
|
||||||
|
{
|
||||||
|
$looktype = (int)$node->getAttribute('looktype');
|
||||||
|
$type = (int)$node->getAttribute('type');
|
||||||
|
$lookname = $node->getAttribute('name');
|
||||||
|
$premium = $node->getAttribute('premium');
|
||||||
|
$unlocked = $node->getAttribute('unlocked');
|
||||||
|
$enabled = $node->getAttribute('enabled');
|
||||||
|
return array('id' => $looktype, 'type' => $type, 'name' => $lookname, 'premium' => $premium, 'unlocked' => $unlocked, 'enabled' => $enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Mounts_loadfromXML(): ?array
|
||||||
|
{
|
||||||
|
global $config;
|
||||||
|
$file_path = $config['data_path'] . 'XML/mounts.xml';
|
||||||
|
if (!file_exists($file_path)) { return null; }
|
||||||
|
|
||||||
|
$xml = new DOMDocument;
|
||||||
|
$xml->load($file_path);
|
||||||
|
|
||||||
|
$mounts = null;
|
||||||
|
foreach ($xml->getElementsByTagName('mount') as $mount) {
|
||||||
|
$mounts[] = Mount_parseNode($mount);
|
||||||
|
}
|
||||||
|
return $mounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Mount_parseNode($node): array
|
||||||
|
{
|
||||||
|
$id = (int)$node->getAttribute('id');
|
||||||
|
$clientid = (int)$node->getAttribute('clientid');
|
||||||
|
$name = $node->getAttribute('name');
|
||||||
|
$speed = (int)$node->getAttribute('speed');
|
||||||
|
$premium = $node->getAttribute('premium');
|
||||||
|
$type = $node->getAttribute('type');
|
||||||
|
return array('id' => $id, 'clientid' => $clientid, 'name' => $name, 'speed' => $speed, 'premium' => $premium, 'type' => $type);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1640,58 +1640,6 @@ function verify_number($number, $name, $max_length)
|
|||||||
echo_error($name . ' cannot be longer than ' . $max_length . ' digits.');
|
echo_error($name . ' cannot be longer than ' . $max_length . ' digits.');
|
||||||
}
|
}
|
||||||
|
|
||||||
function Outfits_loadfromXML()
|
|
||||||
{
|
|
||||||
global $config;
|
|
||||||
$file_path = $config['data_path'] . 'XML/outfits.xml';
|
|
||||||
if (!file_exists($file_path)) { return null; }
|
|
||||||
|
|
||||||
$xml = new DOMDocument;
|
|
||||||
$xml->load($file_path);
|
|
||||||
|
|
||||||
$outfits = null;
|
|
||||||
foreach ($xml->getElementsByTagName('outfit') as $outfit) {
|
|
||||||
$outfits[] = Outfit_parseNode($outfit);
|
|
||||||
}
|
|
||||||
return $outfits;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Outfit_parseNode($node) {
|
|
||||||
$looktype = (int)$node->getAttribute('looktype');
|
|
||||||
$type = (int)$node->getAttribute('type');
|
|
||||||
$lookname = $node->getAttribute('name');
|
|
||||||
$premium = $node->getAttribute('premium');
|
|
||||||
$unlocked = $node->getAttribute('unlocked');
|
|
||||||
$enabled = $node->getAttribute('enabled');
|
|
||||||
return array('id' => $looktype, 'type' => $type, 'name' => $lookname, 'premium' => $premium, 'unlocked' => $unlocked, 'enabled' => $enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Mounts_loadfromXML()
|
|
||||||
{
|
|
||||||
global $config;
|
|
||||||
$file_path = $config['data_path'] . 'XML/mounts.xml';
|
|
||||||
if (!file_exists($file_path)) { return null; }
|
|
||||||
|
|
||||||
$xml = new DOMDocument;
|
|
||||||
$xml->load($file_path);
|
|
||||||
|
|
||||||
$mounts = null;
|
|
||||||
foreach ($xml->getElementsByTagName('mount') as $mount) {
|
|
||||||
$mounts[] = Mount_parseNode($mount);
|
|
||||||
}
|
|
||||||
return $mounts;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Mount_parseNode($node) {
|
|
||||||
$id = (int)$node->getAttribute('id');
|
|
||||||
$clientid = (int)$node->getAttribute('clientid');
|
|
||||||
$name = $node->getAttribute('name');
|
|
||||||
$speed = (int)$node->getAttribute('speed');
|
|
||||||
$premium = $node->getAttribute('premium');
|
|
||||||
$type = $node->getAttribute('type');
|
|
||||||
return array('id' => $id, 'clientid' => $clientid, 'name' => $name, 'speed' => $speed, 'premium' => $premium, 'type' => $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
function left($str, $length) {
|
function left($str, $length) {
|
||||||
return substr($str, 0, $length);
|
return substr($str, 0, $length);
|
||||||
}
|
}
|
||||||
|
|||||||
24
system/src/Server/Outfits.php
Normal file
24
system/src/Server/Outfits.php
Normal 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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
40
system/src/Server/TOML/Outfits.php
Normal file
40
system/src/Server/TOML/Outfits.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
49
system/src/Server/XML/Outfits.php
Normal file
49
system/src/Server/XML/Outfits.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
const SEX_FEMALE = 0;
|
||||||
|
const SEX_MALE = 1;
|
||||||
|
|
||||||
const SKILL_FRAGS = -1;
|
const SKILL_FRAGS = -1;
|
||||||
const SKILL_BALANCE = -2;
|
const SKILL_BALANCE = -2;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user