speeding FX
This commit is contained in:
@@ -40,6 +40,7 @@ import server.cards.CharacterType;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -75,26 +76,15 @@ public class DeckGridAppFX extends Application {
|
|||||||
players.add(new Player("Blue", TotemColor.BLUE));
|
players.add(new Player("Blue", TotemColor.BLUE));
|
||||||
players.add(new Player("Red", TotemColor.RED));
|
players.add(new Player("Red", TotemColor.RED));
|
||||||
|
|
||||||
//players.add(new Player("Purple", TotemColor.PURPLE));
|
players.add(new Player("Purple", TotemColor.PURPLE));
|
||||||
//players.add(new Player("Green", TotemColor.GREEN));
|
players.add(new Player("Green", TotemColor.GREEN));
|
||||||
|
|
||||||
Game game = new Game(players);
|
Game game = new Game(players);
|
||||||
|
|
||||||
InputStream frontStream = getClass().getResourceAsStream("/files/Cards_total_front_PROMO.pdf");
|
//InputStream frontStream = getClass().getResourceAsStream("/files/Cards_total_front_PROMO.pdf");
|
||||||
InputStream backStream = getClass().getResourceAsStream("/files/Cards_total_back_PROMO.pdf");
|
//InputStream backStream = getClass().getResourceAsStream("/files/Cards_total_back_PROMO.pdf");
|
||||||
InputStream csvStream = getClass().getResourceAsStream("/files/cards.csv");
|
InputStream csvStream = getClass().getResourceAsStream("/files/cards.csv");
|
||||||
|
|
||||||
try {
|
|
||||||
documentFront = PDDocument.load(frontStream);
|
|
||||||
pdfRendererFront = new PDFRenderer(documentFront);
|
|
||||||
|
|
||||||
documentBack = PDDocument.load(backStream);
|
|
||||||
pdfRendererBack = new PDFRenderer(documentBack);
|
|
||||||
|
|
||||||
} catch ( IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// using false for Testing purpose
|
// using false for Testing purpose
|
||||||
game.newGame(csvStream, false);
|
game.newGame(csvStream, false);
|
||||||
|
|
||||||
@@ -115,7 +105,7 @@ public class DeckGridAppFX extends Application {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
primaryStage.setTitle("Tavolo da Gioco - Board & Players");
|
primaryStage.setTitle("Mesos - Board & Players");
|
||||||
|
|
||||||
btnTop = new Button("Pick Top");
|
btnTop = new Button("Pick Top");
|
||||||
btnBottom = new Button("Pick Bottom");
|
btnBottom = new Button("Pick Bottom");
|
||||||
@@ -182,8 +172,7 @@ public class DeckGridAppFX extends Application {
|
|||||||
|
|
||||||
|
|
||||||
private void drawGameState(Game game) {
|
private void drawGameState(Game game) {
|
||||||
if (documentFront == null) return;
|
//if (documentFront == null) return;
|
||||||
|
|
||||||
|
|
||||||
topMenu.getChildren().clear();
|
topMenu.getChildren().clear();
|
||||||
topRow.getChildren().clear();
|
topRow.getChildren().clear();
|
||||||
@@ -205,7 +194,7 @@ public class DeckGridAppFX extends Application {
|
|||||||
|
|
||||||
private void drawBottomRow(HBox row, Game game) {
|
private void drawBottomRow(HBox row, Game game) {
|
||||||
for (Card c : game.getGameBoard().getBottomRow()) {
|
for (Card c : game.getGameBoard().getBottomRow()) {
|
||||||
ImageView cardImage = createCardImageFromPdf(c.getCardId(), IMG_HEIGHT, true);
|
ImageView cardImage = createCardImageFromPdf(game.getGameBoard().getCardDeck().getImageCardsMap().get(c.getCardId()), IMG_HEIGHT);
|
||||||
|
|
||||||
if (cardImage != null) {
|
if (cardImage != null) {
|
||||||
|
|
||||||
@@ -261,7 +250,7 @@ public class DeckGridAppFX extends Application {
|
|||||||
|
|
||||||
private void drawTopRow(HBox row, Game game) {
|
private void drawTopRow(HBox row, Game game) {
|
||||||
for (Card c : game.getGameBoard().getTopRow()) {
|
for (Card c : game.getGameBoard().getTopRow()) {
|
||||||
ImageView cardImage = createCardImageFromPdf(c.getCardId(), IMG_HEIGHT, true);
|
ImageView cardImage = createCardImageFromPdf(game.getGameBoard().getCardDeck().getImageCardsMap().get(c.getCardId()), IMG_HEIGHT);
|
||||||
|
|
||||||
if (cardImage != null) {
|
if (cardImage != null) {
|
||||||
|
|
||||||
@@ -366,10 +355,18 @@ public class DeckGridAppFX extends Application {
|
|||||||
turnLabel.setFont(Font.font("System", FontWeight.BOLD, 16));
|
turnLabel.setFont(Font.font("System", FontWeight.BOLD, 16));
|
||||||
turnLabel.setTextFill(Color.DARKBLUE);
|
turnLabel.setTextFill(Color.DARKBLUE);
|
||||||
|
|
||||||
|
String coverpath="";
|
||||||
Card first = game.getGameBoard().getCardDeck().getFirstCardForCover();
|
Card first = game.getGameBoard().getCardDeck().getFirstCardForCover();
|
||||||
if (first!=null){
|
if (first!=null){
|
||||||
ImageView imgCover = createCardImageFromPdf(first.getCardId(), 120, false);
|
if (first.getEra().equals(Era.I))coverpath ="/files/allcards/era1.png";
|
||||||
turnBox.getChildren().addAll(turnLabel, imgCover);
|
else if (first.getEra().equals(Era.II)) coverpath ="/files/allcards/era2.png";
|
||||||
|
else if (first.getEra().equals(Era.III)) coverpath ="/files/allcards/era3.png";
|
||||||
|
else coverpath ="/files/allcards/final.png";
|
||||||
|
//ImageView createCardImage(InputStream imagePath, int height)
|
||||||
|
ImageView cover = createCardImage(getClass().getResourceAsStream( coverpath), 90);
|
||||||
|
//TODO load image cover
|
||||||
|
//ImageView imgCover = createCardImageFromPdf(first.getCardId(), 120, false);
|
||||||
|
turnBox.getChildren().addAll(turnLabel, cover);
|
||||||
} else turnBox.getChildren().addAll(turnLabel);
|
} else turnBox.getChildren().addAll(turnLabel);
|
||||||
|
|
||||||
// Add FIRST
|
// Add FIRST
|
||||||
@@ -484,7 +481,9 @@ public class DeckGridAppFX extends Application {
|
|||||||
HBox cardImagesRow = new HBox(5);
|
HBox cardImagesRow = new HBox(5);
|
||||||
for (Card c : cardsOfType) {
|
for (Card c : cardsOfType) {
|
||||||
// Carte più piccole (90px) per l'area giocatore
|
// Carte più piccole (90px) per l'area giocatore
|
||||||
ImageView img = createCardImageFromPdf(c.getCardId(), 90, true);
|
//ImageView img = createCardImageFromPdf(c.getCardId(), 90, true);
|
||||||
|
ImageView img = createCardImageFromPdf(game.getGameBoard().getCardDeck().getImageCardsMap().get(c.getCardId()), 90);
|
||||||
|
|
||||||
if (img != null) cardImagesRow.getChildren().add(img);
|
if (img != null) cardImagesRow.getChildren().add(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,7 +500,9 @@ public class DeckGridAppFX extends Application {
|
|||||||
HBox cardImagesRow = new HBox(5);
|
HBox cardImagesRow = new HBox(5);
|
||||||
for (Card c : cardsOfType) {
|
for (Card c : cardsOfType) {
|
||||||
// Carte più piccole (90px) per l'area giocatore
|
// Carte più piccole (90px) per l'area giocatore
|
||||||
ImageView img = createCardImageFromPdf(c.getCardId(), 90, true);
|
//ImageView img = createCardImageFromPdf(c.getCardId(), 90, true);
|
||||||
|
ImageView img = createCardImageFromPdf(game.getGameBoard().getCardDeck().getImageCardsMap().get(c.getCardId()), 90);
|
||||||
|
|
||||||
if (img != null) cardImagesRow.getChildren().add(img);
|
if (img != null) cardImagesRow.getChildren().add(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,7 +513,23 @@ public class DeckGridAppFX extends Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageView createCardImageFromPdf(int pageIndex, int height, boolean front) {
|
|
||||||
|
private ImageView createCardImageFromPdf( Image image,int height) {
|
||||||
|
ImageView imageView=null;
|
||||||
|
if (image != null) {
|
||||||
|
imageView = new ImageView(image);
|
||||||
|
imageView.setFitHeight(height);
|
||||||
|
imageView.setPreserveRatio(true);
|
||||||
|
imageView.setStyle("-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.4), 4, 0, 0, 0);");
|
||||||
|
|
||||||
|
// 👉 Add popup on click
|
||||||
|
imageView.setOnMouseClicked(e -> showCardPopup(image, e));
|
||||||
|
}
|
||||||
|
return imageView;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ImageView createCardImageFromPdf333(int pageIndex, int height, boolean front) {
|
||||||
try {
|
try {
|
||||||
BufferedImage bim;
|
BufferedImage bim;
|
||||||
if (front)
|
if (front)
|
||||||
@@ -536,6 +553,7 @@ public class DeckGridAppFX extends Application {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showCardPopup(Image image, MouseEvent event) {
|
private void showCardPopup(Image image, MouseEvent event) {
|
||||||
Stage popup = new Stage();
|
Stage popup = new Stage();
|
||||||
popup.initModality(Modality.NONE);
|
popup.initModality(Modality.NONE);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package server.cards;
|
package server.cards;
|
||||||
|
|
||||||
|
import javafx.scene.image.Image;
|
||||||
import server.Era;
|
import server.Era;
|
||||||
import server.utils.LoadingCardsException;
|
import server.utils.LoadingCardsException;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@@ -9,6 +10,7 @@ import java.io.BufferedReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -18,6 +20,11 @@ public class CardDeck {
|
|||||||
private List<Card> tribeDeck;
|
private List<Card> tribeDeck;
|
||||||
private Map<Era, List<Card>> buildingDeck;
|
private Map<Era, List<Card>> buildingDeck;
|
||||||
private static final Logger logger = LogManager.getLogger(CardDeck.class);
|
private static final Logger logger = LogManager.getLogger(CardDeck.class);
|
||||||
|
private Map<Integer, Image> imageCardsMap = new HashMap<>();
|
||||||
|
|
||||||
|
public Map<Integer, Image> getImageCardsMap() {
|
||||||
|
return imageCardsMap;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Card> getTribeDeck() {
|
public List<Card> getTribeDeck() {
|
||||||
return tribeDeck;
|
return tribeDeck;
|
||||||
@@ -43,6 +50,7 @@ public class CardDeck {
|
|||||||
String cleanRow = row.trim();
|
String cleanRow = row.trim();
|
||||||
String[] fields = cleanRow.split(";");
|
String[] fields = cleanRow.split(";");
|
||||||
logger.info((p++) + " ROW " +row);
|
logger.info((p++) + " ROW " +row);
|
||||||
|
|
||||||
switch (fields[0]) {
|
switch (fields[0]) {
|
||||||
case "C":
|
case "C":
|
||||||
tribe.add(CharacterCard.parsRow(row));
|
tribe.add(CharacterCard.parsRow(row));
|
||||||
@@ -109,6 +117,8 @@ public class CardDeck {
|
|||||||
logger.error(e);
|
logger.error(e);
|
||||||
throw new LoadingCardsException("file not found");
|
throw new LoadingCardsException("file not found");
|
||||||
}
|
}
|
||||||
|
loadCardImage(tribe);
|
||||||
|
loadCardImage(building);
|
||||||
|
|
||||||
if (shuffle) building = CardDeck.shuffle(building);
|
if (shuffle) building = CardDeck.shuffle(building);
|
||||||
|
|
||||||
@@ -120,6 +130,67 @@ public class CardDeck {
|
|||||||
this.buildingDeck = building.stream().collect(Collectors.groupingBy(Card::getEra));
|
this.buildingDeck = building.stream().collect(Collectors.groupingBy(Card::getEra));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadCardImage(List<Card> cards){
|
||||||
|
for (Card c : cards) {
|
||||||
|
String path = "/files/allcards/" + c.getCardId() + ".png";
|
||||||
|
URL resource = getClass().getResource(path);
|
||||||
|
if (resource != null) {
|
||||||
|
Image image = new Image(resource.toExternalForm());
|
||||||
|
imageCardsMap.put(c.getCardId(), image);
|
||||||
|
} else {
|
||||||
|
logger.error("Immagine non trovata per cardId: " + c.getCardId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Card> loadForNPlayerTest(InputStream csvStream, int n, boolean shuffle) throws LoadingCardsException {
|
||||||
|
List<Card> tribe = new ArrayList<>();
|
||||||
|
List<Card> building = new ArrayList<>();
|
||||||
|
List<Card> allCards = new ArrayList<>();
|
||||||
|
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(csvStream))) {
|
||||||
|
String row;
|
||||||
|
int p = 0;
|
||||||
|
while ((row = reader.readLine()) != null) {
|
||||||
|
String cleanRow = row.trim();
|
||||||
|
String[] fields = cleanRow.split(";");
|
||||||
|
|
||||||
|
logger.info((p++) + " ROW " + row);
|
||||||
|
|
||||||
|
switch (fields[0]) {
|
||||||
|
case "C":
|
||||||
|
tribe.add(CharacterCard.parsRow(row));
|
||||||
|
allCards.add(CharacterCard.parsRow(row));
|
||||||
|
break;
|
||||||
|
case "E":
|
||||||
|
tribe.add(EventCard.parsRow(row));
|
||||||
|
allCards.add(EventCard.parsRow(row));
|
||||||
|
break;
|
||||||
|
case "B":
|
||||||
|
building.add(BuildingCard.parsRow(row));
|
||||||
|
allCards.add(BuildingCard.parsRow(row));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new LoadingCardsException("Content not supported");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error(e);
|
||||||
|
throw new LoadingCardsException("file not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shuffle) building = CardDeck.shuffle(building);
|
||||||
|
|
||||||
|
this.tribeDeck = tribe.stream()
|
||||||
|
.filter(card -> card.getForMinPlayer() <= n)
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
|
||||||
|
if (shuffle) this.tribeDeck = CardDeck.shuffle(this.tribeDeck);
|
||||||
|
this.buildingDeck = building.stream().collect(Collectors.groupingBy(Card::getEra));
|
||||||
|
return allCards;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<Card> drawTribe(int n) {
|
public List<Card> drawTribe(int n) {
|
||||||
|
|||||||
BIN
src/main/resources/files/allcards/era1.png
Normal file
BIN
src/main/resources/files/allcards/era1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
BIN
src/main/resources/files/allcards/era2.png
Normal file
BIN
src/main/resources/files/allcards/era2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
BIN
src/main/resources/files/allcards/era3.png
Normal file
BIN
src/main/resources/files/allcards/era3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
BIN
src/main/resources/files/allcards/final.png
Normal file
BIN
src/main/resources/files/allcards/final.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 MiB |
Reference in New Issue
Block a user