@@ -33,6 +33,8 @@ package otlib.things
3333 import otlib.things.FrameGroupType ;
3434 import ob.core.IObjectBuilder ;
3535 import mx.core.FlexGlobals ;
36+ import otlib.utils.SpriteExtent ;
37+ import flash.utils.Dictionary ;
3638
3739 public class ThingType
3840 {
@@ -171,12 +173,10 @@ package otlib.things
171173
172174 public function addFrameGroupState (improvedAnimations :Boolean , duration :uint ):void
173175 {
174- var normal: FrameGroup = this . getFrameGroup(FrameGroupType. DEFAULT );
176+ var normal: FrameGroup = getFrameGroup(FrameGroupType. DEFAULT );
175177 if (! normal || normal. frames < 3 )
176178 return ;
177179
178- var frameId: uint ;
179-
180180 var idle: FrameGroup = normal. clone ();
181181 idle. frames = 1 ;
182182
@@ -201,25 +201,98 @@ package otlib.things
201201 walking. loopCount = 0 ;
202202 walking. startFrame = 0 ;
203203
204- for (frameId = 0 ; frameId < walking. frames; frameId++ ) {
204+ for (var frameId: uint = 0 ; frameId < walking. frames; frameId++ ) {
205205 if (improvedAnimations && normal. frameDurations[ frameId] )
206206 walking. frameDurations[ frameId] = normal. frameDurations[ frameId] . clone ();
207207 else
208208 walking. frameDurations[ frameId] = new FrameDuration(duration , duration );
209209 }
210210
211- this . setFrameGroup(FrameGroupType. DEFAULT , idle);
212- this . setFrameGroup(FrameGroupType. WALKING , walking);
211+ setFrameGroup(FrameGroupType. DEFAULT , idle);
212+ setFrameGroup(FrameGroupType. WALKING , walking);
213+ }
214+
215+ private function countSpritesInFrame (frameGroup :FrameGroup , frame :uint ):uint
216+ {
217+ var sprites: uint = 0 ;
218+ for (var z : uint = 0 ; z < frameGroup. patternZ; z ++ )
219+ {
220+ for (var y : uint = 0 ; y < frameGroup. patternY; y ++ )
221+ {
222+ for (var x : uint = 0 ; x < frameGroup. patternX; x ++ )
223+ {
224+ for (var l: uint = 0 ; l < frameGroup. layers; l++ )
225+ {
226+ for (var w: uint = 0 ; w < frameGroup. width ; w++ )
227+ {
228+ for (var h: uint = 0 ; h < frameGroup. height ; h++ )
229+ sprites++;
230+ }
231+ }
232+ }
233+ }
234+ }
235+
236+ return sprites;
213237 }
214238
215- public function removeFrameGroupState (improvedAnimations :Boolean , duration :uint ):void
239+ public function removeFrameGroupState (improvedAnimations :Boolean , duration :uint , removeMounts : Boolean ):void
216240 {
217- var idle: FrameGroup = this . getFrameGroup(FrameGroupType. DEFAULT );
218- var walking: FrameGroup = this . getFrameGroup(FrameGroupType. WALKING );
219- if (! idle || ! walking)
241+ var idle: FrameGroup = getFrameGroup(FrameGroupType. DEFAULT );
242+ var walking: FrameGroup = getFrameGroup(FrameGroupType. WALKING );
243+ if (! normal && ! walking)
220244 return ;
245+
246+ if (removeMounts)
247+ {
248+ idle. patternZ = 1
249+ walking. patternZ = 1
250+ }
251+
252+ var normal: FrameGroup = idle. clone ();
253+ normal. frames = 3 ;
254+
255+ var spriteIndex: Vector .< uint > = new Vector .< uint > ();
221256
222- //TODO
257+ var frameSpriteLength: uint = countSpritesInFrame(idle, 0 );
258+ for (var spriteId: uint = 0 ; spriteId < frameSpriteLength; spriteId++ )
259+ spriteIndex. push (idle. spriteIndex[ spriteId] )
260+
261+ for (spriteId = 0 ; spriteId < frameSpriteLength; spriteId++ )
262+ spriteIndex. push (walking. spriteIndex[ spriteId] )
263+
264+ var walkingFramesLength: uint = walking. spriteIndex. length
265+ if (walkingFramesLength > frameSpriteLength * 4 )
266+ {
267+ // Check for fourth frame in walking
268+ for (spriteId = frameSpriteLength * 4 ; spriteId < (frameSpriteLength * 4 ) + frameSpriteLength; spriteId++ )
269+ spriteIndex. push (walking. spriteIndex[ spriteId] )
270+ }
271+ else if (walkingFramesLength > frameSpriteLength)
272+ {
273+ // Check for second frame in walking
274+ for (spriteId = frameSpriteLength; spriteId < frameSpriteLength + frameSpriteLength; spriteId++ )
275+ spriteIndex. push (walking. spriteIndex[ spriteId] )
276+ }
277+ else
278+ {
279+ // Add first frame in walking
280+ for (spriteId = 0 ; spriteId < frameSpriteLength; spriteId++ )
281+ spriteIndex. push (walking. spriteIndex[ spriteId] )
282+ }
283+
284+ normal. spriteIndex = spriteIndex;
285+ normal. isAnimation = true ;
286+ normal. frameDurations = new Vector .< FrameDuration> (normal. frames, true );
287+ normal. animationMode = AnimationMode. ASYNCHRONOUS ;
288+ normal. loopCount = 0 ;
289+ normal. startFrame = 0 ;
290+
291+ for (var frameId: uint = 0 ; frameId < normal. frames; frameId++ )
292+ normal. frameDurations[ frameId] = new FrameDuration(duration , duration );
293+
294+ frameGroups = [];
295+ frameGroups[ FrameGroupType. DEFAULT ] = normal;
223296 }
224297
225298 //--------------------------------------------------------------------------
0 commit comments