Commit ad21712f authored by Ryan LeFevre's avatar Ryan LeFevre

Change children to a function for consistency

parent 33021c04
...@@ -8,4 +8,4 @@ console.log(psd.header.export()); ...@@ -8,4 +8,4 @@ console.log(psd.header.export());
// console.log("Finished!"); // console.log("Finished!");
// }); // });
console.log(psd.tree().children[0].children[0].nextSibling().export()); console.log(psd.tree().children()[0].children()[0].nextSibling().export());
\ No newline at end of file \ No newline at end of file
...@@ -10,7 +10,7 @@ module.exports = class Node extends Module ...@@ -10,7 +10,7 @@ module.exports = class Node extends Module
constructor: (@layer, @parent = null) -> constructor: (@layer, @parent = null) ->
@layer.node = @ @layer.node = @
@children = [] @_children = []
@name = @layer.name @name = @layer.name
...@@ -82,11 +82,11 @@ module.exports = class Node extends Module ...@@ -82,11 +82,11 @@ module.exports = class Node extends Module
updateDimensions: -> updateDimensions: ->
return if @isLayer() return if @isLayer()
child.updateDimensions() for child in @children child.updateDimensions() for child in @_children
return if @isRoot() return if @isRoot()
nonEmptyChildren = @children.filter((c) -> not c.isEmpty()) nonEmptyChildren = @_children.filter((c) -> not c.isEmpty())
@left = _.min(nonEmptyChildren.map((c) -> c.left)) or 0 @left = _.min(nonEmptyChildren.map((c) -> c.left)) or 0
@top = _.min(nonEmptyChildren.map((c) -> c.top)) or 0 @top = _.min(nonEmptyChildren.map((c) -> c.top)) or 0
@bottom = _.max(nonEmptyChildren.map((c) -> c.bottom)) or 0 @bottom = _.max(nonEmptyChildren.map((c) -> c.bottom)) or 0
......
...@@ -7,16 +7,18 @@ module.exports = ...@@ -7,16 +7,18 @@ module.exports =
isRoot: -> @depth() is 0 isRoot: -> @depth() is 0
children: -> @_children
ancestors: -> ancestors: ->
return [] if not @parent? or @parent.isRoot() return [] if not @parent? or @parent.isRoot()
return @parent.ancestors().concat [@parent] return @parent.ancestors().concat [@parent]
hasChildren: -> @children.length > 0 hasChildren: -> @_children.length > 0
childless: -> not @hasChildren() childless: -> not @hasChildren()
siblings: -> siblings: ->
return [] unless @parent? return [] unless @parent?
@parent.children @parent.children()
nextSibling: -> nextSibling: ->
return null unless @parent? return null unless @parent?
...@@ -31,7 +33,7 @@ module.exports = ...@@ -31,7 +33,7 @@ module.exports =
hasSiblings: -> @siblings().length > 1 hasSiblings: -> @siblings().length > 1
onlyChild: -> not @hasSiblings() onlyChild: -> not @hasSiblings()
descendants: -> _.flatten @children.map((n) -> n.subtree()) descendants: -> _.flatten @_children.map((n) -> n.subtree())
subtree: -> [@].concat @descendants() subtree: -> [@].concat @descendants()
......
...@@ -8,9 +8,9 @@ module.exports = class Group extends Node ...@@ -8,9 +8,9 @@ module.exports = class Group extends Node
@get('blendingMode') is 'passthru' @get('blendingMode') is 'passthru'
isEmpty: -> isEmpty: ->
return false unless child.isEmpty() for child in @children return false unless child.isEmpty() for child in @_children
export: -> export: ->
_.merge super(), _.merge super(),
type: 'group' type: 'group'
children: @children.map((c) -> c.export()) children: @_children.map((c) -> c.export())
\ No newline at end of file \ No newline at end of file
...@@ -30,7 +30,7 @@ module.exports = class Root extends Node ...@@ -30,7 +30,7 @@ module.exports = class Root extends Node
fillOpacity: -> 255 fillOpacity: -> 255
export: -> export: ->
children: @children.map((c) -> c.export()) children: @_children.map((c) -> c.export())
document: document:
width: @width width: @width
height: @height height: @height
...@@ -50,9 +50,9 @@ module.exports = class Root extends Node ...@@ -50,9 +50,9 @@ module.exports = class Root extends Node
currentGroup = new Group(layer, _.last(parseStack)) currentGroup = new Group(layer, _.last(parseStack))
else if layer.isFolderEnd() else if layer.isFolderEnd()
parent = parseStack.pop() parent = parseStack.pop()
parent.children.push currentGroup parent.children().push currentGroup
currentGroup = parent currentGroup = parent
else else
currentGroup.children.push new Layer(layer, currentGroup) currentGroup.children().push new Layer(layer, currentGroup)
@updateDimensions() @updateDimensions()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment