Skip to content

Commit 56de2d2

Browse files
committed
异步加载
1 parent e93b5fa commit 56de2d2

2 files changed

Lines changed: 131 additions & 62 deletions

File tree

js/cocosUtil.js

Lines changed: 113 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,48 @@ function IsSubPath (name) {
2424
return startWith(name, 'SubPath:')
2525
}
2626

27+
function CheckDeepSame (src, dest) {
28+
if (typeof (src) != typeof (dest)) {
29+
return false
30+
}
31+
32+
if (typeof (src) == 'array') {
33+
if (src.length != dest.length) {
34+
return false
35+
}
36+
for (var i = 0; i < src.length; i++) {
37+
if (!CheckDeepSame(src[i], dest[i])) {
38+
return false
39+
}
40+
}
41+
return true
42+
}
43+
44+
if (typeof (src) == 'object') {
45+
if (Object.keys(src).length != Object.keys(dest).length) {
46+
return false
47+
}
48+
for (var k in src) {
49+
if (!CheckDeepSame(src[k], dest[k])) {
50+
return false
51+
}
52+
}
53+
return true
54+
}
55+
56+
return src == dest
57+
}
58+
59+
function GetNodeUuids (node, result) {
60+
result = result || {}
61+
result[node.uuid] = []
62+
var children = node.getChildren()
63+
for (var i = 0; i < children.length; i++) {
64+
result[node.uuid].push(GetNodeUuids(children[i]))
65+
}
66+
return result
67+
}
68+
2769
function isBaseTypeByName (name) {
2870
if (startWith(name, 'SubPath:')) {
2971
return true
@@ -66,11 +108,30 @@ function setNodeSpriteFrame (path, value, node, fn) {
66108
})
67109
}
68110

69-
function cocosExportNodeBase (node, data) {
111+
function cocosExportNodeBase (node, data, ext) {
70112
if (!data) {
71113
data = {}
72114
}
73115

116+
if (node._name.length > 0) {
117+
data['id'] = node._name
118+
}
119+
if (typeof (node._touchEnabled) == 'boolean') {
120+
data['touchEnabled'] = node._touchEnabled
121+
}
122+
123+
if (node.touchListener) {
124+
data['touchListener'] = node.touchListener
125+
}
126+
127+
// 适用于删除及添加的撤消操作
128+
if (ext && ext.uuid) {
129+
data['uuid'] = node.uuid
130+
data['preuuid'] = CalcPreUUID(node)
131+
}
132+
133+
(!node.isVisible()) && (data['visible'] = node.isVisible())
134+
74135
let parent = node.getParent()
75136
if (node.isWidthPer && parent) {
76137
let ratio = node.width / parent.width * 100
@@ -136,25 +197,7 @@ function cocosExportNodeBase (node, data) {
136197

137198
function cocosExportNodeData (node, ext) {
138199
let data = {}
139-
cocosExportNodeBase(node, data)
140-
if (node._name.length > 0) {
141-
data['id'] = node._name
142-
}
143-
if (typeof (node._touchEnabled) == 'boolean') {
144-
data['touchEnabled'] = node._touchEnabled
145-
}
146-
147-
if (node.touchListener) {
148-
data['touchListener'] = node.touchListener
149-
}
150-
151-
// 适用于删除及添加的撤消操作
152-
if (ext && ext.uuid) {
153-
data['uuid'] = node.uuid
154-
data['preuuid'] = CalcPreUUID(node)
155-
}
156-
157-
(!node.isVisible()) && (data['visible'] = node.isVisible())
200+
cocosExportNodeBase(node, data, ext)
158201

159202
let extControl = GetExtNodeControl(node._className)
160203

@@ -268,28 +311,35 @@ function calcHeight (node, height, parent) {
268311
return ret
269312
}
270313

271-
function cocosGenSubUINode (path, parent) {
314+
function cocosGenSubUINode (data, parent) {
272315
let node = new cc.Node()
273-
node._path = path
274-
if (checkPathRepeat(parent, path)) {
316+
node._path = data.path
317+
if (checkPathRepeat(parent, data.path)) {
275318
return null
276319
}
277-
var data = getPathData(path)
278-
var result = CalcNeedLoadImage(data)
279-
cc.loader.load(TableKeyToArray(result.imageTable), function() {
280-
cocosGenNodeByData(data, parent, node)
320+
var sub_data = getPathData(data.path)
321+
var result = CalcNeedLoadImage(sub_data)
322+
cc.loader.load(TableKeyToArray(result.imageTable), function () {
323+
cocosGenNodeByData(sub_data, parent, node)
324+
cocosSetNodeProp(data, node, parent)
281325
})
282-
node._className = 'SubPath:' + path
326+
node._className = 'SubPath:' + data.path
283327
return node
284328
}
285329

286-
function CalcDataSize(node ,data, parent) {
287-
let widthRet = calcWidth(node, data.width, parent)
288-
let heightRet = calcHeight(node, data.height, parent)
289-
return cc.size(widthRet.width, heightRet.height)
330+
function CalcDataSize (node , data, parent) {
331+
let widthRet = calcWidth(node, data.width, parent)
332+
let heightRet = calcHeight(node, data.height, parent)
333+
return cc.size(widthRet.width, heightRet.height)
290334
}
291335

292336
function cocosGenNodeByDataBase (data, node, parent) {
337+
node.uuid = data.uuid || gen_uuid()
338+
;(data.id) && (node._name = data.id)
339+
340+
;(!isNull(data.touchEnabled)) && (node._touchEnabled = data.touchEnabled)
341+
;(!isNull(data.touchListener)) && (node.touchListener = data.touchListener)
342+
293343
if (!isNull(data.width) || !isNull(data.height)) {
294344
let setFn = node.setPreferredSize ? node.setPreferredSize : node.setContentSize
295345
let widthRet = calcWidth(node, data.width, parent)
@@ -332,7 +382,7 @@ function cocosGenNodeByData (data, parent, outNode) {
332382
if (outNode) {
333383
node = outNode
334384
} else if (data.path) {
335-
node = cocosGenSubUINode(data.path, parent)
385+
node = cocosGenSubUINode(data, parent)
336386
} else if (extControl) {
337387
node = extControl.GenNodeByData(data, parent)
338388
} else if (data.type == 'Scene' || !parent) {
@@ -346,18 +396,21 @@ function cocosGenNodeByData (data, parent, outNode) {
346396
node._className = 'Node'
347397
}
348398
node._name = ''
399+
cocosSetNodeProp(data, node, parent)
349400

350-
// if(parent && !node.getParent() && !node.ignoreAddToParent) {
351-
// parent.addChild(node)
352-
// }
401+
data.children = data.children || []
402+
for (var i = 0; i < data.children.length; i++) {
403+
let child = cocosGenNodeByData(data.children[i], node)
404+
if (child && !child.ignoreAddToParent) {
405+
node.addChild(child)
406+
}
407+
}
408+
return node
409+
}
353410

354-
node.uuid = data.uuid || gen_uuid()
411+
function cocosSetNodeProp (data, node, parent) {
355412
cocosGenNodeByDataBase(data, node, parent)
356-
;(data.id) && (node._name = data.id)
357-
358-
;(!isNull(data.touchEnabled)) && (node._touchEnabled = data.touchEnabled)
359-
;(!isNull(data.touchListener)) && (node.touchListener = data.touchListener)
360-
413+
let extControl = GetExtNodeControl(data.type)
361414
if (extControl) {
362415
extControl.SetNodePropByData(node, data, parent)
363416
} else if (node._path) {
@@ -377,16 +430,6 @@ function cocosGenNodeByData (data, parent, outNode) {
377430
;(data['clippingEnabled']) && (node.setClippingEnabled(data['clippingEnabled']))
378431
;(data['clippingType']) && (node.setClippingType(data['clippingType']))
379432
}
380-
381-
data.children = data.children || []
382-
for (var i = 0; i < data.children.length; i++) {
383-
let child = cocosGenNodeByData(data.children[i], node)
384-
if (child && !child.ignoreAddToParent) {
385-
node.addChild(child)
386-
}
387-
}
388-
389-
return node
390433
}
391434

392435
function getPathData (path) {
@@ -415,7 +458,7 @@ function loadSceneFromFile (filename) {
415458
var scene = ExtScene.GenEmptyNode()
416459
scene.setContentSize(CalcDataSize(scene, data))
417460
var result = CalcNeedLoadImage(data)
418-
cc.loader.load(TableKeyToArray(result.imageTable), function() {
461+
cc.loader.load(TableKeyToArray(result.imageTable), function () {
419462
cocosGenNodeByData(data, null, scene)
420463
})
421464
return scene
@@ -605,10 +648,10 @@ function SetNodifyPropChange (control) {
605648
ResetNodePropByData(control, data)
606649
}
607650

608-
function TableKeyToArray(table) {
651+
function TableKeyToArray (table) {
609652
table = table || {}
610653
var array = []
611-
for(var k in table) {
654+
for (var k in table) {
612655
array.push(k)
613656
}
614657
return array
@@ -644,3 +687,18 @@ function CalcNeedLoadImage (data, result) {
644687
}
645688
return result
646689
}
690+
691+
var isGlobalEnable = false
692+
function EnableGlobalTimeUpdate () {
693+
isGlobalEnable = true
694+
var repeatCheckSence = function () {
695+
Ipc.sendToAll('ui:global_time_update', {})
696+
if (isGlobalEnable) {
697+
setTimeout(repeatCheckSence, 1000)
698+
return
699+
}
700+
}
701+
setTimeout(repeatCheckSence, 1000)
702+
}
703+
704+
EnableGlobalTimeUpdate()

packages/nodeorder/panel/nodeorder.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
this._curOpMode = 'center'
2222
this._scene = null
2323

24+
this._preSceneInfo = {}
25+
2426
this.addEventListener('mousedown', function (e) {
2527
if (e.button == '2') {
2628
e.preventDefault()
@@ -29,16 +31,15 @@
2931
}
3032
})
3133

32-
let self = this;
33-
this.$.input.addEventListener("end-editing", function(e) {
34-
if (e.detail.cancel) {
35-
return
36-
}
37-
self.filterText = e.target.value;
34+
let self = this
35+
this.$.input.addEventListener('end-editing', function (e) {
36+
if (e.detail.cancel) {
37+
return
38+
}
39+
self.filterText = e.target.value
3840
})
3941

4042
this.addEventListener('keydown', function (event) {
41-
4243
if (event.keyCode == KeyCodes('left') || event.keyCode == KeyCodes('right') || event.keyCode == KeyCodes('up') || event.keyCode == KeyCodes('down')) {
4344
this._doItemMove(event)
4445
event.stopPropagation()
@@ -374,6 +375,16 @@
374375
let firstChild = Polymer.dom(parentItem).lastElementChild
375376
this._curOpMode = 'bottom'
376377
this.tryChangeItemPosition(this._curMouseOverItem, firstChild)
378+
},
379+
'ui:global_time_update'(event, message) {
380+
if (!this._scene) {
381+
return
382+
}
383+
var scene_info = GetNodeUuids(this._scene)
384+
if (!CheckDeepSame(scene_info, this._preSceneInfo)) {
385+
this.build()
386+
this._preSceneInfo = scene_info
387+
}
377388
}
378389
}
379390

0 commit comments

Comments
 (0)