Page 1 of 1

SVar "keyword"

PostPosted: 01 Feb 2010, 05:30
by Rob Cashwalker
In the spPumpTgt revision thread, Zerker proposed (sorry Z, I'm already married with kids...) that "X" and "Y" Count$ strings be defined on a separate keyword line.

I've gone ahead and laid the groundwork for an SVar keyword. It makes use of a HashMap in Card.java using a String as the key and it contains another String as the value.

Syntax:
SVar:{Variable Key}:{Variable Value}

This sort of thing may be useful in other areas other than X and Y calculations, so that's why I did this part first.

I haven't started converting the Pump, Draw and Damage code to use it yet, because I still want to get a consensus from the other devs if they feel it should be done. I was hoping to move on to new keywords (or at least revising spLoseLifeGainLife to use X) instead of a second revision to my original ones, but in the spirit of "Make It Right" I'll do it. (Anyone watch "Holmes on Homes" on HGTV? Best DIY-type show since "This Old House", because it shows haw badly "professional" contractors can screw up)

Re: SVar "keyword"

PostPosted: 01 Feb 2010, 18:02
by DennisBergkamp
It should probably be done at some point, I mean it would be good to have a uniform way of writing those keywords. But obviously feel free to do it whenever, there's no rush since the current keywords work just fine. And I can see it would be a bit of a boring job.

Speaking of boring jobs, I've been converting all of the token generation code to use one single makeToken() method. On the bright side, it probably will make our code a few thousand lines more compact, and allow for cards like Doubling Season.

Re: SVar "keyword"

PostPosted: 04 Feb 2010, 01:31
by Rob Cashwalker
I started with abPump[Tgt].

Code: Select all
        if (ptk.length >= 2)   // power/toughness
        {
           if (ptk[0].matches("[XY]"))
           {
              String xy = card.getSVar(ptk[0].replace("+", "").replace("-", ""));
              if (xy.startsWith("Count$"))
              {
                 String kk[] = xy.split("\\$");
                 AttackX[0] = kk[1];

                 if (ptk[0].contains("-"))   // handle "-X" or "-Y"
                    if (AttackX[0].contains("/"))   // already contains math element
                       AttackX[0].replace("/", "/Negative");   // insert into existing math element
                    else
                       AttackX[0] += "/Negative";   // add math element
              }
           }
           else if (ptk[0].matches("[0-9]"))
              NumAttack[0] = Integer.parseInt(ptk[0].replace("+", ""));

           if (ptk[1].matches("[XY]"))
           {
              String xy = card.getSVar(ptk[1].replace("+", "").replace("-", ""));
              if (xy.startsWith("Count$"))
              {
                 String kk[] = xy.split("\\$");
                 DefenseX[0] = kk[1];

                 if (ptk[1].contains("-"))   //handle "-X" or "-Y"
                    if (DefenseX[0].contains("/"))   // already contains math element
                       DefenseX[0].replace("/", "/Negative");   // insert into existing math element
                    else
                       DefenseX[0] += "/Negative";   // add math element
              }
           }
           else if (ptk[1].matches("[0-9]"))
              NumDefense[0] = Integer.parseInt(ptk[1].replace("+", ""));
        }
I haven't tested, because somehting's up with the gui, and I'm missing the left-hand panels.

Re: SVar "keyword"

PostPosted: 04 Feb 2010, 02:24
by DennisBergkamp
I included my display_layout.xml and gui.properties files, extract them into /res/gui. Hope that helps...

Re: SVar "keyword"

PostPosted: 04 Feb 2010, 04:47
by Rob Cashwalker
So far so good, that seems to have done it... thanks.

I wish there was a way to prevent some files from being subject to unneeded updates..

Edit - BTW, the code I posted above for abPump... doesn't work. "+X".matches("[XY]") doesn't return true. Regular expressions and I don't get along well.... I thought the regular expression would match at any point in the string.

PS edit - I think the error was actually in the Card.getSVar method.

Re: SVar "keyword"

PostPosted: 04 Feb 2010, 09:45
by silly freak
if you need to match "+X", "-X", and "X", then use "[-+]?[XY]" it means "a sign, once or not at all, and X or Y". Make sire you don't match any X in the text; probably a word boundary will do

if String.matches doesn't give enough, use Pattern and Matcher. Matcher has methods to match at the beginning somewhere in, or the whole string with a regular expression.

Re: SVar "keyword"

PostPosted: 04 Feb 2010, 14:52
by Rob Cashwalker
While I did switch my regex to "[\\+\\-][XY]", I don't think that was the issue. After some breakpoint debugging, I found that the getSVar method had a bug, and was returning an empty string.