Lengthy Run-On spellText descriptions
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
6 posts
• Page 1 of 1
Lengthy Run-On spellText descriptions
by Chris H. » 09 Sep 2010, 11:34
With the current cards.txt system, we have just one line for an included spellText description. As such, we will sometimes take multiple paragraphs of text and place it into a single paragraph. It would be nice if we had a "hack" that would break this up into multiple paragraphs as the text would become more readable.
As an example, look at the entry for Faceless Butcher. It looks like someone had similar plans in the past. They may have planned to replace the " -- " with "\r\n". But the "\r\n" chars just print and do not advance to the next line.
I hacked the Card.getText() method and we now have in my local copy:
And this works! So my local cards.txt entry for Faceless Butcher now looks like this:
If no-one has an objection, I will merge my code into the SVN and will start updating the cards that I can find that could use this feature. One example that comes to mind is Belligerent Hatchling. I will attach three jpgs to give people a before and after image of this one card.
`
As an example, look at the entry for Faceless Butcher. It looks like someone had similar plans in the past. They may have planned to replace the " -- " with "\r\n". But the "\r\n" chars just print and do not advance to the next line.
- Code: Select all
Faceless Butcher
2 B B
Creature Nightmare Horror
When Faceless Butcher comes into play, remove target creature other than Faceless Butcher from the game. -- When Faceless Butcher is destroyed, return the removed card to play under its owner's control.
2/3
I hacked the Card.getText() method and we now have in my local copy:
- Code: Select all
/*
sb.append("\r\n");
sb.append(text);
sb.append("\r\n");
*/
sb.append("\r\n");
String textArray[] = text.split("\\\\r\\\\n");
for (int i = 0; i < textArray.length; i++) {
sb.append(textArray[i]).append("\r\n");
}
And this works! So my local cards.txt entry for Faceless Butcher now looks like this:
- Code: Select all
Faceless Butcher
2 B B
Creature Nightmare Horror
When Faceless Butcher comes into play, remove target creature other than Faceless Butcher from the game.\r\nWhen Faceless Butcher is destroyed, return the removed card to play under its owner's control.
2/3
If no-one has an objection, I will merge my code into the SVN and will start updating the cards that I can find that could use this feature. One example that comes to mind is Belligerent Hatchling. I will attach three jpgs to give people a before and after image of this one card.
`
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: Lengthy Run-On spellText descriptions
by Rob Cashwalker » 09 Sep 2010, 12:24
Instead of splitting, do a replace.
- Code: Select all
text = text.replaceAll("--", "\r\n");
sb.append("\r\n");
sb.append(text);
sb.append("\r\n");
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: Lengthy Run-On spellText descriptions
by Chris H. » 09 Sep 2010, 14:27
My initial attempts used your code and I was happy with how well it worked. I then pondered, why did the original author stop here and not add in the code to Card.getText()?
Someone adding a card might want the sequence " -- " to be a literal and not have it replaced with a CarriageReturn + LineFeed
People new to the project might have a hard time making the association
It dawned on me that we would probably want a standardized char sequence to represent and only represent a CarriageReturn + LineFeed. I find myself leaning towards using "\r\n". Granted, I found that the "\" caused some early problems but I was able to figure out how to modify the code to recognize the char sequence "\r\n".
Can people live with using the char sequence "\r\n"? Will this be hard for people to remember?
OH, I tried
and it did not work. I found that I had to approach this in a different fashion.
Someone adding a card might want the sequence " -- " to be a literal and not have it replaced with a CarriageReturn + LineFeed


It dawned on me that we would probably want a standardized char sequence to represent and only represent a CarriageReturn + LineFeed. I find myself leaning towards using "\r\n". Granted, I found that the "\" caused some early problems but I was able to figure out how to modify the code to recognize the char sequence "\r\n".
Can people live with using the char sequence "\r\n"? Will this be hard for people to remember?
OH, I tried
- Code: Select all
text.replaceAll"\r\n", "\r\n");
and it did not work. I found that I had to approach this in a different fashion.
-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: Lengthy Run-On spellText descriptions
by silly freak » 09 Sep 2010, 15:58
replaceAll takes a regular expression as its first parameter, and both Java and Regex have special handling of "\":
- Code: Select all
Source Code Java Meaning Regex Meaning
r r r
\r <<CR>> <<CR>>
\\r \r <<CR>>
\\\r \<<CR>> <<CR>>
\\\\r \\r \r
\\\\\r \\<CR>> \<<CR>>
- Code: Select all
text.replaceAll("\\\\r\\\\n", "\r\n");
- Code: Select all
text.replaceAll("\\\\n", System.getProperty("line.separator"));
___
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: Lengthy Run-On spellText descriptions
by Chris H. » 09 Sep 2010, 18:42
Thank you for the info. I spent some time with java doc while working on this part of the project and realized that my education is lacking in this area.
I guess that Rares used "\r\n" throughout the code for some reason and this has become a force of habit for the rest of us. Snacko pointed out that we have far to much string code where we add pieces together and that we should convert this into StringBuilder. I have changed over a small portion of code but there is still so much to fix.
Once again, thank you for the info on Regex. I am now using
and this has simplified the process.

`by the way, why even bother with \r? in the first parameter it's a literal and "\\\\n" is just as good. The replacement is only used inside java, which handles all variants of line endings gracefully.
I guess that Rares used "\r\n" throughout the code for some reason and this has become a force of habit for the rest of us. Snacko pointed out that we have far to much string code where we add pieces together and that we should convert this into StringBuilder. I have changed over a small portion of code but there is still so much to fix.
Once again, thank you for the info on Regex. I am now using
- Code: Select all
text = text.replaceAll("\\\\r\\\\n", "\r\n");
and this has simplified the process.

-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
Re: Lengthy Run-On spellText descriptions
by Chris H. » 11 Sep 2010, 17:35
It took a while to scroll through the list of cards to find some candidates, but I found several dozen cards and I have finished. I hope that I did not disrupt my friends and the cards.txt file too much. 

-
Chris H. - Forge Moderator
- Posts: 6320
- Joined: 04 Nov 2008, 12:11
- Location: Mac OS X Yosemite
- Has thanked: 644 times
- Been thanked: 643 times
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 38 guests