Search in sources :

Example 1 with TileRef

use of com.b3dgs.lionengine.game.feature.tile.TileRef in project lionengine by b3dgs.

the class CircuitsConfig method importTiles.

/**
 * Import all tiles from their nodes.
 *
 * @param nodesTileRef The tiles nodes (must not be <code>null</code>).
 * @return The imported tiles ref.
 */
private static Collection<TileRef> importTiles(Collection<Xml> nodesTileRef) {
    final Collection<TileRef> tilesRef = new HashSet<>(nodesTileRef.size());
    for (final Xml nodeTileRef : nodesTileRef) {
        final TileRef tileRef = TileConfig.imports(nodeTileRef);
        tilesRef.add(tileRef);
    }
    return tilesRef;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef) HashSet(java.util.HashSet)

Example 2 with TileRef

use of com.b3dgs.lionengine.game.feature.tile.TileRef in project lionengine by b3dgs.

the class MapTileGroupModel method changeGroup.

@Override
public void changeGroup(Tile tile, String group) {
    final TileRef ref = new TileRef(tile);
    final String oldGroup = getGroup(tile);
    if (groupTiles.containsKey(oldGroup)) {
        groupTiles.get(oldGroup).remove(ref);
    }
    if (group != null) {
        tilesGroup.put(ref, group);
        if (!groupTiles.containsKey(group)) {
            groupTiles.put(group, new HashSet<TileRef>());
        }
        groupTiles.get(group).add(ref);
    } else {
        tilesGroup.remove(ref);
    }
}
Also used : TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef)

Example 3 with TileRef

use of com.b3dgs.lionengine.game.feature.tile.TileRef in project lionengine by b3dgs.

the class Minimap method computeSheet.

/**
 * Compute the current sheet.
 *
 * @param colors The colors data.
 * @param sheet The sheet number.
 */
private void computeSheet(Map<TileRef, ColorRgba> colors, Integer sheet) {
    final SpriteTiled tiles = map.getSheet(sheet);
    final ImageBuffer tilesSurface = tiles.getSurface();
    final int tw = map.getTileWidth();
    final int th = map.getTileHeight();
    int number = 0;
    for (int i = 0; i < tilesSurface.getWidth(); i += tw) {
        for (int j = 0; j < tilesSurface.getHeight(); j += th) {
            final int h = number * tw % tiles.getWidth();
            final int v = number / tiles.getTilesHorizontal() * th;
            final ColorRgba color = UtilColor.getWeightedColor(tilesSurface, h, v, tw, th);
            if (!(NO_TILE.equals(color) || color.getAlpha() == 0)) {
                colors.put(new TileRef(sheet, number), color);
            }
            number++;
        }
    }
}
Also used : ImageBuffer(com.b3dgs.lionengine.graphic.ImageBuffer) ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) SpriteTiled(com.b3dgs.lionengine.graphic.SpriteTiled) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef)

Example 4 with TileRef

use of com.b3dgs.lionengine.game.feature.tile.TileRef in project lionengine by b3dgs.

the class MinimapConfig method exports.

/**
 * Export tiles colors data to configuration media.
 *
 * @param configMinimap The configuration media output (must not be <code>null</code>).
 * @param tiles The tiles data (must not be <code>null</code>).
 * @throws LionEngineException If error on writing.
 */
public static void exports(Media configMinimap, Map<TileRef, ColorRgba> tiles) {
    Check.notNull(configMinimap);
    Check.notNull(tiles);
    final Map<ColorRgba, Collection<TileRef>> colors = convertToColorKey(tiles);
    final Xml nodeMinimap = new Xml(NODE_MINIMAP);
    for (final Map.Entry<ColorRgba, Collection<TileRef>> entry : colors.entrySet()) {
        final ColorRgba color = entry.getKey();
        final Xml nodeColor = nodeMinimap.createChild(NODE_COLOR);
        nodeColor.writeInteger(ATT_COLOR_RED, color.getRed());
        nodeColor.writeInteger(ATT_COLOR_GREEN, color.getGreen());
        nodeColor.writeInteger(ATT_COLOR_BLUE, color.getBlue());
        for (final TileRef tileRef : entry.getValue()) {
            final Xml nodeTileRef = TileConfig.exports(tileRef);
            nodeColor.add(nodeTileRef);
        }
    }
    nodeMinimap.save(configMinimap);
}
Also used : ColorRgba(com.b3dgs.lionengine.graphic.ColorRgba) Xml(com.b3dgs.lionengine.io.Xml) Collection(java.util.Collection) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with TileRef

use of com.b3dgs.lionengine.game.feature.tile.TileRef in project lionengine by b3dgs.

the class TransitionsConfig method importTiles.

/**
 * Import all tiles from their nodes.
 *
 * @param nodesTileRef The tiles nodes (must not be <code>null</code>).
 * @return The imported tiles ref.
 */
private static Collection<TileRef> importTiles(Collection<Xml> nodesTileRef) {
    final Collection<TileRef> tilesRef = new HashSet<>(nodesTileRef.size());
    for (final Xml nodeTileRef : nodesTileRef) {
        final TileRef tileRef = TileConfig.imports(nodeTileRef);
        tilesRef.add(tileRef);
    }
    return tilesRef;
}
Also used : Xml(com.b3dgs.lionengine.io.Xml) TileRef(com.b3dgs.lionengine.game.feature.tile.TileRef) HashSet(java.util.HashSet)

Aggregations

TileRef (com.b3dgs.lionengine.game.feature.tile.TileRef)13 Xml (com.b3dgs.lionengine.io.Xml)5 ColorRgba (com.b3dgs.lionengine.graphic.ColorRgba)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 TileGroup (com.b3dgs.lionengine.game.feature.tile.TileGroup)1 ImageBuffer (com.b3dgs.lionengine.graphic.ImageBuffer)1 SpriteTiled (com.b3dgs.lionengine.graphic.SpriteTiled)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1