game/_incl_data/class/Inf/Status.php
2023-11-02 15:59:07 +02:00

38 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Inf;
use Core\Config;
use Helper\Conversion;
class Status
{
private array $statuses;
public function add(bool $condition, string $text, int|string|null $timeout = 0, ?string $img = ''): void
{
if (!$condition) {
return;
}
if (!empty($timeout)) {
$text .= ' ещё ' . Conversion::secondsToTimeout($timeout - time());
}
$text = "<span style='vertical-align:middle;'>$text</span>";
if (!empty($img)) {
$text = '<span><img src="' . Config::img() . DIRECTORY_SEPARATOR . $img . '" alt="' . $text . '" style="vertical-align:middle;"></span> ' . $text;
}
$this->statuses[] = "<div>$text</div>"; // обёртка для центрирования картинки с текстом
}
public function print(): void
{
if (empty($this->statuses)) {
return;
}
echo '<br><div style="font-size: smaller;">' . implode('<br>', $this->statuses) . '</div>';
}
}