untied dependencies in newGame, made input field in match final

This commit is contained in:
Maxmtg
2013-03-23 12:14:18 +00:00
parent 76960e7ea8
commit c3f7facedf
6 changed files with 18 additions and 29 deletions

View File

@@ -106,6 +106,7 @@ public class FThreads {
} }
public static final void setInputAndWait(Input inp, CountDownLatch cdl) { public static final void setInputAndWait(Input inp, CountDownLatch cdl) {
checkEDT("FThreads.setInputAndWait", false);
Singletons.getModel().getMatch().getInput().setInputInterrupt(inp); Singletons.getModel().getMatch().getInput().setInputInterrupt(inp);
try { try {
cdl.await(); cdl.await();

View File

@@ -42,17 +42,6 @@ public class InputControl extends MyObservable implements java.io.Serializable {
private final Stack<Input> inputStack = new Stack<Input>(); private final Stack<Input> inputStack = new Stack<Input>();
private final transient GameState game;
/**
* TODO Write javadoc for Constructor.
*
* @param fModel
* the f model
*/
public InputControl(final GameState game0) {
this.game = game0;
}
/** /**
* <p> * <p>
* Setter for the field <code>input</code>. * Setter for the field <code>input</code>.
@@ -126,7 +115,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
* *
* @return a {@link forge.control.input.Input} object. * @return a {@link forge.control.input.Input} object.
*/ */
public final Input getActualInput() { public final Input getActualInput(GameState game) {
if ( !game.hasMulliganned() ) if ( !game.hasMulliganned() )
return new InputMulligan(); return new InputMulligan();
@@ -146,7 +135,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
if (handler.hasPhaseEffects()) { if (handler.hasPhaseEffects()) {
// Handle begin phase stuff, then start back from the top // Handle begin phase stuff, then start back from the top
handler.handleBeginPhase(); handler.handleBeginPhase();
return this.getActualInput(); return this.getActualInput(game);
} }
// If the Phase we're in doesn't allow for Priority, return null to move // If the Phase we're in doesn't allow for Priority, return null to move
@@ -196,7 +185,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
// priority // priority
boolean prioritySkip = pc.mayAutoPass(phase) || pc.isUiSetToSkipPhase(playerTurn, phase); boolean prioritySkip = pc.mayAutoPass(phase) || pc.isUiSetToSkipPhase(playerTurn, phase);
if (this.game.getStack().isEmpty() && prioritySkip) { if (game.getStack().isEmpty() && prioritySkip) {
pc.passPriority(); pc.passPriority();
return null; return null;
} else } else
@@ -208,7 +197,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
public final void setNewInput(GameState game) { public final void setNewInput(GameState game) {
PhaseHandler ph = game.getPhaseHandler(); PhaseHandler ph = game.getPhaseHandler();
final Input tmp = getActualInput(); final Input tmp = getActualInput(game);
String message = String.format("%s's %s, priority of %s [%sP] input is %s \t stack:%s", ph.getPlayerTurn(), ph.getPhase(), ph.getPriorityPlayer(), ph.isPlayerPriorityAllowed() ? "+" : "-", tmp == null ? "null" : tmp.getClass().getSimpleName(), inputStack); String message = String.format("%s's %s, priority of %s [%sP] input is %s \t stack:%s", ph.getPlayerTurn(), ph.getPhase(), ph.getPriorityPlayer(), ph.isPlayerPriorityAllowed() ? "+" : "-", tmp == null ? "null" : tmp.getClass().getSimpleName(), inputStack);
System.out.println(message); System.out.println(message);

View File

@@ -40,15 +40,12 @@ import forge.gui.GuiChoose;
public class GameActionPlay { public class GameActionPlay {
private final GameState game; private final GameState game;
private InputControl matchInput; private final InputControl matchInput;
public GameActionPlay(final GameState game0) { public GameActionPlay(final GameState game0, InputControl input) {
game = game0; game = game0;
} this.matchInput = input;
void setMatchInput(InputControl input) {
this.matchInput = input; // TODO: Add 0 to parameter's name.
} }
public final void playCardWithoutManaCost(final Card c, Player player) { public final void playCardWithoutManaCost(final Card c, Player player) {

View File

@@ -37,6 +37,7 @@ import forge.card.spellability.SpellAbility;
import forge.card.spellability.SpellAbilityStackInstance; import forge.card.spellability.SpellAbilityStackInstance;
import forge.card.trigger.TriggerHandler; import forge.card.trigger.TriggerHandler;
import forge.card.trigger.TriggerType; import forge.card.trigger.TriggerType;
import forge.control.input.InputControl;
import forge.game.phase.Cleanup; import forge.game.phase.Cleanup;
import forge.game.phase.Combat; import forge.game.phase.Combat;
import forge.game.phase.EndOfCombat; import forge.game.phase.EndOfCombat;
@@ -95,8 +96,9 @@ public class GameState {
* Constructor. * Constructor.
* @param players2 * @param players2
* @param match0 * @param match0
* @param input
*/ */
public GameState(Iterable<LobbyPlayer> players2, GameType t, MatchController match0) { /* no more zones to map here */ public GameState(Iterable<LobbyPlayer> players2, GameType t, MatchController match0, InputControl input) { /* no more zones to map here */
type = t; type = t;
List<Player> players = new ArrayList<Player>(); List<Player> players = new ArrayList<Player>();
for (LobbyPlayer p : players2) { for (LobbyPlayer p : players2) {
@@ -108,7 +110,7 @@ public class GameState {
allPlayers = Collections.unmodifiableList(players); allPlayers = Collections.unmodifiableList(players);
roIngamePlayers = Collections.unmodifiableList(ingamePlayers); roIngamePlayers = Collections.unmodifiableList(ingamePlayers);
action = new GameAction(this); action = new GameAction(this);
actionPlay = new GameActionPlay(this); actionPlay = new GameActionPlay(this, input);
stack = new MagicStack(this); stack = new MagicStack(this);
phaseHandler = new PhaseHandler(this); phaseHandler = new PhaseHandler(this);

View File

@@ -129,10 +129,8 @@ public class MatchController {
public void startRound() { public void startRound() {
// Deal with circular dependencies here // Deal with circular dependencies here
currentGame = Singletons.getModel().newGame(players.keySet(),gameType, this); input = new InputControl();
input = new InputControl(currentGame); currentGame = Singletons.getModel().newGame(players.keySet(),gameType, this, input);
currentGame.getActionPlay().setMatchInput(input);
Map<Player, PlayerStartConditions> startConditions = new HashMap<Player, PlayerStartConditions>(); Map<Player, PlayerStartConditions> startConditions = new HashMap<Player, PlayerStartConditions>();
for (Player p : currentGame.getPlayers()) { for (Player p : currentGame.getPlayers()) {

View File

@@ -35,6 +35,7 @@ import forge.card.EditionCollection;
import forge.card.FatPackData; import forge.card.FatPackData;
import forge.card.FormatCollection; import forge.card.FormatCollection;
import forge.card.cardfactory.CardStorageReader; import forge.card.cardfactory.CardStorageReader;
import forge.control.input.InputControl;
import forge.deck.CardCollections; import forge.deck.CardCollections;
import forge.error.BugReporter; import forge.error.BugReporter;
import forge.error.ExceptionHandler; import forge.error.ExceptionHandler;
@@ -401,9 +402,10 @@ public enum FModel {
/** /**
* TODO: Write javadoc for this method. * TODO: Write javadoc for this method.
* @param players * @param players
* @param input
*/ */
public GameState newGame(Iterable<LobbyPlayer> players, GameType type, final MatchController match0) { public GameState newGame(Iterable<LobbyPlayer> players, GameType type, final MatchController match0, InputControl input) {
gameState = new GameState(players,type, match0); gameState = new GameState(players,type, match0, input);
return gameState; return gameState;
} }