-
Notifications
You must be signed in to change notification settings - Fork 980
Card-script param declarations (batch 1: framework classes) #11007
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
base: master
Are you sure you want to change the base?
Changes from all commits
7c19d7f
b9cdcea
92e56a9
9f26bbe
3251764
82dcf10
55b148f
0ac88f9
f28ed9f
0807d69
f26a322
c97dff5
a2e244b
a5fffaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,14 @@ | |
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| public class AbilityUtils { | ||
| public class AbilityUtils implements IHasForgeParams { | ||
| public static final String[] OPTIONAL_PARAMS = { | ||
| "AbilityCount", "AnnounceMax", "Destination", "ETB", "ForgetOtherTargets", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Destination is effect specific? |
||
| "IncludeAllComponentCards", "LockInText", "RememberCostMana", "RememberTargets", | ||
| "Triggered", "UnlessColor", "UnlessCost", "UnlessPayer", "UnlessResolveSubs", | ||
| "UnlessSwitched", "UnlessUpTo", "XMax", "XMin", | ||
| }; | ||
|
|
||
| private final static ImmutableList<String> cmpList = ImmutableList.of("LT", "LE", "EQ", "GE", "GT", "NE"); | ||
|
|
||
| // should the three getDefined functions be merged into one? Or better to | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package forge.game.ability; | ||
|
|
||
| /** | ||
| * Implemented by classes that declare the card-script parameters they consume: the optional params | ||
| * in a {@code public static final String[] OPTIONAL_PARAMS} field, and (for effects) mutually-required | ||
| * groups in a {@code String[][] REQUIRED_PARAMS} field. The accessors expose those fields so the | ||
| * card-script linter can ask a class which params it accepts; CardScriptParamDeclarationTest discovers | ||
| * implementors by classpath scan and guards the declarations against drift. | ||
| * | ||
| * The accessors read the field of the runtime class ({@code getClass()}) rather than returning a field | ||
| * directly. Because the fields are {@code static}, a direct {@code return OPTIONAL_PARAMS} inherited by a | ||
| * subclass would return the superclass's field; reading {@code getClass()}'s field returns the subclass's | ||
| * own declaration (or the inherited one when it declares none), so no per-class override is needed. | ||
| */ | ||
| public interface IHasForgeParams { | ||
| default String[] getOptionalParams() { | ||
| try { | ||
| return (String[]) getClass().getField("OPTIONAL_PARAMS").get(null); | ||
| } catch (NoSuchFieldException | IllegalAccessException e) { | ||
| return new String[0]; | ||
| } | ||
| } | ||
|
|
||
| default String[][] getRequiredParams() { | ||
| try { | ||
| return (String[][]) getClass().getField("REQUIRED_PARAMS").get(null); | ||
| } catch (NoSuchFieldException | IllegalAccessException e) { | ||
| return new String[0][]; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| import forge.card.CardType; | ||
| import forge.card.mana.ManaCost; | ||
| import forge.game.CardTraitBase; | ||
| import forge.game.ability.IHasForgeParams; | ||
| import forge.game.card.Card; | ||
| import forge.game.card.CounterEnumType; | ||
| import forge.game.card.CounterType; | ||
|
|
@@ -46,7 +47,16 @@ | |
| * @author Forge | ||
| * @version $Id$ | ||
| */ | ||
| public class Cost implements Serializable { | ||
| public class Cost implements Serializable, IHasForgeParams { | ||
| public static final String[] OPTIONAL_PARAMS = { | ||
| "AffectedZone", "Amount", "Announce", "Collected", "CollectedCards", "Color", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would like to see the Hash* fields queried instead if possible |
||
| "Cost", "Exiled", "ExiledCards", "FirstForetell", "ForEachShard", "Foraged", | ||
| "ForagedCards", "IgnoreGeneric", "MinMana", "ModeCost", "OnlyFirstSpell", | ||
| "RaiseCost", "RaiseTo", "ReduceAmount", "ReduceCost", "Relative", | ||
| "SpellDescription", "TapCreaturesForMana", "Type", "UnlessValidTarget", "UpTo", | ||
| "ValidCard", "ValidSpell", "ValidTarget", | ||
| }; | ||
|
|
||
| /** | ||
| * Serializables need a version ID. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,18 @@ | |
| * @version $Id$ | ||
| */ | ||
| public abstract class SpellAbility extends CardTraitBase implements ISpellAbility, IIdentifiable, Comparable<SpellAbility> { | ||
| public static final String[] OPTIONAL_PARAMS = { | ||
| "AlternateCost", "Amount", "Announce", "Boast", "CantCopy", "CloakUp", "CostDesc", | ||
| "CumulativeUpkeep", "DisguiseUp", "DividedAsYouChoose", "Exhaust", "Hidden", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sometimes, like with so for this case if it'd show up in a script it'd actually be wrong conceptually I'm not sure yet if we need a third category for params that are technically still implemented but very exotic/deprecated instead 🤔 |
||
| "IsCurse", "ManaRestriction", "ManifestUp", "MaxTotalTargetCMC", | ||
| "MaxTotalTargetPower", "MorphUp", "Origin", "Planeswalker", "PowerUp", | ||
| "PrecostDesc", "SpellDescription", "TargetType", "TargetingPlayer", | ||
| "TargetingPlayerControls", "TargetsWithControllerProperty", | ||
| "TargetsWithDefinedController", "TargetsWithRelatedProperty", | ||
| "TargetsWithSharedCardType", "TargetsWithSharedTypes", "Unlock", "ValidAfterStack", | ||
| "WithoutManaCost", "XColor", | ||
| }; | ||
|
|
||
| private static int maxId = 0; | ||
| private static int nextId() { return ++maxId; } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still like to see
additionalAbilityKeysunioned here less manually