-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload2.jsfl
More file actions
344 lines (264 loc) · 8.67 KB
/
Copy pathload2.jsfl
File metadata and controls
344 lines (264 loc) · 8.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/* *********************************************************
*
* Copyright (c) 2005, Southpaw Technology
* All Rights Reserved
*
* PROPRIETARY INFORMATION. This software is proprietary to
* Southpaw Technolog, and is not to be reproduced, transmitted,
* or disclosed in any way without written permission.
*
*/
function include(file, base_dir)
{
try {
var contents = FLfile.read("file:///" + base_dir + "/" + file )
eval( contents )
} catch (err) {
fl.trace(err)
}
}
/*
* Initialize the session
*/
function init_session(load_mode, prefix_mode, log_path, sandbox_path)
{
// completely create a new set of documents
fl.trace(load_mode)
if (load_mode == "new")
{
fl.closeAll()
fl.createDocument()
}
// create a new document
else if (load_mode == "simple")
{
// create the folder for sandbox
FLfile.createFolder("file:///" + sandbox_path)
}
// if load mode is merge, then don't create a new document
else
{
// do nothing
}
my_load_info.load_mode = load_mode
my_load_info.prefix_mode = prefix_mode
my_load_info.log_path = log_path
my_load_info.sandbox_path = sandbox_path
}
function setup_doc(tmpl_path)
{
var dst_doc = fl.getDocumentDOM()
if (dst_doc == null)
{
if (tmpl_path == null)
dst_doc = fl.createDocument()
else
{
var new_tmpl_path = tmpl_path.replace('.fla', '_tactic.fla')
names = new_tmpl_path.split("/")
var new_tmpl_name = names[names.length - 1]
// copy the tmpl file as something else first since
// it will always get written over on next load
// create the folder for sandbox
FLfile.createFolder("file:///" + my_load_info.sandbox_path)
// TODO: copy to somewhere in the sandbox
new_tmpl_path = my_load_info.sandbox_path + '/' + new_tmpl_name
var dst_URI = "file:///" + new_tmpl_path
if (FLfile.exists(dst_URI))
FLfile.remove(dst_URI)
FLfile.copy("file:///" + tmpl_path, dst_URI)
//fl.trace("opening " + new_tmpl_path )
dst_doc = fl.openDocument(dst_URI)
}
}
return dst_doc
}
/*
* Load an asset into a session
*/
function load_asset(src_path, tmpl_path, layer_name)
{
var common = new Common()
if (my_load_info.load_mode == 'simple')
{
var dst_URI = "file:///" + my_load_info.sandbox_path + '/' + layer_name + '_tactic.fla'
// remove the old one before copying
if (FLfile.exists(dst_URI))
FLfile.remove(dst_URI)
FLfile.copy("file:///" + src_path, dst_URI)
fl.openDocument(dst_URI)
common.exit("Loaded [" + layer_name + "]", my_load_info.log_path)
return
}
// else handle merge mode
// if a template is given open the template, otherwise create a new doc
var dst_doc = setup_doc(tmpl_path)
var src_uri = "file:///" + src_path
if ( FLfile.exists(src_uri) == false)
{
common.exit("File '" + src_path + "' does not exist", my_load_info.log_path)
return
}
// open the src_path
src_doc = fl.openDocument(src_uri)
// get the timelines
src_timeline = src_doc.getTimeline()
// copy the asset over
// TO BE REMOVED: use source's first layer name if load_mode is not merge
// if (my_load_info.load_mode != 'merge')
// layer_name = src_timeline.layers[0].name
common.copy_layers( src_doc, dst_doc, layer_name)
common.match_symbol_folders( src_doc.library, dst_doc.library)
src_doc.close(false)
fl.setActiveWindow(dst_doc)
common.exit("Loaded [" + layer_name + "]", my_load_info.log_path)
}
/* import an asset, expects an image or supported video file */
function import_asset(src_path, tmpl_path, layer_name)
{
var cur_doc = setup_doc(tmpl_path)
timeline = cur_doc.getTimeline()
var common = new Common()
idx = common.create_layer(layer_name, timeline, true)
//if (timeline.frameCount < 1)
// timeline.insertFrames()
timeline.setSelectedFrames(0,1)
// it doesn't really return a value, so we can't check for success
document.importFile("file:///" + src_path)
common.exit("Imported [" + layer_name + "]", my_load_info.log_path)
}
/*
* Import a bunch of frames in a selected directory into the session
*/
function import_leica( src_path, layer_name, start_frame, end_frame )
{
var padding = 4
//TODO: hard code start_frame to 1
var by_frame = 2
start_frame = 1
end_frame = end_frame
var cur_doc = fl.getDocumentDOM()
if (cur_doc == null)
{
cur_doc = fl.createDocument()
}
var timeline = cur_doc.getTimeline()
var library = cur_doc.library
var layers = timeline.layers
// add the appropriate frames in the timeline
for (var i = 0; i < layers.length; i++) {
timeline.setSelectedLayers(i)
timeline.setSelectedFrames(end_frame-2, end_frame-2)
timeline.insertFrames()
}
// add a new Leica layer
timeline.addNewLayer(layer_name)
library.newFolder(layer_name)
leica_index = timeline.findLayerIndex(layer_name)[0]
leica_layer = timeline.layers[leica_index]
// import the leica
for (var i=start_frame; i < end_frame; i += by_frame) {
var idx = i - 1
if (idx < 0) idx = 0
timeline.setSelectedFrames(idx, idx)
frame = new String(i)
digits = frame.length
padded_frame = ""
for (var j = 0; j < padding - digits; j++) {
padded_frame += 0
}
padded_frame += frame
var place_holder = ""
for (var j = 0; j < padding; j++) {
place_holder += "#"
}
path = src_path.replace(place_holder, padded_frame)
path_uri = "file:///" + path
if ( FLfile.exists(path_uri) == false)
{
fl.trace("WARNING: path '" + path + "' does not exist")
continue
}
document.importFile(path_uri)
// scale the element
var scale = 6.4
var element = leica_layer.frames[idx].elements[0]
var matrix = element.matrix
matrix.a = matrix.a * scale
matrix.d = matrix.d * scale
matrix.tx = 0
matrix.ty = 0
element.matrix = matrix
// move the symbols to a Leica folder
last_item = library.items[library.items.length-1]
library.moveToFolder(layer_name, last_item.name)
}
fl.trace("loaded frames: " + start_frame + " to " + end_frame)
}
function import_audio(audio_path, layer_name)
{
// extract the audio file
audio_path_parts = audio_path.split("/")
var audio_file = audio_path_parts[audio_path_parts.length-1]
var cur_doc = fl.getDocumentDOM()
if (cur_doc == null)
{
fl.trace("cur_doc is null")
cur_doc = fl.createDocument()
}
// import audio
timeline = cur_doc.getTimeline()
library = cur_doc.library
// find the layer: if it does not exist, then create it
layer_idx = timeline.findLayerIndex(layer_name)
if (layer_idx == null)
timeline.addNewLayer(layer_name)
library.newFolder(layer_name)
timeline.setSelectedFrames(1,1)
document.importFile("file:///" + audio_path)
library.selectItem(audio_file)
library.addItemToDocument({x:0,y:0},audio_file)
library.newFolder(layer_name)
last_item = library.items[library.items.length-1]
library.moveToFolder(layer_name, last_item.name)
fl.trace("imported " + audio_file)
}
// TODO: this should be a custom post_stage script
function post_stage()
{
// FIXME: BIG HACK
// this is harmelss if there is no "Audio" layer
var cur_doc = fl.getDocumentDOM()
var timeline = cur_doc.getTimeline()
var layers = timeline.layers
// move layers below the guide layer
var guide_idx = 0
for (var i = 0; i < layers.length; i++ ) {
layer = layers[i]
if (layer.layerType == "guide") {
guide_idx = i
break
}
}
// move all the new layers below the guide layer
for (var i = 0; i < guide_idx; i++ ) {
layer = layers[i]
timeline.setSelectedLayers(i, true)
timeline.setSelectedFrames(timeline.frameCount-1, timeline.frameCount-1)
timeline.insertFrames()
timeline.reorderLayer(i, guide_idx+1)
}
// set some default parameters
fl.getDocumentDOM().height = 720;
fl.getDocumentDOM().width= 1280;
fl.getDocumentDOM().frameRate = 24;
}
function reset_document()
{
fl.closeAll()
fl.createDocument()
}
function close_docs()
{
fl.closeAll()
}