11package com .ss .editor ;
22
3- import static java .nio .file .Files .newInputStream ;
4-
53import com .jme3 .asset .AssetInfo ;
64import com .jme3 .asset .AssetKey ;
75import com .jme3 .asset .AssetLocator ;
86import com .jme3 .asset .AssetManager ;
9- import com .jme3 .asset .StreamAssetInfo ;
10- import com .jme3 .asset .plugins .UrlAssetInfo ;
117import com .ss .editor .config .EditorConfig ;
8+ import org .jetbrains .annotations .NotNull ;
129
1310import java .io .IOException ;
14- import java .net . URL ;
11+ import java .io . InputStream ;
1512import java .nio .file .Files ;
1613import java .nio .file .Path ;
17-
18- import org .jetbrains .annotations .NotNull ;
19- import com .ss .rlib .util .FileUtils ;
20- import com .ss .rlib .util .array .Array ;
21- import com .ss .rlib .util .array .ArrayFactory ;
14+ import java .nio .file .StandardOpenOption ;
2215
2316/**
2417 * The implementation of {@link AssetLocator} to load data from an asset folder.
2720 */
2821public class FolderAssetLocator implements AssetLocator {
2922
30- @ NotNull
31- private static final Array <String > URL_EXTENSIONS = ArrayFactory .newArray (String .class );
32-
33- static {
34- URL_EXTENSIONS .add (FileExtensions .MODEL_SCENE );
35- }
36-
3723 @ Override
3824 public void setRootPath (@ NotNull final String rootPath ) {
25+ System .out .println (rootPath );
3926 }
4027
4128 @ Override
@@ -49,21 +36,27 @@ public AssetInfo locate(final AssetManager manager, final AssetKey key) {
4936 final Path resolve = currentAsset .resolve (name );
5037 if (!Files .exists (resolve )) return null ;
5138
52- final String extension = FileUtils .getExtension (resolve );
39+ return new PathAssetInfo (manager , key , resolve );
40+ }
41+
42+ private class PathAssetInfo extends AssetInfo {
5343
54- if (URL_EXTENSIONS .contains (extension )) {
44+ @ NotNull
45+ private final Path path ;
46+
47+ private PathAssetInfo (@ NotNull final AssetManager manager , @ NotNull final AssetKey key ,
48+ @ NotNull final Path path ) {
49+ super (manager , key );
50+ this .path = path ;
51+ }
52+
53+ @ Override
54+ public @ NotNull InputStream openStream () {
5555 try {
56- final URL url = resolve .toUri ().toURL ();
57- return UrlAssetInfo .create (manager , key , url );
56+ return Files .newInputStream (path , StandardOpenOption .READ );
5857 } catch (final IOException e ) {
5958 throw new RuntimeException (e );
6059 }
6160 }
62-
63- try {
64- return new StreamAssetInfo (manager , key , newInputStream (resolve ));
65- } catch (final IOException e ) {
66- throw new RuntimeException (e );
67- }
6861 }
6962}
0 commit comments