Skip to content

Commit

Permalink
fix: show user info
Browse files Browse the repository at this point in the history
  • Loading branch information
TiyoSheng committed Nov 3, 2023
1 parent 7ebe6b3 commit 657dec8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/client/src/components/UserInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface IUserInfo {
const UserInfo = (props: IUserInfo) => {

const { handheld, head, clothes, gem = 0, userUrl, lootUrl, player } = props;
const lootHasLoaded = handheld && head && clothes;
const lootHasLoaded = (handheld && head && clothes) || (player?.equip?.handheld && player?.equip?.head && player?.equip?.clothes);
console.log(handheld, head, clothes, lootHasLoaded);

return (
Expand All @@ -26,7 +26,7 @@ const UserInfo = (props: IUserInfo) => {
<div className="user-detail-wrapper">
<div className="user-appearance-wrapper">
<div className="user-appearance-box">
<Appearance clothes={clothes} handheld={handheld} head={head}/>
<Appearance clothes={clothes || player.equip.clothes} handheld={handheld || player.equip.handheld} head={head || player.equip.head}/>
</div>
</div>
<div className={`loot-wrapper ${lootHasLoaded ? 'loaded' : ''}`}>
Expand All @@ -44,7 +44,7 @@ const UserInfo = (props: IUserInfo) => {
<div className={`user-attr-wrapper ${lootHasLoaded ? 'loaded' : ''}`}>
<dl>
<dt>HP</dt>
<dd><span className="base-attr">{lootHasLoaded ? player?.maxHp?.toString() : 0}</span><span className="extra-attr">{lootHasLoaded ? player?.maxHp?.toString() : ''}</span></dd>
<dd><span className="base-attr">{lootHasLoaded ? player?.maxHp : 0}</span><span className="extra-attr">{lootHasLoaded ? player?.maxHp?.toString() : ''}</span></dd>
</dl>
<dl>
<dt>Attack</dt>
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/UserInfoDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const UserInfoDialog = (props: IProps) => {

return (
<div className={`mi-userinfo-dialog ${visible ? '' : 'hidden'}`}>
<UserInfo {...rest}/>
<UserInfo {...rest} player={rest} />
<button className="mi-btn close-btn" onClick={onClose}>OK</button>
</div>
);
Expand Down
12 changes: 10 additions & 2 deletions packages/client/src/pages/game/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ const Game = () => {
const target = paths[pathIndex - 1];
const isDelivery = DELIVERY.x === target.x && DELIVERY.y === target.y;
if (isDelivery) {
setUserInfoPlayer(curPlayer);
let cur = localStorage.getItem('playerInfo');
if (cur) cur = JSON.parse(cur);
setUserInfoPlayer(cur || curPlayer);
submitGem();
}
}
Expand All @@ -258,6 +260,12 @@ const Game = () => {
};

const showUserInfo = (player) => {
console.log(player);
if (player.addr.toLocaleLowerCase() == account.toLocaleLowerCase()) {
let cur = localStorage.getItem('playerInfo');
if (cur) player = JSON.parse(cur);
}

setUserInfoPlayer(player);
setUserInfoVisible(true);
}
Expand Down Expand Up @@ -390,7 +398,7 @@ const Game = () => {
setUserInfoVisible(false);
}}
gem={userInfoPlayer.gem}
{...userInfoPlayer.equip}
{...userInfoPlayer}
/>
)
}
Expand Down
9 changes: 9 additions & 0 deletions packages/client/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ const Home = () => {
return url
}

const toObject = (obj) => {
return JSON.parse(JSON.stringify(obj, (key, value) => typeof value === 'bigint' ? value.toString() : value
))
}

const mintAndGo = async () => {
setMinting(true);
try {
Expand Down Expand Up @@ -199,6 +204,10 @@ const Home = () => {
setClothes(clothes);
setHandheld(handheld);
setHead(head);

let player = Object.assign(playerData, {username, clothes, handheld, head, userUrl: url.image, lootUrl: lootUrl.image})
console.log(player, 'player')
localStorage.setItem('playerInfo', JSON.stringify(toObject(player)));

let result = await Promise.all([setInfo(username, ''), joinBattlefield()])
console.log(result, 'result')
Expand Down

0 comments on commit 657dec8

Please sign in to comment.