[WIP] Refactoring

This commit is contained in:
slawkens
2026-02-26 16:45:58 +01:00
parent 058e80cfc6
commit f738448f2e
3 changed files with 26 additions and 29 deletions

View File

@@ -9,34 +9,39 @@ class ItemsParser
$ret = []; $ret = [];
$i = 0; $i = 0;
$handle = fopen($path, "r"); $handle = fopen($path, 'r');
if ($handle) {
$parse = '';
while (($line = fgets($handle)) !== false) { if ($handle === false) {
if (str_contains($line, '[[items]]') && $i++ != 0) { throw new \RuntimeException('Failed to open items file: ' . $path);
//global $whoopsHandler; }
//$whoopsHandler->addDataTable('ini', [$parse]);
$ret[] = parse_ini_string($parse);
$parse = '';
continue;
}
// skip lines like this $parse = '';
// field = {type = "fire", initdamage = 20, ticks = 10000, count = 7, damage = 10}
// as it cannot be parsed by parse_ini_string
if (str_contains($line, 'field =')) {
continue;
}
$parse .= $line; while (($line = fgets($handle)) !== false) {
if (str_contains($line, '[[items]]') && $i++ != 0) {
//global $whoopsHandler;
//$whoopsHandler->addDataTable('ini', [$parse]);
$ret[] = parse_ini_string($parse);
$parse = '';
continue;
} }
$ret[] = parse_ini_string($parse); // skip lines like this
// field = {type = "fire", initdamage = 20, ticks = 10000, count = 7, damage = 10}
// as it cannot be parsed by parse_ini_string
if (str_starts_with(ltrim($line), 'field =')) {
continue;
}
fclose($handle); $parse .= $line;
} }
if ($parse !== '') {
$ret[] = parse_ini_string($parse);
}
fclose($handle);
return $ret; return $ret;
} }
} }

View File

@@ -6,7 +6,7 @@ use MyAAC\Cache\PHP as CachePHP;
class Items class Items
{ {
private string $error; private string $error = '';
public function getError(): string { public function getError(): string {
return $this->error; return $this->error;

View File

@@ -40,12 +40,4 @@ class Vocations
public function getFrom(): array { public function getFrom(): array {
return $this->vocationsFrom; return $this->vocationsFrom;
} }
public static function getBase($includingRook = true): array {
return \MyAAC\Server\Vocations::getBase($includingRook);
}
public static function getOriginal(int $id): ?int {
return \MyAAC\Server\Vocations::getOriginal($id);
}
} }