Up to Main Index                          Up to Journal for December, 2020

                   JOURNAL FOR SATURDAY 19TH DECEMBER, 2020
______________________________________________________________________________

SUBJECT: Sort of sorted a sorting problem — with zone updates!
   DATE: Sat 19 Dec 22:09:23 GMT 2020

A good WolfMUD Wednesday, and a few other evenings, with a public dev update!

A while ago[1] I mentioned ordering fields in WolfMUD’s record jar files when
authoring zones. This was in an effort to make maintenance and collaboration
between authors easier. I even presented a list of what I thought the ordering
should be. In that list I accidentally left off some Attribute fields: Gender,
Inv (alias for Inventory) and Health. I also had a few comments from people
saying that the ordering was either too strict, complicated to remember or too
time consuming to implement.

Working with the zone files a lot recently I agree — I’ve actually been using
a tool I wrote called ‘wrjfmt’ to help me. From the command’s help:


  Usage: wrjfmt [-t freetext_field] [-i file] [-o file]

    -i file
          Input file to read (default stdin)
    -o file
          Output file to write (default stdout)
    -t fieldname
          The fieldname of the free text section. (default "description")

  The output file may be the same as the input file, resulting in the original
  file being overwritten.

                                  * !WARNING! *

  All comments will be stripped from the output file. In addition all string
  lists will be collapsed. For example:

    OnAction: N
            : S
            : E
            : W

  Will be re-written in the output file as:

    Onaction: N : S : E : W

  Camel cased field names, e.g OnAction, will be title cased, e.g. Onaction.

  Last of all, named free text fields, e.g. Description, will be turned into
  free text sections.

  You have been warned!


It has a few glaring faults, stripping comments for a start, but it does a
good enough job. This is how I’ve been using it mostly:


  >vimdiff zinara.wrj <(wrjfmt -i zinara.wrj)


In Vim, this will show me the original file on the left and the reformatted
file on the right. I can then make corrections and rerun the tool. You can get
similar results using diff, or any file comparison tool, to compare the files:


  >diff -y zinara.wrj <(wrjfmt -i zinara.wrj)


Or write a temporary file and compare that:


  >wrjfmt -i zinara.wrj -o temp.wrj
  >diff -y zinara.wrj temp.wrj


It’s not perfect, I did consider not releasing the tool due to the current
limitations. However, I’ve found it useful enough for spotting fields in the
wrong order or descriptions where the lines are too long. Maybe someone else
will find it useful, warts and all. Over time I’m sure I’ll improve the tool.

The wrjfmt tool simply reads a record jar and writes it out again — with a
little magic to handle command line options and stdin/stdout processing so it
works well in pipelines. You can find the source code for it in the new tools
package. The code started out at around 10 lines. After today it’s now 134
lines — I thought I’d better add some comments, command line options, help and
other features if I was going to release it.

The sorting is performed by the recordjar package Write method. The Write
method already did simple alphabetical sorting of the fields. Now you can pass
in an optional list of field names in the order you want them to appear. Field
names that are not in the list appear last in the record and are still sorted
alphabetically.

There is another new package attr/ordering which specifies a default list of
Attribute field names and their ordering. This list can easily be changed if
you don’t like my ordering, or make it an empty list to keep the current
alphabetical ordering.

The sorting is only used in two places, by the wrjfmt tool and for saving
player files.

As I mentioned, I’ve been using the wrjfmt tool to help me with updating the
current zones files. The zones files are now ready and out on the public dev
branch along with the other changes mentioned and the wrjfmt tool itself.

If you have any comments or thoughts on the zone files I’d love to hear from
you. Just drop me a quick email: diddymus@wolfmud.org

--
Diddymus

  [1] New job! & Zone file changes: ../11/25.html


  Up to Main Index                          Up to Journal for December, 2020