Search in sources :

Example 1 with AssetManager

use of com.github.jakz.romlib.data.assets.AssetManager in project rom-manager by Jakz.

the class InfoPanel method romSetLoaded.

public void romSetLoaded(final GameSet set) {
    mode = Mode.VIEW;
    this.set = set;
    AssetManager manager = set.getAssetManager();
    Asset[] assets = manager.getSupportedAssets();
    // TODO && uiSettings.showClonesTable
    showClonesTable = set.hasFeature(Feature.CLONES);
    buildMainLayout();
    buildPopupMenu();
    clonesTable.gameSetLoaded(set);
    if (assets.length == 0) {
        images = new AssetImage[0];
        imagesPanel.removeAll();
        imagesPanel.revalidate();
    } else {
        images = new AssetImage[] { new AssetImage(assets[0]), new AssetImage(assets[1]) };
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                imagesPanel.removeAll();
                imagesPanel.add(images[0].image);
                imagesPanel.add(Box.createRigidArea(new Dimension(30, 0)));
                imagesPanel.add(images[1].image);
                for (AssetImage image : images) {
                    image.image.setPreferredSize(((Asset.Image) image.asset).getSize());
                    image.image.revalidate();
                }
                imagesPanel.revalidate();
            }
        });
    }
    buildFields();
}
Also used : AssetManager(com.github.jakz.romlib.data.assets.AssetManager) Asset(com.github.jakz.romlib.data.assets.Asset) Dimension(java.awt.Dimension) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage)

Example 2 with AssetManager

use of com.github.jakz.romlib.data.assets.AssetManager in project rom-manager by Jakz.

the class GameSetManager method loadSetStatus.

public boolean loadSetStatus(GameSet set) {
    try {
        Path basePath = Paths.get("data/", set.ident());
        Path settingsPath = basePath.resolve("settings.json");
        try {
            AssetManager assetManager = set.getAssetManager();
            for (Asset asset : assetManager.getSupportedAssets()) Files.createDirectories(set.getAssetPath(asset, false));
        } catch (IOException e) {
            e.printStackTrace();
        // TODO: log
        }
        if (!Files.exists(settingsPath)) {
            logger.d("Unable to load game status for %s: no saved status found.", set.toString());
            settings.put(set, new Settings(manager, Arrays.asList(set.getSupportedAttributes())));
            return false;
        } else {
            try (BufferedReader rdr = Files.newBufferedReader(settingsPath)) {
                Settings settings = Json.build().fromJson(rdr, Settings.class);
                if (settings == null)
                    throw new JsonParseException("Unable to load settings for gameset " + set);
                this.settings.put(set, settings);
                logger.d("Loaded gameset status for %s", set.toString());
            } catch (JsonParseException e) {
                if (e.getCause() instanceof ClassNotFoundException)
                    Log.getLogger(LogSource.STATUS).e("Error while loading plugin state: %s", e.getCause().toString());
                e.printStackTrace();
            }
            Path statusPath = basePath.resolve("status.json");
            Gson gson = Json.prebuild().registerTypeAdapter(GameList.class, new GameListAdapter(set.list())).create();
            try (BufferedReader rdr = Files.newBufferedReader(statusPath)) {
                gson.fromJson(rdr, GameList.class);
                set.refreshStatus();
                logger.d("Current status: %d/%d roms in %d/%d/%d games", set.status().getFoundRomsCount(), set.info().romCount(), set.status().getCorrectCount(), set.status().getIncompleteCount(), set.info().gameCount());
                if (set.hasFeature(Feature.CLONES))
                    set.clones().updateStatus();
                return true;
            } catch (NoSuchFileException e) {
                return false;
            }
        }
    } catch (FileNotFoundException e) {
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : Path(java.nio.file.Path) AssetManager(com.github.jakz.romlib.data.assets.AssetManager) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) GameListAdapter(com.github.jakz.romlib.json.GameListAdapter) GameList(com.github.jakz.romlib.data.set.GameList) BufferedReader(java.io.BufferedReader) Asset(com.github.jakz.romlib.data.assets.Asset) GlobalSettings(jack.rm.GlobalSettings)

Aggregations

Asset (com.github.jakz.romlib.data.assets.Asset)2 AssetManager (com.github.jakz.romlib.data.assets.AssetManager)2 GameList (com.github.jakz.romlib.data.set.GameList)1 GameListAdapter (com.github.jakz.romlib.json.GameListAdapter)1 Gson (com.google.gson.Gson)1 JsonParseException (com.google.gson.JsonParseException)1 GlobalSettings (jack.rm.GlobalSettings)1 Dimension (java.awt.Dimension)1 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1