Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lane validation to ActionSet #22

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions BinaryMatrixEngine/ActionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface CardSpecification {
public int? ResolveForPlayer(Player player);
}

public struct ActionSet {
public readonly struct ActionSet {
public readonly ActionType type;
public readonly int lane;
public readonly CardSpecification? card;
Expand All @@ -34,15 +34,23 @@ public ActionSet(ActionType type, int lane) {
if(type != ActionType.DRAW && type != ActionType.COMBAT)
throw new ArgumentException("Invalid overload called for this type.", nameof(type));
this.type = type;
this.lane = lane;
this.lane = ValidateLane(lane, allowPseudo: type == ActionType.DRAW);
this.card = default;
}

public ActionSet(ActionType type, CardSpecification card, int lane) {
if(type != ActionType.PLAY && type != ActionType.FACEUP_PLAY && type != ActionType.DISCARD)
throw new ArgumentException("Invalid overload called for this type.", nameof(type));
this.type = type;
this.lane = lane;
this.lane = ValidateLane(lane, allowPseudo: type == ActionType.DISCARD);
this.card = card;
}

private static int ValidateLane(int lane, bool allowPseudo = false) {
return lane switch {
< 0 or > LANE_A => throw new ArgumentOutOfRangeException(nameof(lane), lane, "Lane must be within the range [0; " + LANE_A + "]."),
LANE_A when !allowPseudo => throw new ArgumentOutOfRangeException(nameof(lane), lane, "Lane must name a real lane, not the `a` pseudolane for this action."),
_ => lane
};
}
}
Loading