Tag Archives: automation

Several weeks ago I was involved as software architect to optimize design/configuration/development process of our new social game. So, the configuration of the game is pretty huge JSON file. It contains several collections of entities types available in the game with all their parameters and relations. That JSON config then used on both the client and server side. The game designer prepare the data in the set of spreadsheets. It’s very handy. So, it needs to move the actual data from the spreadsheets to the config file. The best they to do it (to avoid copy-paste by hand) is to provide some automation like CI. Let’s call it Continuous Configuration.

Last year I provided solution for similar problem as transistor tool. I implemented it in python (last year the python was my “default language”). It loads data from CSV sources, process and included as static data right into the sources by appropriate templates. Better approach is to use loadable config file. We can provide changes without re-build. It doesn’t need to create the templates for any language we need to support.

I created Transistor 2.0 tool in CoffeeScript as nodejs application. The code looks like ruby/scala/erlang. Try CoffeeScript and you never back to ugly JavaScript (maybe).

Transistor 2.0 is a command line tool that needs just 2 things described in separate JSON config (one more to rule all of them): description of sources (CSV) and the structure of output JSON. There are 2 roles in this process: a game designer who prepare the data in spreadsheets and the game developer who needs that data as JSON config. Both of them are unchained of spending their time for producing typos during senseless copy-pasting.


The best developer is the professional who try to automate as many tasks as possible. Yesterday I was involved into such automation process. There was the sheet of play cards and I needed to split it into the single card images and import into .fla flash as resource for flash game project. So, I implement Automation even twice.

First task

Spilt sheet into several images. For this first task I used Python and PIL:

# -*- coding: utf-8 -*-

import PIL
from PIL import Image
im_source =“classic-playing-cards.png”)
width = 71
height = 96
ys = (‘c’, ‘h’, ‘s’, ‘d’)
xs = (‘a’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘t’, ‘j’, ‘q’, ‘k’)
for x in xrange(0, 13):
    for y in xrange(0 ,4):
        file_name = “%s%s.png” % (xs[x], ys[y])
        im_c = im_source.copy()
        left = x * (width+2) + 1
        top = y * (height+2) + 1
        im_c = im_source.crop((left+1, top+1, left + width+1, top + height+1))
        print file_name

52 cards. So, this script applying is much faster and safer way than photoshop.

Second task

I imported 52 cards to Flash IDE. And now it needs to generate 52 sprites (one per each card). I used JSFL (JavaScript for Flash) for that:

var doc = fl.getDocumentDOM();
var lib = doc.library;

var items = lib.getSelectedItems();

var prefix = “”;
var ys = [‘a’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘t’, ‘j’, ‘q’, ‘k’];
var xs = [‘c’, ‘d’, ‘h’, ‘s’];

for (var i in items)
     var bitmap = items[i];
     var sX =, 16);
     var sY =, 15);
     var suffix = ys.indexOf(sY) * 4 + xs.indexOf(sX);
     if (suffix < 10)
          suffix = ‘0’ + suffix;
     var card_name = prefix + suffix;

           lib.addNewItem(“movieclip”, card_name);
     var index = lib.findItemIndex(card_name);
     var item = lib.items[index];
     item.linkageExportForAS = true;
     item.linkageExportInFirstFrame = true;
     item.linkageBaseClass = “flash.display.Sprite”;
     item.linkageClassName = card_name;

     lib.addItemToDocument({x:0, y:0}, “cards/bitmaps/” + sY + sX + “.png”);

           lib.moveToFolder(“cards/deck”, card_name);

The most useful automation scenario is using FAR manager macros system. Press Ctr-. to start macro recording. And after apply some set of regular actions that should be repeated press Ctr-. to stop recording and set hot key for the macro. Usually I practice it in internal FAR text editor but it’s ok to use it for any FAR actions.