mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 14:11:19 +07:00
simple refactor base swf types
This commit is contained in:
@@ -80,7 +80,7 @@ namespace FlashTools.Internal {
|
||||
for ( var i = 0; i < shape_def.Bitmaps.Length; ++i ) {
|
||||
var bitmap_id = shape_def.Bitmaps[i];
|
||||
var bitmap_matrix = i < shape_def.Matrices.Length
|
||||
? shape_def.Matrices[i] : SwfMatrix.Identity;
|
||||
? shape_def.Matrices[i] : SwfMatrix.identity;
|
||||
var bitmap_def = ctx.Library.FindDefine<SwfLibraryBitmapDefine>(bitmap_id);
|
||||
if ( bitmap_def != null ) {
|
||||
frame.Insts.Add(new SwfAnimationInstData{
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace FlashTools.Internal.SwfTools {
|
||||
}
|
||||
|
||||
public class SwfLibrarySpriteDefine : SwfLibraryDefine {
|
||||
public SwfControlTags ControlTags = new SwfControlTags();
|
||||
public SwfControlTags ControlTags = SwfControlTags.identity;
|
||||
public override SwfLibraryDefineType Type {
|
||||
get { return SwfLibraryDefineType.Sprite; }
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ namespace FlashTools.Internal.SwfTools {
|
||||
if ( new_inst != null ) {
|
||||
new_inst.Id = tag.CharacterId;
|
||||
new_inst.Depth = tag.Depth;
|
||||
new_inst.Matrix = tag.HasMatrix ? tag.Matrix : SwfMatrix.Identity;
|
||||
new_inst.ColorTransform = tag.HasColorTransform ? tag.ColorTransform : SwfColorTransform.Identity;
|
||||
new_inst.Matrix = tag.HasMatrix ? tag.Matrix : SwfMatrix.identity;
|
||||
new_inst.ColorTransform = tag.HasColorTransform ? tag.ColorTransform : SwfColorTransform.identity;
|
||||
dl.Insts.Add(new_inst.Depth, new_inst);
|
||||
}
|
||||
} else if ( tag.Move && !tag.HasCharacter ) { // move character
|
||||
|
||||
@@ -32,15 +32,15 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
|
||||
public static DefineSceneAndFrameLabelDataTag Create(SwfStreamReader reader) {
|
||||
var tag = new DefineSceneAndFrameLabelDataTag();
|
||||
var scenes = reader.ReadEncodedU32();
|
||||
for ( var i = 0; i < scenes; ++i ) {
|
||||
tag.Scenes.Capacity = (int)reader.ReadEncodedU32();
|
||||
for ( var i = 0; i < tag.Scenes.Capacity; ++i ) {
|
||||
tag.Scenes.Add(new SceneOffsetData{
|
||||
Offset = reader.ReadEncodedU32(),
|
||||
Name = reader.ReadString()
|
||||
});
|
||||
}
|
||||
var frames = reader.ReadEncodedU32();
|
||||
for ( var i = 0; i < frames; ++i ) {
|
||||
tag.Frames.Capacity = (int)reader.ReadEncodedU32();
|
||||
for ( var i = 0; i < tag.Frames.Capacity; ++i ) {
|
||||
tag.Frames.Add(new FrameLabelData{
|
||||
Number = reader.ReadEncodedU32(),
|
||||
Label = reader.ReadString()
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
public ushort ShapeId;
|
||||
public SwfRect ShapeBounds;
|
||||
public SwfRect EdgeBounds;
|
||||
public byte Flags;
|
||||
public SwfShapesWithStyle Shapes;
|
||||
|
||||
public override SwfTagType TagType {
|
||||
@@ -18,8 +19,8 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
public override string ToString() {
|
||||
return string.Format(
|
||||
"DefineShape4Tag. " +
|
||||
"ShapeId: {0}, ShapeBounds: {1}, EdgeBounds: {2}, Shapes: {3}",
|
||||
ShapeId, ShapeBounds, EdgeBounds, Shapes);
|
||||
"ShapeId: {0}, ShapeBounds: {1}, EdgeBounds: {2}, Flags: {3}, Shapes: {4}",
|
||||
ShapeId, ShapeBounds, EdgeBounds, Flags, Shapes);
|
||||
}
|
||||
|
||||
public static DefineShape4Tag Create(SwfStreamReader reader) {
|
||||
@@ -27,7 +28,7 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
tag.ShapeId = reader.ReadUInt16();
|
||||
tag.ShapeBounds = SwfRect.Read(reader);
|
||||
tag.EdgeBounds = SwfRect.Read(reader);
|
||||
reader.ReadByte(); // Flags
|
||||
tag.Flags = reader.ReadByte();
|
||||
tag.Shapes = SwfShapesWithStyle.Read(reader, SwfShapesWithStyle.ShapeStyleType.Shape4);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,9 @@
|
||||
}
|
||||
|
||||
public static FrameLabelTag Create(SwfStreamReader reader) {
|
||||
var tag = new FrameLabelTag();
|
||||
tag.Name = reader.ReadString();
|
||||
if ( !reader.IsEOF ) {
|
||||
tag.AnchorFlag = reader.ReadByte();
|
||||
}
|
||||
var tag = new FrameLabelTag();
|
||||
tag.Name = reader.ReadString();
|
||||
tag.AnchorFlag = reader.IsEOF ? (byte)0 : reader.ReadByte();
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
sb.AppendFormat(", ClipDepth: {0}", ClipDepth);
|
||||
}
|
||||
if ( HasClipActions ) {
|
||||
sb.AppendFormat(", ClipActions: {0}", HasClipActions);
|
||||
sb.AppendFormat(", ClipActions: {0}", ClipActions);
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -67,27 +67,35 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
tag.HasCharacter = reader.ReadBit();
|
||||
tag.Move = reader.ReadBit();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
if ( tag.HasCharacter ) {
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasMatrix ) {
|
||||
tag.Matrix = SwfMatrix.Read(reader);
|
||||
}
|
||||
if ( tag.HasColorTransform ) {
|
||||
tag.ColorTransform = SwfColorTransform.Read(reader, true);
|
||||
}
|
||||
if ( tag.HasRatio ) {
|
||||
tag.Ratio = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasName ) {
|
||||
tag.Name = reader.ReadString();
|
||||
}
|
||||
if ( tag.HasClipDepth ) {
|
||||
tag.ClipDepth = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasClipActions ) {
|
||||
tag.ClipActions = SwfClipActions.Read(reader);
|
||||
}
|
||||
|
||||
tag.CharacterId = tag.HasCharacter
|
||||
? reader.ReadUInt16()
|
||||
: (ushort)0;
|
||||
|
||||
tag.Matrix = tag.HasMatrix
|
||||
? SwfMatrix.Read(reader)
|
||||
: SwfMatrix.identity;
|
||||
|
||||
tag.ColorTransform = tag.HasColorTransform
|
||||
? SwfColorTransform.Read(reader, true)
|
||||
: SwfColorTransform.identity;
|
||||
|
||||
tag.Ratio = tag.HasRatio
|
||||
? reader.ReadUInt16()
|
||||
: (ushort)0;
|
||||
|
||||
tag.Name = tag.HasName
|
||||
? reader.ReadString()
|
||||
: string.Empty;
|
||||
|
||||
tag.ClipDepth = tag.HasClipDepth
|
||||
? reader.ReadUInt16()
|
||||
: (ushort)0;
|
||||
|
||||
tag.ClipActions = tag.HasClipActions
|
||||
? SwfClipActions.Read(reader)
|
||||
: SwfClipActions.identity;
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,43 +88,59 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
tag.HasBlendMode = reader.ReadBit();
|
||||
tag.HasFilterList = reader.ReadBit();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
if ( tag.HasCharacter || (tag.HasImage && tag.HasCharacter) ) {
|
||||
tag.ClassName = reader.ReadString();
|
||||
}
|
||||
if ( tag.HasCharacter ) {
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasMatrix ) {
|
||||
tag.Matrix = SwfMatrix.Read(reader);
|
||||
}
|
||||
if ( tag.HasColorTransform ) {
|
||||
tag.ColorTransform = SwfColorTransform.Read(reader, true);
|
||||
}
|
||||
if ( tag.HasRatio ) {
|
||||
tag.Ratio = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasName ) {
|
||||
tag.Name = reader.ReadString();
|
||||
}
|
||||
if ( tag.HasClipDepth ) {
|
||||
tag.ClipDepth = reader.ReadUInt16();
|
||||
}
|
||||
if ( tag.HasFilterList ) {
|
||||
tag.SurfaceFilters = SwfSurfaceFilters.Read(reader);
|
||||
}
|
||||
if ( tag.HasBlendMode ) {
|
||||
tag.BlendMode = SwfBlendMode.Read(reader);
|
||||
}
|
||||
if ( tag.HasCacheAsBitmap ) {
|
||||
tag.BitmapCache = reader.ReadByte();
|
||||
}
|
||||
if ( tag.HasVisible ) {
|
||||
tag.Visible = reader.ReadByte();
|
||||
tag.BackgroundColor = SwfColor.Read(reader, true);
|
||||
}
|
||||
if ( tag.HasClipActions ) {
|
||||
tag.ClipActions = SwfClipActions.Read(reader);
|
||||
}
|
||||
|
||||
tag.ClassName = (tag.HasCharacter || (tag.HasImage && tag.HasCharacter))
|
||||
? reader.ReadString()
|
||||
: string.Empty;
|
||||
|
||||
tag.CharacterId = tag.HasCharacter
|
||||
? reader.ReadUInt16()
|
||||
: (ushort)0;
|
||||
|
||||
tag.Matrix = tag.HasMatrix
|
||||
? SwfMatrix.Read(reader)
|
||||
: SwfMatrix.identity;
|
||||
|
||||
tag.ColorTransform = tag.HasColorTransform
|
||||
? SwfColorTransform.Read(reader, true)
|
||||
: SwfColorTransform.identity;
|
||||
|
||||
tag.Ratio = tag.HasRatio
|
||||
? reader.ReadUInt16()
|
||||
: (ushort)0;
|
||||
|
||||
tag.Name = tag.HasName
|
||||
? reader.ReadString()
|
||||
: string.Empty;
|
||||
|
||||
tag.ClipDepth = tag.HasClipDepth
|
||||
? reader.ReadUInt16()
|
||||
: (ushort)0;
|
||||
|
||||
tag.SurfaceFilters = tag.HasFilterList
|
||||
? SwfSurfaceFilters.Read(reader)
|
||||
: SwfSurfaceFilters.identity;
|
||||
|
||||
tag.BlendMode = tag.HasBlendMode
|
||||
? SwfBlendMode.Read(reader)
|
||||
: SwfBlendMode.identity;
|
||||
|
||||
tag.BitmapCache = tag.HasCacheAsBitmap
|
||||
? reader.ReadByte()
|
||||
: (byte)0;
|
||||
|
||||
tag.Visible = tag.HasVisible
|
||||
? reader.ReadByte()
|
||||
: (byte)1;
|
||||
|
||||
tag.BackgroundColor = tag.HasVisible
|
||||
? SwfColor.Read(reader, true)
|
||||
: SwfColor.identity;
|
||||
|
||||
tag.ClipActions = tag.HasClipActions
|
||||
? SwfClipActions.Read(reader)
|
||||
: SwfClipActions.identity;
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,13 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
}
|
||||
|
||||
public static PlaceObjectTag Create(SwfStreamReader reader) {
|
||||
var tag = new PlaceObjectTag();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
tag.Matrix = SwfMatrix.Read(reader);
|
||||
if ( reader.IsEOF ) {
|
||||
tag.ColorTransform = SwfColorTransform.Identity;
|
||||
} else {
|
||||
tag.ColorTransform = SwfColorTransform.Read(reader, false);
|
||||
}
|
||||
var tag = new PlaceObjectTag();
|
||||
tag.CharacterId = reader.ReadUInt16();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
tag.Matrix = SwfMatrix.Read(reader);
|
||||
tag.ColorTransform = reader.IsEOF
|
||||
? SwfColorTransform.identity
|
||||
: SwfColorTransform.Read(reader, false);
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,14 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
}
|
||||
public Mode Value;
|
||||
|
||||
public static SwfBlendMode identity {
|
||||
get {
|
||||
return new SwfBlendMode {
|
||||
Value = Mode.Normal
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfBlendMode Read(SwfStreamReader reader) {
|
||||
var mode_id = reader.ReadByte();
|
||||
var mode = ModeFromByte(mode_id);
|
||||
@@ -34,7 +42,7 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
|
||||
static Mode ModeFromByte(byte mode_id) {
|
||||
switch ( mode_id ) {
|
||||
case 0:
|
||||
case 0: // Mode.Normal too
|
||||
case 1: return Mode.Normal;
|
||||
case 2: return Mode.Layer;
|
||||
case 3: return Mode.Multiply;
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
public struct SwfClipActions {
|
||||
public static SwfClipActions identity {
|
||||
get {
|
||||
return new SwfClipActions();
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfClipActions Read(SwfStreamReader reader) {
|
||||
//TODO: IMPLME
|
||||
return new SwfClipActions();
|
||||
return SwfClipActions.identity;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
|
||||
@@ -7,8 +7,18 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
public byte B;
|
||||
public byte A;
|
||||
|
||||
public static SwfColor identity {
|
||||
get {
|
||||
return new SwfColor {
|
||||
R = 1,
|
||||
G = 1,
|
||||
B = 1,
|
||||
A = 1};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfColor Read(SwfStreamReader reader, bool with_alpha) {
|
||||
var color = new SwfColor();
|
||||
var color = SwfColor.identity;
|
||||
color.R = reader.ReadByte();
|
||||
color.G = reader.ReadByte();
|
||||
color.B = reader.ReadByte();
|
||||
|
||||
@@ -13,8 +13,24 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
public short AAdd;
|
||||
public bool HasAdd;
|
||||
|
||||
public static SwfColorTransform identity {
|
||||
get {
|
||||
return new SwfColorTransform {
|
||||
RMul = byte.MaxValue,
|
||||
GMul = byte.MaxValue,
|
||||
BMul = byte.MaxValue,
|
||||
AMul = byte.MaxValue,
|
||||
HasMul = false,
|
||||
RAdd = 0,
|
||||
GAdd = 0,
|
||||
BAdd = 0,
|
||||
AAdd = 0,
|
||||
HasAdd = false};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfColorTransform Read(SwfStreamReader reader, bool with_alpha) {
|
||||
var transform = SwfColorTransform.Identity;
|
||||
var transform = SwfColorTransform.identity;
|
||||
transform.HasAdd = reader.ReadBit();
|
||||
transform.HasMul = reader.ReadBit();
|
||||
var bits = reader.ReadUnsignedBits(4);
|
||||
@@ -61,21 +77,5 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
}
|
||||
return trans;
|
||||
}
|
||||
|
||||
public static SwfColorTransform Identity {
|
||||
get {
|
||||
return new SwfColorTransform {
|
||||
RMul = byte.MaxValue,
|
||||
GMul = byte.MaxValue,
|
||||
BMul = byte.MaxValue,
|
||||
AMul = byte.MaxValue,
|
||||
HasMul = false,
|
||||
RAdd = 0,
|
||||
GAdd = 0,
|
||||
BAdd = 0,
|
||||
AAdd = 0,
|
||||
HasAdd = false};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,16 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
public struct SwfControlTags {
|
||||
public List<SwfTagBase> Tags;
|
||||
|
||||
public static SwfControlTags identity {
|
||||
get {
|
||||
return new SwfControlTags {
|
||||
Tags = new List<SwfTagBase>()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfControlTags Read(SwfStreamReader reader) {
|
||||
var control_tags = new SwfControlTags();
|
||||
control_tags.Tags = new List<SwfTagBase>();
|
||||
var control_tags = SwfControlTags.identity;
|
||||
while ( true ) {
|
||||
var tag = SwfTagBase.Read(reader);
|
||||
if ( tag.TagType == SwfTagType.End ) {
|
||||
|
||||
@@ -14,6 +14,14 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
}
|
||||
public Type Value;
|
||||
|
||||
public static SwfFillStyleType identity {
|
||||
get {
|
||||
return new SwfFillStyleType {
|
||||
Value = Type.SolidColor
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfFillStyleType Read(SwfStreamReader reader) {
|
||||
var type_id = reader.ReadByte();
|
||||
var type = TypeFromByte(type_id);
|
||||
|
||||
@@ -9,8 +9,20 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
public float TranslateX;
|
||||
public float TranslateY;
|
||||
|
||||
public static SwfMatrix identity {
|
||||
get {
|
||||
return new SwfMatrix {
|
||||
ScaleX = 1,
|
||||
ScaleY = 1,
|
||||
RotateSkew0 = 0,
|
||||
RotateSkew1 = 0,
|
||||
TranslateX = 0,
|
||||
TranslateY = 0};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfMatrix Read(SwfStreamReader reader) {
|
||||
var matrix = SwfMatrix.Identity;
|
||||
var matrix = SwfMatrix.identity;
|
||||
var has_scale = reader.ReadBit();
|
||||
if ( has_scale ) {
|
||||
var bits = (byte)reader.ReadUnsignedBits(5);
|
||||
@@ -57,17 +69,5 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
mat.m13 = TranslateY;
|
||||
return mat;
|
||||
}
|
||||
|
||||
public static SwfMatrix Identity {
|
||||
get {
|
||||
return new SwfMatrix {
|
||||
ScaleX = 1,
|
||||
ScaleY = 1,
|
||||
RotateSkew0 = 0,
|
||||
RotateSkew1 = 0,
|
||||
TranslateX = 0,
|
||||
TranslateY = 0};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,16 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
|
||||
public List<FillStyle> FillStyles;
|
||||
|
||||
public static SwfShapesWithStyle identity {
|
||||
get {
|
||||
return new SwfShapesWithStyle {
|
||||
FillStyles = new List<FillStyle>()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfShapesWithStyle Read(SwfStreamReader reader, ShapeStyleType style_type) {
|
||||
var shapes = new SwfShapesWithStyle();
|
||||
var shapes = SwfShapesWithStyle.identity;
|
||||
switch ( style_type ) {
|
||||
case ShapeStyleType.Shape:
|
||||
shapes.FillStyles = ReadFillStyles(reader, false, false);
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
public struct SwfSurfaceFilters {
|
||||
public static SwfSurfaceFilters identity {
|
||||
get {
|
||||
return new SwfSurfaceFilters();
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfSurfaceFilters Read(SwfStreamReader reader) {
|
||||
//TODO: IMPLME
|
||||
return new SwfSurfaceFilters();
|
||||
return SwfSurfaceFilters.identity;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
|
||||
Reference in New Issue
Block a user