Archive

Tag Archives: FAR

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:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import PIL
from PIL import Image
im_source = Image.open(“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))
        im_c.save(file_name)
        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 = “com.kikudjiro.minigames.blackjack.cards.C”;
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 = bitmap.name.substring(15, 16);
     var sY = bitmap.name.substring(14, 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.editItem(card_name);
     lib.addItemToDocument({x:0, y:0}, “cards/bitmaps/” + sY + sX + “.png”);

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

P.S.
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.
Advertisements