@Override public void init() { assetsFolder = fileAccessModule.getAssetsFolder(); sceneBackupFolder = fileAccessModule.getModuleFolder(".sceneBackup"); gson = gsonModule.getCommonGson(); }
@Override public void fileChanged(FileHandle file) { String relativePath = fileAccess.relativizeToAssetsFolder(file); if (ProjectPathUtils.isTexture(relativePath, file.extension())) { cacheWaitTimer.clear(); cacheWaitTimer.scheduleTask( new Task() { @Override public void run() { updateCache(); } }, 0.5f); } if (ProjectPathUtils.isTextureAtlas(file, relativePath)) { atlasWaitTimer.clear(); cacheWaitTimer.scheduleTask( new Task() { @Override public void run() { updateAtlas(file); } }, 0.5f); } }
@Override public void init() { settings = new Settings(); settings.maxWidth = 4096; settings.maxHeight = 4096; settings.combineSubdirectories = true; settings.silent = true; settings.useIndexes = false; settings.fast = true; loadingRegion = Assets.icons.findRegion("refresh-big"); missingRegion = Assets.icons.findRegion("file-question-big"); FileHandle out = fileAccess.getModuleFolder(".textureCache"); cachePath = out.path(); cacheFile = out.child("cache.atlas"); gfxPath = fileAccess.getAssetsFolder().child("gfx").path(); atlasesFolder = fileAccess.getAssetsFolder().child("atlas"); watcher.addListener(this); try { if (cacheFile.exists()) cache = new TextureAtlas(cacheFile); } catch (Exception e) { Log.error("Error while loading texture cache, texture cache will be regenerated"); } try { if (atlasesFolder.exists()) { FileHandle[] files = atlasesFolder.list(); for (FileHandle file : files) if (file.extension().equals("atlas")) updateAtlas(file); } } catch (Exception e) { Log.error("Error encountered while loading one of atlases"); Log.exception(e); } updateCache(); }
private void updateAtlas(FileHandle file) { String relativePath = fileAccess.relativizeToAssetsFolder(file); TextureAtlas atlas = atlases.get(relativePath); if (atlas != null) { atlases.remove(relativePath); atlas.dispose(); } if (file.exists()) { atlases.put(relativePath, new TextureAtlas(file)); App.eventBus.post(new ResourceReloadedEvent(ResourceReloadedEvent.RESOURCE_TEXTURES)); App.eventBus.post(new ResourceReloadedEvent(ResourceReloadedEvent.RESOURCE_TEXTURE_ATLASES)); } }
public EditorScene load(FileHandle fullPathFile) { try { if (fullPathFile.length() == 0) throw new EditorRuntimeException("Scene file does not contain any data"); BufferedReader reader = new BufferedReader(new FileReader(fullPathFile.file())); EditorScene scene = gson.fromJson(reader, EditorScene.class); scene.path = fileAccessModule.relativizeToAssetsFolder(fullPathFile); reader.close(); scene.onDeserialize(); return scene; } catch (IOException e) { throw new IllegalStateException("There was an IO error during scene loading", e); } }