From df6d120424f67a4153e0c09306d123f00f367545 Mon Sep 17 00:00:00 2001 From: Smallpath Date: Thu, 15 Jun 2017 23:17:38 +0800 Subject: [PATCH] generate sequence layer without saving it's material --- dist/Sp_memory.jsx | 65 +++++++++++++++++++++++++++++++++---- lib/AfterEffectsLayer.js | 69 +++++++++++++++++++++++++++++++++++++--- src/ui/function.js | 7 ++-- 3 files changed, 128 insertions(+), 13 deletions(-) diff --git a/dist/Sp_memory.jsx b/dist/Sp_memory.jsx index 9afa80e..11b7c94 100644 --- a/dist/Sp_memory.jsx +++ b/dist/Sp_memory.jsx @@ -874,6 +874,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol } }; + var imagePattern = new RegExp('(ai|bmp|bw|cin|cr2|crw|dcr|dng|dib|dpx|eps|erf|exr|gif|hdr|icb|iff|jpe|jpeg|jpg|mos|mrw|nef|orf|pbm|pef|pct|pcx|pdf|pic|pict|png|ps|psd|pxr|raf|raw|rgb|rgbe|rla|rle|rpf|sgi|srf|tdi|tga|tif|tiff|vda|vst|x3f|xyze)', 'i'); $.layer.extend($.layer.prototype, { getLayerAttr: function getLayerAttr(index) { @@ -904,10 +905,20 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol layerInfo.solidColor = mainSource.color; } else if (mainSource instanceof FileSource && !isNullLayer && !isComp) { layerInfo.sound = thisLayer.hasAudio; - if (layerInfo.sound) { + + if (thisLayer.hasAudio) { layerInfo.type = 'VideoWithSound'; } else { - layerInfo.type = 'VideoWithoutSound'; + var suffix = mainSource.file.toString() || ''; + var matched = suffix.split('.').pop(); + if (mainSource.isStill === true) { + layerInfo.type = 'VideoWithoutSound'; + } else if (matched) { + layerInfo.type = 'VideoWithoutSound'; + layerInfo.sequence = 'true'; + } else { + layerInfo.type = 'VideoWithoutSound'; + } } } else if (isComp) { layerInfo.type = 'Comp'; @@ -1014,7 +1025,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol return layerInfo; }, - getMaterial: function getMaterial(layerInfo, helperObj, thisLayer) { + getMaterial: function getMaterial(layerInfo, helperObj, thisLayer, isSequence) { var file = layerInfo.file = thisLayer.source.mainSource.file; if (this.isSaveMaterial === false) return layerInfo; @@ -1029,6 +1040,24 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol var fileContent = thisFile.read(); thisFile.close(); layerInfo.fileBin = encode(fileContent); + if (layerInfo.sequence.toString() === 'true') { + var fileArr = $.layer.testForSequence(thisFile); + if (fileArr.length !== 0) { + var outter = new XML(''); + + $.layer.forEach.call(fileArr, function (sequenceFile, index) { + try { + var tempXmlBigHere = new XML('' + encode(sequenceFile.name) + ''); + + var temp = new XML(''); + temp.appendChild(tempXmlBigHere); + + outter.appendChild(temp); + } catch (err) {} + }); + layerInfo.fileBinSeq = outter; + } + } } catch (err) {} } catch (err) {} } @@ -1846,6 +1875,13 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol } } if (layer instanceof AVLayer) { + try { + if (xml.sequence.toString() === 'true') { + layer.source.replaceWithSequence(new File(xml.file.toString()), false); + } + } catch (err) { + $.writeln(err.toString()); + } return layer; } else { layer = thisComp.layers.addSolid([0, 0, 0], 'fail due to not instanceof AVLayer', 100, 100, 1); @@ -2723,6 +2759,25 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol $.layer.errorInfoArr = []; }; + $.layer.testForSequence = function (file) { + var searcher = new RegExp('\\d{4,}'); + var files = file.parent.getFiles(); + var defaultResult = searcher.exec(file.name); + if (!defaultResult) return []; + var prefix = file.name.replace(defaultResult[0], ''); + var finalFiles = []; + for (var i = 0; i < files.length; i++) { + var currentResult = searcher.exec(files[i].name); + if (currentResult) { + var testName = files[i].name.replace(currentResult[0], ''); + if (testName === prefix) { + finalFiles.push(files[i]); + } + } + } + return finalFiles; + }; + $.layer.writeErrorFile = function () { var file = new File($.layer.tempFolder.toString() + $.layer.slash.toString() + 'error.txt'); if ($.layer.errorInfoArr.length === 0) { @@ -6509,7 +6564,6 @@ module.exports = function () { } var xml = sp.getXmlFromLayers(thisComp.selectedLayers, itemName, sp); - sp.saveItemToFile(sp.getFileByName(sp.droplist.selection.text), xml); var item = sp.gv.add(decodeURIComponent(itemName), sp.getImage(sp.droplist.selection.text, itemName)); @@ -6846,8 +6900,7 @@ module.exports = function () { sp.parentDroplist.size.height = sp.droplist.size.height; sp.parentDroplist.location.y = 0; sp.parentDroplist.itemSize.width = (parentDroplistWidth - 27 * scale) / scale; - var screen = $.screens[0].toString().split('-').pop().split(':'); - sp.droplist.maximumSize = sp.parentDroplist.maximumSize = [undefined, parseInt(screen[1]) - 100]; + sp.gv.refresh(); }; this.winClose = function () { diff --git a/lib/AfterEffectsLayer.js b/lib/AfterEffectsLayer.js index 2cd760c..7ee2eb6 100644 --- a/lib/AfterEffectsLayer.js +++ b/lib/AfterEffectsLayer.js @@ -48,6 +48,7 @@ } } + const imagePattern = new RegExp('(ai|bmp|bw|cin|cr2|crw|dcr|dng|dib|dpx|eps|erf|exr|gif|hdr|icb|iff|jpe|jpeg|jpg|mos|mrw|nef|orf|pbm|pef|pct|pcx|pdf|pic|pict|png|ps|psd|pxr|raf|raw|rgb|rgbe|rla|rle|rpf|sgi|srf|tdi|tga|tif|tiff|vda|vst|x3f|xyze)', 'i') $.layer.extend($.layer.prototype, { getLayerAttr: function(index) { @@ -78,10 +79,20 @@ layerInfo.solidColor = mainSource.color } else if (mainSource instanceof FileSource && !isNullLayer && !isComp) { layerInfo.sound = thisLayer.hasAudio - if (layerInfo.sound) { + // alert(typeof layerInfo.sound) + if (thisLayer.hasAudio) { layerInfo.type = 'VideoWithSound' } else { - layerInfo.type = 'VideoWithoutSound' + var suffix = mainSource.file.toString() || '' + var matched = suffix.split('.').pop() + if (mainSource.isStill === true) { + layerInfo.type = 'VideoWithoutSound' + } else if (matched) { + layerInfo.type = 'VideoWithoutSound' + layerInfo.sequence = 'true' + } else { + layerInfo.type = 'VideoWithoutSound' + } } } else if (isComp) { layerInfo.type = 'Comp' @@ -93,7 +104,7 @@ layerInfo.type = 'Camera' break } - + // alert(layerInfo.type) layerInfo.name = thisLayer.name layerInfo['@type'] = layerInfo.type @@ -188,7 +199,7 @@ return layerInfo }, - getMaterial: function(layerInfo, helperObj, thisLayer) { + getMaterial: function(layerInfo, helperObj, thisLayer, isSequence) { var file = layerInfo.file = thisLayer.source.mainSource.file if (this.isSaveMaterial === false) return layerInfo @@ -203,6 +214,32 @@ var fileContent = thisFile.read() thisFile.close() layerInfo.fileBin = encode(fileContent) + if (layerInfo.sequence.toString() === 'true') { + // alert('上天套餐') + var fileArr = $.layer.testForSequence(thisFile) + if (fileArr.length !== 0) { + var outter = new XML('') + // var j = 0 + $.layer.forEach.call(fileArr, function(sequenceFile, index) { + // $.writeln('??') + try { + // sequenceFile.open('r') + // sequenceFile.encoding = 'BINARY' + // var content = encode(sequenceFile.read()) + // sequenceFile.close() + var tempXmlBigHere = new XML('' + encode(sequenceFile.name) + '') + // var tempXmlHeres = new XML('' + content + '') + var temp = new XML('') + temp.appendChild(tempXmlBigHere) + // temp.appendChild(tempXmlHeres) + outter.appendChild(temp) + // j += content.length + // $.writeln(j) + } catch (err) {} + }) + layerInfo.fileBinSeq = outter + } + } } catch (err) { } } catch (err) { } } @@ -984,6 +1021,11 @@ } catch (err) { $.layer.errorInfoArr.push({ line: $.line, error: err }) } } if (layer instanceof AVLayer) { + try { + if (xml.sequence.toString() === 'true') { + layer.source.replaceWithSequence(new File(xml.file.toString()), false) + } + } catch (err) { $.writeln(err.toString()) } return layer } else { layer = thisComp.layers.addSolid([0, 0, 0], 'fail due to not instanceof AVLayer', 100, 100, 1) @@ -1812,6 +1854,25 @@ $.layer.errorInfoArr = [] } + $.layer.testForSequence = function(file) { + var searcher = new RegExp('\\d{4,}') + var files = file.parent.getFiles() + var defaultResult = searcher.exec(file.name) + if (!defaultResult) return [] + var prefix = file.name.replace(defaultResult[0], '') + var finalFiles = [] + for (var i = 0; i < files.length; i++) { + var currentResult = searcher.exec(files[i].name) + if (currentResult) { + var testName = files[i].name.replace(currentResult[0], '') + if (testName === prefix) { + finalFiles.push(files[i]) + } + } + } + return finalFiles + } + $.layer.writeErrorFile = function() { var file = new File($.layer.tempFolder.toString() + $.layer.slash.toString() + 'error.txt') if ($.layer.errorInfoArr.length === 0) { diff --git a/src/ui/function.js b/src/ui/function.js index e3f4ea7..1c2fe1a 100644 --- a/src/ui/function.js +++ b/src/ui/function.js @@ -430,7 +430,6 @@ module.exports = function() { } var xml = sp.getXmlFromLayers(thisComp.selectedLayers, itemName, sp) - sp.saveItemToFile(sp.getFileByName(sp.droplist.selection.text), xml) var item = sp.gv.add(decodeURIComponent(itemName), sp.getImage(sp.droplist.selection.text, itemName)) @@ -746,8 +745,10 @@ module.exports = function() { sp.parentDroplist.size.height = sp.droplist.size.height sp.parentDroplist.location.y = 0 // fix margin error for mac sp.parentDroplist.itemSize.width = (parentDroplistWidth - 27 * scale) / scale - var screen = $.screens[0].toString().split('-').pop().split(':') - sp.droplist.maximumSize = sp.parentDroplist.maximumSize = [undefined, parseInt(screen[1]) - 100] + // var screen = $.screens[0].toString().split('-').pop().split(':') + // var max = parseInt(screen[1]) - 500 + // if (sp.droplist.size[1] >= max) sp.droplist.size[1] = max + // if (sp.parentDroplist.size[1] >= max) sp.parentDroplist.size[1] = max sp.gv.refresh() } this.winClose = function() {