My local git sync'ing script with branch support for testing in simulation mode



  • I found it really annoying that your code is shared between simulation mode and the online mode.. it makes it really difficult to develop because you're always working on live code. There's times where I want to test code in simulation before pushing it to my real colonies. I was thinking about making a separate account for testing but didn't feel like juggling logins. So I wrote a new sync script that will let you develop in simulation mode, then push to live when you're ready.

    https://gist.github.com/laverdet/e761440e0918ab1cf21e

    Drop that in your local git directory and run it with ./sync 'username:password'

    What it does is prefixes all your files with either "master/" or "sim/" and then it creates stubs for every file to include the right one depending on the game type. If your current git branch is "master" it'll run on the live world, and if you're in any other branch that code runs only in simulation mode. I'm finding it tough to explain exactly what it's doing but if you play with it you'll see how it works. Please make sure your code is backed up locally before running the script 🙂



  • Uh... its a great idea, but there is a problem with code being run on simulator while having world mode activated (they can end up being run at the same time).

    The easiest way to fix that is to have code to adapt the game mode. So we can let the coder to that, or build a wrapper script that has both a dev and live code version (if only one exists, it will be used to both). But it's way too easy to loose grip on the complexity here, so the script design must be somewhat taken care about (preferably to the needs of the user).



  • That's exactly what the script does-- it uploads a dev version and a live version for every file. It replaces your main.js with this:

    "use strict";
    Game.sim = !!Game.rooms.sim;
    if (Game.sim) {
      require('sim/main');
    } else {
      require('master/main');
    }
    

    Then replaces all your modules with, for instance:
    courier.js:

    module.exports = Game.sim ? require('sim/courier') : require('master/courier');
    


  • Yeah, I see 🙂

    (so great, I can't even say the word frictionless at the same time)