Skip to content

Commit

Permalink
fix: 处理新玩家
Browse files Browse the repository at this point in the history
  • Loading branch information
lovezhangchuangxin committed Nov 10, 2024
1 parent 283bb33 commit 1c47c0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/backend/src/service/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class UserService {
}
const { password: _, ...safeUserInfo } = userInfo
data.user.push(userInfo)
GameDB.getDB().processUserData(data.user, data.userData, true)

// 生成 jwt
const token = jwt.sign(
Expand Down
8 changes: 6 additions & 2 deletions packages/db/src/gamedb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ export class GameDB extends DB {
this.set('game', JSON.stringify(data))
}

processUserData(users: UserModel[], userDataMap: UseDataMap) {
processUserData(
users: UserModel[],
userDataMap: UseDataMap,
newPlayer = false,
) {
users.forEach(({ id }) => {
const userData = userDataMap[id] || {}
if (!userData?.structure) {
userData.structure = {
energyStorage: new EnergyStorage({ level: 1, store: 2000 }),
metalStorage: new MetalStorage({ level: 1, store: 2000 }),
}
} else {
} else if (!newPlayer) {
Object.keys(userData.structure).forEach((key) => {
let structure =
userData.structure[key as keyof typeof userData.structure]
Expand Down

0 comments on commit 1c47c0a

Please sign in to comment.