/*
* Copyright (C) 2014 Tim Declercq <caveman1917@hotmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package chesstrainer.ui;
import chesstrainer.Main;
import chesstrainer.util.EPiece;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.file.Path;
import java.util.EnumMap;
import java.util.Map;
import java.util.logging.Level;
import javax.imageio.ImageIO;
/**
*
* @author Tim Declercq <caveman1917@hotmail.com>
*/
public class CPieceSet {
private Map<EPiece, BufferedImage> pieces = new EnumMap(EPiece.class);
public CPieceSet(String name) {
Path dir = Main.DIRECTORY.resolve("res").resolve("piecesets").resolve(name);
File file;
for (EPiece piece : EPiece.values()) {
file = dir.resolve(piece.name().toLowerCase() + ".png").toFile();
try {
pieces.put(piece, ImageIO.read(file));
} catch (Exception e) {
Main.LOG.log(Level.SEVERE, "cannot load piece image", e);
}
}
}
public BufferedImage getImage(EPiece piece) {
return pieces.get(piece);
}
}