Add Support for Expression Trees
Part of a long term goal for completely replacing HOTC as a codestyle. The idea is to be able to parse any card text (from any card style or any language for that matter), convert it into an Expression Tree.
Using this expression tree allows various functions, from being able to serialize it into another language entirely (using any type of card effect style), or use the data to create card scripts (like that for BlakeWS)
[Sample Format]
// [CONT] Assist All of your characters in front of this card gets +500 power.
// [C] ASSIST All your Characters in front of this gain +500 Power.
private static WSExpressionTree GetSample()
{
return new WSExpressionTree()
{
ExpressionType = WSExpressionType.Continous,
Labels = new[] { WSLabel.Assist },
Condition = null,
Effect = new WSGainATKEffect()
{
ATK = +500,
Target = WSZone.YourStage with {
Condition = WSCondition.InFrontOf(WSTarget.ThisCard)
}
}
};
}
Leaving pseudo-algorithm for the deserializer for a general effect parser.
[AUTO] [(1) Put the top card of your deck into your clock] When this card is placed on stage from your hand, you may pay the cost. If you do, search your deck for up to 1 level 1 or lower character, reveal it to your opponent, add it into your hand, and shuffle your deck.
- First line should expect
[, or if it does not start with this line, imply[AUTO] When this event is played,Regex(?: )*(\[(ACT|AUTO|CONT|REPLAY)\])?(?: )*(.*)is used to get these tokens. - After
AUTOis read, determine that the effect is an auto effect. - Continue parsing, discarding the token, and trim into:
[(1) Put the top card of your deck into your clock] When (...) - Capture all strings before the words
WhenorIforAt, as it's anAUTOability using:(.*)?((When|At|If)((.*)))? - You get
[(1) Put the top card of your deck into your clock]in token 1, andWhen this card is placed (...). - Capture the following tokens using regex
([A-Za-z ]*)(\[(.)*\])?, designed to capture all keywords and the cost if any. (Getting nothing.) - Get The keyword string from {6} with
[(1) Put the top card of your deck into your clock], and remove the[]. - Run result from {7} into the [Effect Parser] to get the cost. Move on to token 1 from {5}
- Run the following regex
When (.*), ((?iI)f (.*)), (.*)to get:- Token 1 for [Automatic Condition Parser].
- Token 2 for [Continuous Condition Parser].
- Token 3 for [Effect Parser].
- End Parsing.