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
Dec 16, 2021
by
liujiaxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: with backend interface
parent
8113a10a
Changes
13
Expand all
Hide 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 diff is collapsed.
Click to expand it.
assets/elephant/scene/elephant.ts
View file @
8020f9d6
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
;
}
}
...
...
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
;
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
;
...
...
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
);
resolve
(
''
);
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
)
})
});
}
...
...
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
();
}
})
}
...
...
assets/elephant/script/MyCocosSceneComponent.ts
View file @
8020f9d6
...
...
@@ -95,8 +95,10 @@ export class MyCocosSceneComponent extends cc.Component {
// this.onLoadEnd();
// next();
// };
this
.
onLoadEnd
();
window
[
"
air
"
].
hideAirClassLoading
();
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
,
()
=>
{
...
...
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
assets/elephant/textures/tips/bg_alert.png
0 → 100644
View file @
8020f9d6
32.1 KB
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
assets/elephant/textures/tips/btn_alert_ok.png
0 → 100644
View file @
8020f9d6
735 Bytes
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
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