mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Misc/Fixups
* Util::writeTable .. border length, toned down colors * Cfg::get .. empty strings and 0 can be valid, return null on failure * Game::getWorldPosForGUID .. fixed referencing soundemitters by soundId instead if index
This commit is contained in:
@@ -145,13 +145,13 @@ class Cfg
|
||||
return 'configuration option not found';
|
||||
|
||||
if (self::$store[$key][self::IDX_FLAGS] & self::FLAG_PERSISTENT)
|
||||
return 'can\'t delete persistent options';
|
||||
return 'can\'t delete persistent option';
|
||||
|
||||
if (!(self::$store[$key][self::IDX_FLAGS] & self::FLAG_PHP))
|
||||
return 'can\'t delete non-php options';
|
||||
return 'can\'t delete non-php option';
|
||||
|
||||
if (self::$store[$key][self::IDX_FLAGS] & self::FLAG_INTERNAL)
|
||||
return 'can\'t delete internal options';
|
||||
return 'can\'t delete internal option';
|
||||
|
||||
if (!DB::Aowow()->query('DELETE FROM ?_config WHERE `key` = ? AND (`flags` & ?d) = 0 AND (`flags` & ?d) > 0', $key, self::FLAG_PERSISTENT, self::FLAG_PHP))
|
||||
return 'internal error';
|
||||
@@ -169,7 +169,7 @@ class Cfg
|
||||
if (self::$isLoaded)
|
||||
self::throwError('cfg not defined: '.strtoupper($key));
|
||||
|
||||
return '';
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($fromDB && $fullInfo)
|
||||
@@ -195,7 +195,7 @@ class Cfg
|
||||
[$oldValue, $flags, , , $comment] = self::$store[$key];
|
||||
|
||||
if ($flags & self::FLAG_INTERNAL)
|
||||
return 'can\'t set internal options directly';
|
||||
return 'can\'t set an internal option directly';
|
||||
|
||||
if ($err = self::validate($value, $flags, $comment))
|
||||
return $err;
|
||||
@@ -250,7 +250,7 @@ class Cfg
|
||||
|
||||
[$oldValue, $flags, , $default, ] = self::$store[$key];
|
||||
if ($flags & self::FLAG_INTERNAL)
|
||||
return 'can\'t set internal options directly';
|
||||
return 'can\'t set an internal option directly';
|
||||
|
||||
if (!$default)
|
||||
return 'config option has no default value';
|
||||
|
||||
@@ -318,16 +318,16 @@ class Game
|
||||
switch ($type)
|
||||
{
|
||||
case Type::NPC:
|
||||
$result = DB::World()->select('SELECT `guid` AS ARRAY_KEY, `id`, `map` AS `mapId`, `position_y` AS `posX`, `position_x` AS `posY` FROM creature WHERE `guid` IN (?a)', $guids);
|
||||
$result = DB::World()->select('SELECT `guid` AS ARRAY_KEY, `id`, `map` AS `mapId`, `position_y` AS `posX`, `position_x` AS `posY` FROM creature WHERE `guid` IN (?a)', $guids);
|
||||
break;
|
||||
case Type::OBJECT:
|
||||
$result = DB::World()->select('SELECT `guid` AS ARRAY_KEY, `id`, `map` AS `mapId`, `position_y` AS `posX`, `position_x` AS `posY` FROM gameobject WHERE `guid` IN (?a)', $guids);
|
||||
$result = DB::World()->select('SELECT `guid` AS ARRAY_KEY, `id`, `map` AS `mapId`, `position_y` AS `posX`, `position_x` AS `posY` FROM gameobject WHERE `guid` IN (?a)', $guids);
|
||||
break;
|
||||
case Type::SOUND:
|
||||
$result = DB::AoWoW()->select('SELECT `soundId` AS ARRAY_KEY, `soundId` AS `id`, `mapId`, `posX`, `posY` FROM ?_soundemitters WHERE `soundId` IN (?a)', $guids);
|
||||
$result = DB::AoWoW()->select('SELECT `id` AS ARRAY_KEY, `soundId` AS `id`, `mapId`, `posX`, `posY` FROM ?_soundemitters WHERE `id` IN (?a)', $guids);
|
||||
break;
|
||||
case Type::AREATRIGGER:
|
||||
$result = DB::AoWoW()->select('SELECT `id` AS ARRAY_KEY, `id`, `mapId`, `posX`, `posY` FROM ?_areatrigger WHERE `id` IN (?a)', $guids);
|
||||
$result = DB::AoWoW()->select('SELECT `id` AS ARRAY_KEY, `id`, `mapId`, `posX`, `posY` FROM ?_areatrigger WHERE `id` IN (?a)', $guids);
|
||||
break;
|
||||
default:
|
||||
trigger_error('Game::getWorldPosForGUID - instanced with unsupported TYPE #'.$type, E_USER_WARNING);
|
||||
|
||||
@@ -177,19 +177,26 @@ abstract class CLI
|
||||
$pads[$j] = max($pads[$j] ?? 0, mb_strlen(self::purgeEscapes($row[$j] ?? '')));
|
||||
}
|
||||
|
||||
foreach ($out as $j => $row)
|
||||
foreach ($out as $i => $row)
|
||||
{
|
||||
for ($i = 0; $i < $nCols; $i++)
|
||||
$row[$i] = str_pad($row[$i] ?? '', $pads[$i] ?? 0);
|
||||
for ($j = 0; $j < $nCols; $j++)
|
||||
{
|
||||
if (!isset($row[$j]))
|
||||
break;
|
||||
|
||||
if ($j || $headless)
|
||||
$len = ($pads[$j] - mb_strlen(self::purgeEscapes($row[$j])));
|
||||
for ($k = 0; $k < $len; $k++) // can't use str_pad(). it counts invisible chars.
|
||||
$row[$j] .= ' ';
|
||||
}
|
||||
|
||||
if ($i || $headless)
|
||||
self::write(' '.implode(' ' . self::tblDelim(' ') . ' ', $row), -1, $timestamp);
|
||||
else
|
||||
self::write(self::tblHead(' '.implode(' ', $row)), -1, $timestamp);
|
||||
}
|
||||
|
||||
if (!$headless)
|
||||
self::write(self::tblHead(str_pad('', array_sum($pads) + (count($pads) - 1) * 3)), -1, $timestamp);
|
||||
self::write(self::tblHead(str_pad('', array_sum($pads) + count($pads) * 3 - 2)), -1, $timestamp);
|
||||
|
||||
self::write();
|
||||
}
|
||||
@@ -222,12 +229,12 @@ abstract class CLI
|
||||
|
||||
private static function tblHead(string $str) : string
|
||||
{
|
||||
return CLI_HAS_E ? "\e[1;39;100m".$str."\e[0m" : $str;
|
||||
return CLI_HAS_E ? "\e[1;48;5;236m".$str."\e[0m" : $str;
|
||||
}
|
||||
|
||||
private static function tblDelim(string $str) : string
|
||||
{
|
||||
return CLI_HAS_E ? "\e[39;100m".$str."\e[0m" : $str;
|
||||
return CLI_HAS_E ? "\e[48;5;236m".$str."\e[0m" : $str;
|
||||
}
|
||||
|
||||
public static function grey(string $str) : string
|
||||
@@ -304,7 +311,7 @@ abstract class CLI
|
||||
|
||||
private static function purgeEscapes(string $msg) : string
|
||||
{
|
||||
return preg_replace(["/\e\[\d+[mK]/", "/\e\[\d+G/"], ['', "\n"], $msg);
|
||||
return preg_replace(["/\e\[[\d;]+[mK]/", "/\e\[\d+G/"], ['', "\n"], $msg);
|
||||
}
|
||||
|
||||
public static function nicePath(string $fileOrPath, string ...$pathParts) : string
|
||||
|
||||
Reference in New Issue
Block a user