Re: Game Nicknames to HTML
by ELISHEVA (Prior) on Mar 29, 2009 at 14:44 UTC
|
I've just taken a look at the VSK5 markup. Converting this to HTML is a rather complicated algorithm to implement for a new Perl programmer. Even assuming your algorithm skills from C programming come back to you, you will also need to learn a great deal of Perl syntax and conventions to do this. If this is a learning project, you might want to try something a little less ambitious.
To implement this you are going to need to:
- create a mapping between the codes and HTML. The mapping will require either in-line CSS or style sheets as some of the attributes are not supported in CSS. You can partly implement this in a lookup table. However, I think you will find constructing a look up table for all of the color markup quite tedious and unmanagable. You will need a function to convert $[0-9a-f][0-9a-f][0-9a-f] the three digit RGB to the 6 digit RGB used by HTML. The function will also need to generate the appropriate style attribute for that HTML
- In well formed HTML, each open tag should match a close tag. Therefore in your generated HTML you are going to need to keep track of all of the open tags you insert. Then when you hit a $z you will need to close them in the reverse order in which you inserted them. This is best managed using an array to hold the tags, push to store the open tags and pop to get the close tags for insertion.
- You may want to consider implementing $t as you read in characters. See uc for a routine to convert letters to upper case.
- You could try to use a fancy regex to parse the string and find all of the VSK5 markup. If you want to do that, check out perlre and perlretut. However, I think you might find it easier to convert the markup by writing a simple state engine that loops through all of the characters of the string and sets the state (processing character or attribute) based on what character is following any $ you encounter. To break the string into characters, use split(//,$sAttributedShipName). split uses the special regular expression // to split a string into characters.
- You may also want to consider a two phase conversion process. In pass one, you convert the string into an array of array references or hash references. Each array reference (or hash reference) would store the letter at position N and all of the attributes that will be set just before that letter. In the second pass, you would convert the array to HTML text. The two phase approach will help you avoid empty HTML tags that arise if someone has an attribute sequence like $i$z. If you choose this approach, you may find perlref helpful.
I did write up a short demo program to generate the HTML (partly to understand what you need to learn to do this task). However, since this is a learning site and not a code writing service, I'd like to see your first attempt at this problem before I post any code.
Best of luck, beth
P.S. There is apparently a book especially designed for C programmers trying to learn Perl - I haven't read it but you might want to take a look at it: Perl for C Programmers.
| [reply] [d/l] [select] |
|
|
| [reply] |
Re: Game Nicknames to HTML
by ig (Vicar) on Mar 29, 2009 at 18:11 UTC
|
With no offence intended to ELISHEVA, I had some fun with this and here is some code. You can look at it later if you want to try yourself first. It may be most helpful as an example of how not to do it. There is no attempt to minimize nesting of tags. You will have to play with CSS to get the effects you want.
update: revised, with thanks to ELISHEVA for guidance, and with tests added (which I should have done in the first place). There may still be bugs, as the test cases aren't exhaustive, but it's less buggy than it was.
| [reply] [d/l] [select] |
|
|
Wow, thank you for that code. I will try to understand what I have got here.
This site has a lot of experts as I see it now!
Thanks a lot
Thomas
| [reply] |
|
|
$s$02fCamster $0bfb$018s$0bfc
$00fS$fffa$00fo$fffr$00fs$fffa $00fB$fffs$00fc
$i$s$f06Jasmine
$i$s$f90Ario$06fñ$f90e $s$ff0 $s$fob
$s$i$00aM$0afarcus b$00as$0afc
$i$fffArthur $s$00fBSC $f00N$fffE$00fD
$w$s$fffSalt$i$m$00fheart
sonny $s$36FBSC
$s$5aaD$ddfia$5aaD$ddfe$5cc§
$ff0hula
$s$i$f00Ma$fffnta $00fGB
$i$s$t $fffPolar Bear
$w$325TULEBA$500(bsc)
$s$i$fffAdoo$015nis $i$0BFb$018s$0BFc
| [reply] [d/l] |
|
|
I have rewritten to avoid nesting of tags. The new version succeeds on all cases except "$i$s$f90Ario$06fñ$f90e $s$ff0 $s$fob" which has an invalid "$fob" at the end. For the moment it leaves the $f unchanged but maybe it should be removed, or maybe only the $ should be removed.
This version of the script seems to work. I would welcome any suggestions for improvement. Are there modules I should consider? Better ways to test??
| [reply] [d/l] |
|
|
Re: Game Nicknames to HTML
by ww (Archbishop) on Mar 29, 2009 at 10:59 UTC
|
Not sure I understand your question, but if you're getting the string you quote from the game's output, there's nothing to prevent you from using your script (and, perhaps, use CGI; to simply feed it back out to the html, using non-interpolating (single) quotes. Even the § will appear, as is, with proper <meta http-equiv="Content-Type" content="text/html; charset=..."> declarations and a reasonable (read, perhaps: Firefox) browser.
If the issue is more complex you may wish to edit your question by adding a bit more detail (identifying the update) and including existing code (within <c>...</c> tags.)
Update: Fixed typo in meta mention. And BTW, this is an example of properly marking an update of an existing node.
| [reply] [d/l] |
|
|
Thanks ww
I have tried it and it is still printing the whole string and not interpreting it.
The page header has
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> in it and the table row looks like
<TD align="center" class="normal">$s$5aaD$ddfia$5aaD$ddfe$5cc§</TD>
Do you see any mistake in here?
thanks, Thomas
| [reply] [d/l] [select] |
Re: Game Nicknames to HTML
by ambrus (Abbot) on Mar 29, 2009 at 11:47 UTC
|
$s<font color="#55aaaa">D</font><font color="#ddddff">ia</font><font c
+olor="#55aaaa">D</font><font color="#ddddff">e</font><font color="#55
+cccc">§</font>
Also, what does the $s mean at the beginning?
| [reply] [d/l] [select] |
|
|
| [reply] |
|
|
What's the name of the game engine? If it's something that's been used widely1, a search on that name might turn something up. Otherwise, you'll probably have to go from the game's documentation (or its source code) to identify the codes and their meanings, then write something to convert them to HTML.
Alternately, if users are running it entirely through a web interface, you could tell them it's time to abandon the legacy formatting codes and switch to BBCode (or raw HTML, if you trust them enough) to format their names.
1 ...this decade. The style of the codes gives me the impression that this may be a converted BBS door game and I have a feeling there aren't too many of those still running around these days.
| [reply] |
|
|
|
|
|
|
OK... then one issue is "What does 'shadowed' mean and is it even important (as opposed to mere decoration)?"
What you list is some kind of markup language, which could be tedious to deal with by hand. OTOH, given ambrus insights, it's one which you can automate with a script using CGI, one or more regular expressions, and other modules (possibly Data::Formatter and -- depending on your html and Perl skills -- one of the templating solutions for creating webpages).
But, at this point, developing a solution is yours to begin. If you get stuck, show us the code you've written and describe how it fails to achieve your goal. And it would still be well to provide a bit more detail, given that we don't know what OS (OSen?) you're using, nor how you intend to use what you originally characterized as a "scoring system." (Is the output going to a public webserver; just to your console (in which case, you can ignore CGI); or something else?)
| [reply] [d/l] [select] |
|
|
Re: Game Nicknames to HTML
by oko1 (Deacon) on Mar 29, 2009 at 14:17 UTC
|
Given your description of how your in-game formatting works, you could do what you're looking for - but it would take quite a bit of work. The problem is that the model used by your formatter is radically different from that used by HTML. Your formatter assumes a dynamic style that's updated by the "$" commands; HTML uses delimiters to enclose the text to be formatted.
The upshot is that you'd have to write some sort of an HTML generator that follows your formatter's rules. This could range from relatively simple to very complex; for example, the "wide/narrow spacing" modifier would be very difficult to reproduce in HTML (a bit easier using CSS, but that's yet another kettle of fish), since you can't guarantee that all your users would have the same fonts.
Your best bet may just be to strip off all the formatting for your result list; that shouldn't be too hard.
$boat_name =~ s/(?<!\$)\$[iswnmgtz]//g;
$boat_name =~ s/\$\$/\$/g;
--
"Language shapes the way we think, and determines what we can think about."
-- B. L. Whorf
| [reply] [d/l] |
|
|
s/\$\$/\$S/g; s/\$[iswnmgtz]//g; s/\$S/\$/g;
Or, to strip the three-hexit color codes as well,
s/\$\$/\$S/g; s/\$(?:[0-9a-fA-F]{3}|[g-z])//g; s/\$S/\$/g;
Update: I should have linked to Re: checking interpreted string for escapes versus literal backslashes?.
| [reply] [d/l] [select] |