2
2
3
3
namespace Aternos \Renderchest \Resource \AtlasSource ;
4
4
5
+ use Aternos \Renderchest \Exception \InvalidResourceLocatorException ;
6
+ use Aternos \Renderchest \Exception \ResourceResolutionException ;
5
7
use Aternos \Renderchest \Resource \AtlasSource \TextureSource \AtlasTextureSource ;
6
8
use Aternos \Renderchest \Resource \AtlasSource \TextureSource \DirectoryAtlasTextureSource ;
7
9
use Aternos \Renderchest \Resource \AtlasSource \TextureSource \PalettedPermutationsTextureSource ;
16
18
class AtlasTextureResolver
17
19
{
18
20
const SOURCES = [
19
- "directory " => DirectoryAtlasTextureSource::class,
20
- "single " => SingleAtlasTextureSource::class,
21
- "unstitch " => UnstitchAtlasTextureSource::class,
22
- "paletted_permutations " => PalettedPermutationsTextureSource::class
21
+ "minecraft: directory " => DirectoryAtlasTextureSource::class,
22
+ "minecraft: single " => SingleAtlasTextureSource::class,
23
+ "minecraft: unstitch " => UnstitchAtlasTextureSource::class,
24
+ "minecraft: paletted_permutations " => PalettedPermutationsTextureSource::class
23
25
];
24
26
25
27
/**
@@ -35,12 +37,17 @@ public function __construct(protected ResourceManagerInterface $resourceManager)
35
37
* @param string $namespace
36
38
* @param stdClass $settings
37
39
* @return $this
40
+ * @throws InvalidResourceLocatorException|ResourceResolutionException
38
41
*/
39
42
public function add (string $ namespace , stdClass $ settings ): static
40
43
{
41
- $ class = static ::SOURCES [$ settings ->type ] ?? null ;
44
+ if (!isset ($ settings ->type ) || !is_string ($ settings ->type )) {
45
+ throw new ResourceResolutionException ("Missing atlas texture source type " );
46
+ }
47
+ $ type = ResourceLocator::parse ($ settings ->type );
48
+ $ class = static ::SOURCES [(string ) $ type ] ?? null ;
42
49
if ($ class === null ) {
43
- return $ this ;
50
+ throw new ResourceResolutionException ( " Unknown atlas texture source type " . $ type ) ;
44
51
}
45
52
array_unshift ($ this ->sources , new $ class ($ this ->resourceManager , $ namespace , $ settings ));
46
53
return $ this ;
0 commit comments