Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
middleLayer_for_iplayabc
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
middleLayer_for_iplayabc
Commits
a4a0c910
Commit
a4a0c910
authored
Jul 26, 2022
by
liujiangnan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 初始化
parent
b074272e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
447 additions
and
10722 deletions
+447
-10722
middleLayer_for_iplayabc.fire
...dleLayer_for_iplayabc/scene/middleLayer_for_iplayabc.fire
+35
-9904
air.js
assets/middleLayer_for_iplayabc/script/air.js
+58
-3
middleLayer.js
assets/middleLayer_for_iplayabc/script/middleLayer.js
+133
-724
util.js
assets/middleLayer_for_iplayabc/script/util.js
+221
-91
No files found.
assets/middleLayer_for_iplayabc/scene/middleLayer_for_iplayabc.fire
View file @
a4a0c910
This source diff could not be displayed because it is too large. You can
view the blob
instead.
assets/middleLayer_for_iplayabc/script/air.js
View file @
a4a0c910
...
@@ -25,7 +25,12 @@ export function initAir(_this) {
...
@@ -25,7 +25,12 @@ export function initAir(_this) {
osmoFingerReadCallback
:
function
(
res
)
{
osmoFingerReadCallback
:
function
(
res
)
{
_this
.
log
(
`***成功调用osmoFingerReadCallback***参数==
${
res
}
`
);
_this
.
log
(
`***成功调用osmoFingerReadCallback***参数==
${
res
}
`
);
},
},
startScanCodeCallback
:
null
,
needUpdateCallback
:
null
,
getEngineInfoCallback
:
null
,
getEngineInfoCallback
:
null
,
takePictureCallBack
:
null
,
configurationPortraitCallback
:
null
,
configurationLandscapeCallback
:
null
,
recognitionCameraCallBack
:
null
,
recognitionCameraCallBack
:
null
,
testCallBack
:
null
,
testCallBack
:
null
,
recordCallBack
:
null
,
recordCallBack
:
null
,
...
@@ -149,14 +154,22 @@ export function initAir(_this) {
...
@@ -149,14 +154,22 @@ export function initAir(_this) {
};
};
window
.
courseware
.
callOcMethod
(
"
stopTest
"
,
{});
window
.
courseware
.
callOcMethod
(
"
stopTest
"
,
{});
},
},
openRecognitionCamera
(
callback
)
{
takePicture
(
callback
)
{
_this
.
log
(
`===成功调用takePicture===`
);
window
.
air
.
takePictureCallBack
=
(
res
)
=>
{
callback
&&
callback
(
JSON
.
stringify
(
res
));
window
.
air
.
takePictureCallBack
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
takePicture
"
,
{});
},
openRecognitionCamera
(
params
=
{},
callback
)
{
window
.
courseware
.
hasCalledOpenRecognitionCamera
=
true
;
window
.
courseware
.
hasCalledOpenRecognitionCamera
=
true
;
_this
.
log
(
`===成功调用openRecognitionCamera===`
);
_this
.
log
(
`===成功调用openRecognitionCamera===
${
JSON
.
stringify
(
params
)}
`
);
window
.
air
.
recognitionCameraCallBack
=
(
res
)
=>
{
window
.
air
.
recognitionCameraCallBack
=
(
res
)
=>
{
callback
&&
callback
(
JSON
.
stringify
(
res
));
callback
&&
callback
(
JSON
.
stringify
(
res
));
window
.
air
.
recognitionCameraCallBack
=
null
;
window
.
air
.
recognitionCameraCallBack
=
null
;
};
};
window
.
courseware
.
callOcMethod
(
"
openRecognitionCamera
"
,
{}
);
window
.
courseware
.
callOcMethod
(
"
openRecognitionCamera
"
,
params
);
},
},
closeRecognitionCamera
()
{
closeRecognitionCamera
()
{
window
.
courseware
.
hasCalledOpenRecognitionCamera
=
false
;
window
.
courseware
.
hasCalledOpenRecognitionCamera
=
false
;
...
@@ -178,6 +191,32 @@ export function initAir(_this) {
...
@@ -178,6 +191,32 @@ export function initAir(_this) {
};
};
window
.
courseware
.
callOcMethod
(
"
getEngineInfo
"
,
{});
window
.
courseware
.
callOcMethod
(
"
getEngineInfo
"
,
{});
},
},
changeHost
()
{
_this
.
log
(
`===成功调用changeHost===`
);
// 调用原生获取机器信息
if
(
window
.
air
.
engineInfo
)
{
const
engineInfo
=
JSON
.
parse
(
window
.
air
.
engineInfo
);
window
.
courseware
.
callOcMethod
(
"
changeHost
"
,
{
isStagingEnv
:
engineInfo
.
isDev
!=
1
});
}
},
needUpdate
(
label
,
url
,
callback
)
{
_this
.
log
(
`===成功调用needUpdate===`
);
// 调用原生获取机器信息
window
.
air
.
needUpdateCallback
=
(
res
)
=>
{
callback
&&
callback
(
res
);
window
.
air
.
needUpdateCallback
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
needUpdate
"
,
{
label
:
label
,
url
:
url
});
},
startScanCode
(
callback
)
{
_this
.
log
(
`===成功调用startScanCode===`
);
// 调用原生开始扫码
window
.
air
.
startScanCodeCallback
=
(
res
)
=>
{
callback
&&
callback
(
res
);
window
.
air
.
startScanCodeCallback
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
startScanCode
"
,
{});
},
openOsmo
(
params
=
{})
{
openOsmo
(
params
=
{})
{
window
.
courseware
.
hasCalledOpenOsmo
=
true
;
window
.
courseware
.
hasCalledOpenOsmo
=
true
;
_this
.
log
(
`===成功调用openOsmo===
${
JSON
.
stringify
(
params
)}
`
);
_this
.
log
(
`===成功调用openOsmo===
${
JSON
.
stringify
(
params
)}
`
);
...
@@ -218,6 +257,22 @@ export function initAir(_this) {
...
@@ -218,6 +257,22 @@ export function initAir(_this) {
_this
.
log
(
`===成功调用closeOsmoFingerRead===`
);
_this
.
log
(
`===成功调用closeOsmoFingerRead===`
);
window
.
courseware
.
callOcMethod
(
"
closeOsmoFingerRead
"
,
{});
window
.
courseware
.
callOcMethod
(
"
closeOsmoFingerRead
"
,
{});
},
},
onConfigurationPortrait
(
params
=
{},
callback
)
{
_this
.
log
(
`===成功调用onConfigurationPortrait||竖屏===`
);
window
.
air
.
configurationPortraitCallback
=
(
res
)
=>
{
callback
&&
callback
(
res
);
window
.
air
.
configurationPortraitCallback
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
onConfigurationPortrait
"
,
params
);
},
onConfigurationLandscape
(
params
=
{},
callback
)
{
_this
.
log
(
`===成功调用onConfigurationLandscape||横屏===`
);
window
.
air
.
configurationLandscapeCallback
=
(
res
)
=>
{
callback
&&
callback
(
res
);
window
.
air
.
configurationLandscapeCallback
=
null
;
};
window
.
courseware
.
callOcMethod
(
"
onConfigurationLandscape
"
,
params
);
},
callOcMethod
(
method
,
param
)
{
callOcMethod
(
method
,
param
)
{
const
paramStr
=
JSON
.
stringify
(
param
);
const
paramStr
=
JSON
.
stringify
(
param
);
_this
.
log
(
`===成功调用原生方法
${
method
}
===参数==
${
paramStr
}
`
);
_this
.
log
(
`===成功调用原生方法
${
method
}
===参数==
${
paramStr
}
`
);
...
...
assets/middleLayer_for_iplayabc/script/middleLayer.js
View file @
a4a0c910
...
@@ -6,745 +6,195 @@ cc.Class({
...
@@ -6,745 +6,195 @@ cc.Class({
properties
:
{
properties
:
{
},
},
callNetworkApiPost
(
baseUrl
,
uri
,
data
,
callBack
)
{
callNetworkApiPost
(
uri
,
data
,
callBack
)
{
const
xhr
=
new
XMLHttpRequest
();
this
.
getBaseUrl
((
baseUrl
)
=>
{
const
url
=
`
${
baseUrl
}${
uri
}
`
;
const
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
"
POST
"
,
url
,
true
);
const
url
=
`
${
baseUrl
}${
uri
}
`
;
xhr
.
setRequestHeader
(
'
content-type
'
,
'
application/json
'
);
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
onreadystatechange
=
()
=>
{
xhr
.
setRequestHeader
(
'
content-type
'
,
'
application/json
'
);
if
(
xhr
.
readyState
==
4
)
{
xhr
.
onreadystatechange
=
()
=>
{
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
if
(
xhr
.
readyState
==
4
)
{
}
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
}
}
xhr
.
send
(
JSON
.
stringify
(
data
));
},
callNetworkApiGet
(
baseUrl
,
uri
,
data
,
callBack
)
{
let
queryStr
=
'
?
'
;
const
params
=
[];
for
(
const
key
in
data
)
{
if
(
Object
.
hasOwnProperty
.
call
(
data
,
key
))
{
params
.
push
(
`
${
key
}
=
${
data
[
key
]}
`
);
}
}
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
}
};
const
url
=
`
${
baseUrl
}${
uri
}${
queryStr
}
`
;
console
.
log
(
'
url =
'
+
url
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
},
callNetworkApiGetLocal
(
baseUrl
,
uri
,
data
,
callBack
)
{
let
queryStr
=
'
?
'
;
const
params
=
[];
for
(
const
key
in
data
)
{
if
(
Object
.
hasOwnProperty
.
call
(
data
,
key
))
{
params
.
push
(
`
${
key
}
=
${
data
[
key
]}
`
);
}
}
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
xhr
.
responseText
);
}
};
const
url
=
`
${
baseUrl
}${
uri
}${
queryStr
}
`
;
console
.
log
(
'
url =
'
+
url
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
},
// 需要预加载的数量
preloadCount
:
null
,
// 统计已加载的数量
loadedCount
:
null
,
baseApiUrl
:
null
,
// API地址
engineCode
:
null
,
// 机器唯一编码
userCode
:
null
,
// 用户唯一编码
name
:
null
,
// 用户取的英文名
birthday
:
null
,
// 用户的生日
courseIds
:
null
,
// 根据推荐生成的课件ID数组
currentIndex
:
null
,
// 当前进行的是courseIds里第几个课件
// 统一释放异步资源的方法
onLoad
()
{
this
.
preloadCount
=
0
;
this
.
loadedCount
=
0
;
initAir
(
this
);
this
.
initAudio
();
},
start
()
{
this
.
turnPageWait
=
0
;
this
.
node
.
zIndex
=
9999
;
cc
.
game
.
addPersistRootNode
(
this
.
node
);
this
.
initListener
();
this
.
initPageInfo
();
this
.
hideUI
();
this
.
showWaitingLetters
();
this
.
initTerminalInfo
(()
=>
{
this
.
getUserStar
();
// 获取用户所获得的星星数量
this
.
getUserQrcode
();
// 获取用户动态小程序码
this
.
loadGame
();
});
},
initAudio
()
{
this
.
bigStarClip
=
cc
.
find
(
'
middleLayer/res/audio/big_star
'
).
getComponent
(
cc
.
AudioSource
).
clip
;
},
initTerminalInfo
(
callback
)
{
window
.
courseware
.
getEngineInfo
(
res
=>
{
const
{
isDev
,
uuid
}
=
JSON
.
parse
(
res
);
if
(
isDev
)
{
// 这里后面给个测试环境地址
this
.
baseApiUrl
=
`https://api.iplayabc.com/`
;
}
else
{
this
.
baseApiUrl
=
`https://api.iplayabc.com/`
;
}
this
.
engineCode
=
uuid
;
this
.
getUserCode
(
callback
);
// 获取用户基本信息
});
},
getUserCode
(
callback
)
{
this
.
callNetworkApiPost
(
this
.
baseApiUrl
,
"
v1/terminal/store
"
,
{
engine_code
:
this
.
engineCode
,
name
:
'
default_name
'
,
birthday
:
'
20200202
'
},
res
=>
{
if
(
res
.
code
===
200
)
{
this
.
userCode
=
res
.
data
.
user_code
;
this
.
name
=
res
.
data
.
name
;
this
.
birthday
=
res
.
data
.
birthday
;
callback
&&
callback
();
}
else
{
console
.
log
(
"
-----error------
"
);
console
.
log
(
res
.
msg
);
// TODO 提示错误和上报错误
}
}
xhr
.
send
(
JSON
.
stringify
(
data
));
});
});
},
},
getUserQrcode
()
{
callNetworkApiGet
(
uri
,
data
,
callBack
)
{
cc
.
assetManager
.
loadRemote
(
`
${
this
.
baseApiUrl
}
v1/wechart/wxacode?user_code=
${
this
.
userCode
}
`
,{
ext
:
'
.jpeg
'
},
(
err
,
img
)
=>
{
this
.
getBaseUrl
((
baseUrl
)
=>
{
if
(
err
)
{
let
queryStr
=
'
?
'
;
console
.
log
(
"
==远程图片加载错误==
"
);
const
params
=
[];
// TODO 上报错误
for
(
const
key
in
data
)
{
}
else
{
if
(
Object
.
hasOwnProperty
.
call
(
data
,
key
))
{
const
spriteFrame
=
new
cc
.
SpriteFrame
(
img
);
params
.
push
(
`
${
key
}
=
${
data
[
key
]}
`
);
cc
.
find
(
'
middleLayer/qrcode
'
).
getComponent
(
cc
.
Sprite
).
spriteFrame
=
spriteFrame
;
}
}
})
},
getUserStar
()
{
this
.
callNetworkApiGet
(
this
.
baseApiUrl
,
"
v1/terminal/user/stars
"
,
{
user_code
:
this
.
userCode
,
},
res
=>
{
if
(
res
.
code
===
200
)
{
// const starLabel = cc.find('middleLayer/star_count_label').getComponent(cc.Label);
const
starLabel
=
cc
.
find
(
'
middleLayer/star_node/star_count_label
'
).
getComponent
(
cc
.
RichText
);
starLabel
.
string
=
`<outline color=black width=2><b>
${
res
.
data
}
</b></outline>`
;
}
else
{
console
.
log
(
"
-----error------
"
);
console
.
log
(
res
.
msg
);
// TODO 提示错误和上报错误
}
}
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
}
};
const
url
=
`
${
baseUrl
}${
uri
}${
queryStr
}
`
;
console
.
warn
(
'
url =
'
+
url
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
});
});
},
},
initPageInfo
()
{
async
getBaseUrl
(
callback
)
{
const
addressText
=
cc
.
find
(
'
middleLayer/ui/address
'
);
const
engineInfo
=
await
this
.
getEngineInfo
();
const
str
=
cc
.
sys
.
localStorage
.
getItem
(
'
ip
'
);
const
{
isDev
,
uuid
}
=
JSON
.
parse
(
engineInfo
);
console
.
log
(
'
str =
'
+
str
);
this
.
isDev
=
isDev
;
if
(
str
)
{
this
.
engineCode
=
uuid
;
addressText
.
getComponent
(
cc
.
EditBox
).
string
=
str
;
if
(
isDev
==
1
)
{
}
callback
(
'
http://staging-openapi.iteachabc.com
'
);
}
else
{
const
nameText
=
cc
.
find
(
'
middleLayer/ui/bundleName
'
);
callback
(
'
http://openapi.iteachabc.com
'
);
const
bundleName
=
cc
.
sys
.
localStorage
.
getItem
(
'
bundleName
'
);
if
(
bundleName
)
{
nameText
.
getComponent
(
cc
.
EditBox
).
string
=
bundleName
;
}
const
courseIdNode
=
cc
.
find
(
'
middleLayer/ui/courseId
'
);
const
courseId
=
cc
.
sys
.
localStorage
.
getItem
(
'
courseId
'
);
if
(
courseId
)
{
courseIdNode
.
getComponent
(
cc
.
EditBox
).
string
=
courseId
;
}
}
global
.
middleLayer
=
cc
.
find
(
'
middleLayer
'
).
getComponent
(
'
middleLayer
'
);
middleLayer
.
log
(
"
middleLayer.log('像这样在这里打log')
"
);
},
},
getHistoryLastCourse
(
callback
)
{
getEngineInfo
()
{
this
.
callNetworkApiGet
(
this
.
baseApiUrl
,
`v1/terminal/user/answers/1`
,
{
user_code
:
this
.
userCode
},
res
=>
{
if
(
window
.
air
.
engineInfo
)
{
callback
(
res
.
data
.
rows
[
0
]);
return
window
.
air
.
engineInfo
;
});
}
else
{
},
return
new
Promise
((
resolve
,
reject
)
=>
{
window
.
courseware
.
getEngineInfo
(()
=>
{
loadGame
()
{
resolve
(
window
.
air
.
engineInfo
);
this
.
callNetworkApiGet
(
this
.
baseApiUrl
,
`v1/preference/courseware`
,
{
user_code
:
this
.
userCode
},
res
=>
{
});
if
(
res
.
code
!==
200
)
{
console
.
log
(
"
-----error------
"
);
console
.
log
(
res
.
msg
);
// TODO 提示错误和上报错误
return
;
}
this
.
courseIds
=
res
.
data
;
this
.
getHistoryLastCourse
(
item
=>
{
this
.
currentIndex
=
item
?
this
.
courseIds
.
indexOf
(
item
.
syllabus_id
):
0
;
this
.
loadOnlineCourseWare
(
this
.
courseIds
[
this
.
currentIndex
],
false
);
});
});
});
},
addStar
(
count
,
animationFlag
)
{
if
(
animationFlag
){
// TODO 添加星星的动画
for
(
let
i
=
0
;
i
<
count
;
i
++
)
{
setTimeout
(()
=>
{
let
star
=
cc
.
find
(
'
middleLayer/star_node/icon_star
'
);
const
resItem
=
cc
.
find
(
'
middleLayer/res/icon_bigstar
'
);
const
starBig
=
cc
.
instantiate
(
resItem
);
starBig
.
parent
=
star
.
parent
;
showBigStar
(
starBig
,
star
);
},
i
*
500
);
}
playAudio
(
this
.
bigStarClip
);
}
this
.
callNetworkApiPost
(
this
.
baseApiUrl
,
`v1/terminal/star/save`
,
{
syllabus_id
:
this
.
courseItem
.
course_id
,
courseware_id
:
this
.
courseItem
.
id
,
engine_code
:
this
.
engineCode
,
template_name
:
this
.
courseItem
.
template_name
,
stars
:
count
,
})
},
preloadAll
()
{
if
(
window
.
preloadBundleAndSourcesFlag
)
{
// 只加载一次就行了
return
;
}
}
window
.
preloadBundleAndSourcesFlag
=
true
;
cc
.
find
(
"
middleLayer/ui/ProgressLabel
"
).
active
=
true
;
cc
.
find
(
'
middleLayer/ui/loadingProgress
'
).
active
=
true
;
let
platform
=
"
web_desktop
"
;
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
)
{
platform
=
"
ios
"
;
}
else
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_ANDROID
)
{
platform
=
"
android
"
;
}
this
.
callNetworkApiGet
(
`http://staging-teach.ireadabc.com`
,
`/api/syllabus/v1/allbundles`
,
{
orgid
:
488
,
platform
},
(
data
)
=>
{
if
(
data
.
rows
&&
data
.
rows
.
length
>
0
)
{
this
.
preloadCount
+=
data
.
rows
.
length
;
}
this
.
callNetworkApiGet
(
`http://staging-teach.ireadabc.com`
,
`/api/syllabus/v1/allresources`
,
{
orgid
:
488
},
(
data1
)
=>
{
if
(
data1
.
rows
&&
data1
.
rows
.
length
>
0
)
{
this
.
preloadCount
+=
data1
.
rows
.
length
;
}
console
.
log
(
'
data.rows =
'
+
JSON
.
stringify
(
data
.
rows
));
this
.
batchPreloadScene
(
data
.
rows
);
this
.
preloadSource
(
data1
.
rows
);
});
});
},
},
asyncCallNetworkApiGet
(
apiName
,
data
)
{
preloadSourceImman
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
// 测试用
this
.
callNetworkApiGet
(
apiName
,
data
,
(
res
=>
{
cc
.
find
(
"
middleLayer/ui/ProgressLabel
"
).
active
=
true
;
resolve
(
res
);
cc
.
find
(
'
middleLayer/ui/loadingProgress
'
).
active
=
true
;
}));
this
.
callNetworkApiGet
(
`http://staging-teach.ireadabc.com`
,
`/api/courseware/v1/getresources`
,
{
courseid
:
20894
},
(
data1
)
=>
{
if
(
data1
.
rows
&&
data1
.
rows
.
length
>
0
)
{
this
.
preloadCount
+=
data1
.
rows
.
length
;
}
this
.
log
(
'
data1.rows =
'
+
JSON
.
stringify
(
data1
.
rows
));
this
.
preloadSource
(
data1
.
rows
);
});
});
},
},
asyncCallNetworkApiPost
(
uri
,
data
)
{
batchPreloadScene
(
scenes
=
[])
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
expects
=
[
this
.
callNetworkApiPost
(
uri
,
data
,
(
res
)
=>
{
// 'op_03_2',
resolve
(
res
);
// 'OP10_online',
];
const
_this
=
this
;
let
i
=
0
;
const
load
=
function
()
{
const
scene
=
scenes
[
i
];
if
(
expects
.
includes
(
scene
.
sceneName
))
{
_this
.
loadedCount
++
;
_this
.
updateProcessBar
();
i
++
;
if
(
i
<
scenes
.
length
)
{
setTimeout
(()
=>
{
load
();
},
1
);
}
return
;
}
cc
.
assetManager
.
loadBundle
(
scene
.
bondleUrl
,
{
version
:
scene
.
version
},
(
err
,
bundle
)
=>
{
console
.
log
(
`
${
scene
.
bondleUrl
}
---场景开始loadBundle----`
);
if
(
!
bundle
)
{
_this
.
loadedCount
++
;
_this
.
updateProcessBar
();
i
++
;
if
(
i
<
scenes
.
length
)
{
setTimeout
(()
=>
{
load
();
},
1
);
}
return
;
}
bundle
.
preloadScene
(
scene
.
sceneName
,
()
=>
{
},
()
=>
{
console
.
log
(
`
${
scene
.
sceneName
}
场景预加载结束`
);
_this
.
loadedCount
++
;
_this
.
updateProcessBar
();
i
++
;
if
(
i
<
scenes
.
length
)
{
setTimeout
(()
=>
{
load
();
},
1
);
}
});
});
});
}
});
if
(
scenes
&&
scenes
.
length
>
0
)
{
load
();
}
},
},
preloadSource
(
array
)
{
onMiddleLayerLoadingFinish
()
{
const
rows
=
array
||
[];
if
(
cc
.
sys
.
isNative
&&
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
)
{
const
batchLoad
=
()
=>
{
jsb
.
reflection
.
callStaticMethod
(
let
tempArr
=
rows
.
splice
(
0
,
10
);
"
RootViewController
"
,
let
len
=
tempArr
.
length
;
"
getMiddleLayerInfoFinish:
"
,
for
(
let
i
=
0
;
i
<
tempArr
.
length
;
i
++
)
{
""
cc
.
assetManager
.
loadRemote
(
tempArr
[
i
],
(
err
,
texture
)
=>
{
);
if
(
err
)
{
console
.
log
(
err
)
}
this
.
loadedCount
++
;
this
.
updateProcessBar
();
if
(
i
===
len
-
1
)
{
batchLoad
();
}
});
}
}
}
batchLoad
();
if
(
cc
.
sys
.
isNative
&&
cc
.
sys
.
os
==
cc
.
sys
.
OS_ANDROID
)
{
},
jsb
.
reflection
.
callStaticMethod
(
"
com/iplayabc/cocos/AppActivity
"
,
updateProcessBar
()
{
"
getMiddleLayerInfoFinish
"
,
const
label
=
cc
.
find
(
"
middleLayer/ui/ProgressLabel
"
).
getComponent
(
cc
.
Label
);
"
(Ljava/lang/String;)Ljava/lang/String;
"
,
const
loadingProgress
=
cc
.
find
(
'
middleLayer/ui/loadingProgress
'
);
""
label
.
string
=
`正在加载:
${
this
.
loadedCount
}
/
${
this
.
preloadCount
}
`
;
);
if
(
this
.
loadedCount
>
this
.
preloadCount
*
0.99
)
{
cc
.
find
(
"
middleLayer/ui/ProgressLabel
"
).
active
=
false
;
loadingProgress
.
active
=
false
;
this
.
showLog
(
"
资源全部加载完成
"
);
}
}
loadingProgress
.
getComponent
(
cc
.
ProgressBar
).
progress
=
this
.
loadedCount
/
this
.
preloadCount
;
},
},
asyncDelayLog
(
str
)
{
// 需要预加载的数量
console
.
log
(
str
);
preloadCount
:
null
,
return
new
Promise
((
resolve
,
reject
)
=>
{
// 统计已加载的数量
setTimeout
(()
=>
{
loadedCount
:
null
,
resolve
();
},
1
);
});
},
initListener
()
{
cc
.
find
(
'
middleLayer/qrcode_bg
'
).
on
(
'
click
'
,
()
=>
{
cc
.
find
(
'
middleLayer/qrcode
'
).
active
=
false
;
cc
.
find
(
'
middleLayer/qrcode_bg
'
).
active
=
false
;
});
cc
.
find
(
'
middleLayer/BtnShowQrcode
'
).
on
(
'
click
'
,
()
=>
{
cc
.
find
(
'
middleLayer/qrcode
'
).
active
=
true
;
cc
.
find
(
'
middleLayer/qrcode_bg
'
).
active
=
true
;
});
cc
.
find
(
'
middleLayer/ExitBtn
'
).
on
(
'
click
'
,
()
=>
{
isDev
:
null
,
cc
.
find
(
'
middleLayer/BtnRight
'
).
active
=
false
;
engineCode
:
null
,
// 机器唯一编码
cc
.
find
(
'
middleLayer/BtnLeft
'
).
active
=
false
;
cc
.
tween
(
exitBtn
)
dataStore
:
null
,
// 内存数据仓库
.
to
(
0.1
,
{
scaleX
:
0.4
,
scaleY
:
0.6
})
currentSceneName
:
null
,
// 当前模板名称
.
to
(
0.1
,
{
scaleX
:
0.6
,
scaleY
:
0.4
})
.
to
(
0.1
,
{
scaleX
:
0.5
,
scaleY
:
0.5
})
.
call
(()
=>
{
exitBtn
.
active
=
false
;
cc
.
game
.
removePersistRootNode
(
this
.
node
);
cc
.
director
.
getScene
().
destroy
();
cc
.
audioEngine
.
stopAll
();
window
.
courseware
.
freeAllOcMethod
();
cc
.
director
.
loadScene
(
"
debug_shell
"
,
null
,
null
,
(
err
,
scene
)
=>
{
});
// 统一释放异步资源的方法
})
onLoad
()
{
.
start
();
this
.
preloadCount
=
0
;
});
this
.
loadedCount
=
0
;
cc
.
find
(
'
middleLayer/BtnRight
'
).
on
(
'
click
'
,
()
=>
{
this
.
goNextPage
();
});
cc
.
find
(
'
middleLayer/BtnLeft
'
).
on
(
'
click
'
,
()
=>
{
this
.
goPrePage
();
});
cc
.
find
(
'
middleLayer/ui/BtnOpenOsmo
'
).
on
(
'
click
'
,
()
=>
{
window
.
courseware
.
openOsmo
();
});
cc
.
find
(
'
middleLayer/ui/BtnCloseOsmo
'
).
on
(
'
click
'
,
()
=>
{
window
.
courseware
.
closeOsmo
();
});
cc
.
find
(
'
middleLayer/ui/BtnOpenRecord
'
).
on
(
'
click
'
,
()
=>
{
window
.
courseware
.
startRecord
(
''
);
});
cc
.
find
(
'
middleLayer/ui/BtnCloseRecord
'
).
on
(
'
click
'
,
()
=>
{
window
.
courseware
.
stopRecord
(
0
,
res
=>
{
this
.
log
(
'
--------录音返回结果 stopRecord ------------
'
);
this
.
log
(
JSON
.
stringify
(
res
))
this
.
log
(
'
------------------------------
'
);
});
});
cc
.
find
(
'
middleLayer/ui/BtnOpenTest
'
).
on
(
'
click
'
,
()
=>
{
window
.
courseware
.
startTest
(
''
);
});
cc
.
find
(
'
middleLayer/ui/BtnCloseTest
'
).
on
(
'
click
'
,
()
=>
{
window
.
courseware
.
stopTest
(
res
=>
{
this
.
log
(
'
--------录音评测返回结果 stopTest ---------
'
);
this
.
log
(
JSON
.
stringify
(
res
))
this
.
log
(
'
------------------------------
'
);
});
});
const
BtnStartLocal
=
cc
.
find
(
'
middleLayer/ui/BtnStartLocal
'
);
BtnStartLocal
.
on
(
'
click
'
,
()
=>
{
const
addressText
=
cc
.
find
(
'
middleLayer/ui/address
'
);
const
str
=
addressText
.
getComponent
(
cc
.
EditBox
).
string
;
cc
.
sys
.
localStorage
.
setItem
(
'
ip
'
,
str
);
const
address
=
str
.
split
(
'
:
'
)[
0
];
const
port
=
str
.
split
(
'
:
'
)[
0
]
|
8081
;
this
.
localMode
=
true
;
this
.
loadLocalBundle
(
address
,
port
);
this
.
showWaitingLetters
();
this
.
hideUI
();
this
.
showDebugUI
();
});
const
BtnStartOnline
=
cc
.
find
(
'
middleLayer/ui/BtnStartOnline
'
);
this
.
dataStore
=
{};
BtnStartOnline
.
on
(
'
click
'
,
()
=>
{
initAir
(
this
);
const
nameText
=
cc
.
find
(
'
middleLayer/ui/bundleName
'
);
this
.
reWriteAir
();
const
bundleName
=
nameText
.
getComponent
(
cc
.
EditBox
).
string
;
},
cc
.
sys
.
localStorage
.
setItem
(
'
bundleName
'
,
bundleName
);
this
.
loadOnlineBundle
(
bundleName
);
this
.
showDebugUI
();
});
const
BtnStartCourseWare
=
cc
.
find
(
'
middleLayer/ui/BtnStartCourseWare
'
);
start
()
{
BtnStartCourseWare
.
on
(
'
click
'
,
()
=>
{
this
.
node
.
zIndex
=
9999
;
const
courseIdNode
=
cc
.
find
(
'
middleLayer/ui/courseId
'
);
cc
.
game
.
addPersistRootNode
(
this
.
node
);
const
courseId
=
courseIdNode
.
getComponent
(
cc
.
EditBox
).
string
;
cc
.
sys
.
localStorage
.
setItem
(
'
courseId
'
,
courseId
);
this
.
loadOnlineCourseWare
(
courseId
);
this
.
showDebugUI
();
});
const
BtnLoad
=
cc
.
find
(
'
middleLayer/ui/BtnLoad
'
);
BtnLoad
.
on
(
'
click
'
,
()
=>
{
this
.
preloadCount
=
0
;
this
.
loadedCount
=
0
;
cc
.
find
(
"
middleLayer/ui/ProgressLabel
"
).
active
=
true
;
cc
.
find
(
'
middleLayer/ui/loadingProgress
'
).
active
=
true
;
// this.preloadAll();
this
.
preloadSourceImman
();
});
const
btnClose
=
cc
.
find
(
'
middleLayer/ConsoleNode/BtnClose
'
);
this
.
initListener
();
const
btnOpen
=
cc
.
find
(
'
middleLayer/ConsoleNode/BtnOpen
'
);
this
.
showWaitingLetters
();
const
consoleNode
=
cc
.
find
(
'
middleLayer/ConsoleNode/Console
'
);
this
.
onMiddleLayerLoadingFinish
();
const
consoleBg
=
cc
.
find
(
'
middleLayer/ConsoleNode/bg
'
);
btnOpen
.
on
(
'
click
'
,
()
=>
{
btnClose
.
active
=
true
;
btnOpen
.
active
=
false
;
consoleNode
.
active
=
true
;
consoleBg
.
active
=
true
;
});
btnClose
.
on
(
'
click
'
,
()
=>
{
this
.
loadOnlineBundle
(
"
OP_03_2
"
);
btnClose
.
active
=
false
;
btnOpen
.
active
=
true
;
consoleNode
.
active
=
false
;
consoleBg
.
active
=
false
;
});
},
},
goNextCourseware
()
{
initListener
()
{
this
.
currentIndex
++
;
if
(
!
this
.
courseIds
[
this
.
currentIndex
]){
this
.
currentIndex
=
0
;
}
this
.
callNetworkApiGet
(
`http://iteachabc.com`
,
`/api/courseware/v1/
${
this
.
courseIds
[
this
.
currentIndex
]}
/list`
,
{},
(
data
)
=>
{
if
(
data
.
rows
&&
data
.
rows
.
length
>
0
)
{
this
.
courses
=
data
.
rows
;
this
.
courseIndex
=
0
;
this
.
courseItem
=
data
.
rows
[
0
];
this
.
loadPageBundle
();
}
else
{
// 没有制作课件页,直接切换到下一个课件
this
.
goNextCourseware
();
}
});
},
},
goPrePage
()
{
reWriteAir
()
{
this
.
goTarIndexPage
(
this
.
courseIndex
-
1
);
window
.
courseware
.
getData
=
async
(
callback
)
=>
{
},
const
data
=
this
.
dataStore
[
this
.
currentSceneName
];
goNextPage
()
{
callback
&&
callback
(
data
);
this
.
goTarIndexPage
(
this
.
courseIndex
+
1
);
}
},
if
(
!
window
.
air
)
{
goTarIndexPage
(
index
)
{
window
.
air
=
{};
if
(
!
this
.
courses
||
index
==
this
.
courseIndex
||
index
<
0
)
{
}
return
;
window
.
air
.
hideAirClassLoading
=
()
=>
{
}
window
.
air
.
onCourseInScreen
&&
window
.
air
.
onCourseInScreen
(()
=>
{
this
.
showMask
();
console
.
log
(
"
***成功调用onCourseInScreen***
"
);
this
.
showWaitingLetters
();
window
.
air
.
onCourseInScreen
=
null
;
window
.
courseware
.
freeAllOcMethod
();
});
this
.
hideWaitingLetters
();
}
},
async
loadOnlineBundle
(
bundleName
)
{
cc
.
audioEngine
.
stopAll
();
this
.
currentSceneName
=
bundleName
;
if
(
index
>
this
.
courses
.
length
-
1
)
{
// 本课件播放完了,切换到下一个课件
this
.
goNextCourseware
();
return
;
}
this
.
courseIndex
=
index
;
this
.
courseItem
=
this
.
courses
[
this
.
courseIndex
];
this
.
loadPageBundle
();
},
log
(
str
)
{
const
logStr
=
`
${
new
Date
().
toLocaleString
()}
:
${
str
}
`
;
console
.
log
(
logStr
);
const
content
=
cc
.
instantiate
(
cc
.
find
(
'
middleLayer/ConsoleNode/content
'
));
content
.
active
=
true
;
const
label
=
content
.
getChildByName
(
'
label
'
);
label
.
getComponent
(
cc
.
Label
).
string
=
logStr
;
const
consoleContent
=
cc
.
find
(
'
middleLayer/ConsoleNode/Console/content
'
);
consoleContent
.
addChild
(
content
);
consoleContent
.
getComponent
(
cc
.
Layout
).
updateLayout
();
},
hideUI
()
{
cc
.
find
(
'
middleLayer/ui
'
).
active
=
false
;
},
loadOnlineBundle
(
bundleName
)
{
this
.
showWaitingLetters
();
this
.
showWaitingLetters
();
this
.
callNetworkApiGet
(
`http://staging-teach.ireadabc.com`
,
`/api/template/v1/
${
bundleName
}
`
,
{},
(
data
)
=>
{
const
data
=
await
this
.
asyncCallNetworkApiGet
(
`/api/template/v1/
${
bundleName
}
`
,
{});
let
configData
=
null
;
let
configData
=
null
;
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
)
{
configData
=
data
.
data
.
conf
.
ios
;
}
else
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_ANDROID
)
{
configData
=
data
.
data
.
conf
.
android
;
}
else
{
configData
=
data
.
data
.
conf
.
web_desktop
;
}
const
sceneName
=
configData
.
sceneName
;
const
version
=
configData
.
version
;
const
bondleUrl
=
configData
.
bondleUrl
;
this
.
loadBundle
(
sceneName
,
version
,
bondleUrl
);
});
},
courses
:
null
,
courseIndex
:
0
,
courseItem
:
null
,
loadOnlineCourseWare
(
courseId
,
linkFlag
)
{
this
.
hideUI
();
this
.
showMask
();
this
.
showWaitingLetters
();
let
api
=
`/api/courseware/v1/
${
courseId
}
/list`
;
if
(
linkFlag
===
true
)
{
api
=
`/api/courseware/v1/
${
courseId
}
/eq/level/list`
;
}
this
.
callNetworkApiGet
(
`http://iteachabc.com`
,
api
,
{},
(
data
)
=>
{
if
(
data
.
rows
&&
data
.
rows
.
length
>
0
)
{
this
.
courses
=
data
.
rows
;
this
.
courseIndex
=
data
.
index
||
0
;
this
.
courseItem
=
data
.
rows
[
this
.
courseIndex
];
}
if
(
this
.
courses
&&
this
.
courses
.
length
>
1
&&
this
.
courseIndex
<=
this
.
courses
.
length
-
1
)
{
// cc.find('middleLayer/BtnRight').active = true;
}
if
(
this
.
courseIndex
>
0
)
{
cc
.
find
(
'
middleLayer/BtnLeft
'
).
active
=
false
;
}
this
.
reWriteAir
();
this
.
loadPageBundle
();
});
},
loadLocalBundle
(
address
,
port
)
{
this
.
callNetworkApiGetLocal
(
`http://
${
address
}
:
${
port
}
`
,
'
/dist/config.json
'
,
{},
(
datastr
)
=>
{
const
data
=
JSON
.
parse
(
datastr
);
let
sceneName
=
''
;
let
version
=
''
;
let
bondleUrl
=
''
;
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
)
{
sceneName
=
data
.
ios
.
sceneName
;
version
=
data
.
ios
.
version
;
bondleUrl
=
`http://
${
address
}
:
${
port
}
/dist/ios/
${
sceneName
}
/`
;
}
else
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_ANDROID
)
{
sceneName
=
data
.
android
.
sceneName
;
version
=
data
.
android
.
version
;
bondleUrl
=
`http://
${
address
}
:
${
port
}
/dist/android/
${
sceneName
}
/`
;
}
else
{
sceneName
=
data
.
android
.
sceneName
;
version
=
""
;
bondleUrl
=
`http://
${
address
}
:
${
port
}
/dist/web_desktop/`
;
}
this
.
loadBundle
(
sceneName
,
version
,
bondleUrl
);
});
},
loadPageBundle
()
{
let
sceneName
,
version
,
bondleUrl
=
""
;
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
)
{
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
)
{
sceneName
=
this
.
courseItem
.
conf
.
ios
.
sceneName
;
configData
=
data
.
data
.
conf
.
ios
;
version
=
this
.
courseItem
.
conf
.
ios
.
version
;
bondleUrl
=
this
.
courseItem
.
conf
.
ios
.
bondleUrl
;
}
else
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_ANDROID
)
{
}
else
if
(
cc
.
sys
.
os
==
cc
.
sys
.
OS_ANDROID
)
{
sceneName
=
this
.
courseItem
.
conf
.
android
.
sceneName
;
configData
=
data
.
data
.
conf
.
android
;
version
=
this
.
courseItem
.
conf
.
android
.
version
;
bondleUrl
=
this
.
courseItem
.
conf
.
android
.
bondleUrl
;
}
else
{
}
else
{
sceneName
=
this
.
courseItem
.
conf
.
web_desktop
.
sceneName
;
configData
=
data
.
data
.
conf
.
web_desktop
;
version
=
this
.
courseItem
.
conf
.
web_desktop
.
version
;
bondleUrl
=
this
.
courseItem
.
conf
.
web_desktop
.
bondleUrl
;
}
}
const
sceneName
=
configData
.
sceneName
;
const
version
=
configData
.
version
;
const
bondleUrl
=
configData
.
bondleUrl
;
this
.
loadBundle
(
sceneName
,
version
,
bondleUrl
);
this
.
loadBundle
(
sceneName
,
version
,
bondleUrl
);
},
},
loadBundle
(
sceneName
,
version
,
bondleUrl
)
{
loadBundle
(
sceneName
,
version
,
bondleUrl
)
{
this
.
currentBundleInfo
=
{
sceneName
,
version
,
bondleUrl
};
cc
.
assetManager
.
loadBundle
(
bondleUrl
,
{
version
:
version
},
async
(
err
,
bundle
)
=>
{
cc
.
assetManager
.
loadBundle
(
bondleUrl
,
{
version
:
version
},
async
(
err
,
bundle
)
=>
{
if
(
err
)
{
if
(
err
)
{
return
this
.
asyncDelayLog
(
err
);
console
.
error
(
err
);
return
;
}
}
bundle
.
loadScene
(
sceneName
,
null
,
null
,
(
err
,
scene
)
=>
{
bundle
.
loadScene
(
sceneName
,
null
,
null
,
(
err
,
scene
)
=>
{
if
(
err
)
{
if
(
err
)
{
this
.
asyncDelayLog
(
'
err:
'
,
err
);
console
.
error
(
err
);
}
}
cc
.
audioEngine
.
stopAll
();
cc
.
director
.
runScene
(
scene
,
null
,
()
=>
{
cc
.
director
.
runScene
(
scene
,
null
,
()
=>
{
console
.
log
(
'
sceneName =
'
+
sceneName
);
const
Canvas
=
cc
.
find
(
'
Canvas
'
);
const
Canvas
=
cc
.
find
(
'
Canvas
'
);
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
// cc.find('middleLayer/ExitBtn').active = true;
this
.
hideMask
();
this
.
hideWaitingLetters
();
Canvas
.
getComponent
(
cc
.
Widget
).
updateAlignment
();
Canvas
.
getComponent
(
cc
.
Widget
).
updateAlignment
();
middleLayer
.
scale
=
Canvas
.
width
/
middleLayer
.
width
;
middleLayer
.
scale
=
Canvas
.
width
/
middleLayer
.
width
;
// this.showLog('middleLayer.scale = ' + middleLayer.scale);
});
});
});
});
});
});
},
},
showMask
()
{
const
mask
=
cc
.
find
(
'
middleLayer/mask
'
);
mask
.
active
=
true
;
cc
.
tween
(
mask
)
.
set
({
opacity
:
0
})
.
to
(
0.2
,
{
opacity
:
180
})
.
start
();
},
hideMask
()
{
const
mask
=
cc
.
find
(
'
middleLayer/mask
'
);
mask
.
stopAllActions
();
cc
.
tween
(
mask
)
.
set
({
opacity
:
180
})
.
to
(
0.2
,
{
opacity
:
0
})
.
call
(()
=>
{
mask
.
active
=
false
;
})
.
start
();
},
turnPageWait
:
0
,
reWriteAir
()
{
window
.
courseware
.
getData
=
(
callback
)
=>
{
let
data
=
null
;
if
(
this
.
courseItem
.
data
)
{
data
=
JSON
.
parse
(
this
.
courseItem
.
data
);
}
this
.
log
(
"
===成功调用getData===
"
+
this
.
courseItem
.
data
);
callback
&&
callback
(
data
);
}
window
.
courseware
.
nextPage
=
()
=>
{
setTimeout
(()
=>
{
this
.
goNextPage
();
},
this
.
turnPageWait
);
this
.
turnPageWait
=
0
;
}
window
.
courseware
.
beforePage
=
()
=>
{
this
.
goPrePage
();
}
window
.
courseware
.
sendAnswer
=
(
answerObj
)
=>
{
this
.
log
(
"
===成功调用sendAnswer===
"
+
JSON
.
stringify
(
answerObj
));
this
.
turnPageWait
=
2000
;
this
.
addStar
(
3
,
true
);
// 上报成绩则获得三颗星星并展示动画
this
.
callNetworkApiPost
(
this
.
baseApiUrl
,
`v1/terminal/save/answer`
,
{
syllabus_id
:
this
.
courseItem
.
course_id
,
courseware_id
:
this
.
courseItem
.
id
,
engine_code
:
this
.
engineCode
,
name
:
this
.
name
,
template_name
:
this
.
courseItem
.
template_name
,
template_description
:
this
.
courseItem
.
template_description
,
result
:
JSON
.
stringify
(
answerObj
),
},
(
data
)
=>
{
answerObj
.
callback
&&
answerObj
.
callback
(
JSON
.
stringify
(
data
.
data
));
});
}
window
.
courseware
.
addStar
=
this
.
addStar
.
bind
(
this
);
},
callNativeFunction
(
param
)
{
const
paramStr
=
JSON
.
stringify
(
param
);
if
(
cc
.
sys
.
isNative
&&
cc
.
sys
.
os
==
cc
.
sys
.
OS_IOS
)
{
return
jsb
.
reflection
.
callStaticMethod
(
'
CocosMng
'
,
'
cocosWithNativeProtocol:
'
,
paramStr
);
}
else
if
(
cc
.
sys
.
isNative
&&
cc
.
sys
.
os
==
cc
.
sys
.
OS_ANDROID
)
{
return
jsb
.
reflection
.
callStaticMethod
(
'
com/iplayabc/cocos/AppActivity
'
,
'
cocosWithNativeProtocol
'
,
'
(Ljava/lang/String;)Ljava/lang/String;
'
,
paramStr
);
}
else
if
(
cc
.
sys
.
isNative
&&
cc
.
sys
.
os
==
cc
.
sys
.
OS_WINDOWS
)
{
console
.
log
(
'
汪汪汪
'
)
}
else
{
console
.
error
(
'
非源生环境
'
);
}
},
showWaitingLetters
()
{
showWaitingLetters
()
{
if
(
this
.
isShowWaiting
)
{
if
(
this
.
isShowWaiting
)
{
return
;
return
;
}
}
...
@@ -783,52 +233,6 @@ cc.Class({
...
@@ -783,52 +233,6 @@ cc.Class({
this
.
isShowWaiting
=
false
;
this
.
isShowWaiting
=
false
;
},
},
showLog
(
str
)
{
if
(
!
this
.
logList
)
{
this
.
logList
=
[];
}
this
.
logList
.
push
(
str
);
console
.
log
(
str
);
if
(
this
.
logList
.
length
==
1
)
{
this
.
showOneLog
();
}
},
showDebugUI
()
{
cc
.
find
(
'
middleLayer/ConsoleNode/BtnOpen
'
).
active
=
true
;
},
showOneLog
()
{
const
str
=
this
.
logList
[
0
];
if
(
str
===
undefined
)
{
return
;
}
const
node
=
new
cc
.
Node
();
node
.
anchorX
=
0.5
;
const
label
=
node
.
addComponent
(
cc
.
RichText
);
label
.
string
=
`<outline color=black width=3>
${
str
}
</outline>`
;
label
.
maxWidth
=
this
.
node
.
width
/
2
;
node
.
x
=
this
.
node
.
width
/
4
;
node
.
y
=
-
this
.
node
.
height
/
2
;
node
.
parent
=
this
.
node
;
cc
.
tween
(
node
)
.
to
(
5
,
{
y
:
this
.
node
.
height
})
.
removeSelf
()
.
start
();
setTimeout
(()
=>
{
this
.
logList
.
shift
();
this
.
showOneLog
();
},
1000
);
},
exit
()
{
cc
.
game
.
removePersistRootNode
(
this
.
node
);
cc
.
director
.
loadScene
(
"
emptyScene
"
,
()
=>
{
this
.
callNativeFunction
({
name
:
'
exit
'
,
value
:
''
});
});
},
getRainbowColorList
()
{
getRainbowColorList
()
{
return
[
return
[
cc
.
color
(
255
,
255
,
0
),
cc
.
color
(
255
,
255
,
0
),
...
@@ -849,5 +253,10 @@ cc.Class({
...
@@ -849,5 +253,10 @@ cc.Class({
cc
.
color
(
255
,
128
,
0
),
cc
.
color
(
255
,
128
,
0
),
cc
.
color
(
255
,
255
,
0
),
cc
.
color
(
255
,
255
,
0
),
];
];
},
log
(
str
)
{
console
.
log
(
str
);
}
}
});
});
assets/middleLayer_for_iplayabc/script/util.js
View file @
a4a0c910
...
@@ -71,64 +71,64 @@ export function setSprNodeMaxLen(sprNode, maxW, maxH) {
...
@@ -71,64 +71,64 @@ export function setSprNodeMaxLen(sprNode, maxW, maxH) {
}
}
export
function
localPosTolocalPos
(
baseNode
,
targetNode
)
{
export
function
localPosTolocalPos
(
baseNode
,
targetNode
)
{
const
worldPos
=
targetNode
.
parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
));
const
worldPos
=
targetNode
.
parent
.
convertToWorldSpaceAR
(
cc
.
v2
(
targetNode
.
x
,
targetNode
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
return
localPos
;
}
}
export
function
worldPosToLocalPos
(
worldPos
,
baseNode
)
{
export
function
worldPosToLocalPos
(
worldPos
,
baseNode
)
{
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
const
localPos
=
baseNode
.
parent
.
convertToNodeSpaceAR
(
cc
.
v2
(
worldPos
.
x
,
worldPos
.
y
));
return
localPos
;
return
localPos
;
}
}
export
function
getScaleRateBy2Node
(
baseNode
,
targetNode
,
maxFlag
=
true
)
{
export
function
getScaleRateBy2Node
(
baseNode
,
targetNode
,
maxFlag
=
true
)
{
const
worldRect1
=
targetNode
.
getBoundingBoxToWorld
();
const
worldRect1
=
targetNode
.
getBoundingBoxToWorld
();
const
worldRect2
=
baseNode
.
getBoundingBoxToWorld
();
const
worldRect2
=
baseNode
.
getBoundingBoxToWorld
();
const
sx
=
worldRect1
.
width
/
worldRect2
.
width
;
const
sx
=
worldRect1
.
width
/
worldRect2
.
width
;
const
sy
=
worldRect1
.
height
/
worldRect2
.
height
;
const
sy
=
worldRect1
.
height
/
worldRect2
.
height
;
if
(
maxFlag
)
{
if
(
maxFlag
)
{
return
Math
.
max
(
sx
,
sy
);
return
Math
.
max
(
sx
,
sy
);
}
else
{
}
else
{
return
Math
.
min
(
sx
,
sy
);
return
Math
.
min
(
sx
,
sy
);
}
}
}
}
export
function
getDistance
(
start
,
end
)
{
export
function
getDistance
(
start
,
end
)
{
var
pos
=
cc
.
v2
(
start
.
x
-
end
.
x
,
start
.
y
-
end
.
y
);
var
pos
=
cc
.
v2
(
start
.
x
-
end
.
x
,
start
.
y
-
end
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
var
dis
=
Math
.
sqrt
(
pos
.
x
*
pos
.
x
+
pos
.
y
*
pos
.
y
);
return
dis
;
return
dis
;
}
}
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
export
function
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
if
(
audio_url
)
{
if
(
audio_url
)
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
if
(
cb
)
{
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
();
cb
();
});
});
}
}
});
});
}
}
}
}
export
function
btnClickAnima
(
btn
,
time
=
0.15
,
rate
=
1.05
)
{
export
function
btnClickAnima
(
btn
,
time
=
0.15
,
rate
=
1.05
)
{
btn
.
tmpScale
=
btn
.
scale
;
btn
.
tmpScale
=
btn
.
scale
;
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_START
,
()
=>
{
cc
.
tween
(
btn
)
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
to
(
time
/
2
,
{
scale
:
btn
.
scale
*
rate
})
.
start
()
.
start
()
})
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
()
=>
{
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_CANCEL
,
()
=>
{
cc
.
tween
(
btn
)
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
.
start
()
})
})
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
()
=>
{
btn
.
on
(
cc
.
Node
.
EventType
.
TOUCH_END
,
()
=>
{
cc
.
tween
(
btn
)
cc
.
tween
(
btn
)
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
to
(
time
/
2
,
{
scale
:
btn
.
tmpScale
})
.
start
()
.
start
()
})
})
}
}
...
@@ -165,10 +165,10 @@ export function getSprNodeByUrl(url, cb) {
...
@@ -165,10 +165,10 @@ export function getSprNodeByUrl(url, cb) {
export
function
playAudio
(
audioClip
,
cb
=
null
)
{
export
function
playAudio
(
audioClip
,
cb
=
null
)
{
if
(
audioClip
)
{
if
(
audioClip
)
{
const
audioId
=
cc
.
audioEngine
.
playEffect
(
audioClip
,
false
,
0.8
);
const
audioId
=
cc
.
audioEngine
.
playEffect
(
audioClip
,
false
);
if
(
cb
)
{
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
cb
&&
cb
();
cb
();
});
});
}
}
}
}
...
@@ -177,15 +177,85 @@ export function playAudio(audioClip, cb = null) {
...
@@ -177,15 +177,85 @@ export function playAudio(audioClip, cb = null) {
export
async
function
asyncDelay
(
time
)
{
export
async
function
asyncDelay
(
time
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
try
{
setTimeout
(()
=>
{
cc
.
tween
(
cc
.
find
(
'
Canvas
'
))
resolve
();
.
delay
(
time
)
},
time
*
1000
);
.
call
(()
=>
{
resolve
(
null
);
})
.
start
();
}
catch
(
e
)
{
}
catch
(
e
)
{
reject
(
e
);
reject
(
e
);
}
}
})
})
}
}
export
async
function
asyncLoadDragonBoneAnime
(
node
,
{
skeJsonData
:
{
url
:
skeJsonDataUrl
},
texJsonData
:
{
url
:
texJsonDataUrl
},
texPngData
:
{
url
:
texPngDataUrl
}
})
{
if
(
!
texPngDataUrl
||
!
texJsonDataUrl
||
!
texPngDataUrl
||
texPngDataUrl
==
''
||
texJsonDataUrl
==
''
||
texPngDataUrl
==
''
)
{
return
;
}
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
node
.
animaNode
)
{
node
.
animaNode
.
removeFromParent
();
}
const
animaNode
=
new
cc
.
Node
();
animaNode
.
name
=
'
animaNode
'
;
animaNode
.
parent
=
node
;
animaNode
.
active
=
true
;
node
.
animaNode
=
animaNode
;
const
dragonDisplay
=
animaNode
.
addComponent
(
dragonBones
.
ArmatureDisplay
);
const
loadTexture
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadRemote
(
texPngDataUrl
,
(
error
,
texture
)
=>
{
if
(
error
)
{
reject
(
error
);
}
resolve
(
texture
);
});
});
const
loadTexJsonData
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadAny
({
url
:
texJsonDataUrl
},
(
error
,
atlasJson
)
=>
{
if
(
error
)
{
reject
(
error
);
}
resolve
(
atlasJson
);
});
});
const
loadSkeJsonData
=
new
Promise
((
resolve
,
reject
)
=>
{
cc
.
assetManager
.
loadAny
({
url
:
skeJsonDataUrl
},
(
error
,
dragonBonesJson
)
=>
{
if
(
error
)
{
reject
(
error
);
}
resolve
(
dragonBonesJson
);
});
});
Promise
.
all
([
loadTexture
,
loadTexJsonData
,
loadSkeJsonData
]).
then
(([
texture
,
atlasJson
,
dragonBonesJson
])
=>
{
const
atlas
=
new
dragonBones
.
DragonBonesAtlasAsset
();
atlas
.
atlasJson
=
JSON
.
stringify
(
atlasJson
);
atlas
.
texture
=
texture
;
const
asset
=
new
dragonBones
.
DragonBonesAsset
();
asset
.
dragonBonesJson
=
JSON
.
stringify
(
dragonBonesJson
);
dragonDisplay
.
dragonAtlasAsset
=
atlas
;
dragonDisplay
.
dragonAsset
=
asset
;
let
armatureNames
=
dragonBonesJson
.
armature
.
map
(
data
=>
data
.
name
);
if
(
armatureNames
.
length
>
0
)
{
dragonDisplay
.
armatureName
=
armatureNames
[
0
];
}
resolve
(
animaNode
);
});
});
}
export
class
FireworkSettings
{
export
class
FireworkSettings
{
baseNode
;
// 父节点
baseNode
;
// 父节点
nodeList
;
// 火花节点的array
nodeList
;
// 火花节点的array
...
@@ -296,7 +366,7 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) {
...
@@ -296,7 +366,7 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) {
cc
.
tween
(
node
)
cc
.
tween
(
node
)
.
to
(
duration
,
obj
,
ease
)
.
to
(
duration
,
obj
,
ease
)
.
call
(()
=>
{
.
call
(()
=>
{
resolve
();
resolve
(
null
);
})
})
.
start
();
.
start
();
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -305,69 +375,13 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) {
...
@@ -305,69 +375,13 @@ export async function asyncTweenTo(node, duration, obj, ease = undefined) {
});
});
}
}
export
function
showBigStar
(
starJump
,
starBase
,
cb
=
null
)
{
const
bigStarBg
=
cc
.
instantiate
(
starJump
);
bigStarBg
.
scale
=
starJump
.
width
/
starBase
.
width
/
1.2
;
starBase
.
scale
=
1
;
// const star = bigStarBg.star;
starJump
.
active
=
true
;
starJump
.
scaleX
=
0.7
/
bigStarBg
.
scale
;
starJump
.
scaleY
=
1
/
bigStarBg
.
scale
;
// starJump.angle = 90;
const
canvas
=
cc
.
find
(
'
Canvas
'
);
const
startPos
=
exchangeNodePos
(
starJump
.
parent
,
canvas
,
cc
.
v2
(
0
,
-
canvas
.
height
/
2
));
const
middlePos
=
exchangeNodePos
(
starJump
.
parent
,
canvas
,
cc
.
v2
(
0
,
-
canvas
.
height
/
4
));
starJump
.
x
=
startPos
.
x
+
Math
.
random
()
*
100
-
50
;
starJump
.
y
=
startPos
.
y
-
starBase
.
height
;
console
.
log
(
'
middlePos =
'
+
JSON
.
stringify
(
middlePos
));
const
time
=
1
;
cc
.
tween
(
starJump
)
.
to
(
0.3
,
{
y
:
middlePos
.
y
+
60
},
{
easing
:
'
quadOut
'
})
.
to
(
0.1
,
{
y
:
middlePos
.
y
+
30
,
scaleX
:
1.2
/
bigStarBg
.
scale
,
scaleY
:
0.8
/
bigStarBg
.
scale
},
{
easing
:
'
quadOut
'
})
.
to
(
0.1
,
{
y
:
middlePos
.
y
,
scaleX
:
1
/
bigStarBg
.
scale
,
scaleY
:
1
/
bigStarBg
.
scale
},
{
easing
:
'
quadOut
'
})
.
delay
(
0.1
)
.
to
(
0.8
,
{
angle
:
-
720
,
scale
:
1
})
.
start
();
cc
.
tween
(
starJump
)
.
delay
(
0.6
)
.
to
(
0.8
,
{
x
:
starBase
.
x
},
{
easing
:
'
sineOut
'
})
.
start
();
cc
.
tween
(
starJump
)
.
delay
(
0.6
)
.
to
(
0.8
,
{
y
:
starBase
.
y
},
{
easing
:
'
backIn
'
})
.
start
();
cc
.
tween
(
starJump
)
.
delay
(
0.6
)
.
to
(
0.8
,
{
scale
:
starBase
.
width
/
starJump
.
width
*
0.5
},
{
easing
:
'
quadOut
'
})
.
call
(()
=>
{
starJump
.
removeFromParent
();
cb
&&
cb
()
})
.
start
();
cc
.
tween
(
starBase
)
.
delay
(
1.4
)
.
to
(
0.1
,
{
scale
:
1.2
},
{
easing
:
'
sineInOut
'
})
.
to
(
1.1
,
{
scale
:
1
},
{
easing
:
'
elasticOut
'
})
.
start
();
}
export
async
function
asyncTweenBy
(
node
,
duration
,
obj
,
ease
=
undefined
)
{
export
async
function
asyncTweenBy
(
node
,
duration
,
obj
,
ease
=
undefined
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
try
{
cc
.
tween
(
node
)
cc
.
tween
(
node
)
.
by
(
duration
,
obj
,
ease
)
.
by
(
duration
,
obj
,
ease
)
.
call
(()
=>
{
.
call
(()
=>
{
resolve
();
resolve
(
null
);
})
})
.
start
();
.
start
();
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -407,4 +421,120 @@ export function onHomeworkFinish() {
...
@@ -407,4 +421,120 @@ export function onHomeworkFinish() {
}
else
{
}
else
{
console
.
log
(
'
onHomeworkFinish
'
);
console
.
log
(
'
onHomeworkFinish
'
);
}
}
}
}
\ No newline at end of file
export
function
asyncCallNetworkApiGet
(
apiName
,
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
callNetworkApiGet
(
apiName
,
data
,
(
res
=>
{
resolve
(
res
);
}));
});
}
export
function
asyncCallNetworkApiPost
(
uri
,
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
callNetworkApiPost
(
uri
,
data
,
(
res
)
=>
{
resolve
(
res
);
});
});
}
export
function
callNetworkApiPost
(
uri
,
data
,
callBack
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
callNetworkApiPost
(
uri
,
data
,
callBack
);
return
;
}
const
baseUrl
=
'
http://staging-openapi.iteachabc.com
'
;
const
xhr
=
new
XMLHttpRequest
();
const
url
=
`
${
baseUrl
}${
uri
}
`
;
xhr
.
open
(
"
POST
"
,
url
,
true
);
xhr
.
setRequestHeader
(
'
content-type
'
,
'
application/json
'
);
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
)
{
callBack
(
JSON
.
parse
(
xhr
.
responseText
));
}
}
xhr
.
send
(
JSON
.
stringify
(
data
));
}
export
function
callNetworkApiGet
(
uri
,
data
,
callBack
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
)?.
getComponent
(
'
middleLayer
'
);
if
(
middleLayer
)
{
middleLayer
.
callNetworkApiGet
(
uri
,
data
,
callBack
);
return
;
}
const
baseUrl
=
'
http://staging-openapi.iteachabc.com
'
;
let
queryStr
=
'
?
'
;
const
params
=
[];
for
(
const
key
in
data
)
{
if
(
Object
.
hasOwnProperty
.
call
(
data
,
key
))
{
params
.
push
(
`
${
key
}
=
${
data
[
key
]}
`
);
}
}
queryStr
+=
params
.
join
(
"
&
"
);
const
xhr
=
new
XMLHttpRequest
();
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
>=
200
&&
xhr
.
status
<
400
))
{
callBack
(
xhr
.
responseText
);
}
};
const
url
=
`
${
baseUrl
}${
uri
}${
queryStr
}
`
;
console
.
log
(
'
url =
'
+
url
);
xhr
.
open
(
'
GET
'
,
url
,
true
);
xhr
.
send
();
}
export
function
jumpToBundle
(
bundleName
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
loadOnlineBundle
(
bundleName
);
}
else
{
console
.
log
(
'
jump to bundle:
'
+
bundleName
);
}
}
export
function
jumpToCourseWare
(
courseWareId
)
{
const
middleLayer
=
cc
.
find
(
'
middleLayer
'
);
if
(
middleLayer
)
{
const
middleLayerComponent
=
middleLayer
.
getComponent
(
'
middleLayer
'
);
middleLayerComponent
.
loadOnlineCourseWare
(
courseWareId
);
}
else
{
console
.
log
(
'
jump to CourseWare:
'
+
courseWareId
);
}
}
export
function
buttonOnceClick
(
button
,
callback
,
scale
=
1.1
)
{
button
.
once
(
'
click
'
,
()
=>
{
if
(
button
[
'
cantClick
'
])
{
return
;
}
button
[
'
cantClick
'
]
=
true
;
cc
.
tween
(
button
)
.
to
(
0.1
,
{
scale
:
scale
})
.
to
(
0.1
,
{
scale
:
1.0
})
.
call
(()
=>
{
button
[
'
cantClick
'
]
=
false
;
callback
&&
callback
();
})
.
start
();
});
}
export
function
buttonOnClick
(
button
,
callback
,
scale
=
1.0
)
{
button
.
on
(
'
click
'
,
()
=>
{
if
(
button
[
'
cantClick
'
])
{
return
;
}
button
[
'
cantClick
'
]
=
true
;
cc
.
tween
(
button
)
.
to
(
0.1
,
{
scale
:
scale
*
1.1
})
.
to
(
0.1
,
{
scale
:
scale
})
.
call
(()
=>
{
button
[
'
cantClick
'
]
=
false
;
callback
&&
callback
();
})
.
start
();
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment