Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib/customs/pieces_bitmaps_manager.js
blob: c109b707ed686e47e909cfa7cf9bba30777ef789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var PiecesBitmapsManager = Class.create();
PiecesBitmapsManager.prototype = {
    // pictures_size : pictures size px
    // loadingCompleteHandler : a function without any argument and returning nothing.
    initialize: function(pictures_size, loadingCompleteHandler){
        this.picturesSize = pictures_size;
        this.piecesImages = {};
        this.loadingQueue = new createjs.LoadQueue(false);
        this.loadingQueue.on("fileload", this.handleFileLoaded, this);
        this.loadingQueue.on("complete", loadingCompleteHandler, this);
    },
    handleFileLoaded : function(file){
        var image = new createjs.Bitmap(file.item.src);
        image.scaleX = this.picturesSize/1000.0;
        image.scaleY = this.picturesSize/1000.0;
        this.piecesImages[file.item.id] = image;
    },
    loadPictures: function() {
        this.loadingQueue.loadManifest([
            {id:"wp", src:"../pictures/wp.png"},
            {id:"wn", src:"../pictures/wn.png"},
            {id:"wb", src:"../pictures/wb.png"},
            {id:"wr", src:"../pictures/wr.png"},
            {id:"wq", src:"../pictures/wq.png"},
            {id:"wk", src:"../pictures/wk.png"},
            {id:"bp", src:"../pictures/bp.png"},
            {id:"bn", src:"../pictures/bn.png"},
            {id:"bb", src:"../pictures/bb.png"},
            {id:"br", src:"../pictures/br.png"},
            {id:"bq", src:"../pictures/bq.png"},
            {id:"bk", src:"../pictures/bk.png"}
        ]);
    },
    
    // e.g wb for white bishop, bn for black knight.
    getPicture: function(id){
        return this.piecesImages[id];
    }
};