[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,8 +9,12 @@ class ItemsParser
$ret = []; $ret = [];
$i = 0; $i = 0;
$handle = fopen($path, "r"); $handle = fopen($path, 'r');
if ($handle) {
if ($handle === false) {
throw new \RuntimeException('Failed to open items file: ' . $path);
}
$parse = ''; $parse = '';
while (($line = fgets($handle)) !== false) { while (($line = fgets($handle)) !== false) {
@@ -25,17 +29,18 @@ class ItemsParser
// skip lines like this // skip lines like this
// field = {type = "fire", initdamage = 20, ticks = 10000, count = 7, damage = 10} // field = {type = "fire", initdamage = 20, ticks = 10000, count = 7, damage = 10}
// as it cannot be parsed by parse_ini_string // as it cannot be parsed by parse_ini_string
if (str_contains($line, 'field =')) { if (str_starts_with(ltrim($line), 'field =')) {
continue; continue;
} }
$parse .= $line; $parse .= $line;
} }
if ($parse !== '') {
$ret[] = parse_ini_string($parse); $ret[] = parse_ini_string($parse);
}
fclose($handle); 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);
}
} }