Restored local changes after SSH re-clone
This commit is contained in:
@@ -6,7 +6,10 @@ import Server.Utils.LoadingCardsException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
@@ -25,7 +28,7 @@ public class CardDeck {
|
||||
return buildingDeck.get(era);
|
||||
}
|
||||
|
||||
public void setForNPlayer(String path, int n) throws LoadingCardsException {
|
||||
public void setForNPlayerPathTest(String path, int n) throws LoadingCardsException {
|
||||
|
||||
List<Card> tribe = new ArrayList<>();
|
||||
List<Card> building = new ArrayList<>();
|
||||
@@ -70,6 +73,52 @@ public class CardDeck {
|
||||
this.buildingDeck = building.stream().collect(Collectors.groupingBy(Card::getEra));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setForNPlayer(InputStream csvStream, int n) throws LoadingCardsException {
|
||||
List<Card> tribe = new ArrayList<>();
|
||||
List<Card> building = 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));
|
||||
break;
|
||||
case "E":
|
||||
tribe.add(EventCard.parsRow(row));
|
||||
break;
|
||||
case "B":
|
||||
building.add(BuildingCard.parsRow(row));
|
||||
break;
|
||||
default:
|
||||
throw new LoadingCardsException("Content not supported");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
logger.error(e);
|
||||
throw new LoadingCardsException("file not found");
|
||||
}
|
||||
|
||||
building = CardDeck.shuffle(building);
|
||||
|
||||
this.tribeDeck = tribe.stream()
|
||||
.filter(card -> card.getForMinPlayer() <= n)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
|
||||
this.tribeDeck = CardDeck.shuffle(this.tribeDeck);
|
||||
this.buildingDeck = building.stream().collect(Collectors.groupingBy(Card::getEra));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<Card> drawTribe(int n) {
|
||||
List<Card> cards = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
|
||||
Reference in New Issue
Block a user