|
@@ -236,103 +236,105 @@ export default class XverseAvatarManager extends EventEmitter {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async addAvatar(e) {
|
|
|
- const {userId: t, isHost: r, avatarPosition: n, avatarId: o, avatarRotation: a, nickname: s, avatarComponents: l=[], priority: u, group: c=AvatarGroup.Npc, avatarScale: h=DEFAULT_AVATAR_SCALE, extraInfo: f, prioritySync: d} = e
|
|
|
- , _ = t === this._room.userId;
|
|
|
- let g = this.avatars.get(t);
|
|
|
- if (g)
|
|
|
- {
|
|
|
- return Promise.resolve(g);
|
|
|
- }
|
|
|
+ async addAvatar({
|
|
|
+ userId, isHost, avatarPosition, avatarId, avatarRotation, nickname, avatarComponents=[], priority, group=AvatarGroup.Npc,
|
|
|
+ avatarScale=DEFAULT_AVATAR_SCALE, extraInfo, prioritySync
|
|
|
+ }) {
|
|
|
+ const isSelf = userId === this._room.userId;
|
|
|
+ let avatar = this.avatars.get(userId);
|
|
|
+ if (avatar) return Promise.resolve(avatar);
|
|
|
|
|
|
- g = new XverseAvatarManager.subAvatar({
|
|
|
- userId: t,
|
|
|
- isHost: r,
|
|
|
- isSelf: _,
|
|
|
+ avatar = new XverseAvatarManager.subAvatar({
|
|
|
+ userId,
|
|
|
+ isHost,
|
|
|
+ isSelf,
|
|
|
room: this._room,
|
|
|
- avatarComponents: l,
|
|
|
- avatarId: o,
|
|
|
- nickname: s,
|
|
|
- group: c
|
|
|
+ avatarComponents,
|
|
|
+ avatarId,
|
|
|
+ nickname,
|
|
|
+ group
|
|
|
});
|
|
|
- this.avatars.set(t, g);
|
|
|
- if (!g.withModel)
|
|
|
- return g.isLoading = !1,
|
|
|
- g.avatarLoadedHook(),
|
|
|
- this._room.emit("avatarChanged", {
|
|
|
- avatars: this._room.avatars
|
|
|
- }),
|
|
|
- g;
|
|
|
- const v = (await this._room.modelManager.getAvatarModelList()).find(b=>b.id === o)
|
|
|
- , y = Date.now();
|
|
|
- if (!v)
|
|
|
- return this._room.emit("avatarChanged", {
|
|
|
- avatars: this._room.avatars
|
|
|
- }),
|
|
|
- this.avatars.delete(t),
|
|
|
- Promise.reject(`no such avatar model with id: ${o}`);
|
|
|
+ this.avatars.set(userId, avatar);
|
|
|
+
|
|
|
+ if (!avatar.withModel) {
|
|
|
+ avatar.isLoading = !1
|
|
|
+ avatar.avatarLoadedHook()
|
|
|
+ this._room.emit("avatarChanged", { avatars: this._room.avatars })
|
|
|
+ return avatar;
|
|
|
+ }
|
|
|
+
|
|
|
+ const avatarData = (await this._room.modelManager.getAvatarModelList()).find(data => data.id === avatarId)
|
|
|
+ , startTime = Date.now();
|
|
|
+ if (!avatarData) {
|
|
|
+ this._room.emit("avatarChanged", { avatars: this._room.avatars })
|
|
|
+ this.avatars.delete(userId)
|
|
|
+ return Promise.reject(`no such avatar model with id: ${avatarId}`);
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
- let b = await avatarComponentsModify(v, l);
|
|
|
+ let b = await avatarComponentsModify(avatarData, avatarComponents);
|
|
|
b = b.filter(A=>A.type != "pendant");
|
|
|
- const T = await avatarComponentsParser(v, b)
|
|
|
- , C = await this.xAvatarManager.loadAvatar({
|
|
|
- id: t,
|
|
|
- avatarType: o,
|
|
|
- priority: u,
|
|
|
+
|
|
|
+ const assets = await avatarComponentsParser(avatarData, b)
|
|
|
+ , xAvatar = await this.xAvatarManager.loadAvatar({
|
|
|
+ id: userId,
|
|
|
+ avatarType: avatarId,
|
|
|
+ priority,
|
|
|
avatarManager: this.xAvatarManager,
|
|
|
- assets: T,
|
|
|
+ assets,
|
|
|
status: {
|
|
|
- avatarPosition: n,
|
|
|
- avatarRotation: a,
|
|
|
- avatarScale: h
|
|
|
+ avatarPosition,
|
|
|
+ avatarRotation,
|
|
|
+ avatarScale
|
|
|
}
|
|
|
})._timeout(8e3, new TimeoutError("loadAvatar timeout(8s)"));
|
|
|
- return C.setPickBoxScale(t === this._room.userId ? 0 : 1),
|
|
|
- g.xAvatar = C,
|
|
|
- g.setScale(h),
|
|
|
- g.extraInfo = f,
|
|
|
- g.priority = u,
|
|
|
- g.isLoading = !1,
|
|
|
- g.prioritySync = !!d,
|
|
|
- g._playAnimation("Idle", !0, !0),
|
|
|
- g.avatarLoadedHook(),
|
|
|
- this._room.emit("avatarChanged", {
|
|
|
- avatars: this._room.avatars
|
|
|
- }),
|
|
|
- s && g._setNickname(s),
|
|
|
- t === this._room.userId && (logger.infoAndReportMeasurement({
|
|
|
- metric: "avatarLoadDuration",
|
|
|
- startTime: y,
|
|
|
- group: "costs"
|
|
|
- }),
|
|
|
- logger.infoAndReportMeasurement({
|
|
|
- metric: "avatarLoadAt",
|
|
|
- startTime: this._room._startTime,
|
|
|
- group: "costs"
|
|
|
- })),
|
|
|
- g
|
|
|
- } catch (b) {
|
|
|
- return g.isLoading = !1,
|
|
|
- this._room.emit("avatarChanged", {
|
|
|
- avatars: this._room.avatars
|
|
|
- }),
|
|
|
- logger.error(b),
|
|
|
- Promise.reject(b)
|
|
|
+ xAvatar.setPickBoxScale(userId === this._room.userId ? 0 : 1);
|
|
|
+
|
|
|
+ avatar.xAvatar = xAvatar
|
|
|
+ avatar.setScale(avatarScale)
|
|
|
+ avatar.extraInfo = extraInfo
|
|
|
+ avatar.priority = priority
|
|
|
+ avatar.isLoading = !1
|
|
|
+ avatar.prioritySync = !!prioritySync
|
|
|
+ avatar._playAnimation("Idle", !0, !0)
|
|
|
+ avatar.avatarLoadedHook()
|
|
|
+ this._room.emit("avatarChanged", { avatars: this._room.avatars })
|
|
|
+ nickname && avatar._setNickname(nickname)
|
|
|
+
|
|
|
+ userId === this._room.userId && (
|
|
|
+ logger.infoAndReportMeasurement({
|
|
|
+ metric: "avatarLoadDuration",
|
|
|
+ startTime,
|
|
|
+ group: "costs"
|
|
|
+ }),
|
|
|
+ logger.infoAndReportMeasurement({
|
|
|
+ metric: "avatarLoadAt",
|
|
|
+ startTime: this._room._startTime,
|
|
|
+ group: "costs"
|
|
|
+ })
|
|
|
+ )
|
|
|
+
|
|
|
+ return avatar
|
|
|
+ } catch (e) {
|
|
|
+ return avatar.isLoading = !1,
|
|
|
+ this._room.emit("avatarChanged", { avatars: this._room.avatars }),
|
|
|
+ logger.error(e),
|
|
|
+ Promise.reject(e)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- removeAvatar(e, t=!1) {
|
|
|
- const r = this.avatars.get(e);
|
|
|
- if (!!r) {
|
|
|
- if (r.removeWhenDisconnected || t) {
|
|
|
- r.xAvatar && this.xAvatarManager.deleteAvatar(r.xAvatar),
|
|
|
- this.avatars.delete(e),
|
|
|
+ removeAvatar(userId, t=!1) {
|
|
|
+ const avatar = this.avatars.get(userId);
|
|
|
+ if (!!avatar) {
|
|
|
+ if (avatar.removeWhenDisconnected || t) {
|
|
|
+ avatar.xAvatar && this.xAvatarManager.deleteAvatar(avatar.xAvatar),
|
|
|
+ this.avatars.delete(userId),
|
|
|
this._room.emit("avatarChanged", {
|
|
|
avatars: this._room.avatars
|
|
|
});
|
|
|
return
|
|
|
}
|
|
|
- r.setConnectionStatus(!0)
|
|
|
+ avatar.setConnectionStatus(!0)
|
|
|
}
|
|
|
}
|
|
|
|