mirror of
https://github.com/openlegends/asset-php.git
synced 2025-08-26 13:51:57 +00:00
init test cards preset
This commit is contained in:
parent
70544ba874
commit
51ed6aca12
140
src/Config.php
140
src/Config.php
@ -1,140 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace OpenLegends\Asset;
|
||||
|
||||
class Config
|
||||
{
|
||||
private string $_asset;
|
||||
|
||||
public function __construct(string $asset)
|
||||
{
|
||||
if (is_dir(__DIR__ . DIRECTORY_SEPARATOR . $asset))
|
||||
{
|
||||
$this->_asset = $asset;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
throw new \Exception();
|
||||
}
|
||||
}
|
||||
|
||||
public function getCards(
|
||||
?string $folder = 'Cards',
|
||||
?array $type = null,
|
||||
?array $attributes = null,
|
||||
?array $title = null,
|
||||
?array $description = null,
|
||||
?array $cost = null,
|
||||
?array $attack = null,
|
||||
?array $health = null,
|
||||
?array $craft = null,
|
||||
?array $extract = null
|
||||
): array
|
||||
{
|
||||
$cards = [];
|
||||
|
||||
foreach (
|
||||
$this->_getConfigs(
|
||||
__DIR__ . DIRECTORY_SEPARATOR . $this->_asset . DIRECTORY_SEPARATOR . $folder
|
||||
) as $card)
|
||||
{
|
||||
if ($type && !in_array($card->type, $type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($attributes && !in_array($card->attributes, $attributes))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($title && !in_array($card->title, $title))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($description && !in_array($card->description, $description))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($cost && !in_array($card->cost, $cost))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($attack && !in_array($card->attack, $attack))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($health && !in_array($card->health, $health))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($craft && !in_array($card->craft, $craft))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($extract && !in_array($card->extract, $extract))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$cards[] = $card;
|
||||
}
|
||||
|
||||
return $cards;
|
||||
}
|
||||
|
||||
private function _getConfigs(
|
||||
string $location
|
||||
): array
|
||||
{
|
||||
$configs = [];
|
||||
|
||||
if (!is_dir($location) || !is_readable($location))
|
||||
{
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
foreach (scandir($location) as $filename)
|
||||
{
|
||||
if (!str_ends_with($filename, '.json'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$configs[] = $this->_getConfig(
|
||||
$location . DIRECTORY_SEPARATOR . $filename
|
||||
);
|
||||
}
|
||||
|
||||
return $configs;
|
||||
}
|
||||
|
||||
private function _getConfig(
|
||||
string $location
|
||||
): object
|
||||
{
|
||||
if (!is_file($location) || !is_readable($location))
|
||||
{
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
if (!$json = file_get_contents($location))
|
||||
{
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
if (!$config = json_decode($json))
|
||||
{
|
||||
throw new \Exception();
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
12
src/Test/Card/Goblin.php
Normal file
12
src/Test/Card/Goblin.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OpenLegends\Asset\Test\Card;
|
||||
|
||||
class Goblin extends \OpenLegends\Engine\Abstract\Card
|
||||
{
|
||||
public function act(
|
||||
\OpenLegends\Engine\Abstract\Card $card
|
||||
) {}
|
||||
}
|
12
src/Test/Card/Mouse.php
Normal file
12
src/Test/Card/Mouse.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OpenLegends\Asset\Test\Card;
|
||||
|
||||
class Mouse extends \OpenLegends\Engine\Abstract\Card
|
||||
{
|
||||
public function act(
|
||||
\OpenLegends\Engine\Abstract\Card $card
|
||||
) {}
|
||||
}
|
12
src/Test/Card/Rat.php
Normal file
12
src/Test/Card/Rat.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OpenLegends\Asset\Test\Card;
|
||||
|
||||
class Rat extends \OpenLegends\Engine\Abstract\Card
|
||||
{
|
||||
public function act(
|
||||
\OpenLegends\Engine\Abstract\Card $card
|
||||
) {}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"attributes":
|
||||
[
|
||||
"attribute 1"
|
||||
],
|
||||
"type":"type 1",
|
||||
"title":"title 1",
|
||||
"description":"description 1",
|
||||
"cost":1,
|
||||
"attack":1,
|
||||
"health":1,
|
||||
"craft":1,
|
||||
"extract":1
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
{
|
||||
"attributes":
|
||||
[
|
||||
"attribute 1",
|
||||
"attribute 2"
|
||||
],
|
||||
"type":"type 2",
|
||||
"title":"title 2",
|
||||
"description":"description 2",
|
||||
"cost":1,
|
||||
"attack":1,
|
||||
"health":1,
|
||||
"craft":1,
|
||||
"extract":1
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
{
|
||||
"attributes":
|
||||
[
|
||||
"attribute 2"
|
||||
],
|
||||
"type":"type 2",
|
||||
"title":"title 3",
|
||||
"description":"description 3",
|
||||
"cost":2,
|
||||
"attack":2,
|
||||
"health":2,
|
||||
"craft":2,
|
||||
"extract":2
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user