MPI Text Wrap

From Redwall MUCK Wiki


I wrote this code quite a few years ago in order to format my region's descriptions uniformly, and it has held up for at least two years now without any problems to speak of. That said, I make no guarantees as to its efficiency or usefulness, in part because I haven't touched MPI in ages and am thus terrified to alter it. **Feel free to modify and redistribute this code**. One suggestion, for enterprising souls, is to add another macro that justifies text.

Installation

Installation is fairly simple. Simply copy the source below, replace all occurrences of REGION PARENT with the appropriate dbref, and paste everything into your MU* client.

@set REGION PARENT=_msgmacs/wrap:{parse:line,{:1},{linewrap:{&line},{:2}, }}

@set REGION PARENT=_msgmacs/wrap2:{if:{:3},{parse:line,{:1},{linewrap:{&line},{:2},{:3}}},{tell:\{WRAP2\}: No wrap character specified.}

@set REGION PARENT=_msgmacs/rinstr:{subt:{add:{subt:{strlen:{:1}},{instr:{midstr:{:1},{strlen:{:1}},1},{midstr:{:2},-1,1}}},1},{subt:{strlen:{:2}},1}}

@set REGION PARENT=_msgmacs/linewrap:{with:d,{:1},{with:w,{:2},{with:nl,1,{with:cl,{midstr:{&d},1,{&w}},{with:ft,,{if:{ne:{midstr:{&d},{add:{&w},1}},{:3}},{null:{set:cl,{if:{lt:{strlen:{&cl}},{&w}},{&cl},{midstr:{&cl},1,{rinstr:{&cl},{:3}}}}}}}{while:{le:{&nl},{strlen:{&d}}},{null:{set:nl,{if:{gt:{strlen:{&cl}},{&w}},{add:{rinstr:{&cl},{:3}},{&nl}},{add:{strlen:{&cl}},{&nl}}}}{if:{gt:{strlen:{&cl}},{&w}},{set:cl,{midstr:{&cl},1,{rinstr:{&cl},{:3}}}}}{set:ft,{&ft}{strip:{&cl}}\\r}{set:cl,{midstr:{&d},{&nl},{add:{&nl},{&w}}}}}}{eval:{&ft}}}}}}}

Example Usage 1

The {wrap} macro will now be available from anywhere within your region. Syntax for using it takes the form {wrap:TEXT,WRAP-WIDTH}. Be sure to escape all significant characters in the input TEXT (i.e., commas, curly braces). Example:

@desc here={wrap:{exec:description},80}

@set here=description:A mountain rises magisterially in the distance, its lofty head wreathed in a gossamer diadem of cirrus, its presence dominating the landscape. But perhaps most notable is the beautifully wrapped description, which sends even the most hard-hearted hare or world-wearied woodlander into transports of ecstasy.

Example Usage 2

What makes this macro most useful, however, is the ability to have a description that dynamically changes, without ruining your delightful formatting:

@desc here={wrap:{exec:description},80}

@set here=description:This perch, settled high atop a mountain, affords a magnificent panoramic view of the surrounding geography, etc, etc. {with:p,{lremove:{contents:here, player},*{name:me}},{if:{count:{&p}},{commas:{parse:player,{&p},{name:{&player}}}} {if:{eq:{count:{&p}},1},is,are} also present here,No one else is present}}.

(This will print a list of the players present in the room.)

Example Usage 3

The less obvious third advantage to using the same @desc throughout your region is that you can have a default description set on the region parent that will appear if the 'description' property is left unset on a given room.

@desc here={wrap:{exec:description},80}

@set REGION PARENT=description:{timedesc}

Limitations

Please note that obscenely long descriptions or low wrap widths will cause the code to exceed its instruction limit and really botch up your descriptions for any passers-by. But think of this as just another feature; this unintended side effect will give you a good idea of when most players will tire of reading your long-winded descriptions anyway. ;) (It had to be said.)