Adding initial support to looking at you team data on profile.

This commit is contained in:
Sergiotarxz 2024-01-13 19:10:40 +01:00
parent 9279e6388a
commit 589782365b
5 changed files with 62 additions and 10 deletions

View File

@ -6,6 +6,7 @@ export default class SelfPlayerUI extends AbstractTopBarInterface {
private selfPlayer: ConquerUser | null = null
private userWelcome: HTMLElement | null = null
private isExplorerModeEnabled: boolean;
private userTeamData: HTMLElement | null = null;
constructor(isExplorerModeEnabled: boolean) {
super();
@ -23,7 +24,6 @@ export default class SelfPlayerUI extends AbstractTopBarInterface {
public async run(): Promise<void> {
const selfPlayerNode = this.getMainNode()
selfPlayerNode.classList.remove('conquer-display-none')
const user = await ConquerUser.getSelfUser()
if (user === null) {
this.runCallbacks('close')
@ -33,6 +33,8 @@ export default class SelfPlayerUI extends AbstractTopBarInterface {
this.populateWelcome()
this.populateCreateNodeOption()
this.populateToggleExplorerModeOption();
await this.populateUserTeamData();
selfPlayerNode.classList.remove('conquer-display-none')
}
private populateToggleExplorerModeOption(): void {
@ -78,6 +80,43 @@ export default class SelfPlayerUI extends AbstractTopBarInterface {
this.getMainNode().appendChild(createNodeButtonInterface)
}
private async getUserTeamData(): Promise<HTMLElement> {
if (this.userTeamData !== null) {
return this.userTeamData;
}
const element = document.createElement('p');
this.userTeamData = element;
if (this.selfPlayer === null) {
throw new Error('User still not set')
}
const team = await this.selfPlayer.getTeam();
if (team === null) {
element.innerText = 'No tienes equipo aun,'
+ ' ve al nodo más cercano para unirte a un equipo.';
return this.userTeamData;
}
const spanCircle = document.createElement('span');
spanCircle.classList.add('conquer-team-circle');
spanCircle.style.backgroundColor = team.getColor();
element.append(spanCircle);
const spanText = document.createElement('span');
spanText.innerText = 'Perteneces al equipo: ';
element.append(spanText);
const spanTeamName = document.createElement('span');
spanTeamName.style.color = team.getColor();
spanTeamName.style.backgroundColor = 'white';
spanTeamName.innerText = team.getName();
element.append(spanTeamName);
return this.userTeamData;
}
private async populateUserTeamData(): Promise<void> {
const userTeamData = await this.getUserTeamData();
const userTeamDataInterface = this.generateInterfaceElementCentered();
userTeamDataInterface.append(userTeamData);
this.getMainNode().append(userTeamDataInterface);
}
private populateWelcome(): void {
const userWelcome = this.getUserWelcome()
const userWelcomeInterface = this.generateInterfaceElementCentered();

View File

@ -16,6 +16,18 @@ export default class ConquerTeam {
@JsonProperty()
private color: string;
public getName(): string {
return this.name;
}
public getDescription(): string {
return this.description;
}
public getColor(): string {
return this.color;
}
constructor(uuid: string, name: string, description: string, points: number, color: string) {
this.kind = 'ConquerTeam';
this.uuid = uuid;

View File

@ -25,8 +25,8 @@ export default class ConquerUser {
private username: string;
@JsonProperty()
private uuid: string;
@JsonProperty({name: 'team'})
private team_uuid: string | null;
@JsonProperty()
private team: string | null;
constructor(kind: string, uuid: string, username: string, is_admin = false, registration_date: string | null = null, last_activity: string | null = null) {
this.kind = kind;
@ -38,10 +38,10 @@ export default class ConquerUser {
}
public async getTeam(): Promise<ConquerTeam | null> {
if (this.team_uuid === null) {
if (this.team === null) {
return null;
}
return ConquerTeam.getTeam(this.team_uuid);
return ConquerTeam.getTeam(this.team);
}
public static async getSelfUser(): Promise<ConquerUser | null> {

View File

@ -37,6 +37,9 @@ __PACKAGE__->add_columns(
},
);
__PACKAGE__->set_primary_key('uuid');
__PACKAGE__->has_many( players => 'BurguillosInfo::Schema::Result::ConquerUser', 'team');
sub serialize ($self) {
$self = $self->get_from_storage();
return {
@ -48,6 +51,4 @@ sub serialize ($self) {
color => $self->color,
};
}
__PACKAGE__->has_many( players => 'BurguillosInfo::Schema::Result::ConquerUser', 'team');
__PACKAGE__->set_primary_key('uuid');
1;

File diff suppressed because one or more lines are too long