mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
This commit is contained in:
parent
d43e96eaf2
commit
a98f72649a
17 changed files with 123 additions and 83 deletions
|
|
@ -11,19 +11,19 @@ public class AmountTestableResult extends BaseTestableResult {
|
|||
|
||||
int amount = 0;
|
||||
|
||||
public void save(boolean status, List<String> info, int amount) {
|
||||
this.save(status, info);
|
||||
public void onFinish(boolean status, List<String> info, int amount) {
|
||||
this.onFinish(status, info);
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
return true;
|
||||
public Boolean getResAssert() {
|
||||
return null; // TODO: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
public void onClear() {
|
||||
super.onClear();
|
||||
this.amount = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class AnnounceXTestableDialog extends BaseTestableDialog {
|
|||
List<String> res = new ArrayList<>();
|
||||
res.add(getGroup() + " - " + this.getName() + " selected " + chooseRes);
|
||||
|
||||
((AmountTestableResult) this.getResult()).save(true, res, chooseRes);
|
||||
((AmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ abstract class BaseTestableDialog implements TestableDialog {
|
|||
|
||||
@Override
|
||||
public void prepare() {
|
||||
this.result.clear();
|
||||
this.result.onClear();
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void showResult(Player player, Game game) {
|
||||
// show message with result
|
||||
game.informPlayer(player, String.join("<br>", getResult().getInfo()));
|
||||
game.informPlayer(player, String.join("<br>", getResult().getResDetails()));
|
||||
// reset game and gui (in most use cases it must return to player's priority)
|
||||
game.firePriorityEvent(player.getId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,41 +10,41 @@ import java.util.List;
|
|||
*/
|
||||
public class BaseTestableResult implements TestableResult {
|
||||
|
||||
boolean saved = false;
|
||||
boolean status = false;
|
||||
List<String> info = new ArrayList<>();
|
||||
boolean isFinished = false;
|
||||
boolean resStatus = false;
|
||||
List<String> resInfo = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public boolean getStatus() {
|
||||
return this.status;
|
||||
public boolean getResStatus() {
|
||||
return this.resStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getInfo() {
|
||||
return this.info;
|
||||
public List<String> getResDetails() {
|
||||
return this.resInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(boolean status, List<String> info) {
|
||||
this.saved = true;
|
||||
this.status = status;
|
||||
this.info = info;
|
||||
public Boolean getResAssert() {
|
||||
return null; // TODO: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
return true;
|
||||
public void onFinish(boolean resStatus, List<String> resDetails) {
|
||||
this.isFinished = true;
|
||||
this.resStatus = resStatus;
|
||||
this.resInfo = resDetails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaved() {
|
||||
return this.saved;
|
||||
public boolean isFinished() {
|
||||
return this.isFinished;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
this.saved = false;
|
||||
this.status = false;
|
||||
this.info.clear();
|
||||
public void onClear() {
|
||||
this.isFinished = false;
|
||||
this.resStatus = false;
|
||||
this.resInfo.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,19 +11,19 @@ public class ChoiceTestableResult extends BaseTestableResult {
|
|||
|
||||
String choice = null;
|
||||
|
||||
public void save(boolean status, List<String> info, String choice) {
|
||||
this.save(status, info);
|
||||
public void onFinish(boolean status, List<String> info, String choice) {
|
||||
this.onFinish(status, info);
|
||||
this.choice = choice;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
return true;
|
||||
public Boolean getResAssert() {
|
||||
return null; // TODO: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
public void onClear() {
|
||||
super.onClear();
|
||||
this.choice = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class ChooseAmountTestableDialog extends BaseTestableDialog {
|
|||
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
|
||||
}
|
||||
|
||||
((TargetTestableResult) this.getResult()).save(chooseRes, res, choosingTarget);
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ class ChooseCardsTestableDialog extends BaseTestableDialog {
|
|||
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
|
||||
}
|
||||
|
||||
((TargetTestableResult) this.getResult()).save(chooseRes, res, choosingTarget);
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class ChooseChoiceTestableDialog extends BaseTestableDialog {
|
|||
res.add(String.format("* selected value: %s", choice));
|
||||
}
|
||||
|
||||
((ChoiceTestableResult) this.getResult()).save(chooseRes, res, choice);
|
||||
((ChoiceTestableResult) this.getResult()).onFinish(chooseRes, res, choice);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class ChoosePileTestableDialog extends BaseTestableDialog {
|
|||
res.add(getGroup() + " - " + this.getName() + " - " + (chooseRes ? "TRUE" : "FALSE"));
|
||||
res.add(" * selected pile: " + (chooseRes ? "pile 1" : "pile 2"));
|
||||
|
||||
this.getResult().save(chooseRes, res);
|
||||
this.getResult().onFinish(chooseRes, res);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -74,14 +74,14 @@ class ChooseTargetTestableDialog extends BaseTestableDialog {
|
|||
Targets.printDebugTargets(getGroup() + " - " + this.getName() + " - " + "FALSE", new Targets(choosingTarget), source, game, res);
|
||||
}
|
||||
|
||||
((TargetTestableResult) this.getResult()).save(chooseRes, res, choosingTarget);
|
||||
((TargetTestableResult) this.getResult()).onFinish(chooseRes, res, choosingTarget);
|
||||
}
|
||||
|
||||
private ChooseTargetTestableDialog aiMustChoose(boolean status, int count) {
|
||||
private ChooseTargetTestableDialog aiMustChoose(boolean resStatus, int targetsCount) {
|
||||
TargetTestableResult res = ((TargetTestableResult) this.getResult());
|
||||
res.aiAssert = true;
|
||||
res.aiMustChooseStatus = status;
|
||||
res.aiMustChooseTargetsCount = count;
|
||||
res.aiAssertEnabled = true;
|
||||
res.aiAssertResStatus = resStatus;
|
||||
res.aiAssertTargetsCount = targetsCount;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class ChooseUseTestableDialog extends BaseTestableDialog {
|
|||
List<String> res = new ArrayList<>();
|
||||
res.add(chooseRes ? "TRUE" : "FALSE");
|
||||
|
||||
this.getResult().save(chooseRes, res);
|
||||
this.getResult().onFinish(chooseRes, res);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class GetAmountTestableDialog extends BaseTestableDialog {
|
|||
List<String> res = new ArrayList<>();
|
||||
res.add(getGroup() + " - " + this.getName() + " selected " + chooseRes);
|
||||
|
||||
((AmountTestableResult) this.getResult()).save(true, res, chooseRes);
|
||||
((AmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class GetMultiAmountTestableDialog extends BaseTestableDialog {
|
|||
}
|
||||
res.add("total selected: " + selectedTotal);
|
||||
|
||||
((MultiAmountTestableResult) this.getResult()).save(true, res, chooseRes);
|
||||
((MultiAmountTestableResult) this.getResult()).onFinish(true, res, chooseRes);
|
||||
}
|
||||
|
||||
static public void register(TestableDialogsRunner runner) {
|
||||
|
|
|
|||
|
|
@ -12,19 +12,19 @@ public class MultiAmountTestableResult extends BaseTestableResult {
|
|||
|
||||
List<Integer> values = new ArrayList<>();
|
||||
|
||||
public void save(boolean status, List<String> info, List<Integer> values) {
|
||||
this.save(status, info);
|
||||
public void onFinish(boolean status, List<String> info, List<Integer> values) {
|
||||
this.onFinish(status, info);
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
return true;
|
||||
public Boolean getResAssert() {
|
||||
return null; // TODO: implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
public void onClear() {
|
||||
super.onClear();
|
||||
this.values.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,33 +13,33 @@ public class TargetTestableResult extends BaseTestableResult {
|
|||
|
||||
Target target = null;
|
||||
|
||||
boolean aiAssert = false;
|
||||
boolean aiMustChooseStatus = false;
|
||||
int aiMustChooseTargetsCount = 0;
|
||||
boolean aiAssertEnabled = false;
|
||||
boolean aiAssertResStatus = false;
|
||||
int aiAssertTargetsCount = 0;
|
||||
|
||||
public void save(boolean status, List<String> info, Target target) {
|
||||
this.save(status, info);
|
||||
public void onFinish(boolean status, List<String> info, Target target) {
|
||||
this.onFinish(status, info);
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOk() {
|
||||
if (!this.aiAssert) {
|
||||
return true;
|
||||
public Boolean getResAssert() {
|
||||
if (!this.aiAssertEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// not finish
|
||||
// not finished
|
||||
if (this.target == null) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
|
||||
// wrong choose
|
||||
if (this.getStatus() != this.aiMustChooseStatus) {
|
||||
if (this.getResStatus() != this.aiAssertResStatus) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// wrong targets
|
||||
if (this.target.getTargets().size() != this.aiMustChooseTargetsCount) {
|
||||
if (this.target.getTargets().size() != this.aiAssertTargetsCount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -48,8 +48,8 @@ public class TargetTestableResult extends BaseTestableResult {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
public void onClear() {
|
||||
super.onClear();
|
||||
this.target = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,21 +9,25 @@ import java.util.List;
|
|||
*/
|
||||
public interface TestableResult {
|
||||
|
||||
boolean getStatus();
|
||||
/**
|
||||
* Dialog's result
|
||||
*/
|
||||
boolean getResStatus();
|
||||
|
||||
List<String> getInfo();
|
||||
/**
|
||||
* Dialog's detail result
|
||||
*/
|
||||
List<String> getResDetails();
|
||||
|
||||
/**
|
||||
* Save new result after show dialog
|
||||
*
|
||||
* @param status result of choice dialog call
|
||||
* @param info detail result to show in GUI
|
||||
*/
|
||||
void save(boolean status, List<String> info);
|
||||
void onFinish(boolean resStatus, List<String> resDetails);
|
||||
|
||||
boolean isSaved();
|
||||
boolean isFinished();
|
||||
|
||||
void clear();
|
||||
void onClear();
|
||||
|
||||
boolean isOk();
|
||||
Boolean getResAssert();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue