Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411413 Posts in 69360 Topics- by 58415 Members - Latest Member: sophi_26

April 16, 2024, 05:10:28 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityDevLogsSnailLife (prev. Gastropoda). Browser based snail simulation.
Pages: 1 2 [3]
Print
Author Topic: SnailLife (prev. Gastropoda). Browser based snail simulation.  (Read 6865 times)
Liza
Level 1
*



View Profile WWW
« Reply #40 on: June 29, 2015, 10:17:14 AM »

I was going to try to remember all the things I’ve done in the last month on snails, but this seems impossible. So here’s a lazy list of git commits within this time:

Code:
* 5 seconds ago, User messaging and cause of death [deploy:development]
* 4 days ago, Some race view fixes, test out increasing AMR for wild snails since too little energy is being burnt during races. [deploy:development]
* 4 days ago, Cancel races that have been unfinished for 24 hours, freeing up others to rent the race jar. [deploy:development]
* 5 days ago, Remove old unneeded Minion and Latchet stuff [deploy:development]
* 5 days ago, Remove unneeded logs, remove old breeding stuff that is no longer required with the brain [deploy:development]
* 5 days ago, Fixes and cleanup, new racing jar in seeder [deploy:development]
* 5 days ago, Remove start countdown from finished races, fix race result view [deploy:development]
* 5 days ago, Fix race finish [deploy:development]
* 5 days ago, Bug fixing in racing and memory saving [deploy:development]
* 6 days ago, Admin option to return foreign snails to owners, get parent jar [deploy:development]
* 6 days ago, Racing refactoring; stop destroying jars since we'll reuse them [deploy:development]
* 7 days ago, More flexibility for historical event logging; correctly represent snails trying to mate with items [deploy:development[
* 8 days ago, Substrate item creation fix [deploy:development]
* 8 days ago, Gather snails to middle of jar, more exact movement, seed race jars for Mr Casinir [deploy:development]
* 2 weeks ago, Ability to humanely euthanise eggs in jar [deploy:development]
* 2 weeks ago, Some safeguards for user entering snail in race before it was returned from previous race [deploy:development]
* 2 weeks ago, Replace finished and started columns with finishDate, startDate. Auto refresh jar page when race has started. [deploy:development]
* 3 weeks ago, Fix move check for jar view [deploy:development]
* 3 weeks ago, use View [deploy:development]
* 3 weeks ago, Fix swallowing, isolate mood update [deploy:development]
* 3 weeks ago, Resident register [deploy:development]
* 3 weeks ago, Draw gravestone under snail pattern [deploy:development]
* 3 weeks ago, Add rainbow bridge page [deploy:development]
* 3 weeks ago, Display estimated race start time [deploy:development]
* 3 weeks ago, Fix fertility spray [deploy:development]
* 3 weeks ago, Fix bank link [deploy:development]
* 3 weeks ago, Only list items user owns in closet [deploy:development]
* 3 weeks ago, Fix for jar installation [deploy:development]
* 3 weeks ago, Add bank hint to tutorial [deploy:development]
* 3 weeks ago, Switch to Single log mode [deploy:development]
* 4 weeks ago, CustomValidator [deploy:development]
* 4 weeks ago, Stop comparing an item to itself... [deploy:development]
* 4 weeks ago, User shouldn't be able to mix a substrate item with itself [deploy:development]
* 4 weeks ago, Toggle disabling item action form elements on action select [deploy:development]
* 4 weeks ago, Some item stuff [deploy:development]

I also decided to try live streaming Gastropoda development. I’ve only done a couple of sessions so far but it does help to keep me focused. Surprisingly enough a few people actually watch and ask questions. I didn’t really think anyone would be that interested in watching someone code some weirdo snail app. It’s nice because a lot of the “Have you thought about doing this” or “What about this” suggestions people have made are things I have thought of and/or already have implemented!
Logged

Nicholas Lives
Level 1
*


Catch of the Day


View Profile WWW
« Reply #41 on: July 11, 2015, 02:58:34 PM »

Hey cool to hear you're live-streaming now! Sorry about being behind on sending more textures by the way, things have been really heating up lately with development on Deeper. Hoping I can get some time this weekend to do some stuff. Any chance you could post a link to your live streams/channel though? I'd love to stop by on em one of these days!
Logged
Liza
Level 1
*



View Profile WWW
« Reply #42 on: July 29, 2015, 05:04:42 AM »

Hey cool to hear you're live-streaming now! Sorry about being behind on sending more textures by the way, things have been really heating up lately with development on Deeper. Hoping I can get some time this weekend to do some stuff. Any chance you could post a link to your live streams/channel though? I'd love to stop by on em one of these days!

Hey! Sorry about the late reply - I tend to post these entries and then forget about checking them Tongue You can see the stream link here:
https://www.livecoding.tv/lazer/

Though I don't get a chance to stream much - you can see the past videos there though. Someone asked who did the art in one of the videos (can't remember which ones) and I showed them your profile. They thought it looked cool!
Logged

Liza
Level 1
*



View Profile WWW
« Reply #43 on: July 29, 2015, 05:06:58 AM »

"What's SnailLife", you say? Well I'm glad you asked! My snail simulation has gone through a couple of names...and even though I was never 100% happy with Gastropoda it was the best I could come up with - a name that was unique and didn't allow the project to sound too "gamey" (because it's not a game). All of the cooler names I could come up with weren't suitable for various reasons (like domain name availability and such).

But recently I found out about the .life TLD! And I decided that nowadays we have such a varied domain name landscape that .com isn't as important as it used to be, and definitely not for an obscure hobby project. So Gastropoda is now SnailLife!
On to the messaging:

Messaging/Notifications

I noticed when working on the simulation that it was tough to figure out who died and why when snails disappeared from a jar.

(Sidenote...I just realized...in real life a snail wouldn't just disappear from a jar if it died. It would sit there and start decomposing until someone put it away. Maybe this should be the case with SnailLife, too).

Anyway, I wanted something to notify me immediately when something important happens, like a snail is born or dies. So I made a rudimentary messaging system to receive notifications from the simulation, which should be able to be pretty easily expanded into a user-to-user messaging system.

First I made a user_messages table with the following columns:
  • messageID
  • recipientID
  • senderID
  • subject
  • content
  • isRead
  • created_at
  • updated_at
Then I made a UserMessage model that looks like this for now:

 
Code: (auto:0)
<?php namespace App;


use 
Illuminate\Database\Eloquent\Model;


class 
UserMessage extends Model {


    public static 
$rules = array(
        
'recipientID'     => 'integer',
        
'senderID'   => 'integer',
        
'subject'    => 'alpha_num_spaces',
        
'content'    => 'alpha_num_spaces',
        
'isRead'     => 'boolean'
    
);


    protected 
$primaryKey 'messageID';


    protected 
$fillable = ['recipientID''senderID''subject''content''isRead''created_at''updated_at'];


    public function 
recipient() {
        
$this->hasOne('App\User''userID''recipientID');
    }


    public function 
sender() {
        
$this->hasOne('App\User''userID''senderID');
    }


    public function 
getSenderUserNameAttribute() {
        
$username 'SnailLife';
        if (isset(
$this->sender)) {
            
$username $this->sender->username;
        }
        return 
$username;
    }


    public function 
updateMessage($propertiesToUpdate) {
        
$this->update($propertiesToUpdate);
        return 
true;
    }
}



When a snail is killed or born we create a new message for the user. For example:

 
Code: (auto:0)
if ($this->isEgg) {
    $notification = [
        'recipientID' => $this->ownerID,
        'subject'     => 'An egg has died!',
        'content'     => 'Egg ID ' . $this->snailID . ' has died. Cause of death: ' . $cod
    ];
}
else {
    $notification = [
        'recipientID' => $this->ownerID,
        'subject'     => 'A snail (' . $this->snailID . ') has died!',
        'content'     => 'SnailID ID ' . $this->snailID . ' has died. Cause of death: ' . $cod
    ];
}
$notification = new UserMessage($notification);
$notification->save();


(An egg is really just an instance of a snail, just one without a birthDate, so when an egg or snail dies it's handled in the same model).

Then there's the view. When logged in the user gets a notification of unread messages in the header:

 
Code: (auto:0)
<p>
    @if (count(Auth::user()->unreadMessages) > 0)
        <a href="/account/messages"><img src="{!! URL::asset('assets/img/graphics/icons/envelope.png') !!}" alt="You have unread messages"></a> - You've got mail!
    @endif
</p>


Oh, we get unread messages in the User model using an Eloquent hasMany relationship:
 
Code: (auto:0)
public function unreadMessages() {
    return $this->hasMany('App\UserMessage', 'recipientID', 'userID')->where('isRead', '=', 0);
}

Once they click through they get taken to their message page (ignore the double-death messages. That's being fixed right now...):



Pretty simple and gets the job done for now.
Logged

Liza
Level 1
*



View Profile WWW
« Reply #44 on: September 18, 2015, 10:17:53 PM »

SnailLife snail stables have always lived in the ether - in some virtual universe with no physical location. Since I'm trying to make SnailLife based in reality, users' snail stables should also be based in real locations. This is why now, upon registration, the user's physical location is used as the location of their snail stable.

Having never used HTML5 geolocation features before, I kind of winged it and hacked together something that works for now. Currently I get the user's location in two cases - on registration, and when searching for wild snails.

Here is how it happens on the registration page:

Code:
<script>
    getLocation();
    function getLocation() {
        console.log('getLocation here');
        if (Modernizr.geolocation) {
            console.log('geolocation in');
            navigator.geolocation.getCurrentPosition(createHiddenInput, geolocationError);
        }
        else {
            console.log('no native support');
        }
    }

    function createHiddenInput(position) {
        var latitude = position.coords.latitude;
        var longitude = position.coords.longitude;
        console.log('latitude: ' + latitude);
        console.log('longitude: ' + longitude);

        jQuery(document).ready(function() {
            $('#registrationForm').append('<input type="hidden" name="stableLatitude" value=' + latitude + '/>');
            $('#registrationForm').append('<input type="hidden" name="stableLongitude" value=' + longitude +'/>');
            $('#registrationForm').append('Stable Location: ' + getCityName(latitude, longitude) + ',' + getCountryName(latitude, longitude));

        });
    }
</script>

Problem - retrieving the location takes a few seconds. If the user happens to register too quickly their location will not be retrieved. As a potential solution I am considering disabling the Submit button until the location is ready...however, what if they don't want to allow me to retrieve their location at all?

If the user does not let me retrieve their location, it will be set by default to some place in Louisiana. Maybe then I can just display a "Don't want to be in Louisiana? Wait while we get your location!" message...

So the latitude and longitude is stored for the user's new account. Then to get the country and city name when displaying where the user is we use the Geonames API. Example:

Code:
public static function GetCityName($latitude, $longitude) {
    $cityName = null;
    if (Utility::InternetOn()) {
        $url = "http://api.geonames.org/findNearbyPlaceName?lat=" . $latitude . "&lng=" . $longitude . "&username=myusername";
        Log::info ('connection');
        $xmlDoc = new \DOMDocument();
        $xmlDoc->load($url);
        $cityNameNode = $xmlDoc->getElementsByTagName("name");
        $cityName = null;
        if ($cityNameNode->length > 0) {
            $cityName = $cityNameNode->item(0)->nodeValue;
        }
    }

    return $cityName;
}

Right now in my snail stable it is 15.5 degrees Celsius. I don't think I'm going to simulate building insulation, so without temperature control it would be about the same temperature in each jar (I may take humidity from the jar's substrate into account, and have other items adding warmth or cold aside from temperature control gadgets). The user won't see their exact jar temperature until they install a thermometer in the jar, and they won't be able to regulate the temperature without installing a temperature controller.

Snail jars have had temperature for a long time, but now that temperature is influenced by real life weather at the stable's location. This will in turn influence the snails within the jar: their health, mood, etc (this last part is not yet implemented...well, it is only implemented very very roughly).

To get temperature I originally tried OpenWeatherMap but that seems very slow and unreliable. So I am trying out The Dark Sky API:

Code:
public static function GetCurrentTemperature($latitude, $longitude) {
    $url = "https://api.forecast.io/forecast/MYAPIKEY/" . $latitude . "," . $longitude;

    $JSON = file_get_contents($url);
    $data = json_decode($JSON);

    $f = $data->currently->temperature;
    $c = Utility::FahrenheitToCelsius($f);

    return $c;
}

The Dark Sky gives me 1000 free API calls per day. I blew through that in under an hour because I was stupid and calling the API each time I needed to get the temperature. Which is a lot...passive events alone blow through about 200 calls in 5 minutes.

So I added a currentTemp field in the User table and a temp_updated_at field. I added a recurring event to update the temperature once per hour.

Different snails will adapt to live better in certain climates, and you will find different kinds of snails in different places. This way if you happen to physically be traveling the world you could hunt for wild snails away from your stable and find totally different patterns, colors, and traits.

Aside from affecting snail health and such in the future, temperature in a jar already affects how quickly consumable items rot. Things rot faster at a higher temperature.

Up next I want to think of a good way to vary snail types based on coordinates. There will be some manually set snail types that are available only in certain areas of the world if I want to make some super cool rare location (eg - get a special snail if you're at the NASA headquarters!), but for the most part I want to create that variation automatically. I just have to think of a good way to approach this. I might even embed a Google Map on the wild-snail-collection page so that instead of just clicking "Look under a rock" or whatever you can click on a spot in your general vicinity on a map and see what snail pops up there!
Logged

Liza
Level 1
*



View Profile WWW
« Reply #45 on: September 24, 2015, 10:17:11 PM »

Did you know that there is an entirely separate formula to calculate the distance between two points on the surface of a sphere? I mean…it kind of makes sense when you think about it. The shortest distance between two points without accounting for the curvature of the sphere would go right through the sphere itself, making it pretty useless when calculating physical distance on, for example, the surface of the Earth.

I’ve been working on creating some variation in the attributes of wild snails you might catch in different parts of the world. It’s not perfect, but the snails you find in Mobile, Alabama now look generally different from the snails you might find in Stockholm, Sweden.
So far the general rules are thus:
  • The snail shells get less red and more blue in them as you travel away from the equator[/*]
  • Snail shells get more green in them as you travel East[/*]
  • Snail pattern colors are the opposite of the above[/*]
  • Snail eye colors are always randomized[/*]
  • Snail pattern shapes and sizes also remin random for now, but will definitely change with the region at some later stage[/*]
I have added an idealTemp column to the snail table. The ideal temperature of snails you find in the wild in various regions tends to change (warmer toward equator and colder toward the poles). This means you will need to be quite careful when trading with others or buying other people’s snails (or even sending your snail overseas for a race on a foreign track). You’d need to closely control temperature and evaluate how your snail might perform on a track where it is currently 40C when it is used to a temperature of 20C. Temperature conditioning will need to be a thing.

Admittedly with these rules the snails you tend to find end up being a little more boring. Instead of a totally random mishmash of colors you end up with something more constrained. But I think this is ok. Wild snails are not meant to be beautiful or exciting - users are supposed to breed for those traits. If you regularly find unique, amazing snails in the wild there won’t be as much incentive or excitement in learning about your snail’s genetic traits and breeding for a desired result.

As I mentioned before, it takes a couple of seconds for HTML5 geolocation to get your coordinates (and then a few more seconds to get city/country name via the Geoname API). If you for some reason click to search for a wild snail before your location is loaded the coordinates of the search default to the coordinates of your stable.

In addition users will eventually be able to release their snails into the wild. At first it will just mean that someone else can find them. Down the line maybe the wild snails will be able to breed amongst themselves and change the attributes of wild snails in that region.
I have taken some screenshots of wild snails you may find in different places. Here they are:

Mobile, Alabama, US



Setauket, New York, US


San Francisco, California, US


Perth, Western Australia


Stockholm, Sweden


Kyoto, Japan


The North Pole
Logged

Pages: 1 2 [3]
Print
Jump to:  

Theme orange-lt created by panic