-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_Project.js.html
1663 lines (1421 loc) · 52.3 KB
/
base_Project.js.html
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: base/Project.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: base/Project.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/*
* Copyright 2020 WICKLETS LLC
*
* This file is part of Wick Engine.
*
* Wick Engine is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Wick Engine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wick Engine. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Class representing a Wick Project.
*/
Wick.Project = class extends Wick.Base {
/**
* Create a project.
* @param {string} name - Project name. Default "My Project".
* @param {number} width - Project width in pixels. Default 720.
* @param {number} height - Project height in pixels. Default 405.
* @param {number} framerate - Project framerate in frames-per-second. Default 12.
* @param {Color} backgroundColor - Project background color in hex. Default #ffffff.
*/
constructor (args) {
if(!args) args = {};
super(args);
this._name = args.name || 'My Project';
this._width = args.width || 720;
this._height = args.height || 405;
this._framerate = args.framerate || 12;
this._backgroundColor = args.backgroundColor || new Wick.Color('#ffffff');
this.pan = {x: 0, y: 0};
this.zoom = 1.0;
this.rotation = 0.0;
this.onionSkinEnabled = false;
this.onionSkinSeekBackwards = 1;
this.onionSkinSeekForwards = 1;
this.selection = new Wick.Selection();
this.history = new Wick.History();
this.clipboard = new Wick.Clipboard();
this.root = new Wick.Clip();
this.root._identifier = 'Project';
this.focus = this.root;
this._mousePosition = {x:0, y:0};
this._lastMousePosition = {x:0, y:0};
this._isMouseDown = false;
this._mouseTargets = [];
this._keysDown = [];
this._keysLastDown = [];
this._currentKey = null;
this._tickIntervalID = null;
this._hideCursor = false;
this._muted = false;
this._publishedMode = false;
this._showClipBorders = true;
this._userErrorCallback = () => {};
this._tools = {
brush: new Wick.Tools.Brush(),
cursor: new Wick.Tools.Cursor(),
ellipse: new Wick.Tools.Ellipse(),
eraser: new Wick.Tools.Eraser(),
eyedropper: new Wick.Tools.Eyedropper(),
fillbucket: new Wick.Tools.FillBucket(),
interact: new Wick.Tools.Interact(),
line: new Wick.Tools.Line(),
none: new Wick.Tools.None(),
pan: new Wick.Tools.Pan(),
pathcursor: new Wick.Tools.PathCursor(),
pencil: new Wick.Tools.Pencil(),
rectangle: new Wick.Tools.Rectangle(),
text: new Wick.Tools.Text(),
zoom: new Wick.Tools.Zoom(),
};
for(var toolName in this._tools) {
this._tools[toolName].project = this;
}
this.activeTool = 'cursor';
this._toolSettings = new Wick.ToolSettings();
this._toolSettings.onSettingsChanged((name, value) => {
if(name === 'fillColor') {
this.selection.fillColor = value.rgba;
} else if (name === 'strokeColor') {
this.selection.strokeColor = value.rgba;
}
});
this._playing = false;
this._scriptSchedule = [];
this._error = null;
this.history.project = this;
this.history.pushState(Wick.History.StateType.ONLY_VISIBLE_OBJECTS);
}
/**
* Used to initialize the state of elements within the project. Should only be called after
* deserialization of project and all objects within the project.
*/
initialize () {
// Fixing all clip positions... This should be done in an internal method when the project is done loading...
this.activeFrame.clips.forEach(clip => {
clip.applySingleFramePosition();
});
}
_deserialize (data) {
super._deserialize(data);
this.name = data.name;
this.width = data.width;
this.height = data.height;
this.framerate = data.framerate;
this.backgroundColor = new Wick.Color(data.backgroundColor);
this._focus = data.focus;
this._hideCursor = false;
this._muted = false;
this._renderBlackBars = true;
// reset rotation, but not pan/zoom.
// not resetting pan/zoom is convenient when preview playing.
this.rotation = 0;
}
_serialize (args) {
var data = super._serialize(args);
data.name = this.name;
data.width = this.width;
data.height = this.height;
data.backgroundColor = this.backgroundColor.rgba;
data.framerate = this.framerate;
data.onionSkinEnabled = this.onionSkinEnabled
data.onionSkinSeekForwards = this.onionSkinSeekForwards;
data.onionSkinSeekBackwards = this.onionSkinSeekBackwards;
data.focus = this.focus.uuid;
// Save some metadata which will eventually end up in the wick file
data.metadata = Wick.WickFile.generateMetaData();
return data;
}
get classname () {
return 'Project';
}
/**
* Assign a function to be called when a user error happens (not script
* errors - errors such as drawing tool errors, invalid selection props, etc)
* @param {Function} fn - the function to call when errors happen
*/
onError (fn) {
this._userErrorCallback = fn;
}
/**
* Called when an error occurs to forward to the onError function
* @param {String} message - the message to display for the error
*/
errorOccured (message) {
this._userErrorCallback(message);
}
/**
* The width of the project.
* @type {number}
*/
get width () {
return this._width;
}
set width (width) {
if(typeof width !== 'number') return;
if(width < 1) width = 1;
if(width > 200000) width = 200000;
this._width = width;
}
/**
* The height of the project.
* @type {number}
*/
get height () {
return this._height;
}
set height (height) {
if(typeof height !== 'number') return;
if(height < 1) height = 1;
if(height > 200000) height = 200000;
this._height = height;
}
/**
* The framerate of the project.
* @type {number}
*/
get framerate () {
return this._framerate;
}
set framerate (framerate) {
if(typeof framerate !== 'number') return;
if(framerate < 1) framerate = 1;
if(framerate > 9999) framerate = 9999;
this._framerate = framerate;
}
/**
* The background color of the project.
* @type {string}
*/
get backgroundColor () {
return this._backgroundColor;
}
set backgroundColor (backgroundColor) {
this._backgroundColor = backgroundColor;
}
/**
* The timeline of the active clip.
* @type {Wick.Timeline}
*/
get activeTimeline () {
return this.focus.timeline;
}
/**
* The active layer of the active timeline.
* @type {Wick.Layer}
*/
get activeLayer () {
return this.activeTimeline.activeLayer;
}
/**
* The active frame of the active layer.
* @type {Wick.Frame}
*/
get activeFrame () {
return this.activeLayer.activeFrame;
}
/**
* The active frames of the active timeline.
* @type {Wick.Frame[]}
*/
get activeFrames () {
return this.focus.timeline.activeFrames;
}
/**
* All frames in this project.
* @type {Wick.Frame[]}
*/
getAllFrames () {
return this.root.timeline.getAllFrames(true);
}
/**
* The project selection.
* @type {Wick.Selection}
*/
get selection () {
return this.getChild('Selection');
}
set selection (selection) {
if(this.selection) {
this.removeChild(this.selection);
}
this.addChild(selection);
}
/**
* An instance of the Wick.History utility class for undo/redo functionality.
* @type {Wick.History}
*/
get history () {
return this._history;
}
set history (history) {
this._history = history;
}
/**
* Undo the last action.
* @returns {boolean} true if there was something to undo, false otherwise.
*/
undo () {
// Undo discards in-progress brush strokes.
if (this._tools.brush.isInProgress()) {
this._tools.brush.discard();
return true;
}
this.selection.clear();
var success = this.project.history.popState();
return success;
}
/**
* Redo the last action that was undone.
* @returns {boolean} true if there was something to redo, false otherwise.
*/
redo () {
this.selection.clear();
var success = this.project.history.recoverState();
return success;
}
/**
* The assets belonging to the project.
* @type {Wick.Asset[]}
*/
get assets () {
return this.getChildren(['ImageAsset','SoundAsset','ClipAsset','FontAsset']);
}
/**
* Adds an asset to the project.
* @param {Wick.Asset} asset - The asset to add to the project.
*/
addAsset (asset) {
if(this.assets.indexOf(asset) === -1) {
this.addChild(asset);
}
}
/**
* Removes an asset from the project. Also removes all instances of that asset from the project.
* @param {Wick.Asset} asset - The asset to remove from the project.
*/
removeAsset (asset) {
asset.removeAllInstances();
this.removeChild(asset);
}
/**
* Retrieve an asset from the project by its UUID.
* @param {string} uuid - The UUID of the asset to get.
* @return {Wick.Asset} The asset
*/
getAssetByUUID (uuid) {
var asset = this.getAssets().find(asset => {
return asset.uuid === uuid;
});
if(asset) {
return asset;
} else {
console.warn('Wick.Project.getAssetByUUID: No asset found with uuid ' + uuid);
}
}
/**
* Retrieve an asset from the project by its name.
* @param {string} name - The name of the asset to get.
* @return {Wick.Asset} The asset
*/
getAssetByName (name) {
return this.getAssets().find(asset => {
return asset.name === name;
});
}
/**
* The assets belonging to the project.
* @param {string} type - Optional, filter assets by type ("Sound"/"Image"/"Clip"/"Button")
* @returns {Wick.Asset[]} The assets in the project
*/
getAssets (type) {
if(!type) {
return this.assets;
} else {
return this.assets.filter(asset => {
return asset instanceof Wick[type+'Asset'];
});
}
}
/**
* A list of all "fontFamily" in the asset library.
* @returns {string[]}
*/
getFonts () {
return this.getAssets('Font').map(asset => {
return asset.fontFamily;
});
}
/**
* Check if a FontAsset with a given fontFamily exists in the project.
* @param {string} fontFamily - The font to check for
* @returns {boolean}
*/
hasFont (fontFamily) {
return this.getFonts().find(seekFontFamily => {
return seekFontFamily === fontFamily;
}) !== undefined;
}
/**
* The root clip.
* @type {Wick.Clip}
*/
get root () {
return this.getChild('Clip');
}
set root (root) {
if(this.root) {
this.removeChild(this.root);
}
this.addChild(root);
}
/**
* The currently focused clip.
* @type {Wick.Clip}
*/
get focus () {
return this._focus && Wick.ObjectCache.getObjectByUUID(this._focus);
}
set focus (focus) {
var focusChanged = this.focus !== null && this.focus !== focus;
this._focus = focus.uuid;
if(focusChanged) {
this.selection.clear();
// Reset timelines of subclips of the newly focused clip
focus.timeline.clips.forEach(subclip => {
subclip.timeline.playheadPosition = 1;
subclip.applySingleFramePosition(); // Make sure to visualize single frame clips properly.
});
// Reset pan and zoom and clear selection on focus change
this.resetZoomAndPan();
} else {
// Make sure the single frame
focus.timeline.clips.forEach(subclip => {
subclip.applySingleFramePosition();
});
}
}
/**
* The position of the mouse
* @type {object}
*/
get mousePosition () {
return this._mousePosition;
}
set mousePosition (mousePosition) {
this._lastMousePosition = {x:this.mousePosition.x, y:this.mousePosition.y};
this._mousePosition = mousePosition;
}
/**
* The amount the mouse has moved in the last tick
* @type {object}
*/
get mouseMove () {
let moveX = this.mousePosition.x - this._lastMousePosition.x;
let moveY = this.mousePosition.y - this._lastMousePosition.y;
return {x: moveX, y: moveY};
}
/**
* Determine if the mouse is down.
* @type {boolean}
*/
get isMouseDown () {
return this._isMouseDown;
}
set isMouseDown (isMouseDown) {
this._isMouseDown = isMouseDown;
}
/**
* The keys that are currenty held down.
* @type {string[]}
*/
get keysDown () {
return this._keysDown;
}
set keysDown (keysDown) {
this._keysDown = keysDown;
}
/**
* The keys were just pressed (i.e., are currently held down, but were not last tick).
* @type {string[]}
*/
get keysJustPressed () {
// keys that are in _keysDown, but not in _keysLastDown
return this._keysDown.filter(key => {
return this._keysLastDown.indexOf(key) === -1;
});
}
/**
* The keys that were just released (i.e. were down last tick back are no longer down.)
* @return {string[]}
*/
get keysJustReleased () {
return this._keysLastDown.filter(key => {
return this._keysDown.indexOf(key) === -1;
});
}
/**
* Check if a key is being pressed.
* @param {string} key - The name of the key to check
*/
isKeyDown (key) {
return this.keysDown.indexOf(key) !== -1;
}
/**
* Check if a key was just pressed.
* @param {string} key - The name of the key to check
*/
isKeyJustPressed (key) {
return this.keysJustPressed.indexOf(key) !== -1;
}
/**
* The key to be used in the global 'key' variable in the scripting API. Update currentKey before you run any key script.
* @type {string[]}
*/
get currentKey () {
return this._currentKey;
}
set currentKey (currentKey) {
this._currentKey = currentKey;
}
/**
* Creates an asset from a File object and adds that asset to the project.
* @param {File} file - File object to be read and converted into an asset.
* @param {function} callback Function with the created Wick Asset. Can be passed undefined on improper file input.
*/
importFile (file, callback) {
let imageTypes = Wick.ImageAsset.getValidMIMETypes();
let soundTypes = Wick.SoundAsset.getValidMIMETypes();
let fontTypes = Wick.FontAsset.getValidMIMETypes();
let clipTypes = Wick.ClipAsset.getValidMIMETypes();
// Fix missing mimetype for wickobj files
var type = file.type;
if(file.type === '' && file.name.endsWith('.wickobj')) {
type = 'application/json';
}
let asset = undefined;
if (imageTypes.indexOf(type) !== -1) {
asset = new Wick.ImageAsset();
} else if (soundTypes.indexOf(type) !== -1) {
asset = new Wick.SoundAsset();
} else if (fontTypes.indexOf(type) !== -1) {
asset = new Wick.FontAsset();
} else if (clipTypes.indexOf(type) !== -1) {
asset = new Wick.ClipAsset();
}
if (asset === undefined) {
console.warn('importFile(): Could not import file ' + file.name + ', filetype: "' + file.type + '" is not supported.');
console.warn('supported image file types:');
console.log(imageTypes)
console.warn('supported sound file types:');
console.log(soundTypes)
console.warn('supported font file types:');
console.log(fontTypes)
console.warn('supported clip file types:');
console.log(clipTypes)
callback(null);
return;
}
let reader = new FileReader();
reader.onload = () => {
let dataURL = reader.result;
asset.src = dataURL;
asset.filename = file.name;
asset.name = file.name;
this.addAsset(asset);
asset.load(() => {
callback(asset);
});
}
reader.readAsDataURL(file);
}
/**
* Deletes all objects in the selection.
*/
deleteSelectedObjects () {
var objects = this.selection.getSelectedObjects();
this.selection.clear();
this.activeTimeline.deferFrameGapResolve();
objects.forEach(object => {
object.remove && object.remove();
});
this.activeTimeline.resolveFrameGaps([]);
}
/**
* Perform a boolean operation on all selected paths.
* @param {string} booleanOpName - The name of the boolean op function to use. See Wick.Path.booleanOp.
*/
doBooleanOperationOnSelection (booleanOpName) {
var paths = this.selection.getSelectedObjects('Path');
this.selection.clear();
var booleanOpResult = Wick.Path.booleanOp(paths, booleanOpName);
paths.forEach(path => {
// Don't remove the topmost path if performing subtration
if(paths.indexOf(path) === paths.length - 1 && booleanOpName === 'subtract') {
return;
}
path.remove();
});
this.activeFrame.addPath(booleanOpResult);
this.selection.select(booleanOpResult);
}
/**
* Copy the contents of the selection to the clipboard.
* @returns {boolean} True if there was something to copy, false otherwise
*/
copySelectionToClipboard () {
var objects = this.selection.getSelectedObjects();
if(objects.length === 0) {
return false;
} else {
this.clipboard.copyObjectsToClipboard(this, objects);
return true;
}
}
/**
* Copy the contents of the selection to the clipboard, and delete what was copied.
* @returns {boolean} True if there was something to cut, false otherwise
*/
cutSelectionToClipboard () {
if(this.copySelectionToClipboard()) {
this.deleteSelectedObjects();
return true;
} else {
return false;
}
}
/**
* Paste the contents of the clipboard into the project.
* @returns {boolean} True if there was something to paste in the clipboard, false otherwise.
*/
pasteClipboardContents () {
return this.clipboard.pasteObjectsFromClipboard(this);
}
/**
* Copy and paste the current selection.
* @returns {boolean} True if there was something to duplicate, false otherwise
*/
duplicateSelection () {
if(!this.copySelectionToClipboard()) {
return false;
} else {
return this.pasteClipboardContents();
}
}
/**
* Cut the currently selected frames.
*/
cutSelectedFrames () {
this.selection.getSelectedObjects('Frame').forEach(frame => {
frame.cut();
});
}
/**
* Inserts a blank frame into the timeline at the position of the playhead.
* If the playhead is over an existing frame, that frame will be cut in half,
* and a blank frame will be added to fill the empty space created by the cut.
*/
insertBlankFrame () {
var playheadPosition = this.activeTimeline.playheadPosition;
var newFrames = [];
// Insert new frames
if(this.selection.numObjects > 0) {
// Insert frames on all frames that are both active and selected
/*this.activeTimeline.activeFrames.filter(frame => {
return frame.isSelected;
}).forEach(frame => {
newFrames.push(frame.parentLayer.insertBlankFrame(playheadPosition));
});*/
this.selection.getSelectedObjects('Frame').forEach(frame => {
newFrames.push(frame.parentLayer.insertBlankFrame(playheadPosition));
});
} else {
// Insert one frame on the active layer
newFrames.push(this.activeLayer.insertBlankFrame(playheadPosition));
}
// Select the newly added frames
this.selection.clear();
newFrames.forEach(frame => {
this.selection.select(frame);
});
}
/**
* A tween can be created if frames are selected or if there is a frame under the playhead on the active layer.
*/
get canCreateTween () {
// Frames are selected, a tween can be created
var selectedFrames = this.selection.getSelectedObjects('Frame');
if(selectedFrames.length > 0) {
// Make sure you can only create tweens on contentful frames
if(selectedFrames.find(frame => {
return !frame.contentful;
})) {
return false
} else {
return true;
}
}
// There is a frame under the playhead on the active layer, a tween can be created
var activeFrame = this.activeLayer.activeFrame;
if(activeFrame) {
// ...but only if that frame is contentful
return activeFrame.contentful;
}
return false;
}
/**
* Create a new tween on all selected frames OR on the active frame of the active layer.
*/
createTween () {
var selectedFrames = this.selection.getSelectedObjects('Frame');
if(selectedFrames.length > 0) {
// Create a tween on all selected frames
this.selection.getSelectedObjects('Frame').forEach(frame => {
frame.createTween();
});
} else {
// Create a tween on the active frame
this.activeLayer.activeFrame.createTween();
}
}
/**
* Tries to create a tween if there is an empty space between tweens.
*/
tryToAutoCreateTween () {
var frame = this.activeFrame;
if(frame.tweens.length > 0 && !frame.getTweenAtPosition(frame.getRelativePlayheadPosition())) {
frame.createTween();
}
}
/**
* Move the right edge of all frames right one frame.
*/
extendFrames (frames) {
frames.forEach(frame => {
frame.end ++;
});
this.activeTimeline.resolveFrameOverlap(frames);
this.activeTimeline.resolveFrameGaps(frames);
}
/**
* Move the right edge of all frames right one frame, and push other frames away.
*/
extendFramesAndPushOtherFrames (frames) {
frames.forEach(frame => {
frame.extendAndPushOtherFrames();
});
}
/**
* Move the right edge of all frames left one frame.
*/
shrinkFrames (frames) {
frames.forEach(frame => {
if(frame.length === 1) return;
frame.end --;
});
this.activeTimeline.resolveFrameOverlap(frames);
this.activeTimeline.resolveFrameGaps(frames);
}
/**
* Move the right edge of all frames left one frame, and pull other frames along.
*/
shrinkFramesAndPullOtherFrames (frames) {
frames.forEach(frame => {
frame.shrinkAndPullOtherFrames();
});
}
/**
* Shift all selected frames over one frame to the right
*/
moveSelectedFramesRight () {
var frames = this.selection.getSelectedObjects('Frame');
frames.forEach(frame => {
frame.end ++;
frame.start ++;
});
this.activeTimeline.resolveFrameOverlap(frames);
this.activeTimeline.resolveFrameGaps();
}
/**
* Shift all selected frames over one frame to the left
*/
moveSelectedFramesLeft () {
var frames = this.selection.getSelectedObjects('Frame');
frames.forEach(frame => {
frame.start --;
frame.end --;
});
this.activeTimeline.resolveFrameOverlap(frames);
this.activeTimeline.resolveFrameGaps();
}
/**
* Selects all objects that are visible on the canvas (excluding locked layers and onion skinned objects)
*/
selectAll () {
this.selection.clear();
this.activeFrames.filter(frame => {
return !frame.parentLayer.locked
&& !frame.parentLayer.hidden;
}).forEach(frame => {
frame.paths.forEach(path => {
this.selection.select(path);
});
frame.clips.forEach(clip => {
this.selection.select(clip);
});
});
}
/**
* Adds an image path to the active frame using a given asset as its image src.
* @param {Wick.Asset} asset - the asset to use for the image src
* @param {number} x - the x position to create the image path at
* @param {number} y - the y position to create the image path at
* @param {function} callback - the function to call after the path is created.
*/
createImagePathFromAsset (asset, x, y, callback) {
asset.createInstance(path => {
this.activeFrame.addPath(path);
path.x = x;
path.y = y;
callback(path);
});
}
/**
* Adds an instance of a clip asset to the active frame.
* @param {Wick.Asset} asset - the asset to create the clip instance from
* @param {number} x - the x position to create the image path at
* @param {number} y - the y position to create the image path at
* @param {function} callback - the function to call after the path is created.
*/
createClipInstanceFromAsset (asset, x, y, callback) {
asset.createInstance(clip => {
this.activeFrame.addPath(clip);
clip.x = x;
clip.y = y;
callback(clip);
}, this);
}
/**
* Creates a symbol from the objects currently selected.
* @param {string} identifier - the identifier to give the new symbol
* @param {string} type - "Clip" or "Button"
*/
createClipFromSelection (args) {
if(!args) {
args = {};
};
if(args.type !== 'Clip' && args.type !== 'Button') {
console.error('createClipFromSelection: invalid type: ' + args.type);
return;
}
var clip = new Wick[args.type]({
identifier: args.identifier,
objects: this.selection.getSelectedObjects('Canvas'),
transformation: new Wick.Transformation({
x: this.selection.x + this.selection.width/2,
y: this.selection.y + this.selection.height/2,
}),
});
this.activeFrame.addClip(clip);
// TODO add to asset library
this.selection.clear();
this.selection.select(clip);
}
/**
* Breaks selected clips into their children clips and paths.
*/
breakApartSelection () {
var leftovers = [];
var clips = this.selection.getSelectedObjects('Clip');
this.selection.clear();
clips.forEach(clip => {
leftovers = leftovers.concat(clip.breakApart());
});
leftovers.forEach(object => {
this.selection.select(object);