Page 1 of 1

Lengthy Run-On spellText descriptions

PostPosted: 09 Sep 2010, 11:34
by Chris H.
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.

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.

`

Re: Lengthy Run-On spellText descriptions

PostPosted: 09 Sep 2010, 12:24
by Rob Cashwalker
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");
I've just tested this to work.

Re: Lengthy Run-On spellText descriptions

PostPosted: 09 Sep 2010, 14:27
by Chris H.
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

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.

Re: Lengthy Run-On spellText descriptions

PostPosted: 09 Sep 2010, 15:58
by silly freak
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>>
So the correct line is

Code: Select all
text.replaceAll("\\\\r\\\\n", "\r\n");
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. If you want to make the text boxes copy-pasteable in a platform independent manner, just use

Code: Select all
text.replaceAll("\\\\n", System.getProperty("line.separator"));
or an equivalent with System.getProperty only called once for the whole application...

Re: Lengthy Run-On spellText descriptions

PostPosted: 09 Sep 2010, 18:42
by Chris H.
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. :D

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. 8)

Re: Lengthy Run-On spellText descriptions

PostPosted: 11 Sep 2010, 17:35
by Chris H.
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. :wink: