use Executor, update MatchScreen

This commit is contained in:
Anthony Calosa
2024-11-23 13:22:41 +08:00
parent 0b9fb9f379
commit b0411423f6
3 changed files with 20 additions and 12 deletions

View File

@@ -79,6 +79,7 @@ public class AiAttackController {
private int aiAggression = 0; // how aggressive the ai is attack will be depending on circumstances private int aiAggression = 0; // how aggressive the ai is attack will be depending on circumstances
private final boolean nextTurn; // include creature that can only attack/block next turn private final boolean nextTurn; // include creature that can only attack/block next turn
private final int timeOut; private final int timeOut;
private List<CompletableFuture<Integer>> futures = new ArrayList<>();
/** /**
* <p> * <p>
@@ -910,7 +911,6 @@ public class AiAttackController {
final AtomicInteger numForcedAttackers = new AtomicInteger(0); final AtomicInteger numForcedAttackers = new AtomicInteger(0);
// nextTurn is now only used by effect from Oracle en-Vec, which can skip check must attack, // nextTurn is now only used by effect from Oracle en-Vec, which can skip check must attack,
// because creatures not chosen can't attack. // because creatures not chosen can't attack.
List<CompletableFuture<Integer>> futures = new ArrayList<>();
if (!nextTurn) { if (!nextTurn) {
for (final Card attacker : this.attackers) { for (final Card attacker : this.attackers) {
final GameEntity finalDefender = defender; final GameEntity finalDefender = defender;

View File

@@ -777,7 +777,7 @@ public class StaticData {
continue; continue;
Map<String, Pair<Boolean, Integer>> cardCount = new HashMap<>(); Map<String, Pair<Boolean, Integer>> cardCount = new HashMap<>();
List<CompletableFuture<Integer>> futures = new ArrayList<>(); List<CompletableFuture<?>> futures = new ArrayList<>();
for (CardEdition.CardInSet c : e.getAllCardsInSet()) { for (CardEdition.CardInSet c : e.getAllCardsInSet()) {
if (cardCount.containsKey(c.name)) { if (cardCount.containsKey(c.name)) {
cardCount.put(c.name, Pair.of(c.collectorNumber != null && c.collectorNumber.startsWith("F"), cardCount.get(c.name).getRight() + 1)); cardCount.put(c.name, Pair.of(c.collectorNumber != null && c.collectorNumber.startsWith("F"), cardCount.get(c.name).getRight() + 1));
@@ -798,12 +798,12 @@ public class StaticData {
} }
if (cp == null) { if (cp == null) {
if (isFunny) //skip funny cards if (isFunny) //skip funny cards
return 0; return null;
if (!loadNonLegalCards && CardEdition.Type.FUNNY.equals(e.getType())) if (!loadNonLegalCards && CardEdition.Type.FUNNY.equals(e.getType()))
return 0; return null;
EDITION_Q.add(e.getCode() + "_" + e.getName()); EDITION_Q.add(e.getCode() + "_" + e.getName());
CNI_Q.add(e.getCode() + "_" + c + "\n"); CNI_Q.add(e.getCode() + "_" + c + "\n");
return 0; return null;
} }
// check the front image // check the front image
String imagePath = ImageUtil.getImageRelativePath(cp, "", true, false); String imagePath = ImageUtil.getImageRelativePath(cp, "", true, false);
@@ -813,7 +813,7 @@ public class StaticData {
file = ImageKeys.setLookUpFile(imagePath, imagePath +"border"); file = ImageKeys.setLookUpFile(imagePath, imagePath +"border");
if (file == null) { if (file == null) {
if (imagePath.isEmpty()) if (imagePath.isEmpty())
return 0; return null;
EDITION_Q.add(e.getCode() + "_" + e.getName()); EDITION_Q.add(e.getCode() + "_" + e.getName());
NIF_Q.add(e.getCode() + "_" + imagePath + "\n"); NIF_Q.add(e.getCode() + "_" + imagePath + "\n");
} }
@@ -827,16 +827,16 @@ public class StaticData {
file = ImageKeys.setLookUpFile(imagePath, imagePath +"border"); file = ImageKeys.setLookUpFile(imagePath, imagePath +"border");
if (file == null) { if (file == null) {
if (imagePath.isEmpty()) if (imagePath.isEmpty())
return 0; return null;
EDITION_Q.add(e.getCode() + "_" + e.getName()); EDITION_Q.add(e.getCode() + "_" + e.getName());
NIF_Q.add(e.getCode() + "_" + imagePath + "\n"); NIF_Q.add(e.getCode() + "_" + imagePath + "\n");
} }
} }
} }
return 0; return null;
}).exceptionally(ex -> { }).exceptionally(ex -> {
ex.printStackTrace(); ex.printStackTrace();
return 0; return null;
})); }));
} }
CompletableFuture<?>[] futuresArray = futures.toArray(new CompletableFuture<?>[0]); CompletableFuture<?>[] futuresArray = futures.toArray(new CompletableFuture<?>[0]);

View File

@@ -91,6 +91,11 @@ public class MatchScreen extends FScreen {
private static List<FDisplayObject> potentialListener; private static List<FDisplayObject> potentialListener;
private int selectedPlayer; private int selectedPlayer;
private final Map<Integer, Vector2> endpoints;
private final Set<CardView> cardsonBattlefield;
private final Set<PlayerView> playerViewSet;
public MatchScreen(List<VPlayerPanel> playerPanels0) { public MatchScreen(List<VPlayerPanel> playerPanels0) {
super(new FMenuBar()); super(new FMenuBar());
@@ -164,6 +169,9 @@ public class MatchScreen extends FScreen {
log.setMenuTab(new HiddenMenuTab(log)); log.setMenuTab(new HiddenMenuTab(log));
devMenu.setMenuTab(new HiddenMenuTab(devMenu)); devMenu.setMenuTab(new HiddenMenuTab(devMenu));
} }
endpoints = new HashMap<>();
cardsonBattlefield = new HashSet<>();
playerViewSet = new HashSet<>();
} }
private boolean is4Player() { private boolean is4Player() {
@@ -459,9 +467,9 @@ public class MatchScreen extends FScreen {
void drawArcs(Graphics g) { void drawArcs(Graphics g) {
//get all card targeting arrow origins on the battlefield //get all card targeting arrow origins on the battlefield
final Map<Integer, Vector2> endpoints = new HashMap<>(); endpoints.clear();
final Set<CardView> cardsonBattlefield = new HashSet<>(); cardsonBattlefield.clear();
final Set<PlayerView> playerViewSet = new HashSet<>(); playerViewSet.clear();
final GameView game = MatchController.instance.getGameView(); final GameView game = MatchController.instance.getGameView();
try { try {
for (PlayerView p : game.getPlayers()) { for (PlayerView p : game.getPlayers()) {