add world interface
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
package chess.view.DDDrender.loader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import chess.model.Color;
|
||||
import chess.model.Piece;
|
||||
import chess.model.PieceVisitor;
|
||||
import chess.model.pieces.Bishop;
|
||||
import chess.model.pieces.King;
|
||||
import chess.model.pieces.Knight;
|
||||
import chess.model.pieces.Pawn;
|
||||
import chess.model.pieces.Queen;
|
||||
import chess.model.pieces.Rook;
|
||||
import chess.view.DDDrender.DDDModel;
|
||||
|
||||
public class Piece3DModel implements PieceVisitor<String> {
|
||||
|
||||
private static final String basePath = "3d/";
|
||||
private static final Map<String, DDDModel> cache = new HashMap<>();
|
||||
|
||||
public DDDModel getModel(Piece piece) throws IOException {
|
||||
if (piece == null)
|
||||
return null;
|
||||
|
||||
String path = basePath + colorToString(piece.getColor()) + "-" + visit(piece) + ".fbx";
|
||||
return getModel(path);
|
||||
}
|
||||
|
||||
private DDDModel getModel(String path) throws IOException {
|
||||
DDDModel model = cache.get(path);
|
||||
if (model != null)
|
||||
return model;
|
||||
|
||||
model = ModelLoader.loadModel(path);
|
||||
cache.put(path, model);
|
||||
return model;
|
||||
}
|
||||
|
||||
private String colorToString(Color color) {
|
||||
return color == Color.Black ? "black" : "white";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPiece(Bishop bishop) {
|
||||
return "bishop";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPiece(King king) {
|
||||
return "king";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPiece(Knight knight) {
|
||||
return "knight";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPiece(Pawn pawn) {
|
||||
return "pawn";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPiece(Queen queen) {
|
||||
return "queen";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPiece(Rook rook) {
|
||||
return "rook";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user