| 1 | package IO::SWF::Tag::Sprite; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use base 'IO::SWF::Tag::Base'; | ||
| 7 | |||
| 8 | use IO::SWF::Bit; | ||
| 9 | use IO::SWF::Tag; | ||
| 10 | |||
| 11 | __PACKAGE__->mk_accessors( qw( | ||
| 12 | _spriteId | ||
| 13 | _frameCount | ||
| 14 | _controlTags | ||
| 15 | )); | ||
| 16 | |||
| 17 | sub parseContent { | ||
| 18 | my ($self, $tagCode, $content, $opts_href) = @_; | ||
| 19 | my $reader = IO::SWF::Bit->new(); | ||
| 20 | $reader->input($content); | ||
| 21 | |||
| 22 | $self->_spriteId($reader->getUI16LE()); | ||
| 23 | $self->_frameCount($reader->getUI16LE()); | ||
| 24 | |||
| 25 | my @controlTags = (); | ||
| 26 | # SWF Tags | ||
| 27 | while (1) { | ||
| 28 | my $tag = IO::SWF::Tag->new($self->swfInfo); | ||
| 29 | $tag->parse($reader); | ||
| 30 | push @controlTags, $tag; | ||
| 31 | if ($tag->code == 0) { # END Tag | ||
| 32 | last; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | $self->_controlTags(\@controlTags); | ||
| 36 | return 1; | ||
| 37 | } | ||
| 38 | |||
| 39 | sub dumpContent { | ||
| 40 | my ($self, $tagCode, $opts_href) = @_; | ||
| 41 | print "\tSprite: SpriteID={" . $self->_spriteId . "} FrameCount={" . $self->_frameCount . "}\n"; | ||
| 42 | foreach my $tag (@{$self->_controlTags}) { | ||
| 43 | print " "; | ||
| 44 | $tag->dump($opts_href); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | sub buildContent { | ||
| 49 | my ($self, $tagCode, $opts_href) = @_; | ||
| 50 | my $writer = IO::SWF::Bit->new(); | ||
| 51 | $writer->putUI16LE($self->_spriteId); | ||
| 52 | $writer->putUI16LE($self->_frameCount); | ||
| 53 | foreach my $tag (@{$self->_controlTags}) { | ||
| 54 | my $tagData = $tag->build(); | ||
| 55 | if ($tagData) { | ||
| 56 | $writer->putData($tag->build()); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | return $writer->output(); | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; |