Commit b66f1ff2 authored by nanahira's avatar nanahira

so far those things

parent c6b7cce5
Pipeline #4945 passed with stage
in 5 minutes and 52 seconds
...@@ -35,27 +35,27 @@ ...@@ -35,27 +35,27 @@
<!--<a href="https://accounts.moecube.com/profiles" id="avatar" mat-raised-button [style.background-image]="'url(' + login.user.avatar_url + ')'">{{login.user.username}}</a>--> <!--<a href="https://accounts.moecube.com/profiles" id="avatar" mat-raised-button [style.background-image]="'url(' + login.user.avatar_url + ')'">{{login.user.username}}</a>-->
<!--</mat-grid-tile>--> <!--</mat-grid-tile>-->
<mat-grid-tile> <mat-grid-tile>
<button mat-raised-button color="primary" (click)="ygopro.request_match('athletic')"> <button mat-raised-button color="primary" [disabled]='ygopro.currentServer && ygopro.currentServer.id !== "tiramisu"' (click)="ygopro.request_match('athletic')">
<mat-icon fontSet="fa" fontIcon="fa-futbol-o"></mat-icon> <mat-icon fontSet="fa" fontIcon="fa-futbol-o"></mat-icon>
<br>竞技匹配 <br>竞技匹配
</button> </button>
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile> <mat-grid-tile>
<button mat-raised-button color="primary" (click)="ygopro.request_match('entertain')"> <button mat-raised-button color="primary" [disabled]='ygopro.currentServer && ygopro.currentServer.id !== "tiramisu"' (click)="ygopro.request_match('entertain')">
<mat-icon>toys</mat-icon> <mat-icon>toys</mat-icon>
<br>娱乐匹配 <br>娱乐匹配
</button> </button>
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile><a mat-raised-button color="primary" routerLink="/ygopro/rooms"> <mat-grid-tile><a mat-raised-button color="primary" [disabled]='ygopro.currentServer && !ygopro.currentServer.custom' routerLink="/ygopro/rooms">
<mat-icon>games</mat-icon> <mat-icon>games</mat-icon>
<br>房间列表</a></mat-grid-tile> <br>房间列表</a></mat-grid-tile>
<mat-grid-tile><a mat-raised-button color="primary" routerLink="/ygopro/rooms/new"> <mat-grid-tile><a mat-raised-button color="primary" [disabled]='ygopro.currentServer && !ygopro.currentServer.custom' routerLink="/ygopro/rooms/new">
<mat-icon>&#xe146;</mat-icon><!--add_box--> <mat-icon>&#xe146;</mat-icon><!--add_box-->
<br>创建房间</a></mat-grid-tile> <br>创建房间</a></mat-grid-tile>
<mat-grid-tile><a mat-raised-button routerLink="/ygopro/windbot"> <mat-grid-tile><a mat-raised-button [disabled]='ygopro.currentServer && !ygopro.currentServer.windbot' routerLink="/ygopro/windbot">
<mat-icon>&#xe195;</mat-icon><!-- airplanemode_active --> <mat-icon>&#xe195;</mat-icon><!-- airplanemode_active -->
<br>单人模式</a></mat-grid-tile> <br>单人模式</a></mat-grid-tile>
<mat-grid-tile><a mat-raised-button routerLink="/ygopro/watch"> <mat-grid-tile><a mat-raised-button [disabled]='ygopro.currentServer && !ygopro.currentServer.replay' routerLink="/ygopro/watch">
<mat-icon>&#xe417;</mat-icon><!--remove_red_eye--> <mat-icon>&#xe417;</mat-icon><!--remove_red_eye-->
<br>观战</a></mat-grid-tile> <br>观战</a></mat-grid-tile>
<!--<mat-grid-tile>--> <!--<mat-grid-tile>-->
......
...@@ -15,7 +15,7 @@ export class RoomListComponent implements OnInit { ...@@ -15,7 +15,7 @@ export class RoomListComponent implements OnInit {
@HostBinding('@routerTransition') animation; @HostBinding('@routerTransition') animation;
displayedColumns = ['title', 'users', 'mode', 'extra']; displayedColumns = ['title', 'users', 'mode', 'extra'];
dataSource = new RoomListDataSource(this.ygopro.servers.filter(server => server.custom!)); dataSource = new RoomListDataSource(this.ygopro);
constructor(public login: LoginService, public ygopro: YGOProService, private changeDetector: ChangeDetectorRef) {} constructor(public login: LoginService, public ygopro: YGOProService, private changeDetector: ChangeDetectorRef) {}
......
环境: <mat-form-field appearance='standard'> 环境: <mat-form-field appearance='standard'>
<!-- <mat-label>Favorite food</mat-label>--> <!-- <mat-label>Favorite food</mat-label>-->
<mat-select> <mat-select [(ngModel)]='ygopro.currentServer'>
<mat-option *ngFor='let server of servers' [value]='server.id'> <mat-option *ngFor='let server of ygopro.selectableServers' [value]='server'>
{{server.name}} {{server.name}}
</mat-option> </mat-option>
</mat-select> </mat-select>
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { YGOProService } from '../ygopro.service';
@Component({ @Component({
selector: 'app-server-select', selector: 'app-server-select',
...@@ -7,9 +8,9 @@ import { Component, OnInit } from '@angular/core'; ...@@ -7,9 +8,9 @@ import { Component, OnInit } from '@angular/core';
}) })
export class ServerSelectComponent implements OnInit { export class ServerSelectComponent implements OnInit {
servers = [{ id: 'mycard', name: '标准' }, { id: 'test', name: '测试' }]; //servers = [{ id: 'mycard', name: '标准' }, { id: 'test', name: '测试' }];
constructor() { constructor(public ygopro: YGOProService) {
} }
ngOnInit() { ngOnInit() {
......
...@@ -14,7 +14,7 @@ export class WatchComponent implements OnInit { ...@@ -14,7 +14,7 @@ export class WatchComponent implements OnInit {
@HostBinding('@routerTransition') animation; @HostBinding('@routerTransition') animation;
displayedColumns = ['mode', 'title', 'users', 'extra']; displayedColumns = ['mode', 'title', 'users', 'extra'];
dataSource = new RoomListDataSource(this.ygopro.servers, 'started'); dataSource = new RoomListDataSource(this.ygopro, 'started');
constructor(public login: LoginService, public ygopro: YGOProService, private changeDetector: ChangeDetectorRef) {} constructor(public login: LoginService, public ygopro: YGOProService, private changeDetector: ChangeDetectorRef) {}
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<mat-icon mat-list-icon>&#xe195;</mat-icon><!-- airplanemode_active --> <mat-icon mat-list-icon>&#xe195;</mat-icon><!-- airplanemode_active -->
<h4 mat-line>随机</h4> <h4 mat-line>随机</h4>
</mat-list-item> </mat-list-item>
<mat-list-item *ngFor="let windbot of ygopro.windbot | async" (click)="ygopro.join_windbot(windbot)"> <mat-list-item *ngFor="let windbot of (ygopro.currentServer ? ygopro.currentServer.windbot : [])" (click)="ygopro.join_windbot(windbot)">
<img mat-list-icon [src]="login.avatar(windbot)"> <img mat-list-icon [src]="login.avatar(windbot)">
<h4 mat-line>{{windbot}}</h4> <h4 mat-line>{{windbot}}</h4>
</mat-list-item> </mat-list-item>
......
...@@ -119,7 +119,6 @@ export interface Points { ...@@ -119,7 +119,6 @@ export interface Points {
export class YGOProService { export class YGOProService {
news: Promise<News[]>; news: Promise<News[]>;
topics: Promise<any[]>; topics: Promise<any[]>;
windbot: Promise<string[]>;
points = new BehaviorSubject<Points | undefined>(undefined); points = new BehaviorSubject<Points | undefined>(undefined);
readonly default_options: Options = { readonly default_options: Options = {
...@@ -136,27 +135,28 @@ export class YGOProService { ...@@ -136,27 +135,28 @@ export class YGOProService {
time_limit: 180, time_limit: 180,
auto_death: false auto_death: false
}; };
readonly servers: Server[] = [ serversPromise: Promise<Server[]>;
{ servers: Server[] = [];
id: 'tiramisu', selectableServers: Server[] = [];
url: 'wss://tiramisu.mycard.moe:7923', currentServer: Server;
address: 'tiramisu.mycard.moe',
port: 7911,
custom: true,
replay: true
},
{
id: 'tiramisu-athletic',
url: 'wss://tiramisu.mycard.moe:8923',
address: 'tiramisu.mycard.moe',
port: 8911,
custom: false,
replay: true
}
];
constructor(private login: LoginService, private http: HttpClient, private dialog: MatDialog, private storage: StorageService) { constructor(private login: LoginService, private http: HttpClient, private dialog: MatDialog, private storage: StorageService) {
const app = this.http.get<App[]>('https://sapi.moecube.com:444/apps.json').pipe(map(apps => apps.find(_app => _app.id === 'ygopro')!), publishLast(), refCount()); const app = this.http.get<App[]>('https://sapi.moecube.com:444/apps.json').pipe(map(apps => apps.find(_app => _app.id === 'ygopro')!), publishLast(), refCount());
this.serversPromise = app
.pipe(
map(_app =>
_app.data.servers
)
)
.toPromise();
this.serversPromise.then((servers) => {
this.servers = servers;
this.selectableServers = servers.filter(s => !s.hidden);
this.currentServer = this.selectableServers[0];
})
this.news = app this.news = app
.pipe( .pipe(
map(_app => map(_app =>
...@@ -171,7 +171,7 @@ export class YGOProService { ...@@ -171,7 +171,7 @@ export class YGOProService {
) )
) )
.toPromise(); .toPromise();
this.windbot = app.pipe(map(_app => (<YGOProData>_app.data).windbot['zh-CN'])).toPromise(); // this.windbot = app.pipe(map(_app => (<YGOProData>_app.data).windbot['zh-CN'])).toPromise();
this.topics = this.http this.topics = this.http
.get<TopResponse>('https://ygobbs.com/top/quarterly.json') .get<TopResponse>('https://ygobbs.com/top/quarterly.json')
...@@ -291,7 +291,7 @@ export class YGOProService { ...@@ -291,7 +291,7 @@ export class YGOProService {
// body: `房间密码是 ${this.host_password}, 您的对手可在自定义游戏界面输入密码与您对战。` // body: `房间密码是 ${this.host_password}, 您的对手可在自定义游戏界面输入密码与您对战。`
// }); // });
// } // }
this.join(password, this.servers[0]); this.join(password, this.currentServer);
} }
join_room(room: Room) { join_room(room: Room) {
...@@ -329,14 +329,14 @@ export class YGOProService { ...@@ -329,14 +329,14 @@ export class YGOProService {
const name = options_buffer.toString('base64') + password.replace(/\s/, String.fromCharCode(0xfeff)); const name = options_buffer.toString('base64') + password.replace(/\s/, String.fromCharCode(0xfeff));
this.join(name, this.servers[0]); this.join(name, this.currentServer);
} }
async join_windbot(name?: string) { async join_windbot(name?: string) {
if (!name) { if (!name) {
name = sample(await this.windbot); name = sample(this.currentServer.windbot!);
} }
return this.join('AI#' + name, this.servers[0]); return this.join('AI#' + name, this.currentServer);
} }
join(password: string, server: Server) { join(password: string, server: Server) {
...@@ -427,7 +427,7 @@ export class RoomListDataSource extends DataSource<Room> { ...@@ -427,7 +427,7 @@ export class RoomListDataSource extends DataSource<Room> {
empty = new EventEmitter(); empty = new EventEmitter();
error = new EventEmitter(); error = new EventEmitter();
constructor(private servers: Server[], private type = 'waiting') { constructor(private ygopro: YGOProService, private type = 'waiting') {
super(); super();
} }
...@@ -435,7 +435,7 @@ export class RoomListDataSource extends DataSource<Room> { ...@@ -435,7 +435,7 @@ export class RoomListDataSource extends DataSource<Room> {
connect(): Observable<Room[]> { connect(): Observable<Room[]> {
this.loading.emit(true); this.loading.emit(true);
return combineLatest( return combineLatest(
this.servers.map(server => { this.ygopro.servers.filter(s => s.url && (s.custom || s.replay)).map(server => {
const url = new URL(server.url!); const url = new URL(server.url!);
url.searchParams.set('filter', this.type); url.searchParams.set('filter', this.type);
// 协议处理 // 协议处理
...@@ -458,10 +458,10 @@ export class RoomListDataSource extends DataSource<Room> { ...@@ -458,10 +458,10 @@ export class RoomListDataSource extends DataSource<Room> {
).pipe( ).pipe(
// 把多个服务器的数据拼接起来 // 把多个服务器的数据拼接起来
map((sources: Room[][]) => (<Room[]>[]).concat(...sources)), map((sources: Room[][]) => (<Room[]>[]).concat(...sources)),
// 筛选一下房间,只扔进去当前房间或者竞技匹配的
// 房间排序 // 房间排序
map(rooms => map(rooms =>
sortBy(rooms, room => { sortBy(rooms.filter(r => r.arena || r.server === this.ygopro.currentServer), room => {
if (room.arena === 'athletic') { if (room.arena === 'athletic') {
return 0; return 0;
} else if (room.arena === 'entertain') { } else if (room.arena === 'entertain') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment