mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Fix the refactored GUI code so that games can now be played.
This commit is contained in:
@@ -227,7 +227,7 @@ public abstract class GuiDownloadService implements Runnable {
|
||||
p = new Proxy(TYPES[type], new InetSocketAddress(txtAddress.getText(), Integer.parseInt(txtPort.getText())));
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
BugReporter.reportException(ex,
|
||||
BugReporter.reportException(ex, gui,
|
||||
"Proxy connection could not be established!\nProxy address: %s\nProxy port: %s",
|
||||
txtAddress.getText(), txtPort.getText());
|
||||
return;
|
||||
|
||||
@@ -114,15 +114,15 @@ public class BugReporter {
|
||||
/**
|
||||
* Alias for reportException(ex, null).
|
||||
*/
|
||||
public static void reportException(final Throwable ex) {
|
||||
reportException(ex, null);
|
||||
public static void reportException(final Throwable ex, final IGuiBase gui) {
|
||||
reportException(ex, gui, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for reportException(ex, String.format(format, args)).
|
||||
*/
|
||||
public static void reportException(final Throwable ex, final String format, final Object... args) {
|
||||
reportException(ex, String.format(format, args));
|
||||
public static void reportException(final Throwable ex, final IGuiBase gui, final String format, final Object... args) {
|
||||
reportException(ex, gui, String.format(format, args));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.lang.Thread.UncaughtExceptionHandler;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.MultiplexOutputStream;
|
||||
|
||||
@@ -46,6 +47,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
|
||||
System.setProperty("sun.awt.exception.handler", ExceptionHandler.class.getName());
|
||||
}
|
||||
|
||||
private static IGuiBase gui;
|
||||
private static PrintStream oldSystemOut;
|
||||
private static PrintStream oldSystemErr;
|
||||
private static OutputStream logFileStream;
|
||||
@@ -54,10 +56,12 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
|
||||
* Call this at the beginning to make sure that the class is loaded and the
|
||||
* static initializer has run.
|
||||
*/
|
||||
public static void registerErrorHandling() {
|
||||
public static void registerErrorHandling(final IGuiBase gui) {
|
||||
//initialize log file
|
||||
File logFile = new File(ForgeConstants.LOG_FILE);
|
||||
|
||||
ExceptionHandler.gui = gui;
|
||||
|
||||
int i = 0;
|
||||
while (logFile.exists() && !logFile.delete()) {
|
||||
String pathname = logFile.getPath().replaceAll("[0-9]{0,2}.log$", String.valueOf(i++) + ".log");
|
||||
@@ -101,7 +105,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public final void uncaughtException(final Thread t, final Throwable ex) {
|
||||
BugReporter.reportException(ex);
|
||||
BugReporter.reportException(ex, gui);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,6 +116,6 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
|
||||
* a {@link java.lang.Throwable} object.
|
||||
*/
|
||||
public final void handle(final Throwable ex) {
|
||||
BugReporter.reportException(ex);
|
||||
BugReporter.reportException(ex, gui);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
package forge.gauntlet;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
@@ -8,19 +21,11 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader;
|
||||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
|
||||
|
||||
import forge.deck.CardPool;
|
||||
import forge.error.BugReporter;
|
||||
import forge.item.PaperCard;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.util.IgnoringXStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class GauntletIO {
|
||||
/** Prompt in text field for new (unsaved) built gauntlets. */
|
||||
public static final String TXF_PROMPT = "[New Gauntlet]";
|
||||
@@ -85,7 +90,6 @@ public class GauntletIO {
|
||||
|
||||
return data;
|
||||
} catch (final Exception ex) {
|
||||
BugReporter.reportException(ex, "Error loading Gauntlet Data");
|
||||
throw new RuntimeException(ex);
|
||||
} finally {
|
||||
if (null != zin) {
|
||||
@@ -100,7 +104,6 @@ public class GauntletIO {
|
||||
final XStream xStream = GauntletIO.getSerializer(false);
|
||||
GauntletIO.savePacked(xStream, gd0);
|
||||
} catch (final Exception ex) {
|
||||
BugReporter.reportException(ex, "Error saving Gauntlet Data.");
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,10 +46,10 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
public InputBase(final PlayerControllerHuman controller) {
|
||||
this.controller = controller;
|
||||
}
|
||||
protected final PlayerControllerHuman getController() {
|
||||
public final PlayerControllerHuman getController() {
|
||||
return this.controller;
|
||||
}
|
||||
protected IGuiBase getGui() {
|
||||
public IGuiBase getGui() {
|
||||
return getController().getGui();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,9 @@ import forge.util.ThreadUtil;
|
||||
public class InputLockUI implements Input {
|
||||
private final AtomicInteger iCall = new AtomicInteger();
|
||||
|
||||
private final IGuiBase gui;
|
||||
private IGuiBase gui;
|
||||
private final Game game;
|
||||
public InputLockUI(final IGuiBase gui, final Game game, final InputQueue inputQueue) {
|
||||
this.gui = gui;
|
||||
public InputLockUI(final Game game, final InputQueue inputQueue) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
@@ -25,6 +24,10 @@ public class InputLockUI implements Input {
|
||||
return gui;
|
||||
}
|
||||
|
||||
public void setGui(final IGuiBase gui) {
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
public void showMessageInitial() {
|
||||
int ixCall = 1 + iCall.getAndIncrement();
|
||||
ThreadUtil.delay(500, new InputUpdater(ixCall));
|
||||
|
||||
@@ -22,7 +22,7 @@ public class InputPlaybackControl extends InputSyncronizedBase implements InputS
|
||||
control = fControlGamePlayback;
|
||||
}
|
||||
@Override
|
||||
protected IGuiBase getGui() {
|
||||
public IGuiBase getGui() {
|
||||
return gui;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ import java.util.Observer;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.game.Game;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.util.gui.SOptionPane;
|
||||
import forge.view.CardView;
|
||||
import forge.view.IGameView;
|
||||
import forge.view.PlayerView;
|
||||
import forge.view.SpellAbilityView;
|
||||
|
||||
@@ -43,22 +43,18 @@ public class InputProxy implements Observer {
|
||||
|
||||
/** The input. */
|
||||
private AtomicReference<Input> input = new AtomicReference<Input>();
|
||||
private IGameView game = null;
|
||||
private final Game game;
|
||||
|
||||
// private static final boolean DEBUG_INPUT = true; // false;
|
||||
|
||||
private final PlayerControllerHuman controller;
|
||||
public InputProxy(final PlayerControllerHuman controller) {
|
||||
public InputProxy(final PlayerControllerHuman controller, final Game game) {
|
||||
this.controller = controller;
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
private IGuiBase getGui() {
|
||||
return controller.getGui();
|
||||
}
|
||||
|
||||
public void setGame(IGameView game0) {
|
||||
game = game0;
|
||||
getGui().getInputQueue().addObserver(this);
|
||||
return this.controller.getGui();
|
||||
}
|
||||
|
||||
public boolean passPriority() {
|
||||
@@ -80,7 +76,6 @@ public class InputProxy implements Observer {
|
||||
@Override
|
||||
public final void update(final Observable observable, final Object obj) {
|
||||
final Input nextInput = getGui().getInputQueue().getActualInput(game);
|
||||
|
||||
/* if(DEBUG_INPUT)
|
||||
System.out.printf("%s ... \t%s on %s, \tstack = %s%n",
|
||||
FThreads.debugGetStackTraceItem(6, true), nextInput == null ? "null" : nextInput.getClass().getSimpleName(),
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
|
||||
import forge.game.Game;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.view.IGameView;
|
||||
import forge.game.player.Player;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -37,8 +37,13 @@ public class InputQueue extends Observable {
|
||||
private final BlockingDeque<InputSynchronized> inputStack = new LinkedBlockingDeque<InputSynchronized>();
|
||||
private final InputLockUI inputLock;
|
||||
|
||||
public InputQueue(final IGuiBase gui, final Game game) {
|
||||
inputLock = new InputLockUI(gui, game, this);
|
||||
public InputQueue(final Game game) {
|
||||
inputLock = new InputLockUI(game, this);
|
||||
for (final Player p : game.getPlayers()) {
|
||||
if (p.getController() instanceof PlayerControllerHuman) {
|
||||
this.addObserver(((PlayerControllerHuman) p.getController()).getInputProxy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void updateObservers() {
|
||||
@@ -66,7 +71,7 @@ public class InputQueue extends Observable {
|
||||
*
|
||||
* @return a {@link forge.gui.input.InputBase} object.
|
||||
*/
|
||||
public final Input getActualInput(IGameView game) {
|
||||
public final Input getActualInput(final Game game) {
|
||||
Input topMost = inputStack.peek(); // incoming input to Control
|
||||
if (topMost != null && !game.isGameOver()) {
|
||||
return topMost;
|
||||
@@ -79,8 +84,9 @@ public class InputQueue extends Observable {
|
||||
return inputStack.toString();
|
||||
}
|
||||
|
||||
public void setInput(InputSynchronized input) {
|
||||
public void setInput(final InputSynchronized input) {
|
||||
this.inputStack.push(input);
|
||||
inputLock.setGui(input.getGui());
|
||||
syncPoint();
|
||||
this.updateObservers();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package forge.match.input;
|
||||
|
||||
import forge.interfaces.IGuiBase;
|
||||
|
||||
public interface InputSynchronized extends Input {
|
||||
void awaitLatchRelease();
|
||||
void relaseLatchWhenGameIsOver();
|
||||
IGuiBase getGui();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
|
||||
cdlDone.await();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
BugReporter.reportException(e);
|
||||
BugReporter.reportException(e, getGui());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import forge.game.player.PlayerController;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.match.input.InputProxy;
|
||||
import forge.view.CardView;
|
||||
import forge.view.CombatView;
|
||||
import forge.view.GameEntityView;
|
||||
@@ -26,16 +27,22 @@ import forge.view.StackItemView;
|
||||
public abstract class PlayerControllerHuman extends PlayerController {
|
||||
|
||||
private final IGuiBase gui;
|
||||
private final InputProxy inputProxy;
|
||||
|
||||
public PlayerControllerHuman(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) {
|
||||
super(game0, p, lp);
|
||||
this.gui = gui;
|
||||
this.inputProxy = new InputProxy(this, game0);
|
||||
}
|
||||
|
||||
public final IGuiBase getGui() {
|
||||
return this.gui;
|
||||
}
|
||||
|
||||
public final InputProxy getInputProxy() {
|
||||
return this.inputProxy;
|
||||
}
|
||||
|
||||
public abstract boolean canUndoLastAction();
|
||||
public abstract boolean tryUndoLastAction();
|
||||
|
||||
|
||||
@@ -78,7 +78,6 @@ import forge.match.input.InputConfirm;
|
||||
import forge.match.input.InputConfirmMulligan;
|
||||
import forge.match.input.InputPassPriority;
|
||||
import forge.match.input.InputProliferate;
|
||||
import forge.match.input.InputProxy;
|
||||
import forge.match.input.InputSelectCardsForConvoke;
|
||||
import forge.match.input.InputSelectCardsFromList;
|
||||
import forge.match.input.InputSelectEntitiesFromList;
|
||||
@@ -106,18 +105,12 @@ import forge.view.ViewUtil;
|
||||
* Handles phase skips for now.
|
||||
*/
|
||||
public class PlayerControllerLocal extends PlayerControllerHuman implements IGameView {
|
||||
private final InputProxy inputProxy;
|
||||
public PlayerControllerLocal(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) {
|
||||
super(game0, p, lp, gui);
|
||||
this.inputProxy = new InputProxy(this);
|
||||
// aggressively cache a view for each player
|
||||
// aggressively cache a view for each player (also caches cards)
|
||||
for (final Player player : game.getRegisteredPlayers()) {
|
||||
getPlayerView(player);
|
||||
}
|
||||
// aggressively cache a view for each card
|
||||
for (final Card c : game.getCardsInGame()) {
|
||||
getCardView(c);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUiSetToSkipPhase(final Player turn, final PhaseType phase) {
|
||||
@@ -126,7 +119,7 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
|
||||
/**
|
||||
* Uses GUI to learn which spell the player (human in our case) would like to play
|
||||
*/
|
||||
*/
|
||||
public SpellAbility getAbilityToPlay(final List<SpellAbility> abilities, final ITriggerEvent triggerEvent) {
|
||||
final SpellAbilityView choice = getGui().getAbilityToPlay(getSpellAbilityViews(abilities), triggerEvent);
|
||||
return getSpellAbility(choice);
|
||||
@@ -1354,6 +1347,9 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
*/
|
||||
@Override
|
||||
public CombatView getCombat(final Combat c) {
|
||||
if (c == null) {
|
||||
return null;
|
||||
}
|
||||
updateCombatView(c);
|
||||
return combatView;
|
||||
}
|
||||
@@ -1361,9 +1357,10 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
private final void updateCombatView(final Combat combat) {
|
||||
combatView.reset();
|
||||
for (final AttackingBand b : combat.getAttackingBands()) {
|
||||
if (b == null) continue;
|
||||
final GameEntity defender = combat.getDefenderByAttacker(b);
|
||||
final List<Card> blockers = b.isBlocked() ? combat.getBlockers(b) : null;
|
||||
combatView.addAttackingBand(getCardViews(b.getAttackers()), getGameEntityView(defender), getCardViews(blockers));
|
||||
final List<Card> blockers = b.isBlocked() == null ? null : combat.getBlockers(b);
|
||||
combatView.addAttackingBand(getCardViews(b.getAttackers()), getGameEntityView(defender), blockers == null ? null : getCardViews(blockers));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1411,32 +1408,32 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
|
||||
@Override
|
||||
public void selectButtonOk() {
|
||||
inputProxy.selectButtonOK();
|
||||
getInputProxy().selectButtonOK();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectButtonCancel() {
|
||||
inputProxy.selectButtonCancel();
|
||||
getInputProxy().selectButtonCancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passPriority() {
|
||||
return inputProxy.passPriority();
|
||||
return getInputProxy().passPriority();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPlayer(final PlayerView player, final ITriggerEvent triggerEvent) {
|
||||
inputProxy.selectPlayer(player, triggerEvent);
|
||||
getInputProxy().selectPlayer(player, triggerEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectCard(final CardView card, final ITriggerEvent triggerEvent) {
|
||||
inputProxy.selectCard(card, triggerEvent);
|
||||
getInputProxy().selectCard(card, triggerEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectAbility(final SpellAbilityView sa) {
|
||||
inputProxy.selectAbility(sa);
|
||||
getInputProxy().selectAbility(sa);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -1538,12 +1535,16 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
getPlayerView(p, view);
|
||||
} else {
|
||||
view = new PlayerView(p.getLobbyPlayer(), p.getController());
|
||||
getPlayerView(p, view);
|
||||
players.put(p, view);
|
||||
getPlayerView(p, view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private PlayerView getPlayerViewFast(final Player p) {
|
||||
return players.get(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer(final PlayerView p) {
|
||||
return players.inverse().get(p);
|
||||
@@ -1565,6 +1566,10 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
view.setGraveCards(getCardViews(p.getCardsIn(ZoneType.Graveyard)));
|
||||
view.setHandCards(getCardViews(p.getCardsIn(ZoneType.Hand)));
|
||||
view.setLibraryCards(getCardViews(p.getCardsIn(ZoneType.Library)));
|
||||
|
||||
for (final byte b : MagicColor.WUBRGC) {
|
||||
view.setMana(b, p.getManaPool().getAmountOfColor(b));
|
||||
}
|
||||
}
|
||||
|
||||
public CardView getCardView(final Card c) {
|
||||
@@ -1578,13 +1583,28 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
view = cards.get(cUi);
|
||||
writeCardToView(cUi, view);
|
||||
} else {
|
||||
view = new CardView(cUi, cUi.getUniqueNumber(), cUi == c);
|
||||
writeCardToView(cUi, view);
|
||||
view = new CardView(cUi.getUniqueNumber(), cUi == c);
|
||||
cards.put(cUi, view);
|
||||
writeCardToView(cUi, view);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private CardView getCardViewFast(final Card c) {
|
||||
return cards.get(c);
|
||||
}
|
||||
|
||||
private final Function<Card, CardView> FN_GET_CARDVIEW_FAST = new Function<Card, CardView>() {
|
||||
@Override
|
||||
public CardView apply(Card input) {
|
||||
return getCardViewFast(input);
|
||||
}
|
||||
};
|
||||
|
||||
private Iterable<CardView> getCardViewsFast(final Iterable<Card> cards) {
|
||||
return Iterables.transform(cards, FN_GET_CARDVIEW_FAST);
|
||||
}
|
||||
|
||||
public Card getCard(final CardView c) {
|
||||
return cards.inverse().get(c);
|
||||
}
|
||||
@@ -1599,29 +1619,30 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
// First, write the values independent of other views.
|
||||
ViewUtil.writeNonDependentCardViewProperties(c, view);
|
||||
// Next, write the values that depend on other views.
|
||||
view.setOwner(getPlayerView(c.getOwner()));
|
||||
view.setController(getPlayerView(c.getController()));
|
||||
view.setOwner(getPlayerViewFast(c.getOwner()));
|
||||
view.setController(getPlayerViewFast(c.getController()));
|
||||
view.setAttacking(game.getCombat() != null && game.getCombat().isAttacking(c));
|
||||
view.setBlocking(game.getCombat() != null && game.getCombat().isBlocking(c));
|
||||
view.setChosenPlayer(getPlayerView(c.getChosenPlayer()));
|
||||
view.setEquipping(getCardView(Iterables.getFirst(c.getEquipping(), null)));
|
||||
view.setEquippedBy(getCardViews(c.getEquippedBy()));
|
||||
view.setEnchantingCard(getCardView(c.getEnchantingCard()));
|
||||
view.setEnchantingPlayer(getPlayerView(c.getEnchantingPlayer()));
|
||||
view.setEnchantedBy(getCardViews(c.getEnchantedBy()));
|
||||
view.setFortifiedBy(getCardViews(c.getFortifiedBy()));
|
||||
view.setGainControlTargets(getCardViews(c.getGainControlTargets()));
|
||||
view.setCloneOrigin(getCardView(c.getCloneOrigin()));
|
||||
view.setImprinted(getCardViews(c.getImprinted()));
|
||||
view.setHauntedBy(getCardViews(c.getHauntedBy()));
|
||||
view.setHaunting(getCardView(c.getHaunting()));
|
||||
view.setMustBlock(c.getMustBlockCards() == null ? Collections.<CardView>emptySet() : getCardViews(c.getMustBlockCards()));
|
||||
view.setPairedWith(getCardView(c.getPairedWith()));
|
||||
view.setChosenPlayer(getPlayerViewFast(c.getChosenPlayer()));
|
||||
view.setEquipping(getCardViewFast(Iterables.getFirst(c.getEquipping(), null)));
|
||||
view.setEquippedBy(getCardViewsFast(c.getEquippedBy()));
|
||||
view.setEnchantingCard(getCardViewFast(c.getEnchantingCard()));
|
||||
view.setEnchantingPlayer(getPlayerViewFast(c.getEnchantingPlayer()));
|
||||
view.setEnchantedBy(getCardViewsFast(c.getEnchantedBy()));
|
||||
view.setFortifiedBy(getCardViewsFast(c.getFortifiedBy()));
|
||||
view.setGainControlTargets(getCardViewsFast(c.getGainControlTargets()));
|
||||
view.setCloneOrigin(getCardViewFast(c.getCloneOrigin()));
|
||||
view.setImprinted(getCardViewsFast(c.getImprinted()));
|
||||
view.setHauntedBy(getCardViewsFast(c.getHauntedBy()));
|
||||
view.setHaunting(getCardViewFast(c.getHaunting()));
|
||||
view.setMustBlock(c.getMustBlockCards() == null ? Collections.<CardView>emptySet() : getCardViewsFast(c.getMustBlockCards()));
|
||||
view.setPairedWith(getCardViewFast(c.getPairedWith()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayShowCard(final CardView c) {
|
||||
return cards.inverse().get(c).canBeShownTo(player);
|
||||
final Card card = cards.inverse().get(c);
|
||||
return card == null || card.canBeShownTo(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1649,6 +1670,7 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
|
||||
|
||||
private void writeSpellAbilityToView(final SpellAbility sa, final SpellAbilityView view) {
|
||||
view.setHostCard(getCardView(sa.getHostCard()));
|
||||
view.setDescription(sa.getDescription());
|
||||
view.setCanPlay(sa.canPlay());
|
||||
view.setPromptIfOnlyPossibleAbility(sa.promptIfOnlyPossibleAbility());
|
||||
}
|
||||
|
||||
@@ -20,19 +20,18 @@ package forge.properties;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import forge.interfaces.IGuiBase;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.util.BuildInfo;
|
||||
|
||||
public final class ForgeConstants {
|
||||
public static void init(final IGuiBase gui) {
|
||||
ASSETS_DIR = gui.getAssetsDir();
|
||||
}
|
||||
|
||||
private static String ASSETS_DIR;
|
||||
public static String ASSETS_DIR() { return ASSETS_DIR; }
|
||||
public static final String PROFILE_FILE = ASSETS_DIR() + "forge.profile.properties";
|
||||
public static final String ASSETS_DIR = StringUtils.containsIgnoreCase(BuildInfo.getVersionString(), "svn") ?
|
||||
"../forge-gui/" : "";
|
||||
public static final String PROFILE_FILE = ASSETS_DIR + "forge.profile.properties";
|
||||
public static final String PROFILE_TEMPLATE_FILE = PROFILE_FILE + ".example";
|
||||
|
||||
public static final String RES_DIR = ASSETS_DIR() + "res/";
|
||||
public static final String RES_DIR = ASSETS_DIR + "res/";
|
||||
public static final String LISTS_DIR = RES_DIR + "lists/";
|
||||
public static final String KEYWORD_LIST_FILE = LISTS_DIR + "NonStackingKWList.txt";
|
||||
public static final String TYPE_LIST_FILE = LISTS_DIR + "TypeLists.txt";
|
||||
@@ -46,9 +45,9 @@ public final class ForgeConstants {
|
||||
public static final String IMAGE_LIST_QUEST_PRECONS_FILE = LISTS_DIR + "precon-images.txt";
|
||||
public static final String IMAGE_LIST_QUEST_TOURNAMENTPACKS_FILE = LISTS_DIR + "tournamentpack-images.txt";
|
||||
|
||||
public static final String CHANGES_FILE = ASSETS_DIR() + "CHANGES.txt";
|
||||
public static final String LICENSE_FILE = ASSETS_DIR() + "LICENSE.txt";
|
||||
public static final String README_FILE = ASSETS_DIR() + "README.txt";
|
||||
public static final String CHANGES_FILE = ASSETS_DIR + "CHANGES.txt";
|
||||
public static final String LICENSE_FILE = ASSETS_DIR + "LICENSE.txt";
|
||||
public static final String README_FILE = ASSETS_DIR + "README.txt";
|
||||
public static final String HOWTO_FILE = RES_DIR + "howto.txt";
|
||||
|
||||
public static final String DRAFT_DIR = RES_DIR + "draft/";
|
||||
|
||||
@@ -150,7 +150,7 @@ public class ForgeProfileProperties {
|
||||
// returns a pair <userDir, cacheDir>
|
||||
private static Pair<String, String> getDefaultDirs() {
|
||||
if (isRunningOnDesktop) { //special case for mobile devices
|
||||
String assetsDir = ForgeConstants.ASSETS_DIR();
|
||||
String assetsDir = ForgeConstants.ASSETS_DIR;
|
||||
return Pair.of(assetsDir + "data" + File.separator, assetsDir + "cache" + File.separator);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,35 @@
|
||||
*/
|
||||
package forge.quest.io;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.converters.Converter;
|
||||
import com.thoughtworks.xstream.converters.MarshallingContext;
|
||||
@@ -29,39 +58,30 @@ import forge.deck.CardPool;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.deck.DeckSection;
|
||||
import forge.error.BugReporter;
|
||||
import forge.item.*;
|
||||
import forge.item.BoosterBox;
|
||||
import forge.item.BoosterPack;
|
||||
import forge.item.FatPack;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.PreconDeck;
|
||||
import forge.item.TournamentPack;
|
||||
import forge.model.FModel;
|
||||
import forge.properties.ForgeConstants;
|
||||
import forge.quest.QuestController;
|
||||
import forge.quest.QuestEventDraft;
|
||||
import forge.quest.QuestMode;
|
||||
import forge.quest.bazaar.QuestItemType;
|
||||
import forge.quest.data.*;
|
||||
import forge.quest.data.GameFormatQuest;
|
||||
import forge.quest.data.QuestAchievements;
|
||||
import forge.quest.data.QuestAssets;
|
||||
import forge.quest.data.QuestData;
|
||||
import forge.quest.data.QuestEventDraftContainer;
|
||||
import forge.quest.data.QuestItemCondition;
|
||||
import forge.util.FileUtil;
|
||||
import forge.util.IgnoringXStream;
|
||||
import forge.util.ItemPool;
|
||||
import forge.util.XmlUtil;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.w3c.dom.*;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* QuestDataIO class.
|
||||
@@ -130,14 +150,15 @@ public class QuestDataIO {
|
||||
QuestDataIO.updateSaveFile(data, bigXML, xmlSaveFile.getName().replace(".dat", ""));
|
||||
}
|
||||
catch (final Exception e) {
|
||||
BugReporter.reportException(e);
|
||||
//BugReporter.reportException(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
BugReporter.reportException(ex, "Error loading Quest Data");
|
||||
//BugReporter.reportException(ex, "Error loading Quest Data");
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
@@ -371,7 +392,7 @@ public class QuestDataIO {
|
||||
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
BugReporter.reportException(ex, "Error saving Quest Data.");
|
||||
//BugReporter.reportException(ex, "Error saving Quest Data.");
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@ import forge.card.CardEdition;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CounterType;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.item.IPaperCard;
|
||||
|
||||
public class CardView extends GameEntityView {
|
||||
|
||||
@@ -59,11 +57,7 @@ public class CardView extends GameEntityView {
|
||||
private Iterable<CardView> mustBlock;
|
||||
private CardView pairedWith;
|
||||
|
||||
@Deprecated
|
||||
public final Card card;
|
||||
|
||||
public CardView(@Deprecated final Card card, final int id, final boolean isUiDisplayable) {
|
||||
this.card = card;
|
||||
public CardView(final int id, final boolean isUiDisplayable) {
|
||||
this.id = id;
|
||||
this.isUiDisplayable = isUiDisplayable;
|
||||
this.reset();
|
||||
@@ -755,7 +749,7 @@ public class CardView extends GameEntityView {
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
return this.getState().getName() + " (" + this.getId() + ")";
|
||||
return this.getState().toString();
|
||||
}
|
||||
|
||||
public class CardStateView {
|
||||
@@ -791,6 +785,11 @@ public class CardView extends GameEntityView {
|
||||
this.hasTrample = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getName() + " (" + this.getCard().getId() + ")";
|
||||
}
|
||||
|
||||
public CardView getCard() {
|
||||
return CardView.this;
|
||||
}
|
||||
@@ -1022,11 +1021,4 @@ public class CardView extends GameEntityView {
|
||||
return this.type.contains("Planeswalker");
|
||||
}
|
||||
}
|
||||
|
||||
public static CardView getCardForUi(final IPaperCard pc) {
|
||||
final Card c = Card.getCardForUi(pc);
|
||||
final CardView view = new CardView(c, -1, true);
|
||||
ViewUtil.writeNonDependentCardViewProperties(c, view);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import forge.LobbyPlayer;
|
||||
@@ -18,7 +19,14 @@ public class PlayerView extends GameEntityView {
|
||||
private int life, poisonCounters, maxHandSize, numDrawnThisTurn, preventNextDamage;
|
||||
private List<String> keywords;
|
||||
private String commanderInfo;
|
||||
private List<CardView> anteCards, bfCards, commandCards, exileCards, flashbackCards, graveCards, handCards, libraryCards;
|
||||
private List<CardView> anteCards = Lists.newArrayList(),
|
||||
bfCards = Lists.newArrayList(),
|
||||
commandCards = Lists.newArrayList(),
|
||||
exileCards = Lists.newArrayList(),
|
||||
flashbackCards = Lists.newArrayList(),
|
||||
graveCards = Lists.newArrayList(),
|
||||
handCards = Lists.newArrayList(),
|
||||
libraryCards = Lists.newArrayList();
|
||||
private boolean hasUnlimitedHandSize;
|
||||
private Map<Byte, Integer> mana = Maps.newHashMapWithExpectedSize(MagicColor.NUMBER_OR_COLORS + 1);
|
||||
|
||||
@@ -160,7 +168,8 @@ public class PlayerView extends GameEntityView {
|
||||
* @param anteCards the anteCards to set
|
||||
*/
|
||||
public void setAnteCards(final List<CardView> anteCards) {
|
||||
this.anteCards = ImmutableList.copyOf(anteCards);
|
||||
this.anteCards.clear();
|
||||
this.anteCards.addAll(anteCards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +183,8 @@ public class PlayerView extends GameEntityView {
|
||||
* @param bfCards the bfCards to set
|
||||
*/
|
||||
public void setBfCards(final List<CardView> bfCards) {
|
||||
this.bfCards = ImmutableList.copyOf(bfCards);
|
||||
this.bfCards.clear();
|
||||
this.bfCards.addAll(bfCards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,7 +198,8 @@ public class PlayerView extends GameEntityView {
|
||||
* @param commandCards the commandCards to set
|
||||
*/
|
||||
public void setCommandCards(List<CardView> commandCards) {
|
||||
this.commandCards = commandCards;
|
||||
this.commandCards.clear();
|
||||
this.commandCards.addAll(commandCards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,7 +213,8 @@ public class PlayerView extends GameEntityView {
|
||||
* @param exileCards the exileCards to set
|
||||
*/
|
||||
public void setExileCards(final List<CardView> exileCards) {
|
||||
this.exileCards = ImmutableList.copyOf(exileCards);
|
||||
this.exileCards.clear();
|
||||
this.exileCards.addAll(exileCards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +228,8 @@ public class PlayerView extends GameEntityView {
|
||||
* @param flashbackCards the flashbackCards to set
|
||||
*/
|
||||
public void setFlashbackCards(final List<CardView> flashbackCards) {
|
||||
this.flashbackCards = ImmutableList.copyOf(flashbackCards);
|
||||
this.flashbackCards.clear();
|
||||
this.flashbackCards.addAll(flashbackCards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +243,8 @@ public class PlayerView extends GameEntityView {
|
||||
* @param graveCards the graveCards to set
|
||||
*/
|
||||
public void setGraveCards(final List<CardView> graveCards) {
|
||||
this.graveCards = ImmutableList.copyOf(graveCards);
|
||||
this.graveCards.clear();
|
||||
this.graveCards.addAll(graveCards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -244,7 +258,8 @@ public class PlayerView extends GameEntityView {
|
||||
* @param handCards the handCards to set
|
||||
*/
|
||||
public void setHandCards(final List<CardView> handCards) {
|
||||
this.handCards = ImmutableList.copyOf(handCards);
|
||||
this.handCards.clear();
|
||||
this.handCards.addAll(handCards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,7 +273,8 @@ public class PlayerView extends GameEntityView {
|
||||
* @param libraryCards the libraryCards to set
|
||||
*/
|
||||
public void setLibraryCards(final List<CardView> libraryCards) {
|
||||
this.libraryCards = ImmutableList.copyOf(libraryCards);
|
||||
this.libraryCards.clear();
|
||||
this.libraryCards.addAll(libraryCards);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,10 +292,10 @@ public class PlayerView extends GameEntityView {
|
||||
}
|
||||
|
||||
public int getMana(final Byte color) {
|
||||
return this.mana.get(color).intValue();
|
||||
return this.mana.containsKey(color) ? this.mana.get(color).intValue() : 0;
|
||||
}
|
||||
|
||||
private void setMana(final byte color, final int mana) {
|
||||
public void setMana(final byte color, final int mana) {
|
||||
this.mana.put(Byte.valueOf(color), Integer.valueOf(mana));
|
||||
}
|
||||
public void setWhiteMana(final int mana) {
|
||||
|
||||
@@ -3,8 +3,14 @@ package forge.view;
|
||||
public class SpellAbilityView {
|
||||
|
||||
private CardView hostCard;
|
||||
private String description;
|
||||
private boolean canPlay, promptIfOnlyPossibleAbility;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the hostCard
|
||||
*/
|
||||
@@ -19,6 +25,20 @@ public class SpellAbilityView {
|
||||
this.hostCard = hostCard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the canPlay
|
||||
*/
|
||||
|
||||
@@ -47,4 +47,8 @@ public class StackItemView {
|
||||
return optionalTrigger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getText();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Collections;
|
||||
import forge.card.CardCharacteristicName;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardCharacteristics;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.view.CardView.CardStateView;
|
||||
|
||||
public final class ViewUtil {
|
||||
@@ -23,7 +24,7 @@ public final class ViewUtil {
|
||||
*/
|
||||
public static void writeNonDependentCardViewProperties(final Card c, final CardView view) {
|
||||
final boolean hasAltState = c.isDoubleFaced() || c.isFlipCard() || c.isFaceDown();
|
||||
view.setZone(c.getZone().getZoneType());
|
||||
view.setZone(c.getZone() == null ? null : c.getZone().getZoneType());
|
||||
view.setHasAltState(hasAltState);
|
||||
view.setFaceDown(c.isFaceDown());
|
||||
view.setFoilIndex(c.getFoil());
|
||||
@@ -87,4 +88,11 @@ public final class ViewUtil {
|
||||
altView.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public static CardView getCardForUi(final IPaperCard pc) {
|
||||
final Card c = Card.getCardForUi(pc);
|
||||
final CardView view = new CardView(-1, true);
|
||||
writeNonDependentCardViewProperties(c, view);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user