137 lines
5.2 KiB
TypeScript
137 lines
5.2 KiB
TypeScript
import { DatePipe, DecimalPipe } from '@angular/common';
|
|
import { Title } from '@angular/platform-browser';
|
|
import { trigger, state, style, animate, transition } from '@angular/animations';
|
|
import { Component, DestroyRef, inject, OnInit } from '@angular/core';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { MatCardModule } from '@angular/material/card';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatDividerModule } from '@angular/material/divider';
|
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
import { MatIconModule } from '@angular/material/icon';
|
|
import { MatInputModule } from '@angular/material/input';
|
|
import { MatTabsModule } from '@angular/material/tabs';
|
|
|
|
import { CardContainerComponent, ListErrorsComponent, GuildwarAttackComponent, GuildwarDefenceComponent } from '@components/shared';
|
|
import { CardColors, Errors, HWActivityStat, HWGuildClan, HWMember } from '@models';
|
|
import { ClanViewModel, MembersViewModel } from '@viewmodels/herowars';
|
|
import { HWClanService, HWMemberService, UtilitiesService } from '@services';
|
|
import { MAX_CLAN_MEMBERS } from '@constants';
|
|
|
|
import guildData from '@data/hw-guild-data.json'; // page Membres
|
|
import guildStatistics from '@data/hw-guild-statistics.json'; // page Overview -> Statistics
|
|
|
|
@Component({
|
|
selector: 'app-herowars-guildwar',
|
|
standalone: true,
|
|
imports: [
|
|
DatePipe, DecimalPipe, FormsModule, CardContainerComponent, ListErrorsComponent,
|
|
MatButtonModule, MatCardModule, MatDividerModule, MatFormFieldModule,
|
|
MatIconModule, MatInputModule, MatTabsModule,
|
|
GuildwarAttackComponent, GuildwarDefenceComponent
|
|
],
|
|
templateUrl: './herowars-guildwar.component.html',
|
|
styleUrl: './herowars-guildwar.component.scss',
|
|
animations: [
|
|
trigger('flyInOut', [
|
|
state('in', style({ transform: 'translateY(0)' })),
|
|
transition('void => *', [
|
|
style({ transform: 'translateY(-100%)' }),
|
|
animate(200)
|
|
]),
|
|
transition('* => void', [
|
|
style({ transform: 'translateY(100%)' }),
|
|
animate(200)
|
|
])
|
|
])
|
|
]
|
|
})
|
|
export class HerowarsGuildwarComponent implements OnInit {
|
|
public destroyRef = inject(DestroyRef);
|
|
public title = 'Guild War';
|
|
public subtitle = 'Log';
|
|
public description = 'Tools in working progress.';
|
|
public colors: CardColors = { background: 'bg-raspberry', text: 'text-bg-primary' };
|
|
public errors: Errors = { errors: {} };
|
|
public now = new Date();
|
|
public daysToWarn = 1;
|
|
public maxClanMembers = MAX_CLAN_MEMBERS;
|
|
public clanLoaded = false;
|
|
public membersLoaded = false;
|
|
public clanViewModel: ClanViewModel = {} as ClanViewModel;
|
|
public membersViewModel: MembersViewModel = {} as MembersViewModel;
|
|
private _guildClan: HWGuildClan = {} as HWGuildClan;
|
|
private _guildMembers: HWMember[] = [];
|
|
private _guildInfo: HWActivityStat = {} as HWActivityStat;
|
|
|
|
constructor(
|
|
private _titleService: Title,
|
|
private _utilitiesService: UtilitiesService,
|
|
private _clanService: HWClanService,
|
|
private _memberService: HWMemberService
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
this._titleService.setTitle(this.title);
|
|
}
|
|
|
|
getClanViewModel(): ClanViewModel {
|
|
return this.clanViewModel;
|
|
}
|
|
|
|
getMembersViewModel(): MembersViewModel {
|
|
return this.membersViewModel;
|
|
}
|
|
|
|
getColors(color = 'megna'): CardColors {
|
|
if (color === 'accent') {
|
|
this.colors = { background: 'bg-accent', text: 'text-navy' };
|
|
} else if (color === 'raspberry') {
|
|
this.colors = { background: 'bg-raspberry', text: 'text-bg-primary' };
|
|
} else {
|
|
this.colors = { background: 'bg-megna', text: 'text-bg-primary' };
|
|
}
|
|
return this.colors;
|
|
}
|
|
|
|
loadClan(): void {
|
|
this._guildClan = this._clanService.loadClan();
|
|
this.clanViewModel = new ClanViewModel(this._guildClan);
|
|
this.clanLoaded = true;
|
|
}
|
|
|
|
loadData(): void {
|
|
this._guildClan = this._clanService.loadClan();
|
|
this._guildMembers = this._memberService.loadMembers(this._guildClan);
|
|
this._guildClan = this._clanService.loadClanStats(this._guildClan, this._guildMembers);
|
|
this.daysToWarn = (parseInt(this._guildClan.daysToKick) / 2);
|
|
this.clanViewModel = new ClanViewModel(this._guildClan);
|
|
this.clanLoaded = true;
|
|
this.membersViewModel = new MembersViewModel(this._guildMembers);
|
|
this.membersLoaded = true;
|
|
console.log(this._guildClan);
|
|
console.log(this._guildMembers);
|
|
}
|
|
|
|
loadMembers(): void {
|
|
this._guildMembers = this._memberService.loadMembers(this._guildClan);
|
|
this.membersViewModel = new MembersViewModel(this._guildMembers);
|
|
this._guildClan = this._clanService.loadClanStats(this._guildClan, this._guildMembers);
|
|
this.membersLoaded = true;
|
|
}
|
|
|
|
getMembers(): HWMember[] {
|
|
return this._guildMembers;
|
|
}
|
|
|
|
syncClan(): void {
|
|
console.log(this._guildClan);
|
|
console.log(guildData);
|
|
}
|
|
|
|
syncMembers(): void {
|
|
console.log(this._guildMembers);
|
|
console.log(guildStatistics);
|
|
}
|
|
|
|
}
|