Skip to content

Commit

Permalink
fix(world): labels and avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
7185 committed Nov 11, 2024
1 parent 42a9887 commit d9cffdc
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 65 deletions.
75 changes: 38 additions & 37 deletions frontend/src/app/engine/engine.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,46 @@
z-index: 0;
pointer-events: all;
background-color: #111;
}

#render-canvas {
width: 100%;
height: 100%;
touch-action: none;
}
#render-canvas {
width: 100%;
height: 100%;
touch-action: none;
}

#render-canvas:focus {
outline: none;
}
#render-canvas:focus {
outline: none;
}

#label-zone {
top: 0;
position: absolute;
pointer-events: none;
color: #fff;
text-shadow:
#000 2px 0 0,
#000 1.7552px 0.9589px 0,
#000 1.0806px 1.6829px 0,
#000 0.1415px 1.9950px 0,
#000 -0.8323px 1.8186px 0,
#000 -1.6023px 1.1969px 0,
#000 -1.9800px 0.2822px 0,
#000 -1.8729px -0.7016px 0,
#000 -1.3073px -1.5136px 0,
#000 -0.4216px -1.9551px 0,
#000 0.5673px -1.9179px 0,
#000 1.4173px -1.4111px 0,
#000 1.9203px -0.5588px 0;
}
#label-zone {
top: 0;
position: absolute;
pointer-events: none;
color: #fff;
text-shadow:
#000 2px 0 0,
#000 1.7552px 0.9589px 0,
#000 1.0806px 1.6829px 0,
#000 0.1415px 1.9950px 0,
#000 -0.8323px 1.8186px 0,
#000 -1.6023px 1.1969px 0,
#000 -1.9800px 0.2822px 0,
#000 -1.8729px -0.7016px 0,
#000 -1.3073px -1.5136px 0,
#000 -0.4216px -1.9551px 0,
#000 0.5673px -1.9179px 0,
#000 1.4173px -1.4111px 0,
#000 1.9203px -0.5588px 0;
}

#label-desc {
position: absolute;
display: none;
background-color: rgba(0 0 0 / 40%);
color: #fff;
padding: 2px;
border-radius: 6px;
max-width: 20vw;
}
#label-desc {
position: absolute;
display: none;
background-color: rgba(0 0 0 / 40%);
color: #fff;
padding: 2px;
border-radius: 6px;
max-width: 20vw;
}

2 changes: 1 addition & 1 deletion frontend/src/app/network/http.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class HttpService extends HttpClient {
}

getLogged() {
if (this.userLogged().id == null) {
if (!this.userLogged().id) {
this.session().subscribe()
}
return this.userLogged
Expand Down
1 change: 0 additions & 1 deletion frontend/src/app/ui/ui-toolbar/ui-toolbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export class UiToolbarComponent implements OnInit {
effect(() => {
const u = this.http.getLogged()()
this.userId = u.id
this.userSvc.currentName = u.name
if (u.id != null) {
this.http
.worlds()
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/app/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {User} from './user.model'
export class UserService {
userList = signal<User[]>([])
avatarChanged = new Subject<User>()
currentName = 'Anonymous'

private readonly http = inject(HttpService)

Expand All @@ -22,8 +21,8 @@ export class UserService {

refreshList(list: User[]) {
// Remove unlisted users
const newList = this.userList().filter(
(u) => list.map((c) => c.id).includes(u.id)
const newList = this.userList().filter((u) =>
list.map((c) => c.id).includes(u.id)
)
for (const u of list) {
// Still update world for listed users
Expand All @@ -46,7 +45,7 @@ export class UserService {

setAvatar(userId: string, avatarId: number) {
const user = this.getUser(userId)
if (user != null && user.name !== this.currentName) {
if (user?.id !== this.http.getLogged()().id) {
user.avatar = avatarId
this.avatarChanged.next(user)
}
Expand Down
46 changes: 24 additions & 22 deletions frontend/src/app/world/world.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,13 @@ export class WorldService {
for (const u of this.userSvc.userList()) {
const user = this.engineSvc.users().find((o) => o.name === u.id)
if (
user == null &&
this.avatarList.length > 0 &&
u.world === this.worldId
user != null ||
this.avatarList.length == 0 ||
u.world !== this.worldId
) {
this.addUser(u)
continue
}
this.addUser(u)
}
})

Expand Down Expand Up @@ -576,7 +577,7 @@ export class WorldService {
? new Map<number, number>(savedAvatars)
: new Map<number, number>()
this.avatarSub.next(avatarMap.get(this.worldId) || 0)
// Trigger list update to create users
// Force list update to create users now that avatars are known
this.userSvc.userList.set([...this.userSvc.userList()])
})

Expand All @@ -585,23 +586,24 @@ export class WorldService {
}

private addUser(user: User) {
if (user.name !== this.userSvc.currentName) {
const group = new Group()
group.name = user.id
group.position.set(user.x, user.y, user.z)
group.rotation.set(user.roll, user.yaw, user.pitch)
group.userData.player = true
const avatarEntry = this.avatarList[user.avatar]
this.setAvatar(
this.avatarList[user.avatar].geometry,
this.anmSvc.getAvatarAnimationManager(
avatarEntry.name,
avatarEntry.implicit,
avatarEntry.explicit
),
group
)
this.engineSvc.addUser(group)
if (user.id === this.http.getLogged()().id) {
return
}
const group = new Group()
group.name = user.id
group.position.set(user.x, user.y, user.z)
group.rotation.set(user.roll, user.yaw, user.pitch)
group.userData.player = true
const avatarEntry = this.avatarList[user.avatar]
this.setAvatar(
this.avatarList[user.avatar].geometry,
this.anmSvc.getAvatarAnimationManager(
avatarEntry.name,
avatarEntry.implicit,
avatarEntry.explicit
),
group
)
this.engineSvc.addUser(group)
}
}

0 comments on commit d9cffdc

Please sign in to comment.