增加玩家头像和昵称
This commit is contained in:
parent
a0fd49d6a9
commit
3582ab5726
@ -46,7 +46,7 @@ export class PuzzleMathRoom extends Room {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onJoin(client: Client, options: any) {
|
onJoin(client: Client, options: any) {
|
||||||
const data = {client, accountId: options.accountid,}
|
const data = {client, accountId: options.accountid, nickname: options.nickname, avatar: options.avatar}
|
||||||
this.dispatcher.dispatch(new OnJoinCommand(), data)
|
this.dispatcher.dispatch(new OnJoinCommand(), data)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,6 +163,27 @@ export class PuzzleMathRoom extends Room {
|
|||||||
this.state.round = round
|
this.state.round = round
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户信息
|
||||||
|
* @param datas
|
||||||
|
*/
|
||||||
|
updatePlayerInfo(datas: any) {
|
||||||
|
console.log(`[${this.roomId}] admin updatePlayerInfo: ${JSON.stringify(datas)}`)
|
||||||
|
for (let data of datas) {
|
||||||
|
for (let [,player] of this.state.players) {
|
||||||
|
if (player.accountId == data.accountid) {
|
||||||
|
if (data.nickname) {
|
||||||
|
player.nickname = data.nickname
|
||||||
|
}
|
||||||
|
if (data.avatar) {
|
||||||
|
player.avatar = data.avatar
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个计时器
|
* 添加一个计时器
|
||||||
|
@ -6,9 +6,13 @@ import { Player } from '../schema/Player'
|
|||||||
export class OnJoinCommand extends Command<PuzzleGameState, {
|
export class OnJoinCommand extends Command<PuzzleGameState, {
|
||||||
client: Client,
|
client: Client,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
|
nickname: string,
|
||||||
|
avatar: string
|
||||||
}> {
|
}> {
|
||||||
async execute({ client, accountId} = this.payload) {
|
async execute({ client, accountId, nickname, avatar} = this.payload) {
|
||||||
let player = new Player(client.id, accountId)
|
let player = new Player(client.id, accountId)
|
||||||
|
player.nickname = nickname
|
||||||
|
player.avatar = avatar
|
||||||
this.state.players.set(client.sessionId, player)
|
this.state.players.set(client.sessionId, player)
|
||||||
this.room.bUserJoin(`${ client.sessionId }`, { except: client })
|
this.room.bUserJoin(`${ client.sessionId }`, { except: client })
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,12 @@ export class Player extends Schema {
|
|||||||
@type('string')
|
@type('string')
|
||||||
accountId: string
|
accountId: string
|
||||||
|
|
||||||
|
@type('string')
|
||||||
|
nickname: string
|
||||||
|
|
||||||
|
@type('string')
|
||||||
|
avatar: string
|
||||||
|
|
||||||
@type('number')
|
@type('number')
|
||||||
score: number
|
score: number
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user