Recording snail history logs

I’ve decided that it’s about time to start recording event histories for snails. I keep going back to the database and checking which event ran on which snail by IDs and such and it’s getting to be a hassle. I’d rather just be able to go to the snail’s profile page and see all the important stuff that’s happened to it. Since this was always meant to be a feature anyway, I figured I may as well do it now.

I’m still not sure if I’m doing it in the dumbest way possible, but here’s how I set it up.

The tables

I added two new tables to the database:

snail_history_templates

The structure of this table is as follows:

Gastropoda - snail history templates table structure

The purpose of the table is to have a number of pre-set templates for events to follow. So far I have 4 templates defined, but eventually there will be much more.

Gastropoda - snail history templates table

You’ll see above that some of the templates use punctuation in them…these are meant to be replaced with relevant information when the log is actually pulled out for display:

snail_history_logs

So far the snail_history_logs table is structured like this:

Gastropoda - snail history logs table structure

Here is what’s been recorded in this table so far. I think I will end up adding a field for what kind of object is being referenced as the targetObjectID (after all, it should be able to be a snail, user, item, etc).

Gastropoda - snail history logs table

And here is what it looks like when you go to a snail’s profile page (I’ll have to reverse the table to show most recent events first):

Gastropoda - Lil Dude event log

How events are recorded and displayed

Events like birth or energy consumption are recorded using an object called HistoricalEvent, which extends Event. When you go to a snail’s profile page, all HistoricalEvents are loaded and their full text is generated (as you can see targetObject isn’t implemented yet):

    function GenerateFullText() {
        $snailmanager = new SnailManager();
        $snail = $snailmanager->LoadSnailInfo($this->snailID);
        if (!$snail->name) {
            $snail->name = "Unnamed";
        }
        $this->text = str_replace("@",$snail->name,$this->text);
        $this->text = str_replace("#",$this->numericalValue,$this->text);
    }

{:lang=“php”}

comments powered by Disqus