mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 14:11:19 +07:00
fix some bugs
This commit is contained in:
@@ -89,7 +89,7 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
tag.HasFilterList = reader.ReadBit();
|
||||
tag.Depth = reader.ReadUInt16();
|
||||
|
||||
tag.ClassName = (tag.HasCharacter || (tag.HasImage && tag.HasCharacter))
|
||||
tag.ClassName = (tag.HasClassName || (tag.HasImage && tag.HasCharacter))
|
||||
? reader.ReadString()
|
||||
: string.Empty;
|
||||
|
||||
@@ -133,11 +133,11 @@ namespace FlashTools.Internal.SwfTools.SwfTags {
|
||||
? reader.ReadByte()
|
||||
: (byte)1;
|
||||
|
||||
tag.BackgroundColor = tag.HasVisible
|
||||
tag.BackgroundColor = tag.HasVisible && !reader.IsEOF
|
||||
? SwfColor.Read(reader, true)
|
||||
: SwfColor.identity;
|
||||
|
||||
tag.ClipActions = tag.HasClipActions
|
||||
tag.ClipActions = tag.HasClipActions && !reader.IsEOF
|
||||
? SwfClipActions.Read(reader)
|
||||
: SwfClipActions.identity;
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
var has_rotate = reader.ReadBit();
|
||||
if ( has_rotate ) {
|
||||
var bits = (byte)reader.ReadUnsignedBits(5);
|
||||
matrix.RotateSkew0 = reader.ReadFixedPoint16(bits);
|
||||
matrix.RotateSkew1 = reader.ReadFixedPoint16(bits);
|
||||
matrix.RotateSkew0 = reader.ReadFixedPoint16(bits) / 20.0f;
|
||||
matrix.RotateSkew1 = reader.ReadFixedPoint16(bits) / 20.0f;
|
||||
} else {
|
||||
matrix.RotateSkew0 =
|
||||
matrix.RotateSkew1 = 0.0f;
|
||||
|
||||
@@ -37,23 +37,27 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
switch ( style_type ) {
|
||||
case ShapeStyleType.Shape:
|
||||
shapes.FillStyles = ReadFillStyles(reader, false, false);
|
||||
SkipLineStyles(reader, false, false, false);
|
||||
SkipShapeRecords(reader, false, false, false);
|
||||
//SkipLineStyles(reader, false, false, false);
|
||||
//SkipShapeRecords(reader, false, false, false);
|
||||
//reader.AlignToByte();
|
||||
break;
|
||||
case ShapeStyleType.Shape2:
|
||||
shapes.FillStyles = ReadFillStyles(reader, true, false);
|
||||
SkipLineStyles(reader, true, false, false);
|
||||
SkipShapeRecords(reader, true, false, false);
|
||||
//SkipLineStyles(reader, true, false, false);
|
||||
//SkipShapeRecords(reader, true, false, false);
|
||||
//reader.AlignToByte();
|
||||
break;
|
||||
case ShapeStyleType.Shape3:
|
||||
shapes.FillStyles = ReadFillStyles(reader, true, true);
|
||||
SkipLineStyles(reader, true, true, false);
|
||||
SkipShapeRecords(reader, true, true, false);
|
||||
//SkipLineStyles(reader, true, true, false);
|
||||
//SkipShapeRecords(reader, true, true, false);
|
||||
//reader.AlignToByte();
|
||||
break;
|
||||
case ShapeStyleType.Shape4:
|
||||
shapes.FillStyles = ReadFillStyles(reader, true, true);
|
||||
SkipLineStyles(reader, true, true, true);
|
||||
SkipShapeRecords(reader, true, true, true);
|
||||
//SkipLineStyles(reader, true, true, true);
|
||||
//SkipShapeRecords(reader, true, true, true);
|
||||
//reader.AlignToByte();
|
||||
break;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
|
||||
@@ -121,10 +121,10 @@ namespace FlashTools {
|
||||
_triangles.Add(_vertices.Count - 4 + 2);
|
||||
|
||||
var source_rect = bitmap.SourceRect;
|
||||
_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMax));
|
||||
_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMax));
|
||||
_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMin));
|
||||
_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMin));
|
||||
_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMin));
|
||||
_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMax));
|
||||
_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMax));
|
||||
|
||||
_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
|
||||
@@ -1,4 +1,37 @@
|
||||
(function () {
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// JS core
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
if (!String.prototype.format) {
|
||||
String.prototype.format = function () {
|
||||
var args = arguments;
|
||||
return this.replace(/{(\d+)}/g, function (match, number) {
|
||||
return typeof args[number] != 'undefined' ? args[number] : match;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function (oThis) {
|
||||
if (typeof this !== 'function') {
|
||||
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
|
||||
}
|
||||
var aArgs = Array.prototype.slice.call(arguments, 1);
|
||||
var fToBind = this;
|
||||
var fNOP = function () {};
|
||||
var fBound = function () {
|
||||
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis,
|
||||
aArgs.concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
fNOP.prototype = this.prototype;
|
||||
fBound.prototype = new fNOP();
|
||||
return fBound;
|
||||
};
|
||||
}
|
||||
|
||||
(function () {
|
||||
|
||||
"use strict";
|
||||
|
||||
@@ -158,6 +191,28 @@
|
||||
}
|
||||
};
|
||||
|
||||
ftd.full_exit_edit_mode = function (document) {
|
||||
for (var i = 0; i < 100; ++i) {
|
||||
document.exitEditMode();
|
||||
}
|
||||
};
|
||||
|
||||
ftd.delete_unused_items = function(document) {
|
||||
var unused_items = document.library.unusedItems;
|
||||
ft.array_foreach(unused_items, function (item) {
|
||||
ft.trace_fmt("Remove unused item: {0}", item.name);
|
||||
document.library.deleteItem(item.name);
|
||||
});
|
||||
};
|
||||
|
||||
ftd.convert_shapes = function(document) {
|
||||
ftt.convert(document.getTimeline());
|
||||
ftlib.convert(document.library, document);
|
||||
|
||||
ftt.prepare(document.getTimeline(), document);
|
||||
ftlib.prepare(document.library, document);
|
||||
};
|
||||
|
||||
ftd.prepare_bitmaps = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
ft.array_foreach(document.library.items, function(item) {
|
||||
@@ -197,6 +252,173 @@
|
||||
ftd.get_document_name(document) + ".swf");
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Timeline
|
||||
// ------------------------------------
|
||||
|
||||
var ftt = {};
|
||||
|
||||
ftt.remove_empty_layers = function(timeline) {
|
||||
var layers = timeline.layers;
|
||||
for ( var i = layers.length - 1; i >= 0; --i ) {
|
||||
if (ftl.is_empty(layers[i])) {
|
||||
timeline.deleteLayer(i);
|
||||
layers = timeline.layers;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ftt.convert = function(timeline) {
|
||||
ftt.remove_empty_layers(timeline);
|
||||
if ( timeline.layers.length > 0 && timeline.frameCount > 1 ) {
|
||||
timeline.selectAllFrames();
|
||||
timeline.convertToKeyframes();
|
||||
}
|
||||
ft.array_reverse_foreach(timeline.layers, function(layer, index) {
|
||||
timeline.setSelectedLayers(index);
|
||||
ftl.convert(layer);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
ftt.prepare = function(timeline, document) {
|
||||
ft.array_reverse_foreach(timeline.layers, function(layer, index) {
|
||||
timeline.setSelectedLayers(index);
|
||||
ftl.prepare(layer, timeline, document);
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Layer
|
||||
// ------------------------------------
|
||||
|
||||
var ftl = {};
|
||||
|
||||
ftl.do_in_unlocked = function(layer, func) {
|
||||
ft.type_assert(func, Function);
|
||||
var prev_locked = layer.locked;
|
||||
var prev_visible = layer.visible;
|
||||
layer.locked = false;
|
||||
layer.visible = true;
|
||||
func();
|
||||
layer.locked = prev_locked;
|
||||
layer.visible = prev_visible;
|
||||
};
|
||||
|
||||
ftl.convert = function(layer) {
|
||||
ftl.do_in_unlocked(layer, function() {
|
||||
ft.array_foreach(layer.frames, function(frame, index) {
|
||||
frame.convertToFrameByFrameAnimation();
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
ftl.is_element_shape = function(element) {
|
||||
return element.elementType == "shape"
|
||||
};
|
||||
|
||||
ftl.is_frame_empty = function(frame) {
|
||||
return frame.elements.length == 0;
|
||||
};
|
||||
|
||||
ftl.is_empty = function(layer) {
|
||||
if ( !layer.visible ) {
|
||||
return true;
|
||||
}
|
||||
if ( layer.layerType == "guide" || layer.layerType == "mask" || layer.layerType == "folder" ) {
|
||||
return false;
|
||||
}
|
||||
var frames = layer.frames;
|
||||
for ( var i = 0; i < frames.length; ++i ) {
|
||||
if (!ftl.is_frame_empty(frames[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
ftl.prepare = function(layer, timeline, document) {
|
||||
ftl.do_in_unlocked(layer, function() {
|
||||
ft.array_foreach(layer.frames, function(frame, index) {
|
||||
if (frame.startFrame == index) {
|
||||
timeline.setSelectedFrames(index, index + 1);
|
||||
|
||||
timeline.currentFrame = frame.startFrame;
|
||||
document.selectNone();
|
||||
document.selection = ft.array_filter(
|
||||
frame.elements,
|
||||
ftl.is_element_shape.bind(this));
|
||||
if ( document.selection.length > 0 ) {
|
||||
document.convertSelectionToBitmap();
|
||||
document.arrange("back");
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// Library
|
||||
// ------------------------------------
|
||||
|
||||
var ftlib = {};
|
||||
|
||||
ftlib.is_folder_item = function (item) {
|
||||
ft.type_assert(item, LibraryItem);
|
||||
return item.itemType == "folder";
|
||||
};
|
||||
|
||||
ftlib.is_bitmap_item = function (item) {
|
||||
ft.type_assert(item, LibraryItem);
|
||||
return item.itemType == "bitmap";
|
||||
};
|
||||
|
||||
ftlib.is_symbol_item = function (item) {
|
||||
ft.type_assert(item, LibraryItem);
|
||||
return item.itemType == "graphic" || item.itemType == "movie clip";
|
||||
};
|
||||
|
||||
ftlib.for_each_by_items = function (library, func, filter) {
|
||||
ft.type_assert(func, Function);
|
||||
ft.type_assert_if_defined(filter, Function);
|
||||
ft.array_foreach(library.items, func, filter);
|
||||
};
|
||||
|
||||
ftlib.convert = function(library, document) {
|
||||
ft.type_assert(document, Document);
|
||||
ftlib.for_each_by_items(library, function (item) {
|
||||
if ( library.editItem(item.name) ) {
|
||||
ft.trace_fmt("Convert: {0}", item.name);
|
||||
ftsym.convert(item, document);
|
||||
document.exitEditMode();
|
||||
}
|
||||
}.bind(this), this.is_symbol_item.bind(this));
|
||||
};
|
||||
|
||||
ftlib.prepare = function(library, document) {
|
||||
ft.type_assert(document, Document);
|
||||
ftlib.for_each_by_items(library, function (item) {
|
||||
if ( library.editItem(item.name) ) {
|
||||
ft.trace_fmt("Prepare: {0}", item.name);
|
||||
ftsym.prepare(item, document);
|
||||
document.exitEditMode();
|
||||
}
|
||||
}.bind(this), this.is_symbol_item.bind(this));
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Symbol
|
||||
// ------------------------------------
|
||||
|
||||
var ftsym = {};
|
||||
|
||||
ftsym.convert = function(item, document) {
|
||||
ftt.convert(item.timeline);
|
||||
};
|
||||
|
||||
ftsym.prepare = function(item, document) {
|
||||
ftt.prepare(item.timeline, document);
|
||||
};
|
||||
|
||||
// ------------------------------------
|
||||
// Main
|
||||
// ------------------------------------
|
||||
@@ -206,9 +428,12 @@
|
||||
ft.array_foreach(fl.documents, function (document) {
|
||||
ft.trace_fmt("Doc: {0}", document.name);
|
||||
ftd.prepare_folders(document);
|
||||
ftd.full_exit_edit_mode(document);
|
||||
ftd.delete_unused_items(document);
|
||||
ftd.convert_shapes(document);
|
||||
ftd.prepare_bitmaps(document);
|
||||
ftd.export_swf(document);
|
||||
fl.revertDocument(document);
|
||||
//fl.revertDocument(document);
|
||||
});
|
||||
})();
|
||||
})();
|
||||
Reference in New Issue
Block a user