66 lines
1.5 KiB
PHP
66 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Game;
|
|
|
|
use App\Support\Set;
|
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
class GameSettings
|
|
{
|
|
public Set $classes;
|
|
|
|
public Set $roles;
|
|
|
|
public Set $characters;
|
|
|
|
public Set $raids;
|
|
|
|
public function __construct($settings = [])
|
|
{
|
|
$this->classes = new Set();
|
|
$this->characters = new Set();
|
|
$this->raids = new Set();
|
|
$this->roles = new Set();
|
|
$this->fromArray($settings);
|
|
}
|
|
|
|
public function fromArray(array $array)
|
|
{
|
|
if (isset($array['classes'])) {
|
|
$this->classes->fill($array['classes']);
|
|
}
|
|
|
|
if (isset($array['raids'])) {
|
|
$this->raids->fill($array['raids']);
|
|
}
|
|
|
|
if (isset($array['characters'])) {
|
|
$this->characters->fill($array['characters']);
|
|
}
|
|
|
|
if (isset($array['roles'])) {
|
|
$this->roles->fill($array['roles']);
|
|
}
|
|
}
|
|
|
|
public function toArray() : array
|
|
{
|
|
return [
|
|
'classes' => $this->classes->toArray(),
|
|
'roles' => $this->roles->toArray(),
|
|
'raids' => $this->raids->toArray(),
|
|
'characters' => $this->characters->toArray()
|
|
];
|
|
}
|
|
|
|
public function all() : Collection
|
|
{
|
|
return collect([
|
|
'classes' => $this->classes->all()->toArray(),
|
|
'roles' => $this->roles->all()->toArray(),
|
|
'raids' => $this->raids->all()->toArray(),
|
|
'characters' => $this->characters->all()->toArray()
|
|
])->filter();
|
|
}
|
|
}
|