Search in sources :

Example 1 with Asset

use of com.github.jakz.romlib.data.assets.Asset 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 Asset

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

the class OfflineListProviderPlugin method buildRomSets.

@Override
public GameSet[] buildRomSets(List<DatParserPlugin> datParsers) {
    DatParserPlugin parser = this.findDatParser(datParsers, "offline-list");
    List<GameSet> sets = new ArrayList<>();
    try {
        {
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", new GBASaveParserOL());
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            sets.add(new GameSet(Platforms.GBA, KnownProviders.OFFLINE_LIST.derive("", "", "Replouf66", new Provider.Source("http://offlinelistgba.free.fr/tool/ReleaseList/gba_OL_0.7.1.zip")), datParser, format, GBA_ATTRIBUTES, new AssetManager(GBA_ASSETS, new URL("http://offlinelistgba.free.fr/imgs/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
        }
        {
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", new GBASaveParserAS());
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            sets.add(new GameSet(Platforms.GBA, KnownProviders.ADVAN_SCENE.derive("pure", "", "AdvanScene", new Provider.Source("http://www.advanscene.com/offline/datas/ADVANsCEne_GBA.zip")), datParser, format, GBA_ATTRIBUTES, new AssetManager(GBA_ASSETS, new URL("http://www.advanscene.com/offline/imgs/ADVANsCEne_GBA/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
        }
        {
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", (SaveParser) (s -> GameSave.NULL));
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            final Asset[] PSP_ASSETS = { new Asset.Image(Paths.get("title"), new Dimension(208, 181 * 2)), new Asset.Image(Paths.get("gameplay"), new Dimension(320 * 2, 181 * 2)) };
            final Attribute[] attributes = { GameAttribute.TITLE, GameAttribute.NUMBER, GameAttribute.SIZE, GameAttribute.PUBLISHER, GameAttribute.LOCATION, GameAttribute.LANGUAGE, GameAttribute.GROUP, GameAttribute.COMMENT };
            sets.add(new GameSet(Platforms.PSP, KnownProviders.ADVAN_SCENE.derive("", "", "AdvanScene", new Provider.Source("http://www.advanscene.com/offline/datas/ADVANsCEne_PSP.zip")), datParser, format, attributes, new AssetManager(PSP_ASSETS, new URL("http://www.advanscene.com/offline/imgs/ADVANsCEne_PSP/")), s -> new MyGameSetFeatures(s)));
        }
        {
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", new NDSSaveParser());
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            sets.add(new GameSet(Platforms.NDS, KnownProviders.ADVAN_SCENE.derive("collection", "", "AdvanScene", new Provider.Source("http://www.advanscene.com/offline/datas/ADVANsCEne_NDS.zip")), datParser, format, GBA_ATTRIBUTES, new AssetManager(NDS_ASSETS, new URL("http://www.advanscene.com/offline/imgs/ADVANsCEne_NDS/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
        }
        /* Nintendo 3DS */
        {
            final Asset[] _3DS_ASSETS = { new Asset.Image(Paths.get("title"), new Dimension(268, 480)), new Asset.Image(Paths.get("gameplay"), new Dimension(400, 480)) };
            final Attribute[] _3DS_ATTRIBUTES = { GameAttribute.TITLE, GameAttribute.NUMBER, GameAttribute.SIZE, GameAttribute.PUBLISHER, GameAttribute.GROUP, GameAttribute.SAVE_TYPE, GameAttribute.LOCATION, GameAttribute.LANGUAGE, GameAttribute.COMMENT };
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", (SaveParser) s -> null);
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            sets.add(new GameSet(Platforms._3DS, KnownProviders.ADVAN_SCENE.derive("", "", "AdvanScene", new Provider.Source("http://www.advanscene.com/offline/datas/ADVANsCEne_3DS.zip")), datParser, format, _3DS_ATTRIBUTES, new AssetManager(_3DS_ASSETS, new URL("http://www.advanscene.com/offline/imgs/ADVANsCEne_3DS/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
        }
        {
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", (SaveParser) (r -> null));
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            sets.add(new GameSet(Platforms.GBC, KnownProviders.NO_INTRO.derive("", "", "Replouf66", new Provider.Source("http://nointro.free.fr/datas/Official%20No-Intro%20Nintendo%20Gameboy%20Color.zip")), datParser, format, GB_ATTRIBUTES, new AssetManager(GB_ASSETS, new URL("http://nointro.free.fr/imgs/Official%20No-Intro%20Nintendo%20Gameboy%20Color/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
        }
        {
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", (SaveParser) (r -> null));
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            sets.add(new GameSet(Platforms.GB, KnownProviders.NO_INTRO.derive("", "", "MadBob", new Provider.Source("http://nointro.free.fr/datas/Official%20No-Intro%20Nintendo%20Gameboy.zip")), datParser, format, GB_ATTRIBUTES, new AssetManager(GB_ASSETS, new URL("http://nointro.free.fr/imgs/Official%20No-Intro%20Nintendo%20Gameboy/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
        }
        {
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", (SaveParser) (r -> null));
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            sets.add(new GameSet(Platforms.NES, KnownProviders.NO_INTRO.derive("", "", "Zepman", new Provider.Source("http://nointro.free.fr/datas/Official%20No-Intro%20Nintendo%20NES%20-%20Famicom.zip")), datParser, format, NES_ATTRIBUTES, new AssetManager(GB_ASSETS, new URL("http://nointro.free.fr/imgs/Official%20No-Intro%20Nintendo%20NES%20-%20Famicom/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
            sets.add(new GameSet(Platforms.NES, KnownProviders.OFFLINE_LIST.derive("", "", "Zepman", new Provider.Source("http://nesofflinelist.free.fr/dat/nes_OL.zip")), datParser, format, NES_ATTRIBUTES, new AssetManager(NES_ASSETS, new URL("http://nesofflinelist.free.fr/imgs/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
        }
        {
            Map<String, Object> args = new HashMap<>();
            args.put("save-parser", (SaveParser) (r -> null));
            DataSupplier datParser = parser.buildDatLoader("offline-list", args);
            DatFormat format = datParser.getFormat();
            sets.add(new GameSet(Platforms.LYNX, KnownProviders.NO_INTRO.derive("", "", "Atari Lynx", new Provider.Source("http://nointro.free.fr/datas/Official%20No-Intro%20Atari%20Lynx.zip")), datParser, format, NES_ATTRIBUTES, new AssetManager(LYNX_ASSETS, new URL("http://nointro.free.fr/imgs/Official%20No-Intro%20Atari%20Lynx/")), s -> new MyGameSetFeatures(s, Feature.FINITE_SIZE_SET)));
        }
        return sets.toArray(new GameSet[sets.size()]);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Arrays(java.util.Arrays) SaveParser(com.github.jakz.romlib.parsers.SaveParser) URL(java.net.URL) GameAttribute(com.github.jakz.romlib.data.game.attributes.GameAttribute) DatFormat(com.github.jakz.romlib.data.set.DatFormat) Asset(com.github.jakz.romlib.data.assets.Asset) Game(com.github.jakz.romlib.data.game.Game) DataSupplier(com.github.jakz.romlib.data.set.DataSupplier) HashMap(java.util.HashMap) MyGameSetFeatures(jack.rm.data.romset.MyGameSetFeatures) Attribute(com.github.jakz.romlib.data.game.attributes.Attribute) ProviderPlugin(jack.rm.plugins.types.ProviderPlugin) Platforms(com.github.jakz.romlib.data.platforms.Platforms) ArrayList(java.util.ArrayList) GameSet(com.github.jakz.romlib.data.set.GameSet) Map(java.util.Map) DatParserPlugin(jack.rm.plugins.types.DatParserPlugin) Feature(com.github.jakz.romlib.data.set.Feature) NDS(com.github.jakz.romlib.data.platforms.NDS) MalformedURLException(java.net.MalformedURLException) Version(com.github.jakz.romlib.data.game.Version) DecimalFormat(java.text.DecimalFormat) UnknownFormatConversionException(java.util.UnknownFormatConversionException) Dimension(java.awt.Dimension) List(java.util.List) Paths(java.nio.file.Paths) GameSave(com.github.jakz.romlib.data.game.GameSave) Provider(com.github.jakz.romlib.data.set.Provider) GBA(com.github.jakz.romlib.data.platforms.GBA) RomSize(com.github.jakz.romlib.data.game.RomSize) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) Dimension(java.awt.Dimension) URL(java.net.URL) SaveParser(com.github.jakz.romlib.parsers.SaveParser) DataSupplier(com.github.jakz.romlib.data.set.DataSupplier) MyGameSetFeatures(jack.rm.data.romset.MyGameSetFeatures) DatFormat(com.github.jakz.romlib.data.set.DatFormat) HashMap(java.util.HashMap) Map(java.util.Map) DatParserPlugin(jack.rm.plugins.types.DatParserPlugin) GameSet(com.github.jakz.romlib.data.set.GameSet)

Example 3 with Asset

use of com.github.jakz.romlib.data.assets.Asset 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)

Example 4 with Asset

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

the class InfoPanel method setImage.

void setImage(Game rom, Asset asset, JLabel dest) {
    AssetData data = rom.getAssetData(asset);
    if (data.isPresent()) {
        Asset.Image imageAsset = (Asset.Image) asset;
        Dimension size = imageAsset.getSize();
        ImageIcon i = data.asImage();
        Image img = i.getImage();
        BufferedImage bi = new BufferedImage(size.width, size.height, BufferedImage.TYPE_INT_ARGB);
        Graphics g = bi.createGraphics();
        g.drawImage(img, 0, 0, size.width, size.height, null);
        dest.setText("");
        dest.setIcon(new ImageIcon(bi));
    } else {
        dest.setText("Asset Missing");
        dest.setIcon(null);
    }
}
Also used : Graphics(java.awt.Graphics) ImageIcon(javax.swing.ImageIcon) Asset(com.github.jakz.romlib.data.assets.Asset) AssetData(com.github.jakz.romlib.data.assets.AssetData) Dimension(java.awt.Dimension) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage)

Aggregations

Asset (com.github.jakz.romlib.data.assets.Asset)4 Dimension (java.awt.Dimension)3 AssetManager (com.github.jakz.romlib.data.assets.AssetManager)2 Image (java.awt.Image)2 BufferedImage (java.awt.image.BufferedImage)2 AssetData (com.github.jakz.romlib.data.assets.AssetData)1 Game (com.github.jakz.romlib.data.game.Game)1 GameSave (com.github.jakz.romlib.data.game.GameSave)1 RomSize (com.github.jakz.romlib.data.game.RomSize)1 Version (com.github.jakz.romlib.data.game.Version)1 Attribute (com.github.jakz.romlib.data.game.attributes.Attribute)1 GameAttribute (com.github.jakz.romlib.data.game.attributes.GameAttribute)1 GBA (com.github.jakz.romlib.data.platforms.GBA)1 NDS (com.github.jakz.romlib.data.platforms.NDS)1 Platforms (com.github.jakz.romlib.data.platforms.Platforms)1 DatFormat (com.github.jakz.romlib.data.set.DatFormat)1 DataSupplier (com.github.jakz.romlib.data.set.DataSupplier)1 Feature (com.github.jakz.romlib.data.set.Feature)1 GameList (com.github.jakz.romlib.data.set.GameList)1 GameSet (com.github.jakz.romlib.data.set.GameSet)1