This commit is contained in:
2016-01-30 05:51:54 +06:00
parent 3cbda5ba75
commit 3ff6fe4ef4

View File

@@ -1,5 +1,5 @@
// ------------------------------------
// JS functions
// ------------------------------------
// JS core
// ------------------------------------
if ( !String.prototype.format ) {
@@ -20,9 +20,7 @@ if ( !Function.prototype.bind ) {
var fToBind = this;
var fNOP = function() {};
var fBound = function() {
return fToBind.apply(this instanceof fNOP && oThis
? this
: oThis,
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
fNOP.prototype = this.prototype;
@@ -32,8 +30,8 @@ if ( !Function.prototype.bind ) {
}
if ( !Array.prototype.find ) {
Array.prototype.find = function(predicate) {
if (this == null) {
Array.prototype.find = function(predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
@@ -54,32 +52,30 @@ if ( !Array.prototype.find ) {
}
(function() {
// ------------------------------------
// ft
// ------------------------------------
var ft = {};
ft.default_indent = " ";
ft.trace = function() {
fl.outputPanel.trace(
Array.prototype.join.call(arguments, " "));
};
ft.trace_fmt = function(format) {
var args = Array.prototype.slice.call(arguments, 1);
ft.trace(format.format.apply(format, args));
};
ft.clear_output = function() {
fl.outputPanel.clear();
};
ft.assert = function(expr, format) {
if ( !expr ) {
if ( format == undefined ) {
if ( format === undefined ) {
throw "!!!Assert!!!";
} else {
var args = Array.prototype.slice.call(arguments, 2);
@@ -87,7 +83,7 @@ if ( !Array.prototype.find ) {
}
}
};
ft.type_assert = function(item, type) {
var type_is_string = (typeof type === 'string');
ft.assert(
@@ -97,34 +93,34 @@ if ( !Array.prototype.find ) {
typeof item,
type_is_string ? type : type.constructor.name);
};
ft.type_assert_if_defined = function(item, type) {
if ( item != undefined ) {
if ( item !== undefined ) {
ft.type_assert(item, type);
}
};
ft.escape_path = function(path) {
ft.type_assert(path, 'string');
return path.replace(/ /g, '%20');
};
ft.escape_string = function(str) {
ft.type_assert(str, 'string');
return str
.replace(/\&/g, '&')
.replace(/\"/g, '"')
.replace(/\'/g, ''')
.replace(/\</g, '&lt;')
.replace(/\>/g, '&gt;');
.replace(/</g , '&lt;')
.replace(/>/g , '&gt;');
};
ft.combine_path = function(lhs, rhs) {
ft.type_assert(lhs, 'string');
ft.type_assert(rhs, 'string');
return ft.escape_path(lhs) + ft.escape_path(rhs);
};
ft.array_foreach = function(arr, func, filter) {
ft.type_assert(arr, Array);
ft.type_assert(func, Function);
@@ -136,7 +132,7 @@ if ( !Array.prototype.find ) {
}
}
};
ft.object_foreach = function(obj, func, filter) {
ft.type_assert(obj, 'object');
ft.type_assert(func, Function);
@@ -150,31 +146,31 @@ if ( !Array.prototype.find ) {
}
}
};
// ------------------------------------
// UniqueIds
// ------------------------------------
var UniqueIds = function() {
this.clear();
};
UniqueIds.prototype.clear = function() {
this.stringIds = {};
this.lastStringId = 0;
};
UniqueIds.prototype.get_string_id = function(str) {
ft.type_assert(str, 'string');
var id = this.stringIds[str];
if ( id == undefined ) {
if ( id === undefined ) {
this.stringIds[str] = ++this.lastStringId;
return this.lastStringId;
} else {
return id;
}
};
UniqueIds.prototype.save = function(xml_path) {
ft.type_assert(xml_path, 'string');
var xml_node = new XmlNode("strings");
@@ -185,11 +181,11 @@ if ( !Array.prototype.find ) {
});
xml_node.save(xml_path);
};
// ------------------------------------
// XmlNode
// ------------------------------------
var XmlNode = function(node_name, node_parent) {
ft.type_assert(node_name, 'string');
ft.type_assert_if_defined(node_parent, XmlNode);
@@ -198,7 +194,7 @@ if ( !Array.prototype.find ) {
this.attrs = [];
this.children = [];
};
XmlNode.prototype.attr = function(attr_name, attr_value) {
ft.type_assert(attr_name, 'string');
attr_value = ft.escape_string(attr_value.toString());
@@ -212,14 +208,14 @@ if ( !Array.prototype.find ) {
}
return this;
};
XmlNode.prototype.child = function(child_name) {
ft.type_assert(child_name, 'string');
var child = new XmlNode(child_name, this);
this.children.push(child);
return child;
};
XmlNode.prototype.content = function(indent) {
indent = indent || "";
var str = '{0}<{1}'.format(indent, this.name);
@@ -229,439 +225,432 @@ if ( !Array.prototype.find ) {
if ( this.children.length > 0 ) {
str += ">\n";
ft.array_foreach(this.children, function(child) {
str += child.content(indent + ft.default_indent) + "\n";
str += child.content(indent + "\t") + "\n";
});
return str + "{0}<{1}/>".format(indent, this.name);
} else {
return str + "/>";
}
};
XmlNode.prototype.save = function(xml_path) {
if ( !FLfile.write(xml_path, this.content()) ) {
throw "Can't save xml to {0}!".format(xml_path);
}
};
// ------------------------------------
// FlashTools
// ------------------------------------
// ------------------------------------
// FlashTools
// ------------------------------------
var FlashTools = function() {
this.uniqueIds = new UniqueIds();
};
var FlashTools = function() {
this.uniqueIds = new UniqueIds();
};
// ------------------------------------
// Xml functions
// ------------------------------------
// ------------------------------------
// Library item
// ------------------------------------
FlashTools.prototype.XmlNode = function(node_name) {
return new XmlNode(node_name);
};
FlashTools.prototype.IsFolderLibraryItem = function(item) {
ft.type_assert(item, LibraryItem);
return item.itemType == "folder";
};
// ------------------------------------
// Library item functions
// ------------------------------------
FlashTools.prototype.IsBitmapLibraryItem = function(item) {
ft.type_assert(item, LibraryItem);
return item.itemType == "bitmap";
};
FlashTools.prototype.IsFolderLibraryItem = function(item) {
ft.type_assert(item, LibraryItem);
return item.itemType == "folder";
};
FlashTools.prototype.IsSymbolLibraryItem = function(item) {
ft.type_assert(item, LibraryItem);
var item_type = item.itemType;
return item_type == "graphic" || item_type == "component" || item_type == "movie clip";
};
FlashTools.prototype.IsBitmapLibraryItem = function(item) {
ft.type_assert(item, LibraryItem);
return item.itemType == "bitmap";
};
// ------------------------------------
// Bitmap item
// ------------------------------------
FlashTools.prototype.IsSymbolLibraryItem = function(item) {
ft.type_assert(item, LibraryItem);
var item_type = item.itemType;
return item_type == "graphic" || item_type == "component" || item_type == "movie clip";
};
FlashTools.prototype.BitmapItem_TraceInfo = function(item) {
ft.type_assert(item, BitmapItem);
ft.trace_fmt("Name : {0}", item.name);
ft.trace_fmt("ExportFilename : {0}", this.BitmapItem_GetExportFilename(item));
};
// ------------------------------------
// Bitmap item functions
// ------------------------------------
FlashTools.prototype.BitmapItem_GetExportFilename = function(item) {
ft.type_assert(item, BitmapItem);
var item_id = this.uniqueIds.get_string_id(item.name);
return "bitmaps/{0}.png".format(item_id);
};
FlashTools.prototype.BitmapItem_TraceInfo = function(item) {
ft.type_assert(item, BitmapItem);
ft.trace_fmt("Name : {0}", item.name);
ft.trace_fmt("ExportFilename : {0}", this.BitmapItem_GetExportFilename(item));
};
FlashTools.prototype.BitmapItem_GetExportFullFilename = function(document, item) {
ft.type_assert(document, Document);
ft.type_assert(item, BitmapItem);
return ft.combine_path(
this.Document_GetExportFolder(document),
this.BitmapItem_GetExportFilename(item));
};
FlashTools.prototype.BitmapItem_GetExportFilename = function(item) {
ft.type_assert(item, BitmapItem);
var item_id = this.uniqueIds.get_string_id(item.name);
return "bitmaps/{0}.png".format(item_id);
};
FlashTools.prototype.BitmapItem_Export = function(document, item) {
ft.type_assert(document, Document);
ft.type_assert(item, BitmapItem);
var item_export_path = this.BitmapItem_GetExportFullFilename(document, item);
if ( !item.exportToFile(item_export_path) ) {
throw "Can't export bitmap ({0})!"
.format(item_export_path);
}
};
FlashTools.prototype.BitmapItem_GetExportFullFilename = function(document, item) {
ft.type_assert(document, Document);
ft.type_assert(item, BitmapItem);
return ft.combine_path(
this.Document_GetExportFolder(document),
this.BitmapItem_GetExportFilename(item));
};
FlashTools.prototype.BitmapItem_ExportXmlDescription = function(xml_node, item) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(item, BitmapItem);
xml_node.child("asset")
.attr("name" , this.uniqueIds.get_string_id(item.name))
.attr("type" , "bitmap")
.attr("filename", this.BitmapItem_GetExportFilename(item));
};
FlashTools.prototype.BitmapItem_Export = function(document, item) {
ft.type_assert(document, Document);
ft.type_assert(item, BitmapItem);
var item_export_path = this.BitmapItem_GetExportFullFilename(document, item);
if ( !item.exportToFile(item_export_path) ) {
throw "Can't export bitmap ({0})!"
.format(item_export_path);
}
};
// ------------------------------------
// Symbol item
// ------------------------------------
FlashTools.prototype.BitmapItem_ExportXmlDescription = function(xml_node, item) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(item, BitmapItem);
xml_node.child("asset")
.attr("name" , this.uniqueIds.get_string_id(item.name))
.attr("type" , "bitmap")
.attr("filename", this.BitmapItem_GetExportFilename(item));
};
FlashTools.prototype.SymbolItem_TraceInfo = function(item) {
ft.type_assert(item, SymbolItem);
ft.trace_fmt("Name : {0}", item.name);
ft.trace_fmt("ExportFilename : {0}", this.SymbolItem_GetExportFilename(item));
};
// ------------------------------------
// Symbol item functions
// ------------------------------------
FlashTools.prototype.SymbolItem_GetExportFilename = function(item) {
ft.type_assert(item, SymbolItem);
var item_id = this.uniqueIds.get_string_id(item.name);
return "symbols/{0}.xml".format(item_id);
};
FlashTools.prototype.SymbolItem_TraceInfo = function(item) {
ft.type_assert(item, SymbolItem);
ft.trace_fmt("Name : {0}", item.name);
ft.trace_fmt("ExportFilename : {0}", this.SymbolItem_GetExportFilename(item));
};
FlashTools.prototype.SymbolItem_GetExportFullFilename = function(document, item) {
ft.type_assert(item, SymbolItem);
return ft.combine_path(
this.Document_GetExportFolder(document),
this.SymbolItem_GetExportFilename(item));
};
FlashTools.prototype.SymbolItem_GetExportFilename = function(item) {
ft.type_assert(item, SymbolItem);
var item_id = this.uniqueIds.get_string_id(item.name);
return "symbols/{0}.xml".format(item_id);
};
FlashTools.prototype.SymbolItem_Export = function(document, item) {
ft.type_assert(document, Document);
ft.type_assert(item, SymbolItem);
var xml_node = new XmlNode("symbol")
.attr("name", this.uniqueIds.get_string_id(item.name));
this.Timeline_ExportXmlContent(xml_node, item.timeline);
xml_node.save(this.SymbolItem_GetExportFullFilename(document, item));
};
FlashTools.prototype.SymbolItem_GetExportFullFilename = function(document, item) {
ft.type_assert(item, SymbolItem);
return ft.combine_path(
this.Document_GetExportFolder(document),
this.SymbolItem_GetExportFilename(item));
};
FlashTools.prototype.SymbolItem_ExportXmlDescription = function(xml_node, item) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(item, SymbolItem);
xml_node.child("symbol")
.attr("name" , this.uniqueIds.get_string_id(item.name))
.attr("type" , "symbol")
.attr("filename", this.SymbolItem_GetExportFilename(item));
};
FlashTools.prototype.SymbolItem_Export = function(document, item) {
ft.type_assert(document, Document);
ft.type_assert(item, SymbolItem);
var xml_node = this.XmlNode("symbol")
.attr("name", this.uniqueIds.get_string_id(item.name));
this.Timeline_ExportXmlContent(xml_node, item.timeline);
xml_node.save(this.SymbolItem_GetExportFullFilename(document, item));
};
// ------------------------------------
// Element
// ------------------------------------
FlashTools.prototype.SymbolItem_ExportXmlDescription = function(xml_node, item) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(item, SymbolItem);
xml_node.child("symbol")
.attr("name" , this.uniqueIds.get_string_id(item.name))
.attr("type" , "symbol")
.attr("filename", this.SymbolItem_GetExportFilename(item));
};
FlashTools.prototype.Element_ExportXmlContent = function(xml_node, element) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(element, Element);
// ------------------------------------
// Element functions
// ------------------------------------
FlashTools.prototype.Element_ExportXmlContent = function(xml_node, element) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(element, Element);
if ( element.elementType == "shape" ) {
/// \TODO: shape to bitmap
} else if ( element.elementType == "instance" ) {
if ( element.instanceType == "bitmap" ) {
} else if ( element.instanceType == "symbol" ) {
if ( element.elementType == "shape" ) {
/// \TODO: shape to bitmap
} else if ( element.elementType == "instance" ) {
if ( element.instanceType == "bitmap" ) {
} else if ( element.instanceType == "symbol" ) {
} else {
throw "Unsupported element type ({0})!"
.format(element.elementType);
}
//ft.trace("Instance type : " + element.instanceType);
//ft.trace("Library item : " + element.libraryItem.name);
} else {
throw "Unsupported element type ({0})!"
.format(element.elementType);
}
//ft.trace("Instance type : " + element.instanceType);
//ft.trace("Library item : " + element.libraryItem.name);
} else {
throw "Unsupported element type ({0})!"
.format(element.elementType);
}
var element_node = xml_node.child("element")
.attr("name" , this.uniqueIds.get_string_id(element.name))
.attr("depth", element.depth);
this.ElementTransform_ExportXmlContent(element_node, element);
};
FlashTools.prototype.ElementTransform_ExportXmlContent = function(xml_node, element) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(element, Element);
xml_node.child("transform")
.attr("a" , element.matrix.a)
.attr("b" , element.matrix.b)
.attr("c" , element.matrix.c)
.attr("d" , element.matrix.d)
.attr("tx", element.matrix.tx)
.attr("ty", element.matrix.ty);
};
var element_node = xml_node.child("element")
.attr("name" , this.uniqueIds.get_string_id(element.name))
.attr("depth", element.depth);
this.ElementTransform_ExportXmlContent(element_node, element);
};
// ------------------------------------
// Frame functions
// ------------------------------------
FlashTools.prototype.ElementTransform_ExportXmlContent = function(xml_node, element) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(element, Element);
xml_node.child("transform")
.attr("a" , element.matrix.a)
.attr("b" , element.matrix.b)
.attr("c" , element.matrix.c)
.attr("d" , element.matrix.d)
.attr("tx", element.matrix.tx)
.attr("ty", element.matrix.ty);
};
FlashTools.prototype.Frame_ExportXmlContent = function(xml_node, frame) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(frame, Frame);
var frame_node = xml_node.child("frame")
.attr("name" , this.uniqueIds.get_string_id(frame.name))
.attr("start_frame", frame.startFrame)
.attr("duration" , frame.duration)
.attr("elements" , frame.elements.length);
this.FrameElements_ExportXmlContent(frame_node, frame);
};
// ------------------------------------
// Frame
// ------------------------------------
FlashTools.prototype.FrameElements_ExportXmlContent = function(xml_node, frame) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(frame, Frame);
ft.array_foreach(frame.elements, function(element) {
this.Element_ExportXmlContent(xml_node, element);
}.bind(this));
};
FlashTools.prototype.Frame_ExportXmlContent = function(xml_node, frame) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(frame, Frame);
var frame_node = xml_node.child("frame")
.attr("name" , this.uniqueIds.get_string_id(frame.name))
.attr("start_frame", frame.startFrame)
.attr("duration" , frame.duration)
.attr("elements" , frame.elements.length);
this.FrameElements_ExportXmlContent(frame_node, frame);
};
// ------------------------------------
// Layer functions
// ------------------------------------
FlashTools.prototype.FrameElements_ExportXmlContent = function(xml_node, frame) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(frame, Frame);
ft.array_foreach(frame.elements, function(element) {
this.Element_ExportXmlContent(xml_node, element);
}.bind(this));
};
FlashTools.prototype.Layer_ExportXmlContent = function(xml_node, layer) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(layer, Layer);
var layer_node = xml_node.child("layer")
.attr("name" , this.uniqueIds.get_string_id(layer.name))
.attr("type" , layer.layerType)
.attr("frames" , layer.frameCount)
.attr("locked" , layer.locked)
.attr("visible" , layer.visible)
.attr("animation_type", layer.animationType);
if ( layer.parentLayer ) {
layer_node.attr("parent_layer", this.uniqueIds.get_string_id(layer.parentLayer.name));
}
this.LayerFrames_ExportXmlContent(layer_node, layer);
};
// ------------------------------------
// Layer
// ------------------------------------
FlashTools.prototype.LayerFrames_ExportXmlContent = function(xml_node, layer) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(layer, Layer);
ft.array_foreach(layer.frames, function(frame) {
this.Frame_ExportXmlContent(xml_node, frame);
}.bind(this));
};
FlashTools.prototype.Layer_ExportXmlContent = function(xml_node, layer) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(layer, Layer);
var layer_node = xml_node.child("layer")
.attr("name" , this.uniqueIds.get_string_id(layer.name))
.attr("type" , layer.layerType)
.attr("frames" , layer.frameCount)
.attr("locked" , layer.locked)
.attr("visible" , layer.visible)
.attr("animation_type", layer.animationType);
if ( layer.parentLayer ) {
layer_node.attr("parent_layer", this.uniqueIds.get_string_id(layer.parentLayer.name));
}
this.LayerFrames_ExportXmlContent(layer_node, layer);
};
// ------------------------------------
// Timeline functions
// ------------------------------------
FlashTools.prototype.LayerFrames_ExportXmlContent = function(xml_node, layer) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(layer, Layer);
ft.array_foreach(layer.frames, function(frame) {
this.Frame_ExportXmlContent(xml_node, frame);
}.bind(this));
};
FlashTools.prototype.Timeline_TraceInfo = function(timeline) {
ft.type_assert(timeline, Timeline);
ft.trace_fmt("Name : {0}", timeline.name);
ft.trace_fmt("Layer count : {0}", timeline.layerCount);
ft.trace_fmt("Frame count : {0}", timeline.frameCount);
};
// ------------------------------------
// Timeline
// ------------------------------------
FlashTools.prototype.Timeline_ExportXmlContent = function(xml_node, timeline) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(timeline, Timeline);
var timeline_node = xml_node.child("timeline")
.attr("layers", timeline.layerCount)
.attr("frames", timeline.frameCount);
this.TimelineLayers_ExportXmlContent(timeline_node, timeline);
};
FlashTools.prototype.Timeline_TraceInfo = function(timeline) {
ft.type_assert(timeline, Timeline);
ft.trace_fmt("Name : {0}", timeline.name);
ft.trace_fmt("Layer count : {0}", timeline.layerCount);
ft.trace_fmt("Frame count : {0}", timeline.frameCount);
};
FlashTools.prototype.TimelineLayers_ExportXmlContent = function(xml_node, timeline) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(timeline, Timeline);
ft.array_foreach(timeline.layers, function(layer) {
this.Layer_ExportXmlContent(xml_node, layer);
}.bind(this));
};
FlashTools.prototype.Timeline_ExportXmlContent = function(xml_node, timeline) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(timeline, Timeline);
var timeline_node = xml_node.child("timeline")
.attr("layers", timeline.layerCount)
.attr("frames", timeline.frameCount);
this.TimelineLayers_ExportXmlContent(timeline_node, timeline);
};
// ------------------------------------
// Document functions
// ------------------------------------
FlashTools.prototype.TimelineLayers_ExportXmlContent = function(xml_node, timeline) {
ft.type_assert(xml_node, XmlNode);
ft.type_assert(timeline, Timeline);
ft.array_foreach(timeline.layers, function(layer) {
this.Layer_ExportXmlContent(xml_node, layer);
}.bind(this));
};
FlashTools.prototype.Document_TraceInfo = function(document) {
ft.type_assert(document, Document);
ft.trace_fmt("Name : {0}", document.name);
ft.trace_fmt("Path : {0}", this.Document_GetPath(document));
ft.trace_fmt("ExportFolder : {0}", this.Document_GetExportFolder(document));
};
// ------------------------------------
// Document
// ------------------------------------
FlashTools.prototype.Document_GetPath = function(document) {
ft.type_assert(document, Document);
return ft.escape_path(document.pathURI);
};
FlashTools.prototype.Document_TraceInfo = function(document) {
ft.type_assert(document, Document);
ft.trace_fmt("Name : {0}", document.name);
ft.trace_fmt("Path : {0}", this.Document_GetPath(document));
ft.trace_fmt("ExportFolder : {0}", this.Document_GetExportFolder(document));
};
FlashTools.prototype.Document_GetExportFolder = function(document) {
ft.type_assert(document, Document);
return ft.combine_path(
this.Document_GetPath(document),
"_export/");
};
FlashTools.prototype.Document_GetPath = function(document) {
ft.type_assert(document, Document);
return ft.escape_path(document.pathURI);
};
FlashTools.prototype.Document_GetStageExportPath = function(document) {
ft.type_assert(document, Document);
return ft.combine_path(
this.Document_GetExportFolder(document),
"stage.xml");
};
FlashTools.prototype.Document_GetExportFolder = function(document) {
ft.type_assert(document, Document);
return ft.combine_path(
this.Document_GetPath(document),
"_export/");
};
FlashTools.prototype.Document_GetLibraryExportPath = function(document) {
ft.type_assert(document, Document);
return ft.combine_path(
this.Document_GetExportFolder(document),
"library.xml");
};
FlashTools.prototype.Document_GetStageExportPath = function(document) {
ft.type_assert(document, Document);
return ft.combine_path(
this.Document_GetExportFolder(document),
"stage.xml");
};
FlashTools.prototype.Document_GetStringIdsExportPath = function(document) {
ft.type_assert(document, Document);
return ft.combine_path(
this.Document_GetExportFolder(document),
"strings.xml");
};
FlashTools.prototype.Document_GetLibraryExportPath = function(document) {
ft.type_assert(document, Document);
return ft.combine_path(
this.Document_GetExportFolder(document),
"library.xml");
};
FlashTools.prototype.Document_ExitEditMode = function(document) {
ft.type_assert(document, Document);
for ( var i = 0; i < 100; ++i ) {
document.exitEditMode();
}
};
FlashTools.prototype.Document_GetStringIdsExportPath = function(document) {
ft.type_assert(document, Document);
return ft.combine_path(
this.Document_GetExportFolder(document),
"strings.xml");
};
FlashTools.prototype.Document_ForEachByLibraryItems = function(document, func, filter) {
ft.type_assert(document, Document);
ft.type_assert(func, Function);
ft.type_assert_if_defined(filter, Function);
ft.array_foreach(document.library.items, func, filter);
};
FlashTools.prototype.Document_ExitEditMode = function(document) {
ft.type_assert(document, Document);
for ( var i = 0; i < 100; ++i ) {
document.exitEditMode();
}
};
FlashTools.prototype.Document_PrepareExportFolder = function(document) {
ft.type_assert(document, Document);
var export_folder = this.Document_GetExportFolder(document);
if ( FLfile.exists(export_folder) ) {
if ( !FLfile.remove(export_folder) ) {
throw "Can't remove document export folder ({0})!"
FlashTools.prototype.Document_ForEachByLibraryItems = function(document, func, filter) {
ft.type_assert(document, Document);
ft.type_assert(func, Function);
ft.type_assert_if_defined(filter, Function);
ft.array_foreach(document.library.items, func, filter);
};
FlashTools.prototype.Document_PrepareExportFolder = function(document) {
ft.type_assert(document, Document);
var export_folder = this.Document_GetExportFolder(document);
if ( FLfile.exists(export_folder) ) {
if ( !FLfile.remove(export_folder) ) {
throw "Can't remove document export folder ({0})!"
.format(export_folder);
}
}
if ( !FLfile.createFolder(export_folder) ) {
throw "Can't create document export folder ({0})!"
.format(export_folder);
}
}
if ( !FLfile.createFolder(export_folder) ) {
throw "Can't create document export folder ({0})!"
.format(export_folder);
}
};
};
FlashTools.prototype.Document_ExportLibrary = function(document) {
ft.type_assert(document, Document);
var xml_node = this.XmlNode("library")
.attr("frame_rate", document.frameRate);
this.Document_ForEachByLibraryItems(document, function(item) {
if ( this.IsFolderLibraryItem(item) ) {
// nothing
} else if ( this.IsBitmapLibraryItem(item) ) {
this.BitmapItem_ExportXmlDescription(xml_node, item);
} else if ( this.IsSymbolLibraryItem(item) ) {
this.SymbolItem_ExportXmlDescription(xml_node, item);
} else {
throw "Unsupported library item type ({0})!"
.format(item.itemType);
FlashTools.prototype.Document_ExportLibrary = function(document) {
ft.type_assert(document, Document);
var xml_node = new XmlNode("library")
.attr("frame_rate", document.frameRate);
this.Document_ForEachByLibraryItems(document, function(item) {
if ( this.IsFolderLibraryItem(item) ) {
// nothing
} else if ( this.IsBitmapLibraryItem(item) ) {
this.BitmapItem_ExportXmlDescription(xml_node, item);
} else if ( this.IsSymbolLibraryItem(item) ) {
this.SymbolItem_ExportXmlDescription(xml_node, item);
} else {
throw "Unsupported library item type ({0})!"
.format(item.itemType);
}
}.bind(this));
xml_node.save(this.Document_GetLibraryExportPath(document));
};
FlashTools.prototype.Document_ExportBitmaps = function(document) {
ft.type_assert(document, Document);
this.Document_ForEachByLibraryItems(document, function(item) {
this.BitmapItem_Export(document, item);
}.bind(this), this.IsBitmapLibraryItem.bind(this));
};
FlashTools.prototype.Document_ExportSymbols = function(document) {
ft.type_assert(document, Document);
this.Document_ForEachByLibraryItems(document, function(item) {
this.SymbolItem_Export(document, item);
}.bind(this), this.IsSymbolLibraryItem.bind(this));
};
FlashTools.prototype.Document_ExportStage = function(document) {
ft.type_assert(document, Document);
this.Document_ExitEditMode(document);
var xml_node = new XmlNode("stage");
this.Timeline_ExportXmlContent(xml_node, document.getTimeline());
xml_node.save(this.Document_GetStageExportPath(document));
};
FlashTools.prototype.Document_ExportStringIds = function(document) {
ft.type_assert(document, Document);
this.uniqueIds.save(this.Document_GetStringIdsExportPath(document));
};
// ------------------------------------
// Convert
// ------------------------------------
FlashTools.prototype.ConvertAll = function() {
ft.array_foreach(fl.documents, function(document) {
this.ConvertOne(document);
}.bind(this));
};
FlashTools.prototype.ConvertOne = function(document) {
ft.type_assert(document, Document);
this.uniqueIds.clear();
ft.trace("-= Convert document start =-");
try {
this.Document_TraceInfo(document);
this.Document_PrepareExportFolder(document);
this.Document_ExportLibrary(document);
this.Document_ExportBitmaps(document);
this.Document_ExportSymbols(document);
this.Document_ExportStage(document);
this.Document_ExportStringIds(document);
ft.trace("-= Convert document finish =-");
} catch ( e ) {
ft.trace("-= Convert document error =- : " + e);
}
}.bind(this));
xml_node.save(this.Document_GetLibraryExportPath(document));
};
};
FlashTools.prototype.Document_ExportBitmaps = function(document) {
ft.type_assert(document, Document);
this.Document_ForEachByLibraryItems(document, function(item) {
this.BitmapItem_Export(document, item);
}.bind(this), this.IsBitmapLibraryItem.bind(this));
};
// ------------------------------------
// Tests
// ------------------------------------
FlashTools.prototype.Document_ExportSymbols = function(document) {
ft.type_assert(document, Document);
this.Document_ForEachByLibraryItems(document, function(item) {
this.SymbolItem_Export(document, item);
}.bind(this), this.IsSymbolLibraryItem.bind(this));
};
FlashTools.prototype.Test0 = function() {
ft.assert(true);
};
FlashTools.prototype.Document_ExportStage = function(document) {
ft.type_assert(document, Document);
this.Document_ExitEditMode(document);
var xml_node = this.XmlNode("stage");
this.Timeline_ExportXmlContent(xml_node, document.getTimeline());
xml_node.save(this.Document_GetStageExportPath(document));
};
FlashTools.prototype.Test1 = function() {
ft.assert(true);
};
FlashTools.prototype.Document_ExportStringIds = function(document) {
ft.type_assert(document, Document);
this.uniqueIds.save(this.Document_GetStringIdsExportPath(document));
};
FlashTools.prototype.RunTests = function() {
try {
this.Test0();
this.Test1();
return true;
} catch ( e ) {
ft.trace_fmt("!!!Error!!! Unit test fail: {0}", e);
return false;
}
};
// ------------------------------------
// Convert functions
// ------------------------------------
FlashTools.prototype.ConvertAll = function() {
ft.array_foreach(fl.documents, function(document) {
this.ConvertOne(document);
}.bind(this));
};
FlashTools.prototype.ConvertOne = function(document) {
ft.type_assert(document, Document);
this.uniqueIds.clear();
ft.trace("-= Convert document start =-");
try {
this.Document_TraceInfo(document);
this.Document_PrepareExportFolder(document);
this.Document_ExportLibrary(document);
this.Document_ExportBitmaps(document);
this.Document_ExportSymbols(document);
this.Document_ExportStage(document);
this.Document_ExportStringIds(document);
ft.trace("-= Convert document finish =-");
} catch ( e ) {
ft.trace("-= Convert document error =- : " + e);
}
};
// ------------------------------------
// Test functions
// ------------------------------------
FlashTools.prototype.Test0 = function() {
ft.assert(true);
};
FlashTools.prototype.Test1 = function() {
ft.assert(true);
};
FlashTools.prototype.RunTests = function() {
try {
this.Test0();
this.Test1();
return true;
} catch ( e ) {
ft.trace_fmt("!!!Error!!! Unit test fail: {0}", e);
return false;
}
};
// ------------------------------------
// Run
// ------------------------------------
ft.clear_output();
var flash_tools = new FlashTools();
if ( flash_tools.RunTests() ) {
flash_tools.ConvertAll();
}
// ------------------------------------
// Main
// ------------------------------------
(function() {
ft.clear_output();
var flash_tools = new FlashTools();
if ( flash_tools.RunTests() ) {
flash_tools.ConvertAll();
}
})();
})();