Skip to content

Commit ea8a1da

Browse files
committed
add accessors for oDrawing and oElement to get the synched elements/synched drawings with current drawing/element
1 parent 8f5e28b commit ea8a1da

File tree

5 files changed

+101
-27
lines changed

5 files changed

+101
-27
lines changed

openHarmony/openHarmony_column.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ Object.defineProperty($.oColumn.prototype, 'subColumns', {
213213

214214
/**
215215
* The type of easing used by the column
216-
* @name $.oColumn#subColumns
216+
* @name $.oColumn#easeType
217217
* @readonly
218218
* @type {object}
219219
*/
@@ -498,8 +498,6 @@ $.oColumn.prototype.interpolateValueAtFrame = function(percentage, frameNumber){
498498
if (typeof frameNumber === 'undefined') var frameNumber = this.$.scn.currentFrame;
499499
if (typeof percentage === 'undefined') var percentage = 50;
500500

501-
$.log(frameNumber)
502-
$.log(this.frames[frameNumber])
503501
var _frame = this.frames[frameNumber];
504502
var _leftKey = _frame.keyframeLeft;
505503
var _rightKey = _frame.keyframeRight;
@@ -578,7 +576,12 @@ $.oDrawingColumn.prototype.constructor = $.oColumn;
578576
*/
579577
Object.defineProperty($.oDrawingColumn.prototype, 'element', {
580578
get : function(){
581-
return new this.$.oElement(column.getElementIdOfDrawing( this.uniqueName), this);
579+
// get info about synched layer if the column is fetched from the attribute (which is the case most of the time)
580+
var _synchedLayer = null;
581+
if (this.attributeObject){
582+
_synchedLayer = this.attributeObject.layer.getValue();
583+
}
584+
return new this.$.oElement(column.getElementIdOfDrawing( this.uniqueName), _synchedLayer, this);
582585
},
583586

584587
set : function(oElementObject){

openHarmony/openHarmony_drawing.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ $.oDrawing = function (name, synchedLayer, oElementObject) {
7474
this._key = Drawing.Key({
7575
elementId: oElementObject.id,
7676
exposure: name
77-
});
77+
});
7878
}
7979

8080
this._overlay = new this.$.oArtLayer(3, this);
@@ -430,6 +430,26 @@ Object.defineProperty($.oDrawing.prototype, 'drawingData', {
430430
})
431431

432432

433+
/**
434+
* The drawings of the same name in other elements synched with this one.
435+
* @name $.oDrawing#synchedDrawing
436+
* @type {$.oDrawing[]}
437+
* @readonly
438+
* @private
439+
*/
440+
Object.defineProperty($.oDrawing.prototype, 'synchedDrawings', {
441+
get: function () {
442+
var _syncedElements = this.element.synchedElements;
443+
var _syncedDrawings = []
444+
for (e in _syncedElements){
445+
// skip this element
446+
if (_syncedElements[e]._synchedLayer == this.element._synchedLayer) continue;
447+
_syncedDrawings.push(_syncedElements[e].getDrawingByName(this.name));
448+
}
449+
return _syncedDrawings;
450+
}
451+
})
452+
433453

434454

435455
// $.oDrawing Class methods
@@ -575,11 +595,24 @@ $.oDrawing.prototype.setAsActiveDrawing = function (artLayer) {
575595
* @param {string} [newName] A new name for the drawing. By default, the name will be the number of the frame.
576596
* @returns {$.oDrawing} the newly created drawing
577597
*/
578-
$.oDrawing.prototype.duplicate = function(frame, newName){
598+
$.oDrawing.prototype.duplicate = function(frame, newName, duplicateSynchedDrawings){
579599
var _element = this.element
600+
if (typeof duplicateSynchedDrawings === 'undefined') duplicateSynchedDrawings = true; // hidden parameter used to avoid recursion bomb
580601
if (typeof frame ==='undefined') var frame = this.$.scn.currentFrame;
581602
if (typeof newName === 'undefined') var newName = frame;
582-
var newDrawing = _element.addDrawing(frame, newName, this.path)
603+
var newDrawing = _element.addDrawing(frame, newName, this.path);
604+
605+
// also duplicate synched drawings
606+
if (duplicateSynchedDrawings){
607+
var _syncedDrawings = newDrawing.synchedDrawings;
608+
for (var i in _syncedDrawings){
609+
var _originalDrawing = _syncedDrawings[i].element.getDrawingByName(this.name);
610+
var _file = new this.$.oFile(_originalDrawing.path);
611+
var _path = new this.$.oFile(_syncedDrawings[i].path);
612+
return _file.copy(_path.folder, _path.name, true);
613+
}
614+
}
615+
583616
return newDrawing;
584617
}
585618

openHarmony/openHarmony_element.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@
5454
* @constructor
5555
* @classdesc $.oElement Class
5656
* @param {int} id The element ID.
57+
* @param {str} synchedLayer The value of the Drawing Node drawing.element.layer attribute for synched layers
5758
* @param {$.oColumn} oColumnObject The column object associated to the element.
5859
*
5960
* @property {int} id The element ID.
6061
* @property {$.oColumn} oColumnObject The column object associated to the element.
6162
*/
6263
$.oElement = function( id, synchedLayer, oColumnObject){
63-
if (typeof synchedLayer === 'undefined') synchedLayer = null;
64+
if (typeof synchedLayer === 'undefined' || !synchedLayer) synchedLayer = null;
6465
this._type = "element";
6566

6667
this._synchedLayer = synchedLayer;
@@ -147,6 +148,20 @@ Object.defineProperty($.oElement.prototype, 'palettes', {
147148
})
148149

149150

151+
/**
152+
* A list of the other elements synched with this one.
153+
* @name $.oElement#synchedElements
154+
* @readonly
155+
* @type {$.oDrawing[]}
156+
*/
157+
Object.defineProperty($.oElement.prototype, 'synchedElements', {
158+
get : function(){
159+
var _id = this.id;
160+
return $.scene.elements.filter(function(e){return e.id == _id});
161+
}
162+
})
163+
164+
150165
// $.oElement Class methods
151166

152167
/**

openHarmony/openHarmony_node.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,9 +1978,7 @@ $.oDrawingNode.prototype.constructor = $.oDrawingNode;
19781978
*/
19791979
Object.defineProperty($.oDrawingNode.prototype, "element", {
19801980
get : function(){
1981-
var _column = this.attributes.drawing.element.column;
1982-
var _synchedLayer = this.attributes.drawing.element.layer;
1983-
return ( new this.$.oElement( node.getElementId(this.path), _synchedLayer.getValue(), _column ) );
1981+
return this.timingColumn.element;
19841982
},
19851983

19861984
set : function( oElementObject ){
@@ -1997,8 +1995,7 @@ Object.defineProperty($.oDrawingNode.prototype, "element", {
19971995
*/
19981996
Object.defineProperty($.oDrawingNode.prototype, "timingColumn", {
19991997
get : function(){
2000-
var _column = this.attributes.drawing.element.column;
2001-
return _column;
1998+
return this.attributes.drawing.element.column;
20021999
},
20032000

20042001
set : function (oColumnObject){

openHarmony/openHarmony_scene.js

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,10 @@ Object.defineProperty($.oScene.prototype, 'columns', {
527527
get : function(){
528528
var _columns = [];
529529
for (var i=0; i<column.numberOf(); i++){
530-
_columns.push( this.$column(column.getName(i)) );
530+
// no attribute can be passed to the constructor
531+
// since a column can be linked to several attributes.
532+
// access it from the node to get the missing information.
533+
_columns.push( this.$getColumnByName(column.getName(i)) );
531534
}
532535
return _columns;
533536
}
@@ -562,30 +565,53 @@ Object.defineProperty($.oScene.prototype, 'palettes', {
562565
Object.defineProperty($.oScene.prototype, 'elements', {
563566
get : function(){
564567
var _elements = [];
565-
var _columns = this.columns;
566-
var _ids = [];
567-
for (var i in _columns){
568-
if (_columns.type != "DRAWING") continue;
569-
var _element = _columns[i].element
570-
_elements.push(_element);
571-
if (_ids.indexOf(_element.id) == -1) _ids.push (_element.id);
568+
var _ids = {};
569+
570+
// fetching the elements from the nodes to get the synched drawing attribute value
571+
var _nodes = $.scene.getNodesByType("READ");
572+
for (var n in _nodes) {
573+
var _element = _nodes[n].element;
574+
var _layer = _element._synchedLayer;
575+
var _foundDuplicate = false;
576+
// store ids and layer info (synced drawings) to avoid duplicates
577+
578+
function isInKeys(value, object){
579+
// for some reason we can't use Object.keys(_ids).indexOf(_element.id), so we fake it
580+
var _keys = Object.keys(object);
581+
var _exists = false;
582+
for (var i in _keys)
583+
if (_keys[i] == value) _exists = true;
584+
return _exists;
585+
}
586+
587+
if (!isInKeys(_element.id, _ids)){
588+
_ids[_element.id] = [];
589+
}
590+
if (_ids[_element.id].indexOf(_layer) == -1){
591+
_ids[_element.id].push(_layer);
592+
}else{
593+
_foundDuplicate = true;
594+
}
595+
596+
if(!_foundDuplicate){
597+
_elements.push(_nodes[n].element);
598+
}
572599
}
573600

574601
// adding the elements not linked to columns
575602
var _elementNum = element.numberOf();
576603
for (var i = 0; i<_elementNum; i++){
577604
var _id = element.id(i);
578-
if (_ids.indexOf(_id) == -1) {
579-
_elements.push(new this.$.oElement(_id));
580-
_ids.push (_id)
605+
if (!isInKeys(_id, _ids)) {
606+
_elements.push(new this.$.oElement(_id)); // these elements have no column and no attribute
607+
_ids[_id] = [];
581608
}
582609
}
583610
return _elements;
584611
}
585612
});
586613

587614

588-
589615
/**
590616
* The length of the scene.
591617
* @name $.oScene#length
@@ -820,8 +846,8 @@ $.oScene.prototype.getNodeByPath = function(fullPath){
820846
}
821847

822848
/**
823-
* Returns the nodes of a certain type in the entire scene.
824-
* @param {string} typeName The name of the node.
849+
* Returns the nodes of a certain type in the entire scene (includes group contents).
850+
* @param {string} typeName The type of node.
825851
*
826852
* @return {$.oNode[]} The nodes found.
827853
*/

0 commit comments

Comments
 (0)