initial commit

This commit is contained in:
Chris Chen
2022-09-30 10:53:48 -07:00
commit 911b45739d
1026 changed files with 149872 additions and 0 deletions
@@ -0,0 +1,22 @@
<h2>隊長:{{leader?leader.username + ' 提拔階段':'請選擇初始隊長!'}}</h2>
<ng-container *ngIf="me.isLeader">
<div class="row">
<div class="col-md-6 form-group" *ngFor="let p of players;let i=index">
<nb-checkbox name="goingTo{{i}}" [ngModel]="p.goingToQuest" (checkedChange)="toggleTeamMate(p,$event)">
{{p.username}}</nb-checkbox>
</div>
</div>
<button nbButton hero fullWidth status="primary" class="mt-2" (click)="pickTeamMate()">送出名單</button>
</ng-container>
<ng-container *ngIf="isHost">
<h2>選擇隊長:</h2>
<div class="row">
<div class="col-6 form-group" *ngFor="let player of players">
<button nbButton fullWidth hero status="info" (click)="changeLeader(player)">{{player.username}}</button>
</div>
</div>
</ng-container>
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PickTeammateComponent } from './pick-teammate.component';
describe('PickTeammateComponent', () => {
let component: PickTeammateComponent;
let fixture: ComponentFixture<PickTeammateComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ PickTeammateComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(PickTeammateComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,59 @@
import { ChangeDetectorRef, Component, NgZone, OnInit } from '@angular/core';
import { Player, AvalonStage } from '../../../entity/Avalon';
import { AvalonService } from '../../../services/avalon.service';
import { MsgBoxService } from '../../../services/msg-box.service';
import { ADIcon } from '../../../ui/alert-dlg/alert-dlg.component';
import { AvalonBase } from '../avalonBase';
@Component({
selector: 'avalon-pick-teammate',
templateUrl: './pick-teammate.component.html',
styleUrls: ['./pick-teammate.component.scss']
})
export class PickTeammateComponent extends AvalonBase implements OnInit {
constructor(
protected cdRef: ChangeDetectorRef,
protected avalonService: AvalonService,
private ngZone: NgZone,
private msgBoxService: MsgBoxService
) {
super(cdRef, avalonService);
}
ngOnInit(): void {
}
toggleTeamMate(player: Player, value: boolean) {
player.goingToQuest = value;
this.cdRef.detectChanges();
}
public pickTeamMate() {
let teamSize = this.players.filter(p => p.goingToQuest).length;
if (teamSize == this.currentQuest.teamSize) {
this.avalonService.data.stage = AvalonStage.TeamVote;
this.clearVoteStatus();
this.broadcastAll();
this.avalonService.applyCdChange$.next();
} else {
this.ngZone.run(_ => {
this.msgBoxService.show('任務編組錯誤!', `本次任務出場人數為 ${this.currentQuest.teamSize} 人!`, ADIcon.WARNING);
});
}
}
public changeLeader(newLeader: Player) {
let oldLeader = this.players.find(p => p.isLeader);
if (oldLeader) oldLeader.isLeader = false;
newLeader.isLeader = true;
for (let i = 0; i < this.players.length; i++) {
const player = this.players[i];
player.goingToQuest = false;
}
this.refreshAllInfo();
this.cdRef.detectChanges();
}
}