mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Inputs: InputBase no longer requires neither InputQueue nor Player in constructor. Only some subclasses require player member.
InputNonSyncBase - base class for non-waiting inputs
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -14153,6 +14153,7 @@ src/main/java/forge/control/input/InputBlock.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputCleanup.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputConfirmMulligan.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputLockUI.java -text
|
||||
src/main/java/forge/control/input/InputNonSyncBase.java -text
|
||||
src/main/java/forge/control/input/InputPassPriority.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputPayManaBase.java -text
|
||||
src/main/java/forge/control/input/InputPayManaExecuteCommands.java svneol=native#text/plain
|
||||
|
||||
@@ -10,7 +10,7 @@ import forge.game.player.Player;
|
||||
public interface Input {
|
||||
|
||||
// showMessage() is always the first method called
|
||||
void showMessage();
|
||||
void showMessage(InputQueue iq);
|
||||
|
||||
void selectCard(Card c, boolean isMetaDown);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import forge.view.ButtonUtil;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InputAttack extends InputBase {
|
||||
public class InputAttack extends InputNonSyncBase {
|
||||
/** Constant <code>serialVersionUID=7849903731842214245L</code>. */
|
||||
private static final long serialVersionUID = 7849903731842214245L;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import forge.game.player.Player;
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class InputAutoPassPriority extends InputBase {
|
||||
public class InputAutoPassPriority extends InputNonSyncBase {
|
||||
private static final long serialVersionUID = -7520803307255234647L;
|
||||
|
||||
public InputAutoPassPriority(Player player) {
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package forge.control.input;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.framework.SDisplayUtil;
|
||||
import forge.gui.match.CMatchUI;
|
||||
@@ -35,14 +34,16 @@ import forge.gui.match.views.VMessage;
|
||||
public abstract class InputBase implements java.io.Serializable, Input {
|
||||
/** Constant <code>serialVersionUID=-6539552513871194081L</code>. */
|
||||
private static final long serialVersionUID = -6539552513871194081L;
|
||||
protected final Player player;
|
||||
public InputBase(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
private InputQueue queue;
|
||||
|
||||
// showMessage() is always the first method called
|
||||
@Override
|
||||
public abstract void showMessage();
|
||||
public final void showMessage(InputQueue iq) {
|
||||
queue = iq;
|
||||
showMessage();
|
||||
}
|
||||
|
||||
protected abstract void showMessage();
|
||||
|
||||
@Override
|
||||
public void selectCard(final Card c, boolean isMetaDown) { }
|
||||
@@ -61,23 +62,13 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
// Removes this input from the stack and releases any latches (in synchronous imports)
|
||||
protected final void stop() {
|
||||
// clears a "temp" Input like Input_PayManaCost if there is one
|
||||
player.getGame().getInputQueue().removeInput(this);
|
||||
queue.removeInput(this);
|
||||
afterStop(); // sync inputs will release their latch there
|
||||
}
|
||||
|
||||
protected void afterStop() { }
|
||||
|
||||
protected void passPriority() {
|
||||
final Runnable pass = new Runnable() {
|
||||
@Override public void run() {
|
||||
player.getController().passPriority();
|
||||
}
|
||||
};
|
||||
if( FThreads.isEDT() )
|
||||
player.getGame().getInputQueue().LockAndInvokeGameAction(pass);
|
||||
else
|
||||
pass.run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected final void flashIncorrectAction() {
|
||||
|
||||
@@ -37,7 +37,7 @@ import forge.view.ButtonUtil;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InputBlock extends InputBase {
|
||||
public class InputBlock extends InputNonSyncBase {
|
||||
/** Constant <code>serialVersionUID=6120743598368928128L</code>. */
|
||||
private static final long serialVersionUID = 6120743598368928128L;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import forge.view.ButtonUtil;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InputCleanup extends InputBase {
|
||||
public class InputCleanup extends InputNonSyncBase {
|
||||
/** Constant <code>serialVersionUID=-4164275418971547948L</code>. */
|
||||
private static final long serialVersionUID = -4164275418971547948L;
|
||||
private final GameState game;
|
||||
|
||||
@@ -39,13 +39,16 @@ public class InputConfirmMulligan extends InputSyncronizedBase {
|
||||
/** Constant <code>serialVersionUID=-8112954303001155622L</code>. */
|
||||
private static final long serialVersionUID = -8112954303001155622L;
|
||||
|
||||
|
||||
boolean keepHand = false;
|
||||
final boolean isCommander;
|
||||
final List<Card> selected = new ArrayList<Card>();
|
||||
final private Player startingPlayer;
|
||||
|
||||
private final List<Card> selected = new ArrayList<Card>();
|
||||
private final Player player;
|
||||
private final Player startingPlayer;
|
||||
|
||||
public InputConfirmMulligan(Player humanPlayer, Player startsGame, boolean commander) {
|
||||
super(humanPlayer);
|
||||
player = humanPlayer;
|
||||
isCommander = commander;
|
||||
startingPlayer = startsGame;
|
||||
}
|
||||
|
||||
@@ -15,15 +15,12 @@ import forge.view.ButtonUtil;
|
||||
public class InputLockUI implements Input {
|
||||
private final AtomicInteger iCall = new AtomicInteger();
|
||||
private final InputQueue iq;
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param inputQueue
|
||||
*/
|
||||
|
||||
public InputLockUI(InputQueue inputQueue) {
|
||||
iq = inputQueue;
|
||||
}
|
||||
|
||||
public void showMessage() {
|
||||
public void showMessage(InputQueue iq) {
|
||||
int ixCall = 1 + iCall.getAndIncrement();
|
||||
FThreads.delay(500, new InputUpdater(ixCall));
|
||||
}
|
||||
|
||||
25
src/main/java/forge/control/input/InputNonSyncBase.java
Normal file
25
src/main/java/forge/control/input/InputNonSyncBase.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package forge.control.input;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.game.player.Player;
|
||||
|
||||
public abstract class InputNonSyncBase extends InputBase {
|
||||
private static final long serialVersionUID = -4038934296796872326L;
|
||||
protected final Player player;
|
||||
|
||||
public InputNonSyncBase(Player p) {
|
||||
this.player = p;
|
||||
}
|
||||
|
||||
protected void passPriority() {
|
||||
final Runnable pass = new Runnable() {
|
||||
@Override public void run() {
|
||||
player.getController().passPriority();
|
||||
}
|
||||
};
|
||||
if( FThreads.isEDT() )
|
||||
player.getGame().getInputQueue().LockAndInvokeGameAction(pass);
|
||||
else
|
||||
pass.run();
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ import forge.view.ButtonUtil;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InputPassPriority extends InputBase {
|
||||
public class InputPassPriority extends InputNonSyncBase {
|
||||
/** Constant <code>serialVersionUID=-581477682214137181L</code>. */
|
||||
private static final long serialVersionUID = -581477682214137181L;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import forge.card.spellability.AbilityManaPart;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.GameState;
|
||||
import forge.game.player.HumanPlay;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.gui.GuiChoose;
|
||||
|
||||
@@ -29,6 +30,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
|
||||
protected int phyLifeToLose = 0;
|
||||
|
||||
protected final Player player;
|
||||
protected final GameState game;
|
||||
protected ManaCostBeingPaid manaCost;
|
||||
protected final SpellAbility saPaidFor;
|
||||
@@ -36,7 +38,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
boolean bPaid = false;
|
||||
|
||||
protected InputPayManaBase(SpellAbility saToPayFor) {
|
||||
super(saToPayFor.getActivatingPlayer());
|
||||
this.player = saToPayFor.getActivatingPlayer();
|
||||
this.game = player.getGame();
|
||||
this.saPaidFor = saToPayFor;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ public abstract class InputSelectCards extends InputSelectManyBase<Card> {
|
||||
private static final long serialVersionUID = -6609493252672573139L;
|
||||
|
||||
protected InputSelectCards(int min, int max) {
|
||||
|
||||
super(min, max);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.List;
|
||||
|
||||
import forge.Card;
|
||||
import forge.GameEntity;
|
||||
import forge.Singletons;
|
||||
import forge.view.ButtonUtil;
|
||||
|
||||
public abstract class InputSelectManyBase<T extends GameEntity> extends InputSyncronizedBase implements InputSelectMany<T> {
|
||||
@@ -24,7 +23,6 @@ public abstract class InputSelectManyBase<T extends GameEntity> extends InputSyn
|
||||
|
||||
|
||||
protected InputSelectManyBase(int min, int max) {
|
||||
super(Singletons.getControl().getPlayer());
|
||||
selected = new ArrayList<T>();
|
||||
if (min > max) {
|
||||
throw new IllegalArgumentException("Min must not be greater than Max");
|
||||
|
||||
@@ -43,7 +43,6 @@ public final class InputSelectTargets extends InputSyncronizedBase {
|
||||
* @param mandatory
|
||||
*/
|
||||
public InputSelectTargets(List<Card> choices, SpellAbility sa, boolean mandatory) {
|
||||
super(sa.getActivatingPlayer());
|
||||
this.choices = choices;
|
||||
this.tgt = sa.getTarget();
|
||||
this.sa = sa;
|
||||
|
||||
@@ -5,16 +5,15 @@ import java.util.concurrent.CountDownLatch;
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.error.BugReporter;
|
||||
import forge.game.player.Player;
|
||||
|
||||
public abstract class InputSyncronizedBase extends InputBase implements InputSynchronized {
|
||||
private static final long serialVersionUID = 8756177361251703052L;
|
||||
|
||||
private boolean finished = false;
|
||||
private final CountDownLatch cdlDone;
|
||||
|
||||
|
||||
public InputSyncronizedBase(Player player) {
|
||||
super(player);
|
||||
public InputSyncronizedBase() {
|
||||
cdlDone = new CountDownLatch(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package forge.game.ai;
|
||||
import java.util.List;
|
||||
|
||||
import forge.Card;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.control.input.InputNonSyncBase;
|
||||
import forge.game.GameState;
|
||||
import forge.game.phase.CombatUtil;
|
||||
import forge.game.player.Player;
|
||||
@@ -12,7 +12,7 @@ import forge.game.player.Player;
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class AiInputBlock extends InputBase {
|
||||
public class AiInputBlock extends InputNonSyncBase {
|
||||
private final GameState game;
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
package forge.game.ai;
|
||||
|
||||
import forge.control.input.InputBase;
|
||||
import forge.control.input.InputNonSyncBase;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -27,7 +27,7 @@ import forge.control.input.InputBase;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AiInputCommon extends InputBase implements AiInput {
|
||||
public class AiInputCommon extends InputNonSyncBase implements AiInput {
|
||||
/** Constant <code>serialVersionUID=-3091338639571662216L</code>. */
|
||||
private static final long serialVersionUID = -3091338639571662216L;
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class InputProxy implements Observer {
|
||||
@Override public void run() {
|
||||
if(INPUT_DEBUG)
|
||||
System.out.printf("%s > showMessage @ %s during %s%n", FThreads.debugGetCurrThreadId(), nextInput.getClass().getSimpleName(), ph.debugPrintState());
|
||||
nextInput.showMessage();
|
||||
nextInput.showMessage(game.getInputQueue());
|
||||
}
|
||||
};
|
||||
// if( nextInput instanceof AiInput )
|
||||
|
||||
Reference in New Issue
Block a user