SVar "keyword"
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
SVar "keyword"
by Rob Cashwalker » 01 Feb 2010, 05:30
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)
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)
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: SVar "keyword"
by DennisBergkamp » 01 Feb 2010, 18:02
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.
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.
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: SVar "keyword"
by Rob Cashwalker » 04 Feb 2010, 01:31
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("+", ""));
}
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: SVar "keyword"
by DennisBergkamp » 04 Feb 2010, 02:24
I included my display_layout.xml and gui.properties files, extract them into /res/gui. Hope that helps...
- Attachments
-
gui_files.rar
- (1.04 KiB) Downloaded 356 times
-
DennisBergkamp - AI Programmer
- Posts: 2602
- Joined: 09 Sep 2008, 15:46
- Has thanked: 0 time
- Been thanked: 0 time
Re: SVar "keyword"
by Rob Cashwalker » 04 Feb 2010, 04:47
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.
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.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: SVar "keyword"
by silly freak » 04 Feb 2010, 09:45
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.
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.
___
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
where's the "trust me, that will work!" switch for the compiler?
Laterna Magica - blog, forum, project, 2010/09/06 release!
- silly freak
- DEVELOPER
- Posts: 598
- Joined: 26 Mar 2009, 07:18
- Location: Vienna, Austria
- Has thanked: 93 times
- Been thanked: 25 times
Re: SVar "keyword"
by Rob Cashwalker » 04 Feb 2010, 14:52
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.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
7 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 20 guests