Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
E
elephant
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
elephant
Commits
8020f9d6
Commit
8020f9d6
authored
3 years ago
by
liujiaxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: with backend interface
parent
8113a10a
Changes
13
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
4270 additions
and
1405 deletions
+4270
-1405
elephant.fire
assets/elephant/scene/elephant.fire
+3852
-1301
elephant.ts
assets/elephant/scene/elephant.ts
+215
-40
item.ts
assets/elephant/scene/model/item.ts
+4
-2
shop.ts
assets/elephant/scene/model/shop.ts
+5
-2
user.ts
assets/elephant/scene/model/user.ts
+15
-13
api.ts
assets/elephant/scene/net/api.ts
+48
-14
pg.ts
assets/elephant/scene/pg.ts
+53
-17
MyCocosSceneComponent.ts
assets/elephant/script/MyCocosSceneComponent.ts
+6
-4
eat.meta
assets/elephant/textures/ani/eat.meta
+0
-12
bg_alert.png
assets/elephant/textures/tips/bg_alert.png
+0
-0
bg_alert.png.meta
assets/elephant/textures/tips/bg_alert.png.meta
+36
-0
btn_alert_ok.png
assets/elephant/textures/tips/btn_alert_ok.png
+0
-0
btn_alert_ok.png.meta
assets/elephant/textures/tips/btn_alert_ok.png.meta
+36
-0
No files found.
assets/elephant/scene/elephant.fire
View file @
8020f9d6
This source diff could not be displayed because it is too large. You can
view the blob
instead.
This diff is collapsed.
Click to expand it.
assets/elephant/scene/elephant.ts
View file @
8020f9d6
...
...
@@ -46,13 +46,33 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
onLoadEnd
()
{
globalThis
.
USER_TOKEN
=
"
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2Mzk2MjE3MTIsImV4cCI6MTY0MjIxMzcxMiwiaWQiOjQwMDY2LCJwYXNzd29yZCI6IjE5QTEwM0E3NUUzM0QzQTNCODg0QkQxNTUwMjhENTA1Iiwic2Nob29sX2lkIjoyODYsInBob25lIjoiMTMxMDAwMDAwMDAiLCJuYW1lIjoi5bCP546J5rWL6K-VMCIsInN0YXR1cyI6MCwidHlwZSI6MCwicm9sZXMiOjEsImV4cGlyZWQiOiIyMDIyLTAzLTE5VDE2OjAwOjAwLjAwMFoiLCJzY2hvb2xfbmFtZSI6Iue7mOeOqea1i-ivleeOr-Wig-WtpuagoSIsInNjaG9vbF90eXBlIjoyLCJjcmVhdGVvbiI6MTU3MDc2MTk3NDAwMCwiY2xhc3NfbmFtZSI6IuS4ieW5tDHnj60iLCJjbGFzc19pbmZvIjpbeyJjbGFzc19pZCI6MzkxNSwiY2xhc3NfbmFtZSI6IuS4ieW5tDHnj60ifV0sIm90aGVycyI6W119.4T-Lnsl25aJ-rvUOCDwShq4F5u3BbR86ZLPew4zyULU
"
globalThis
.
CLIENT_TYPE
=
'
student
'
globalThis
.
SERVER_HOST
=
'
http://192.168.3.127:3900
'
// globalThis.SERVER_HOST = 'http://staging.ireadabc.com'
this
.
initGame
();
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
Api
.
askUser
().
then
(()
=>
{
this
.
initData
();
this
.
initView
();
this
.
initEvent
();
this
.
initTipSys
();
// TODO 加载完成后的逻辑写在这里, 下面的代码仅供参考
this
.
fetchUserData
();
return
Promise
.
resolve
()
}
fetchUserData
()
{
this
.
showWaitingLetters
();
return
Api
.
askUser
().
then
(()
=>
{
this
.
hideWaitingLetters
()
this
.
initData
();
}).
catch
((
e
)
=>
{
this
.
hideWaitingLetters
()
this
.
openTipAlert
({
message
:
'
网络错误,请返回重新进入
'
,
callback
:
()
=>
{
this
.
closeTipAlert
();
this
.
fetchUserData
();
}})
})
}
initGame
()
{
...
...
@@ -68,12 +88,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
private
home
:
cc
.
Node
;
private
kitchen
:
cc
.
Node
;
private
shop
:
cc
.
Node
;
private
loading
:
cc
.
Node
;
tws
:
any
[]
=
[];
LoadingCount
:
number
=
1
;
initView
()
{
this
.
tws
=
[];
this
.
LoadingCount
=
0
;
this
.
home
=
pg
.
view
.
find
(
this
,
"
home
"
);
this
.
kitchen
=
pg
.
view
.
find
(
this
,
"
kitchen
"
);
this
.
shop
=
pg
.
view
.
find
(
this
,
"
shop
"
);
this
.
elephant
=
pg
.
view
.
find
(
this
.
home
,
"
elephant
"
);
this
.
loading
=
pg
.
view
.
find
(
this
,
"
loading
"
);
this
.
elephentState
(
0
);
}
...
...
@@ -116,12 +141,17 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
updateShopBtns
();
}
onTouchShopHouse
()
{
this
.
shopType
=
ITEM_TYPE
.
HOUSE
;
const
list
=
this
.
updateShopList
();
if
(
!
list
.
length
)
{
this
.
openTipEmpty
(()
=>
{
this
.
closeTipEmpty
();
})
// this.shopType = ITEM_TYPE.HOUSE
;
// this.updateShopList();
//
this.updateShopBtns();
});
return
;
}
this
.
updateShopBtns
();
}
onTouchShopClothes
()
{
this
.
openTipEmpty
(()
=>
{
...
...
@@ -138,12 +168,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
updateShopList
()
{
let
scroll
=
pg
.
view
.
find
(
this
.
shop
,
"
scrollview
"
);
let
svt
=
scroll
.
getComponent
(
"
svt
"
);
let
list
=
kitchen
.
getListByType
(
this
.
shopType
);
let
list
=
shop
.
getListByType
(
this
.
shopType
);
svt
.
list
=
list
;
if
(
list
.
length
==
0
)
{
return
list
;
}
svt
.
updateItem
=
this
.
updateShopItems
;
svt
.
target
=
this
;
svt
.
addNum
=
4
;
svt
.
flush
();
return
list
;
}
updateShopBtns
()
{
let
btns
=
pg
.
view
.
find
(
this
.
shop
,
"
btns
"
);
...
...
@@ -165,44 +199,49 @@ export default class SceneComponent extends MyCocosSceneComponent {
for
(
let
i
=
0
;
i
<
datas
.
length
;
i
++
)
{
let
it
=
item
.
children
[
i
];
let
dt
=
datas
[
i
];
if
(
dt
)
{
// console.log(dt.name);
this
.
updateShopItem
(
it
,
dt
);
}
}
}
updateShopItem
(
item
,
data
:
Item
)
{
item
.
active
=
true
;
let
growth
=
pg
.
view
.
find
(
item
,
"
growth
"
);
let
txt
=
pg
.
view
.
find
(
item
,
"
txt
"
);
let
name
=
pg
.
view
.
find
(
item
,
"
name
"
);
let
icon
=
pg
.
view
.
find
(
item
,
"
icon
"
);
let
discount
=
pg
.
view
.
find
(
item
,
"
discount
"
);
let
btn_buy
=
pg
.
view
.
find
(
item
,
"
btn_buy
"
);
let
growth
=
pg
.
view
.
find
(
item
,
"
bg_food/
growth
"
);
let
txt
=
pg
.
view
.
find
(
item
,
"
bg_food/
txt
"
);
let
name
=
pg
.
view
.
find
(
item
,
"
bg_food/
name
"
);
let
icon
=
pg
.
view
.
find
(
item
,
"
bg_food/
icon
"
);
let
discount
=
pg
.
view
.
find
(
item
,
"
bg_food/
discount
"
);
let
btn_buy
=
pg
.
view
.
find
(
item
,
"
b
g_food/b
tn_buy
"
);
pg
.
view
.
setString
(
txt
,
`可增加 个成长值`
)
pg
.
view
.
setString
(
growth
,
data
.
growthValue
)
pg
.
view
.
setString
(
name
,
data
.
name
)
icon
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
this
[
data
.
icon
];
// console.log(data.cover);
pg
.
view
.
setNetImg
(
icon
,
data
.
cover
,
false
)
// icon.getComponent(cc.Sprite).spriteFrame = this[data.icon];
let
dis
=
Math
.
round
((
1
-
data
.
discount
)
*
100
);
if
(
dis
>
0
)
{
pg
.
view
.
setString
(
discount
,
`
${
dis
}
%`
)
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
bg_sale
"
),
true
);
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
discount
"
),
true
);
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
bg_
food/bg_
sale
"
),
true
);
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
bg_food/
discount
"
),
true
);
}
else
{
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
bg_sale
"
),
false
);
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
discount
"
),
false
);
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
bg_
food/bg_
sale
"
),
false
);
pg
.
view
.
visible
(
pg
.
view
.
find
(
item
,
"
bg_food/
discount
"
),
false
);
}
pg
.
view
.
setString
(
pg
.
view
.
find
(
btn_buy
,
"
num
"
),
data
.
cost
)
pg
.
view
.
touchOn
(
btn_buy
,
this
.
onTouchShopItem
,
this
);
pg
.
view
.
touchOn
(
item
,
this
.
onTouchShopItem
,
this
);
item
.
data
=
data
;
}
onTouchShopItem
(
e
)
{
let
item
=
e
.
target
.
parent
;
let
item
=
e
.
target
;
//
.parent;
let
data
:
Item
=
item
.
data
;
if
(
data
.
type
==
1
)
{
//弹出购买弹窗
console
.
log
(
user
)
if
(
user
.
coin
>=
data
.
cost
*
data
.
discount
)
{
this
.
openTipNormal
(
data
,
()
=>
{
this
.
buy
(
data
);
...
...
@@ -226,10 +265,28 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
buy
(
data
)
{
Api
.
askBuyItem
(
data
).
then
(()
=>
{
this
.
showWaitingLetters
();
Api
.
askBuyItem
(
data
).
then
((
resp
)
=>
{
this
.
fetchUserData
().
then
(
ud
=>
{
this
.
hideWaitingLetters
(
true
)
this
.
updateShopCoin
();
this
.
openTipBuy
(
data
,
()
=>
{
this
.
closeTipBuy
();
});
}).
catch
(
e
=>
{
this
.
hideWaitingLetters
(
true
);
this
.
openTipAlert
({
message
:
'
网络错误,请重试(err: 1)
'
,
callback
:
()
=>
{
this
.
closeTipAlert
();
}
})
});
}).
catch
(
e
=>
{
this
.
hideWaitingLetters
(
true
);
this
.
openTipAlert
({
message
:
'
网络错误,请重试(err: 2)
'
,
callback
:
()
=>
{
this
.
closeTipAlert
();
}
})
})
}
...
...
@@ -255,10 +312,13 @@ export default class SceneComponent extends MyCocosSceneComponent {
for
(
let
i
=
0
;
i
<
datas
.
length
;
i
++
)
{
let
it
=
item
.
children
[
i
];
let
dt
=
datas
[
i
];
if
(
dt
)
{
this
.
updateChickenItem
(
it
,
dt
);
}
}
}
updateChickenItem
(
item
,
data
:
Item
)
{
// console.log(data);
item
.
active
=
true
;
let
growth
=
pg
.
view
.
find
(
item
,
"
growth
"
);
let
name
=
pg
.
view
.
find
(
item
,
"
name
"
);
...
...
@@ -267,7 +327,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg
.
view
.
setString
(
growth
,
`成长值+
${
data
.
growthValue
}
`
)
pg
.
view
.
setString
(
name
,
data
.
name
)
pg
.
view
.
setString
(
num
,
data
.
num
)
icon
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
this
[
data
.
icon
];
// icon.getComponent(cc.Sprite).spriteFrame = this[data.icon];
pg
.
view
.
setNetImg
(
icon
,
data
.
cover
)
pg
.
view
.
touchOn
(
item
,
this
.
onTouchChickenItem
,
this
);
item
.
data
=
data
;
}
...
...
@@ -283,11 +344,30 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
}
eating
(
data
)
{
Api
.
askUseItem
(
data
).
then
(()
=>
{
//可以检测是否升级等---升级说明之类的
this
.
showWaitingLetters
();
Api
.
askUseItem
(
data
).
then
((
resp
)
=>
{
this
.
fetchUserData
().
then
(
ud
=>
{
this
.
hideWaitingLetters
(
true
);
this
.
elephentState
(
3
);
this
.
onTouchKitchenClose
();
}).
catch
(
e
=>
{
this
.
hideWaitingLetters
(
true
);
this
.
openTipAlert
({
message
:
'
网络错误,请重试(err: 1)
'
,
callback
:
()
=>
{
this
.
closeTipAlert
();
}
})
});
}).
catch
(
e
=>
{
this
.
hideWaitingLetters
(
true
);
this
.
openTipAlert
({
message
:
'
网络错误,请重试(err: 2)
'
,
callback
:
()
=>
{
this
.
closeTipAlert
();
}
})
})
//可以检测是否升级等---升级说明之类的
}
...
...
@@ -426,23 +506,28 @@ export default class SceneComponent extends MyCocosSceneComponent {
private
tip_buy
:
cc
.
Node
;
private
tip_fail
:
cc
.
Node
;
private
tip_empty
:
cc
.
Node
;
private
tip_alert
:
cc
.
Node
;
private
tipSuccess
:
Function
;
private
tipCancel
:
Function
;
private
tipBuySuccess
:
Function
;
private
tipFailSuccess
:
Function
;
private
tipFailCancel
:
Function
;
private
tipEmptySuccess
:
Function
;
private
tipAlertCallback
:
Function
;
initTipSys
()
{
this
.
tip_normal
=
pg
.
view
.
find
(
this
,
"
tip_normal
"
);
this
.
tip_buy
=
pg
.
view
.
find
(
this
,
"
tip_buy
"
);
this
.
tip_fail
=
pg
.
view
.
find
(
this
,
"
tip_fail
"
);
this
.
tip_empty
=
pg
.
view
.
find
(
this
,
"
tip_empty
"
);
this
.
tip_alert
=
pg
.
view
.
find
(
this
,
"
tip_alert
"
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_normal
,
"
btn_sure
"
),
()
=>
{
this
.
tipSuccess
&&
this
.
tipSuccess
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_normal
,
"
btn_cancel
"
),
()
=>
{
this
.
tipCancel
&&
this
.
tipCancel
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_buy
,
"
btn_cancel
"
),
()
=>
{
this
.
tipBuySuccess
&&
this
.
tipBuySuccess
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_fail
,
"
btn_sure
"
),
()
=>
{
this
.
tipFailSuccess
&&
this
.
tipFailSuccess
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_fail
,
"
btn_cancel
"
),
()
=>
{
this
.
tipFailCancel
&&
this
.
tipFailCancel
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_empty
,
"
btn_cancel
"
),
()
=>
{
this
.
tipEmptySuccess
&&
this
.
tipEmptySuccess
()
},
this
);
pg
.
view
.
touchOn
(
pg
.
view
.
find
(
this
.
tip_alert
,
"
btn_cancel
"
),
()
=>
{
this
.
tipAlertCallback
&&
this
.
tipAlertCallback
()
},
this
);
}
openTipNormal
(
data
:
Item
,
success
,
cancel
)
{
this
.
tip_normal
.
active
=
true
;
...
...
@@ -451,7 +536,8 @@ export default class SceneComponent extends MyCocosSceneComponent {
if
(
data
)
{
pg
.
view
.
setString
(
pg
.
view
.
find
(
this
.
tip_normal
,
"
desc
"
),
`确定花
${
data
.
cost
*
data
.
discount
}
金币购买
${
data
.
name
}
吗?`
);
let
icon
=
pg
.
view
.
find
(
this
.
tip_normal
,
"
icon
"
);
icon
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
this
[
data
.
icon
];
// icon.getComponent(cc.Sprite).spriteFrame = this[data.icon];
pg
.
view
.
setNetImg
(
icon
,
data
.
cover
)
}
}
closeTipNormal
()
{
...
...
@@ -474,8 +560,9 @@ export default class SceneComponent extends MyCocosSceneComponent {
this
.
tip_buy
.
active
=
true
;
this
.
tipBuySuccess
=
success
;
if
(
data
)
{
let
icon
=
pg
.
view
.
find
(
this
.
tip_normal
,
"
icon
"
);
icon
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
this
[
data
.
icon
];
let
icon
=
pg
.
view
.
find
(
this
.
tip_buy
,
"
icon
"
);
// icon.getComponent(cc.Sprite).spriteFrame = this[data.icon];
pg
.
view
.
setNetImg
(
icon
,
data
.
cover
,
false
)
}
}
closeTipBuy
()
{
...
...
@@ -492,6 +579,94 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
openTipAlert
({
message
,
btnText
,
callback
}:
{
message
?:
string
,
btnText
?:
string
,
callback
:
(...
args
)
=>
void
})
{
if
(
message
)
{
const
tipNode
=
this
.
tip_alert
.
getChildByName
(
'
tip_empty
'
);
const
messageNode
=
tipNode
.
getChildByName
(
'
message
'
);
const
lbl
=
messageNode
.
getComponent
(
cc
.
RichText
);
lbl
.
string
=
`<color=#333333>
${
message
}
</color>`
;
}
if
(
btnText
)
{
const
btnNode
=
this
.
tip_alert
.
getChildByName
(
'
btn_ok
'
);
const
btnTxtNode
=
btnNode
.
getChildByName
(
'
txt
'
);
const
lbl
=
btnTxtNode
.
getComponent
(
cc
.
Label
);
lbl
.
string
=
btnText
;
}
this
.
tip_alert
.
active
=
true
;
this
.
tipAlertCallback
=
callback
;
}
closeTipAlert
()
{
this
.
tip_alert
.
active
=
false
;
}
hideWaitingLetters
(
force
=
false
)
{
if
(
force
)
{
this
.
LoadingCount
=
0
;
}
else
{
this
.
LoadingCount
--
;
}
if
(
this
.
LoadingCount
<=
0
)
{
this
.
LoadingCount
=
0
;
setTimeout
(()
=>
{
if
(
this
.
tws
){
for
(
const
tw
of
this
.
tws
)
{
tw
.
node
.
y
=
0
;
tw
.
tw
.
stop
();
}
}
this
.
loading
.
active
=
false
;
});
}
}
showWaitingLetters
()
{
this
.
LoadingCount
+=
1
;
if
(
this
.
loading
.
active
)
{
return
;
}
const
colorList
=
this
.
getRainbowColorList
();
const
text
=
this
.
loading
.
getChildByName
(
'
text
'
)
text
.
children
.
forEach
((
node
,
idx
)
=>
{
node
.
color
=
colorList
[
idx
];
const
tw
=
cc
.
tween
(
node
)
.
delay
(
idx
/
4
)
.
to
(
0.3
,
{
y
:
30
},
{
easing
:
'
sineOut
'
})
.
to
(
0.3
,
{
y
:
-
30
},
{
easing
:
'
sineIn
'
})
.
delay
((
text
.
children
.
length
-
idx
)
/
4
)
.
union
()
.
repeatForever
()
.
start
();
this
.
tws
.
push
({
tw
,
node
});
});
this
.
loading
.
active
=
true
;
}
getRainbowColorList
()
{
return
[
cc
.
color
(
255
,
255
,
0
),
cc
.
color
(
128
,
255
,
0
),
cc
.
color
(
0
,
255
,
0
),
cc
.
color
(
0
,
255
,
128
),
cc
.
color
(
0
,
255
,
255
),
cc
.
color
(
0
,
128
,
255
),
cc
.
color
(
0
,
0
,
255
),
cc
.
color
(
128
,
0
,
255
),
cc
.
color
(
255
,
0
,
255
),
cc
.
color
(
255
,
0
,
128
),
cc
.
color
(
255
,
0
,
0
),
cc
.
color
(
255
,
128
,
0
),
cc
.
color
(
255
,
255
,
0
),
];
}
...
...
This diff is collapsed.
Click to expand it.
assets/elephant/scene/model/item.ts
View file @
8020f9d6
...
...
@@ -5,6 +5,7 @@ class Item {
public
icon
:
string
;
//商品图片--可用type生成
public
growthValue
:
number
;
//生长值
public
cost
:
number
;
//费用
public
cover
:
string
;
public
discount
:
number
;
//折扣
public
num
:
number
;
//拥有数量
public
levelLimite
:
number
;
//等级限制
...
...
@@ -15,8 +16,9 @@ class Item {
this
.
icon
=
obj
.
icon
;
this
.
growthValue
=
obj
.
growthValue
;
this
.
cost
=
obj
.
cost
;
this
.
discount
=
obj
.
discount
;
this
.
num
=
obj
.
num
;
this
.
cover
=
obj
.
cover
;
this
.
discount
=
obj
.
discount
||
1
;
this
.
num
=
obj
.
amount
;
this
.
levelLimite
=
obj
.
levelLimite
;
}
}
...
...
This diff is collapsed.
Click to expand it.
assets/elephant/scene/model/shop.ts
View file @
8020f9d6
...
...
@@ -14,6 +14,9 @@ class Shop {
get
list
()
{
return
this
.
_list
;
}
getListByType
(
type
:
number
)
{
return
this
.
_list
.
filter
(
li
=>
li
.
type
==
type
)
}
}
export
default
S
hop
;
const
shop
=
new
Shop
();
export
default
s
hop
;
This diff is collapsed.
Click to expand it.
assets/elephant/scene/model/user.ts
View file @
8020f9d6
...
...
@@ -5,6 +5,7 @@ class User {
public
coin
:
number
;
public
level
:
number
;
public
growth
:
number
;
//当前成长值
public
growthLevel
:
number
;
public
growthDaily
:
number
;
public
growthDailyMax
:
number
;
public
eatTime
:
number
;
...
...
@@ -20,12 +21,13 @@ class User {
this
.
coin
=
data
.
coin
;
this
.
level
=
data
.
level
;
this
.
growth
=
data
.
growth
;
this
.
growthLevel
=
data
.
growthLevel
;
this
.
growthDaily
=
data
.
growthDaily
;
this
.
growthDailyMax
=
data
.
growthDailyMax
;
this
.
eatTime
=
data
.
eatTime
;
this
.
useFurniture
=
data
.
useFurniture
;
this
.
useClothes
=
data
.
useClothes
;
this
.
mood
=
1
;
this
.
mood
=
data
.
mood
;
}
isDailyMax
()
{
return
this
.
growthDailyMax
>=
this
.
growthDaily
...
...
@@ -38,18 +40,18 @@ class User {
useCoin
(
val
)
{
this
.
coin
-=
val
;
}
//当前等级成长值最大值
public
get
growthLevel
():
number
{
let
max
=
1
;
for
(
let
i
=
1
;
i
<
100
;
i
++
)
{
let
val
=
LEVEL
[
`level_
${
i
}
`
].
growth
;
if
(
this
.
growth
<
val
)
{
max
=
val
break
;
}
}
return
max
}
//
//
当前等级成长值最大值
//
public get growthLevel(): number {
//
let max = 1;
//
for (let i = 1; i < 100; i++) {
//
let val = LEVEL[`level_${i}`].growth;
//
if (this.growth < val) {
//
max = val
//
break;
//
}
//
}
//
return max
//
}
}
let
user
=
new
User
();
export
default
user
;
...
...
This diff is collapsed.
Click to expand it.
assets/elephant/scene/net/api.ts
View file @
8020f9d6
...
...
@@ -2,25 +2,52 @@ import pg from "../pg";
import
{
ITEMS
,
USER
}
from
"
../config/config
"
import
user
from
"
../model/user
"
;
import
kitchen
from
"
../model/kitchen
"
;
import
shop
from
"
../model/shop
"
;
//获取信息,购买物品,使用物品(吃东西),穿戴衣服/更换家具
class
Api
{
static
askUser
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
pg
.
http
.
send
(
"
GET
"
,
"
http://www.baidu.com
"
,
{}).
then
((
data
:
any
)
=>
{
let
userInfo
=
USER
;
user
.
parse
(
userInfo
);
let
kitchenInfo
=
ITEMS
;
kitchen
.
parse
(
kitchenInfo
);
pg
.
http
.
send
(
"
GET
"
,
`
${
globalThis
.
SERVER_HOST
}
/api/pets/info`
,
null
).
then
((
userInfo
:
any
)
=>
{
// let userInfo = USER;
try
{
const
mood
=
(
Date
.
now
()
-
userInfo
.
status
.
eat
.
time
)
>
4
*
60
*
60
*
1000
?
1
:
0
;
// 4 hours
const
info
=
{
name
:
userInfo
.
name
,
coin
:
userInfo
.
coins
,
level
:
userInfo
.
level
,
eatTime
:
userInfo
.
status
.
eat
.
time
,
useFurniture
:
userInfo
.
furniture
,
useClothes
:
userInfo
.
dress
,
growth
:
userInfo
.
current_exp
,
growthLevel
:
userInfo
.
need_exp
,
mood
};
console
.
log
(
info
);
user
.
parse
(
info
);
// let kitchenInfo = ITEMS;
kitchen
.
parse
(
userInfo
.
my_items
);
shop
.
parse
(
userInfo
.
shop_items
);
resolve
(
''
);
}
catch
(
e
)
{
reject
(
e
)
}
}).
catch
(
e
=>
{
reject
(
e
)
})
});
}
static
askUseItem
(
data
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
pg
.
http
.
send
(
"
GET
"
,
"
http://www.baidu.com
"
,
{}).
then
((
data
:
any
)
=>
{
user
.
addGrowth
(
data
.
growthValue
);
kitchen
.
use
(
data
.
id
);
resolve
(
''
);
pg
.
http
.
send
(
"
POST
"
,
`
${
globalThis
.
SERVER_HOST
}
/api/pets/use/item`
,
{
item_id
:
data
.
id
}).
then
((
resp
:
any
)
=>
{
// user.addGrowth(data.growthValue);
// kitchen.use(data.id);
try
{
resolve
(
resp
);
}
catch
(
e
)
{
reject
(
e
)
}
}).
catch
(
e
=>
{
reject
(
e
)
})
});
}
...
...
@@ -28,10 +55,17 @@ class Api {
return
new
Promise
((
resolve
,
reject
)
=>
{
data
.
id
;
data
.
type
;
pg
.
http
.
send
(
"
GET
"
,
"
http://www.baidu.com
"
,
{}).
then
((
data
:
any
)
=>
{
user
.
useCoin
(
data
.
cost
*
data
.
discount
);
kitchen
.
buy
(
data
.
id
);
resolve
(
''
);
pg
.
http
.
send
(
"
POST
"
,
`
${
globalThis
.
SERVER_HOST
}
/api/pets/item/buy`
,
{
item_id
:
data
.
id
}).
then
((
resp
:
any
)
=>
{
// user.useCoin(data.cost * data.discount);
// kitchen.buy(data.id);
try
{
resolve
(
resp
);
}
catch
(
e
)
{
reject
(
e
)
}
}).
catch
(
e
=>
{
reject
(
e
)
})
});
}
...
...
This diff is collapsed.
Click to expand it.
assets/elephant/scene/pg.ts
View file @
8020f9d6
...
...
@@ -130,7 +130,7 @@ let pg = {
})
})
},
setNetImg
(
item
,
res
)
{
setNetImg
(
item
,
res
,
cache
=
true
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
item
)
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的item
"
);
let
node
=
item
.
node
?
item
.
node
:
item
;
...
...
@@ -139,7 +139,7 @@ let pg = {
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的res
"
);
}
if
(
!
node
)
return
pg
.
logger
.
w
(
"
图片更换失败,传入了错误的item
"
);
if
(
node
.
net_url
==
res
)
return
;
if
(
cache
&&
node
.
net_url
==
res
)
return
;
let
w
=
node
.
width
;
let
h
=
node
.
height
;
node
.
active
=
false
;
//
...
...
@@ -147,15 +147,30 @@ let pg = {
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
i
(
"
节点已销毁
"
);
let
nw
=
node
.
width
=
texture
.
width
;
let
nh
=
node
.
height
=
texture
.
height
;
let
component
=
node
.
getComponent
(
cc
.
Sprite
);
let
spriteFrame
=
new
cc
.
SpriteFrame
(
texture
);
component
.
spriteFrame
=
spriteFrame
;
node
.
net_url
=
res
;
const
cover
=
node
.
getChildByName
(
'
cover
'
);
if
(
cover
)
{
const
{
width
,
height
}
=
spriteFrame
.
getOriginalSize
()
cover
.
getComponent
(
cc
.
Sprite
).
spriteFrame
=
spriteFrame
;
cover
.
width
=
width
;
cover
.
height
=
height
;
const
sx
=
node
.
width
/
width
;
const
sy
=
node
.
height
/
height
;
const
s
=
Math
.
min
(
sx
,
sy
);
cover
.
scale
=
Math
.
round
(
s
*
1000
)
/
1000
;
}
else
{
let
component
=
node
.
getComponent
(
cc
.
Sprite
);
component
.
spriteFrame
=
spriteFrame
;
node
.
width
=
w
;
node
.
height
=
h
;
}
// setTimeout(() => {
if
(
!
cc
.
isValid
(
node
))
return
pg
.
logger
.
i
(
"
节点已销毁
"
);
if
(
!
node
)
return
pg
.
logger
.
w
(
"
节点已销毁
"
);
node
.
width
=
w
;
node
.
height
=
h
;
node
.
active
=
true
;
// }, 30);
resolve
({
w
:
nw
,
h
:
nh
});
...
...
@@ -317,36 +332,57 @@ let pg = {
http
:
{
//http访问
send
:
function
(
type
,
url
,
data
)
{
return
new
Promise
((
resolve
)
=>
{
return
setTimeout
(()
=>
{
return
resolve
({
status
:
200
});
},
60
);
return
new
Promise
((
resolve
,
reject
)
=>
{
//
return setTimeout(() => {
//
return resolve({ status: 200 });
//
}, 60);
let
xhr
=
cc
.
loader
.
getXMLHttpRequest
();
xhr
.
timeout
=
5
000
;
xhr
.
timeout
=
30
000
;
xhr
.
responseType
=
"
text
"
;
xhr
.
open
(
type
,
url
,
true
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/x-www-form-urlencoded
"
);
xhr
.
setRequestHeader
(
"
token
"
,
globalThis
.
USER_TOKEN
);
xhr
.
setRequestHeader
(
"
Client-Type
"
,
globalThis
.
CLIENT_TYPE
);
xhr
.
setRequestHeader
(
"
Content-Type
"
,
"
application/json
"
);
xhr
.
onreadystatechange
=
()
=>
{
if
(
xhr
.
readyState
!==
4
)
return
;
if
(
xhr
.
status
>=
200
&&
xhr
.
status
<
300
)
{
try
{
let
resp
=
xhr
.
responseText
;
pg
.
logger
.
d
(
"
resp->
"
+
JSON
.
stringify
(
resp
));
// pg.logger.d("resp->" + JSON.stringify(resp));
if
(
typeof
resp
===
'
string
'
)
{
resp
=
JSON
.
parse
(
resp
);
// @ts-ignore
if
(
resp
.
code
!=
200
)
{
// @ts-ignore
reject
(
resp
.
message
)
return
}
// @ts-ignore
resp
=
resp
.
data
;
}
resolve
(
resp
);
}
catch
(
e
)
{
reject
(
e
)
}
}
else
{
}
else
{
pg
.
logger
.
w
(
"
onerror->
"
+
url
+
'
;resp =
'
+
xhr
.
responseText
);
reject
(
xhr
.
responseText
)
}
};
xhr
.
onerror
=
(
e
)
=>
{
pg
.
logger
.
w
(
"
onerror->
"
+
url
);
reject
(
e
);
};
xhr
.
ontimeout
=
(
e
)
=>
{
pg
.
logger
.
w
(
"
ontimeout->
"
+
url
);
reject
(
e
);
};
xhr
.
send
(
data
);
if
(
data
)
{
xhr
.
send
(
JSON
.
stringify
(
data
));
}
else
{
xhr
.
send
();
}
})
}
...
...
This diff is collapsed.
Click to expand it.
assets/elephant/script/MyCocosSceneComponent.ts
View file @
8020f9d6
...
...
@@ -95,8 +95,10 @@ export class MyCocosSceneComponent extends cc.Component {
// this.onLoadEnd();
// next();
// };
this
.
onLoadEnd
()
;
this
.
onLoadEnd
()
.
then
(()
=>
{
window
[
"
air
"
].
hideAirClassLoading
();
});
}
else
{
this
.
onLoadEnd
();
}
...
...
@@ -115,7 +117,7 @@ export class MyCocosSceneComponent extends cc.Component {
}
onLoadEnd
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{});
}
...
...
@@ -164,7 +166,7 @@ export class MyCocosSceneComponent extends cc.Component {
playAudioByUrl
(
audio_url
,
cb
=
null
)
{
if
(
audio_url
)
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
)
=>
{
cc
.
assetManager
.
loadRemote
(
audio_url
,
(
err
,
audioClip
:
cc
.
AudioClip
)
=>
{
const
audioId
=
cc
.
audioEngine
.
play
(
audioClip
,
false
,
0.8
);
if
(
cb
)
{
cc
.
audioEngine
.
setFinishCallback
(
audioId
,
()
=>
{
...
...
This diff is collapsed.
Click to expand it.
assets/elephant/textures/ani/eat.meta
deleted
100644 → 0
View file @
8113a10a
{
"ver": "1.1.2",
"uuid": "df38fb90-8e23-45a6-8a15-dbb6c2ef0a5f",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
assets/elephant/textures/tips/bg_alert.png
0 → 100644
View file @
8020f9d6
32.1 KB
This diff is collapsed.
Click to expand it.
assets/elephant/textures/tips/bg_alert.png.meta
0 → 100644
View file @
8020f9d6
{
"ver": "2.3.5",
"uuid": "c3393c60-0fc9-4915-91d9-485a561738ef",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 644,
"height": 317,
"platformSettings": {},
"subMetas": {
"bg_alert": {
"ver": "1.0.4",
"uuid": "1da38dd7-6872-4ddf-a558-19368fccb1d5",
"rawTextureUuid": "c3393c60-0fc9-4915-91d9-485a561738ef",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 644,
"height": 317,
"rawWidth": 644,
"rawHeight": 317,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
assets/elephant/textures/tips/btn_alert_ok.png
0 → 100644
View file @
8020f9d6
735 Bytes
This diff is collapsed.
Click to expand it.
assets/elephant/textures/tips/btn_alert_ok.png.meta
0 → 100644
View file @
8020f9d6
{
"ver": "2.3.5",
"uuid": "ada08f28-6853-4b73-b40c-f890cf785859",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 186,
"height": 63,
"platformSettings": {},
"subMetas": {
"btn_alert_ok": {
"ver": "1.0.4",
"uuid": "5bc8143f-384b-4b62-8d62-846f1f6dc2ea",
"rawTextureUuid": "ada08f28-6853-4b73-b40c-f890cf785859",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 186,
"height": 63,
"rawWidth": 186,
"rawHeight": 63,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
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