Skip to content

Commit

Permalink
allow namespaces in atlas source type fields
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Jan 22, 2025
1 parent 482a6bc commit 35cfb21
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Resource/AtlasSource/AtlasTextureResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Aternos\Renderchest\Resource\AtlasSource;

use Aternos\Renderchest\Exception\InvalidResourceLocatorException;
use Aternos\Renderchest\Exception\ResourceResolutionException;
use Aternos\Renderchest\Resource\AtlasSource\TextureSource\AtlasTextureSource;
use Aternos\Renderchest\Resource\AtlasSource\TextureSource\DirectoryAtlasTextureSource;
use Aternos\Renderchest\Resource\AtlasSource\TextureSource\PalettedPermutationsTextureSource;
Expand All @@ -16,10 +18,10 @@
class AtlasTextureResolver
{
const SOURCES = [
"directory" => DirectoryAtlasTextureSource::class,
"single" => SingleAtlasTextureSource::class,
"unstitch" => UnstitchAtlasTextureSource::class,
"paletted_permutations" => PalettedPermutationsTextureSource::class
"minecraft:directory" => DirectoryAtlasTextureSource::class,
"minecraft:single" => SingleAtlasTextureSource::class,
"minecraft:unstitch" => UnstitchAtlasTextureSource::class,
"minecraft:paletted_permutations" => PalettedPermutationsTextureSource::class
];

/**
Expand All @@ -35,12 +37,17 @@ public function __construct(protected ResourceManagerInterface $resourceManager)
* @param string $namespace
* @param stdClass $settings
* @return $this
* @throws InvalidResourceLocatorException|ResourceResolutionException
*/
public function add(string $namespace, stdClass $settings): static
{
$class = static::SOURCES[$settings->type] ?? null;
if (!isset($settings->type) || !is_string($settings->type)) {
throw new ResourceResolutionException("Missing atlas texture source type");
}
$type = ResourceLocator::parse($settings->type);
$class = static::SOURCES[(string) $type] ?? null;
if ($class === null) {
return $this;
throw new ResourceResolutionException("Unknown atlas texture source type " . $type);
}
array_unshift($this->sources, new $class($this->resourceManager, $namespace, $settings));
return $this;
Expand Down
4 changes: 4 additions & 0 deletions src/Resource/FolderResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Aternos\Renderchest\Resource;

use Aternos\Renderchest\Exception\FileResolutionException;
use Aternos\Renderchest\Exception\InvalidResourceLocatorException;
use Aternos\Renderchest\Exception\ItemResolutionException;
use Aternos\Renderchest\Exception\ModelResolutionException;
use Aternos\Renderchest\Exception\ResourceResolutionException;
use Aternos\Renderchest\Exception\TextureResolutionException;
use Aternos\Renderchest\Model\GeneratedItem;
use Aternos\Renderchest\Model\Model;
Expand Down Expand Up @@ -64,6 +66,8 @@ protected function getGeneratorFor(string $namespace): ?DynamicResourceGenerator

/**
* @return void
* @throws InvalidResourceLocatorException
* @throws ResourceResolutionException
*/
protected function loadTextureSources(): void
{
Expand Down

0 comments on commit 35cfb21

Please sign in to comment.