Dev: added additional info to some classes for easy debug;

This commit is contained in:
Oleg Agafonov 2021-03-07 17:16:54 +04:00
parent bde6222ea6
commit 0e916b6e29
19 changed files with 133 additions and 19 deletions

View file

@ -1,6 +1,7 @@
package mage.view; package mage.view;
import mage.game.Game; import mage.game.Game;
import mage.util.CardUtil;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -43,27 +44,12 @@ public class ChatMessage implements Serializable {
this.username = username; this.username = username;
this.message = message; this.message = message;
this.time = time; this.time = time;
this.turnInfo = prepareTurnInfo(game); this.turnInfo = CardUtil.getTurnInfo(game);
this.color = color; this.color = color;
this.messageType = messageType; this.messageType = messageType;
this.soundToPlay = soundToPlay; this.soundToPlay = soundToPlay;
} }
private String prepareTurnInfo(Game game) {
// no turn info
if (game == null) {
return null;
}
// not started game
if (game.getStep() == null) {
return "T0";
}
// normal game
return "T" + game.getTurnNum() + "." + game.getStep().getType().getStepShortText();
}
public String getMessage() { public String getMessage() {
return message; return message;
} }

View file

@ -4201,4 +4201,8 @@ public class TestPlayer implements Player {
return rollbackActions; return rollbackActions;
} }
@Override
public String toString() {
return computerPlayer.toString();
}
} }

View file

@ -339,4 +339,9 @@ public abstract class MageObjectImpl implements MageObject {
} }
} }
} }
@Override
public String toString() {
return getIdName() + " (" + super.getClass().getSuperclass().getSimpleName() + " -> " + this.getClass().getSimpleName() + ")";
}
} }

View file

@ -100,6 +100,15 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
public int hashCode() { public int hashCode() {
return Objects.hash(amount, snowAmount); return Objects.hash(amount, snowAmount);
} }
@Override
public String toString() {
if (amount != 0 || snowAmount != 0) {
return amount + "/" + snowAmount;
} else {
return "";
}
}
} }
private static final transient Logger logger = Logger.getLogger(Mana.class); private static final transient Logger logger = Logger.getLogger(Mana.class);

View file

@ -75,5 +75,4 @@ public class GenericManaCost extends ManaCostImpl {
public boolean containsColor(ColoredManaSymbol coloredManaSymbol) { public boolean containsColor(ColoredManaSymbol coloredManaSymbol) {
return false; return false;
} }
} }

View file

@ -284,4 +284,8 @@ public abstract class ManaCostImpl extends CostImpl implements ManaCost {
} }
} }
@Override
public String toString() {
return getText();
}
} }

View file

@ -54,5 +54,4 @@ public interface ManaCosts<T extends ManaCost> extends List<T>, ManaCost {
.collect(Collectors.toCollection(ManaCostsImpl::new)); .collect(Collectors.toCollection(ManaCostsImpl::new));
} }
} }

View file

@ -1498,4 +1498,8 @@ public class ContinuousEffects implements Serializable {
} }
} }
@Override
public String toString() {
return "Effects: " + allEffectsLists.stream().mapToInt(ContinuousEffectsList::size).sum();
}
} }

View file

@ -1,11 +1,16 @@
package mage.game; package mage.game;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import mage.abilities.Abilities; import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl; import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.counters.Counter;
import mage.counters.Counters; import mage.counters.Counters;
/** /**
@ -127,4 +132,30 @@ public class CardState implements Serializable {
this.melded = melded; this.melded = melded;
} }
@Override
public String toString() {
List<String> info = new ArrayList<>();
if (this.faceDown) {
info.add("face down");
}
if (this.counters != null && !this.counters.isEmpty()) {
info.add("counters: " + this.counters.values().stream().mapToInt(Counter::getCount).sum());
}
if (this.abilities != null && !this.abilities.isEmpty()) {
info.add("abilities: " + abilities.size());
}
if (this.lostAllAbilities) {
info.add("lost all");
}
if (this.melded) {
info.add("melded");
}
if (info.isEmpty()) {
return "";
} else {
return String.join("; ", info);
}
}
} }

View file

@ -120,4 +120,12 @@ public class Exile implements Serializable, Copyable<Exile> {
} }
} }
} }
@Override
public String toString() {
return "Cards: " + exileZones.values()
.stream()
.mapToInt(ExileZone::size)
.sum();
}
} }

View file

@ -3476,4 +3476,14 @@ public abstract class GameImpl implements Game, Serializable {
return gameStopped; return gameStopped;
} }
@Override
public String toString() {
Player activePayer = this.getPlayer(this.getActivePlayerId());
StringBuilder sb = new StringBuilder()
.append(this.getGameType().toString())
.append("; ").append(CardUtil.getTurnInfo(this))
.append("; active: ").append((activePayer == null ? "none" : activePayer.getName()))
.append("; stack: ").append(this.getStack().toString());
return sb.toString();
}
} }

View file

@ -28,6 +28,7 @@ import mage.players.Player;
import mage.players.PlayerList; import mage.players.PlayerList;
import mage.players.Players; import mage.players.Players;
import mage.target.Target; import mage.target.Target;
import mage.util.CardUtil;
import mage.util.Copyable; import mage.util.Copyable;
import mage.util.ThreadLocalStringBuilder; import mage.util.ThreadLocalStringBuilder;
import mage.watchers.Watcher; import mage.watchers.Watcher;
@ -1384,4 +1385,9 @@ public class GameState implements Serializable, Copyable<GameState> {
public boolean isManaBurn() { public boolean isManaBurn() {
return manaBurn; return manaBurn;
} }
@Override
public String toString() {
return CardUtil.getTurnInfo(this);
}
} }

View file

@ -382,4 +382,9 @@ public class Battlefield implements Serializable {
.mapToInt(x -> x ? 1 : 0) .mapToInt(x -> x ? 1 : 0)
.sum(); .sum();
} }
@Override
public String toString() {
return "Permanents: " + field.size();
}
} }

View file

@ -1131,4 +1131,8 @@ public class Spell extends StackObjImpl implements Card {
throw new UnsupportedOperationException("Spells should not loose all abilities. Check if this operation is correct."); throw new UnsupportedOperationException("Spells should not loose all abilities. Check if this operation is correct.");
} }
@Override
public String toString() {
return ability.toString();
}
} }

View file

@ -144,4 +144,8 @@ public class SpellStack extends ArrayDeque<StackObject> {
return dateLastAdded; return dateLastAdded;
} }
@Override
public String toString() {
return this.size() + (this.isEmpty() ? "" : " (top: " + this.getFirst().toString() + ")");
}
} }

View file

@ -251,4 +251,9 @@ public class Library implements Serializable {
} }
return -1; return -1;
} }
@Override
public String toString() {
return "Cards: " + library.size();
}
} }

View file

@ -531,4 +531,9 @@ public class ManaPool implements Serializable {
public boolean getLastPaymentWasSnow() { public boolean getLastPaymentWasSnow() {
return lastPaymentWasSnow; return lastPaymentWasSnow;
} }
@Override
public String toString() {
return getMana().toString();
}
} }

View file

@ -4706,7 +4706,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override @Override
public String toString() { public String toString() {
return getName() + " " + super.toString(); return getName() + " (" + super.getClass().getSimpleName() + ")";
} }
} }

View file

@ -21,6 +21,7 @@ import mage.filter.Filter;
import mage.filter.predicate.mageobject.NamePredicate; import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.CardState; import mage.game.CardState;
import mage.game.Game; import mage.game.Game;
import mage.game.GameState;
import mage.game.command.Commander; import mage.game.command.Commander;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -1290,4 +1291,29 @@ public final class CardUtil {
} }
return mapOldToNew; return mapOldToNew;
} }
/**
* Return turn info for game. Uses in game logs and debug.
*
* @param game
* @return
*/
public static String getTurnInfo(Game game) {
return getTurnInfo(game == null ? null : game.getState());
}
public static String getTurnInfo(GameState gameState) {
// no turn info
if (gameState == null) {
return null;
}
// not started game
if (gameState.getTurn().getStep() == null) {
return "T0";
}
// normal game
return "T" + gameState.getTurnNum() + "." + gameState.getTurn().getStep().getType().getStepShortText();
}
} }