OSDN Git Service

MC に持たせる制御タグをフレーム毎に分別格納する
[flapp/flapp.git] / movieclip.js
1 (function(global) {
2     var FlappMovieClip = function(parentMovieClip) {
3         this.parentMovieClip = parentMovieClip?parentMovieCli:this;
4         this.rootMovieClip = parentMovieClip?parentMovieClip.rootMovieClip:this;
5         this.childMovieClips = {}; // name => movieClip
6         this.clearControlTags();
7         //
8         this.prevShowFramePos = 0;
9         //
10         canvas = document.createElement('canvas');
11         canvas.width = 240; // XXX
12         canvas.height = 240; // XXX
13         this.canvas = canvas;
14         this.canvasDirty = false; // dirtyFlag
15         //
16         this.displayList = {}; // depth => [tag, matrix, colorTransform]
17         //
18         this.totalframes = 0;
19         this.currentFrame = 0;
20     };
21     FlappMovieClip.prototype = {
22         clearControlTags: function(controlTag) {
23             this.controlTagsList = [[]]; //
24             this.labelMap = {}; // label => frameNum
25             this.framesLoaded = 0;
26         },
27         appendControlTag: function(controlTag) {
28             // console.debug("FlappMovieClip::appendControlTag");
29             this.controlTagsList[this.framesLoaded].push(controlTag);
30             if (controlTag.code === 1) { // ShowFrame
31                 this.controlTagsList.push([]);
32                 this.framesLoaded++;
33             } else if (controlTag.code === 43) { // FrameLabel
34                 this.labelMap[controlTag.name] = this.framesLoaded;
35             }
36         },
37         setControlTags: function(controlTags) {
38             this.clearControlTags();
39             for (var i = 0, l = controlTags.length ; i < l ; i++) {
40                 this.appendControlTag(controlTags[i]);
41             }
42         },
43         control: function(dict) {
44             console.debug("FlappMovieClip::control");
45             var tag, i, l;
46             if (this.framesLoaderd < this.totalframes) { // imcomplete
47                 if (this.currentFrame < this.framesLoaderd) {
48                     return false; // idle
49                 }
50             }
51             var controlTags = this.controlTagsList[this.currentFrame];
52             this.actionTagList = [];
53             for (i = 0, l = controlTags.length ; i < l ; i++) {
54                 tag = this.controlTags[i];
55                 switch (tag.code) {
56                 case 1: // ShowFrame
57                     break;
58                 case 12: // DoAction
59                     this.actionTagList.push(tag);
60                     break;
61                 case 26: // PlaceObject2
62                     // set display List;
63                     break;
64                 }
65             }
66             this.currentFrame = 0;
67             return true;
68         },
69         action: function() {
70             console.debug("FlappMovieClip::action");
71             var tag, i, l;
72             for (i = 0, l = this.actionTagList.length ; i < l ; i++) {
73                 tag = this.actionTagList[i];
74                 ;
75             }
76         },
77         render: function(canvas, matrix, colorTransform) {
78             console.debug("FlappMovieClip::render");
79             
80         }
81     };
82     global.FlappMovieClip = FlappMovieClip;
83 })(this);