| 11-17-2007, 08:30 AM | #1 |
TextParse System - Version 1.20 Created by Ammorth Requires Table and JassHelper by Vexorian Parses a string to fit a certain width. Mainly used for multiboards. Download Now Readme:==============READ-ME================ * TextParse System - Version 1.20 * Compiled on February 23, 2009 * Created by Ammorth * Uses Table by Vexorian * Requires JassHelper =============Installation============ 1) Copy the trigger/library "TextParse" to your map. 2) Save your map using JassHelper ================About================ TextParse takes a string and will format it to fit to a certain width. This can be used to display text messages on multiboards. The system supports new lines "|n", color codes "|cAARRGGBB" and color ends "|r". It will wrap color to the lines below automatically. ================Usage================ To use, simple pass the string to be parsed to the function TextParse_ParseString, where it will output a TextParse (struct). You can then display the lines of text using either method DisplayString or method DisplayAllStrings. You can also use method GetNumberStrings to find out the number of lines of the parsed string. Example code with comments: function PlayerChat takes nothing returns nothing local real width = 15. // the width the text should be. This is really the percentage of the screen when using a multiboard. local string s = GetEventPlayerChatString() // the string that will be parsed local TextParse t = TextParse_ParseString(s, width) // parse the string with the width and set it to t local integer i = t.GetNumberStrings // get the number of strings so we can loop through them all and display them local integer n = 1 // our counter for the loop loop exitwhen n > i call MultiboardSetItemValueBJ(SomeMultiboard, 1, n, t.DisplayString(n)) // set the text of each line to the multiboard set n = n + 1 endloop call t.destroy() // destroy the parsed string so it doesn't leak. endfunction ===========List of Functions========= function TextParse_ParseString takes string s, real width returns TextParse (outside library) or public function ParseString takes string s, real width returns TextParse (in library) - string s - the string that will be parsed - real width - the max width each line can only be (must be between 2 and 100) - returns TextParse - the final parsed text that is output SomeParse.DisplayString takes integer line returns string (with variable SomeParse) or method DisplayString takes integer line returns string (inside struct) - integer line - the line number that should be displayed - returns string - the string of that line. will return "" if the line doesnt exist SomeParse.DisplayAllStrings takes nothing returns string (with variable SomeParse) or method DisplayAllStrings takes nothing returns string (inside struct) - returns string - returns the entire parsed string with line separation between each line ("|n") and formated color codes. SomeParse.GetNumberLines takes nothing returns integer (with variable SomeParse) or method GetNumberLines takes nothing returns integer (inside struct) - returns integer - the number of lines the current parsed string has. SomeParse.destroy takes nothing returns nothing (with variable SomeParse) or method onDestroy takes nothing returns nothing (inside struct) - destroys the TextParse so it doesnt leak. - Note: strings do not leak, it is the TextParse struct that leaks if you do not destroy it. =============Change-Log============== Version 1.20 - Fixed database values (now only works correctly with multiboards) - Updated to use Table - Refined some functions Version 1.10 - Updated to vJass - Included support for color-codes - Improved parsing function - Converted to CSCache to generalize storage method Version 1.00 - First Public Release |
| 11-17-2007, 08:52 AM | #2 |
Sexy. |
| 11-17-2007, 08:59 AM | #3 |
There are non greedy algorithms for solving this problem in linear time. In particular you should check out the Knuth Plass linebreaking algorithm. Knuth and Plass, "Breaking Paragraphs into Lines" 1981 |
| 11-17-2007, 10:17 AM | #4 |
@PipeDream How the hell do you know so much about algorithms if you are not a programmer? |
| 11-17-2007, 11:02 AM | #5 |
He knows shit loads about code... maybe he's a hacker! O.O; *changes password* |
| 11-17-2007, 11:46 AM | #6 | |
Quote:
*assuming sarcasm* I'll check it out this system as soon as I get home. |
| 11-17-2007, 12:18 PM | #7 | |
Quote:
I can't think of a way to make an algorithm for this that had worse complexity than linear... I guess I am gonna take a look at code. |
| 11-17-2007, 02:06 PM | #8 |
When I try to test the map i just end up at Frozen Throne menu, (when you start up warcraft) Help? |
| 11-17-2007, 02:16 PM | #9 |
Looks very good. I'm too lazy (or bad :P) to look at the code and possibly understand something, but based on the demo, it works fine. Grats |
| 11-17-2007, 08:13 PM | #10 |
His algorithm is linear. What I meant was that you can pack in more text to fewer lines with out sacrificing time complexity. Obviously for typical text not much more, particularly if you have only short snippets. |
| 11-18-2007, 12:51 AM | #11 |
I looked into the method PipeDream stated and it seems like it would be more costly than the linear approach (requires building possible breaks and then finding the best route through the breaks). Edit: I'm working on a syllable splitter that should increase the amount of text per line and stop the weird formatting, without requiring many more calculations. |
| 01-07-2008, 09:53 PM | #13 |
After my check I haven't found anything strange. *Approved* |
| 08-12-2008, 06:18 PM | #15 |
This system rocks! It is just what I was looking for and it seems to be working flawlessly. Huge bonus that it can handle color codes and breaks! Very well done, I will definately use this system for my ORPG Dark Invasion II (uses many multiboards with virtual items etc.). |
