Search in sources :

Example 1 with Tileset

use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.

the class AssetPanel method loadTilesets.

public void loadTilesets(List<Tileset> tilesets) {
    this.load(tilesets, () -> {
        Collections.sort(tilesets);
        for (Tileset tileset : tilesets) {
            AssetPanelItem panelItem = new AssetPanelItem(Icons.DOC_TILESET, tileset.getName(), tileset);
            this.add(panelItem);
            panelItem.validate();
        }
    });
}
Also used : Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)

Example 2 with Tileset

use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.

the class AssetPanelItem method exportTileset.

private void exportTileset() {
    if (!(this.getOrigin() instanceof Tileset)) {
        return;
    }
    Tileset tileset = (Tileset) this.getOrigin();
    XmlExportDialog.export(tileset, "Tileset", tileset.getName(), Tileset.FILE_EXTENSION);
}
Also used : Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)

Example 3 with Tileset

use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.

the class EditorScreen method loadSpriteSheets.

private void loadSpriteSheets(Map map) {
    List<SpriteSheetInfo> infos = new ArrayList<>();
    int cnt = 0;
    for (ITileset tileSet : map.getTilesets()) {
        if (tileSet.getImage() == null || Spritesheet.find(tileSet.getName()) != null) {
            continue;
        }
        Spritesheet sprite = Spritesheet.find(tileSet.getImage().getSource());
        if (sprite == null) {
            sprite = Spritesheet.load(tileSet);
            if (sprite == null) {
                continue;
            }
        }
        infos.add(new SpriteSheetInfo(sprite));
        cnt++;
    }
    for (IImageLayer imageLayer : map.getImageLayers()) {
        Spritesheet sprite = Spritesheet.find(imageLayer.getImage().getSource());
        if (sprite == null) {
            BufferedImage img = Resources.getImage(imageLayer.getImage().getAbsoluteSourcePath(), true);
            sprite = Spritesheet.load(img, imageLayer.getImage().getSource(), img.getWidth(), img.getHeight());
            if (sprite == null) {
                continue;
            }
        }
        SpriteSheetInfo info = new SpriteSheetInfo(sprite);
        infos.add(info);
        this.getGameFile().getSpriteSheets().removeIf(x -> x.getName().equals(info.getName()));
        this.getGameFile().getSpriteSheets().add(info);
        cnt++;
    }
    this.loadSpriteSheets(infos, false);
    for (SpriteSheetInfo info : infos) {
        if (!this.getGameFile().getSpriteSheets().stream().anyMatch(x -> x.getName().equals(info.getName()))) {
            this.getGameFile().getSpriteSheets().add(info);
        }
    }
    if (cnt > 0) {
        log.log(Level.INFO, "{0} tilesets loaded from {1}", new Object[] { cnt, map.getFileName() });
    }
}
Also used : Color(java.awt.Color) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) EditorComponent(de.gurkenlabs.utiliti.components.EditorComponent) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) Point(java.awt.Point) ComponentType(de.gurkenlabs.utiliti.components.EditorComponent.ComponentType) MathUtilities(de.gurkenlabs.litiengine.util.MathUtilities) SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) Map(de.gurkenlabs.litiengine.environment.tilemap.xml.Map) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) MapComponent(de.gurkenlabs.utiliti.components.MapComponent) Graphics2D(java.awt.Graphics2D) ImageCache(de.gurkenlabs.litiengine.graphics.ImageCache) FileUtilities(de.gurkenlabs.litiengine.util.io.FileUtilities) Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset) JFileChooser(javax.swing.JFileChooser) Resources(de.gurkenlabs.litiengine.Resources) IImageLayer(de.gurkenlabs.litiengine.environment.tilemap.IImageLayer) BufferedImage(java.awt.image.BufferedImage) Font(java.awt.Font) EmitterData(de.gurkenlabs.litiengine.graphics.particles.xml.EmitterData) Collection(java.util.Collection) IOException(java.io.IOException) Logger(java.util.logging.Logger) JOptionPane(javax.swing.JOptionPane) FileFilter(javax.swing.filechooser.FileFilter) Collectors(java.util.stream.Collectors) MapObjectPanel(de.gurkenlabs.utiliti.swing.panels.MapObjectPanel) File(java.io.File) GameData(de.gurkenlabs.litiengine.GameData) Input(de.gurkenlabs.litiengine.input.Input) ImageFormat(de.gurkenlabs.litiengine.graphics.ImageFormat) List(java.util.List) CustomEmitter(de.gurkenlabs.litiengine.graphics.particles.xml.CustomEmitter) XmlUtilities(de.gurkenlabs.litiengine.util.io.XmlUtilities) Paths(java.nio.file.Paths) Screen(de.gurkenlabs.litiengine.gui.screens.Screen) RenderEngine(de.gurkenlabs.litiengine.graphics.RenderEngine) SpritesheetImportPanel(de.gurkenlabs.utiliti.swing.dialogs.SpritesheetImportPanel) Game(de.gurkenlabs.litiengine.Game) ScreenInfo(de.gurkenlabs.litiengine.annotation.ScreenInfo) XmlImportDialog(de.gurkenlabs.utiliti.swing.XmlImportDialog) SpriteSheetInfo(de.gurkenlabs.litiengine.SpriteSheetInfo) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) Spritesheet(de.gurkenlabs.litiengine.graphics.Spritesheet) ArrayList(java.util.ArrayList) IImageLayer(de.gurkenlabs.litiengine.environment.tilemap.IImageLayer) Point(java.awt.Point) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint) BufferedImage(java.awt.image.BufferedImage)

Example 4 with Tileset

use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.

the class EditorScreen method importTilesets.

public void importTilesets() {
    XmlImportDialog.importXml("Tilesets", Tileset.FILE_EXTENSION, files -> {
        for (File file : files) {
            Tileset tileset = XmlUtilities.readFromFile(Tileset.class, file.toString());
            if (tileset == null) {
                continue;
            }
            String path = FileUtilities.getParentDirPath(file.getPath());
            tileset.setMapPath(path);
            if (this.gameFile.getTilesets().stream().anyMatch(x -> x.getName().equals(tileset.getName()))) {
                int result = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), Resources.get("import_tileset_title", tileset.getName()), Resources.get("import_tileset_title"), JOptionPane.YES_NO_OPTION);
                if (result == JOptionPane.NO_OPTION) {
                    continue;
                }
                this.getMapComponent().loadTileset(tileset, false);
            }
            log.log(Level.INFO, "imported tileset {0} from {1}", new Object[] { tileset.getName(), file });
        }
    });
}
Also used : File(java.io.File) ITileset(de.gurkenlabs.litiengine.environment.tilemap.ITileset) Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset) Point(java.awt.Point) Blueprint(de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)

Example 5 with Tileset

use of de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset in project litiengine by gurkenlabs.

the class GameData method load.

public static GameData load(final String file) {
    try {
        GameData gameFile = getGameFileFromFile(file);
        if (gameFile == null) {
            return null;
        }
        gameFile.getMaps().parallelStream().forEach(map -> {
            for (final Tileset tileset : map.getRawTileSets()) {
                tileset.load(gameFile.getTilesets());
            }
            map.updateTileTerrain();
        });
        return gameFile;
    } catch (final JAXBException | IOException e) {
        log.log(Level.SEVERE, e.getMessage(), e);
    }
    return null;
}
Also used : JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) Tileset(de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)

Aggregations

Tileset (de.gurkenlabs.litiengine.environment.tilemap.xml.Tileset)10 ITileset (de.gurkenlabs.litiengine.environment.tilemap.ITileset)5 Blueprint (de.gurkenlabs.litiengine.environment.tilemap.xml.Blueprint)4 Map (de.gurkenlabs.litiengine.environment.tilemap.xml.Map)4 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Resources (de.gurkenlabs.litiengine.Resources)3 ImageFormat (de.gurkenlabs.litiengine.graphics.ImageFormat)3 Game (de.gurkenlabs.litiengine.Game)2 GameData (de.gurkenlabs.litiengine.GameData)2 SpriteSheetInfo (de.gurkenlabs.litiengine.SpriteSheetInfo)2 IImageLayer (de.gurkenlabs.litiengine.environment.tilemap.IImageLayer)2 ImageCache (de.gurkenlabs.litiengine.graphics.ImageCache)2 RenderEngine (de.gurkenlabs.litiengine.graphics.RenderEngine)2 Spritesheet (de.gurkenlabs.litiengine.graphics.Spritesheet)2 EditorScreen (de.gurkenlabs.utiliti.EditorScreen)2 Program (de.gurkenlabs.utiliti.Program)2 Dimension (java.awt.Dimension)2 Point (java.awt.Point)2