Up to Main Index Up to Journal for February, 2018 JOURNAL FOR WEDNESDAY 21ST FEBRUARY, 2018 ______________________________________________________________________________ SUBJECT: Sunny Sunday afternoon DATE: Wed 21 Feb 22:33:40 GMT 2018 Sunday afternoon was amazing. I spent it sat at my parents wooden dining table. Open before me was my Chromebook, and I was hacking on WolfMUD. The warm sun streaming through the window and mum providing plenty of hot, black coffee. I finished off the last of the marshalers for the current attributes. Then I documented the additional recordjar encoder methods I had written. It’s the most peaceful and productive I’ve been in ages. The marshalers still have a few issues. For example KeyedStringList does not format multiple pairs in the way I would prefer. For example: Vetoes: GET→You cannot get that! : LOOK→Your eyes hurt to look at it! Is formatted as: vetoes: GET→You cannot get that! : LOOK→Your eyes hurt to look at it! The same goes for StringList as used in actions. Instead of: OnAction: The rabbit hops around a bit. : You see the rabbit twitch its little nose, Ahh... : The rabbit makes a soft squeaking and chattering noise. It is formatted as: Onaction: The rabbit hops around a bit. : You see the rabbit twitch its little nose, Ahh... : The rabbit makes a soft squeaking and chattering noise. Also notice that the field name is ‘Onaction’ instead of ‘OnAction’. At the moment field names are lowercased, then the first letter is titled cased. This avoids having to remember whether strings should be all lowercase or cased as expected. I might have to change that now I think about it… I’ve also corrected the it’s/its usage in the definition of the rabbit and cat. Commit pending. My ultimate aim is to be able to unmarshal a .wrj file, then marshal it back to a .wrj file and have the two nearly identical. In fact I am planning a simple gofmt like tool for .wrj files which would define a standard formatting for .wrj files. It would also be useful for testing as well ;) I’ve committed the encoder and marshaler changes so that people can poke at the code. Note that none of the marshalers are actually ‘wired up’ yet. Before I wire everything up I need to sort out inventories so that their content can be recursively written out. Remember, containers can contain other containers ad infinitum. The question is, where should the logic go? For the unmarshalers the logic is kept separate in the zones package. If you look at zones package it currently does all of the messy bookkeeping. In fact the current zones package is inadequate and needs some work. It needs refactoring into a generic loader that can handle any .wrj file — zones, players, single items. For that to happen most of the bookkeeping probably needs moving to post-unmarshaler handlers. That way inventories would be able to populate themselves, exits link themselves and so on. At least I think that is what I need, but I’m still thinking it through. The marshalers are simpler. I just need some logic somewhere that can unwind inventories. This could be added to the Thing attribute itself as part of the marshaler method. Really it should be added to the Inventory attribute as a Thing shouldn’t know anything about Inventories. Although taking a quick look at the code for a Thing I’ve already messed that up with the SetOrigins method. Time for a quick detour. Looking at the SetOrigins method I can see an chunk of unwieldy code that doesn’t seem right: // Set our origin to that of the parent Inventory if l := FindLocate(t); l.Found() { if i := FindInventory(l.Where().Parent()); i.Found() { l.SetOrigin(i) } } The FindLocate function tells us which Inventory a Thing is in. We then get the parent of the Inventory only to look up the Inventory again!? No, no, no, what was I thinking? Let’s fix that while we have the source open anyway: // Set our origin to that of the parent Inventory if l := FindLocate(t); l.Found() { l.SetOrigin(l.Where()) } That’s simpler and more performant. Another change that will be on the public dev branch by the time you read this. :) -- Diddymus Up to Main Index Up to Journal for February, 2018