speeding FX
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package server.cards;
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
import server.Era;
|
||||
import server.utils.LoadingCardsException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -9,6 +10,7 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
@@ -18,6 +20,11 @@ public class CardDeck {
|
||||
private List<Card> tribeDeck;
|
||||
private Map<Era, List<Card>> buildingDeck;
|
||||
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() {
|
||||
return tribeDeck;
|
||||
@@ -43,6 +50,7 @@ public class CardDeck {
|
||||
String cleanRow = row.trim();
|
||||
String[] fields = cleanRow.split(";");
|
||||
logger.info((p++) + " ROW " +row);
|
||||
|
||||
switch (fields[0]) {
|
||||
case "C":
|
||||
tribe.add(CharacterCard.parsRow(row));
|
||||
@@ -109,6 +117,8 @@ public class CardDeck {
|
||||
logger.error(e);
|
||||
throw new LoadingCardsException("file not found");
|
||||
}
|
||||
loadCardImage(tribe);
|
||||
loadCardImage(building);
|
||||
|
||||
if (shuffle) building = CardDeck.shuffle(building);
|
||||
|
||||
@@ -120,6 +130,67 @@ public class CardDeck {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user