game/_incl_data/class/Model/Constant/Stat.php

53 lines
1.3 KiB
PHP

<?php
namespace Model\Constant;
use Enum\StatFilterCellName;
class Stat extends Constant
{
public readonly array $sysBonusNames;
public readonly array $sysRequirementNames;
public readonly array $bonusNames;
public readonly array $requirementNames;
public function __construct()
{
self::$tableName = 'const_stats';
parent::__construct();
}
private function filterByCell(StatFilterCellName $cellName): array
{
$result = [];
foreach ($this->rows as $row) {
if (!$row[$cellName->value]) {
continue;
}
$result[$row['sys_name']] = $row['name'];
}
return $result;
}
/**
* Создаёт и заполняет массивы bonusNames и sysBonusNames.
* @return void
*/
public function getBonus(): void
{
$this->bonusNames = $this->filterByCell(StatFilterCellName::Bonus);
$this->sysBonusNames = array_keys($this->bonusNames);
}
/**
* Создаёт и заполняет массивы requirementNames и sysRequirementNames.
* @return void
*/
public function getRequirement(): void
{
$this->requirementNames = $this->filterByCell(StatFilterCellName::Requirement);
$this->sysRequirementNames = array_keys($this->requirementNames);
}
}