Commit e8b523b0 authored by nanahira's avatar nanahira

Merge branch 'v3-abstract-ygopro' into v3

parents 9372c2cd 8de4a1f3
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Created by zh99998 on 16/9/2. * Created by zh99998 on 16/9/2.
*/ */
import {Component} from '@angular/core'; import {Component} from '@angular/core';
@Component({ @Component({
moduleId: module.id, moduleId: module.id,
selector: 'about', selector: 'about',
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
</div> </div>
<!--应用ready--> <!--应用ready-->
<div *ngIf="currentApp.isReady() && (currentApp.id != 'ygopro')" class="i-b"> <div *ngIf="currentApp.isReady() && !currentApp.isYGOPro" class="i-b">
<button *ngIf="currentApp.runnable()" (click)="runApp(currentApp)" [disabled]="!appsService.allReady(currentApp)" type="button" class="btn btn-primary btn-sm"> <button *ngIf="currentApp.runnable()" (click)="runApp(currentApp)" [disabled]="!appsService.allReady(currentApp)" type="button" class="btn btn-primary btn-sm">
<i class="fa fa-play" aria-hidden="true"></i> <span i18n>运行</span></button> <i class="fa fa-play" aria-hidden="true"></i> <span i18n>运行</span></button>
<button *ngIf="currentApp.actions.get('network')" [disabled]="!appsService.allReady(currentApp)" (click)="runApp(currentApp,'network')" type="button" class="btn btn-primary btn-sm"> <button *ngIf="currentApp.actions.get('network')" [disabled]="!appsService.allReady(currentApp)" (click)="runApp(currentApp,'network')" type="button" class="btn btn-primary btn-sm">
...@@ -65,13 +65,13 @@ ...@@ -65,13 +65,13 @@
</div> </div>
<!--<button (click)="log(appsService)">test</button>--> <!--<button (click)="log(appsService)">test</button>-->
<network *ngIf="(currentApp.id != 'ygopro') && currentApp && currentApp.network && currentApp.network.protocol == 'maotama'" [currentApp]="currentApp"></network> <network *ngIf="currentApp && !currentApp.isYGOPro && currentApp.network && currentApp.network.protocol == 'maotama'" [currentApp]="currentApp"></network>
<ygopro *ngIf="currentApp.isReady() && (currentApp.id == 'ygopro')" [app]="currentApp" [currentApp]="currentApp" (points)="onPoints($event)"></ygopro> <ygopro *ngIf="currentApp.isReady() && currentApp.isYGOPro" [app]="currentApp" [currentApp]="currentApp" (points)="onPoints($event)"></ygopro>
</div> </div>
</div> </div>
<div id="arena" class="panel panel-default" *ngIf="currentApp.id === 'ygopro' && points "> <div id="arena" class="panel panel-default" *ngIf="currentApp.isYGOPro && points ">
<h2 i18n>排位成绩</h2> <h2 i18n>排位成绩</h2>
<table class="table table-sm"> <table class="table table-sm">
<tbody> <tbody>
......
...@@ -55,13 +55,15 @@ export class AppDetailComponent implements OnInit, OnChanges { ...@@ -55,13 +55,15 @@ export class AppDetailComponent implements OnInit, OnChanges {
'mysterious': '迷之物体', 'mysterious': '迷之物体',
'touhou': '东方 Project', 'touhou': '东方 Project',
'touhou_pc98': '东方旧作', 'touhou_pc98': '东方旧作',
'language': '语言包' 'language': '语言包',
'ygopro': 'YGOPro'
} : { } : {
'recommend': 'Recommended', 'recommend': 'Recommended',
'mysterious': 'Something', 'mysterious': 'Something',
'touhou': 'Touhou Project', 'touhou': 'Touhou Project',
'touhou_pc98': 'Touhou old series', 'touhou_pc98': 'Touhou old series',
'language': 'Language Pack' 'language': 'Language Pack',
'ygopro': 'YGOPro'
}; };
} }
......
import {App} from './app'; import {App} from './app';
/** /**
* Created by zh99998 on 16/9/6. * Created by zh99998 on 16/9/6.
*/ */
......
import { AppLocal } from './app-local'; import {AppLocal} from './app-local';
import * as path from 'path'; import * as path from 'path';
import * as ini from 'ini'; import * as ini from 'ini';
import * as fs from 'fs'; import * as fs from 'fs';
import * as child_process from 'child_process'; import * as child_process from 'child_process';
import * as Mustache from 'mustache';
export enum Category { export enum Category {
game, game,
...@@ -62,6 +63,13 @@ export class AppStatus { ...@@ -62,6 +63,13 @@ export class AppStatus {
progressMessage: string; progressMessage: string;
} }
export interface YGOProDistroData {
deckPath: string;
replayPath: string;
systemConf: string;
}
export class App { export class App {
id: string; id: string;
name: string; // i18n name: string; // i18n
...@@ -239,7 +247,7 @@ export class App { ...@@ -239,7 +247,7 @@ export class App {
return dependencies.every((dependency) => dependency.isReady()); return dependencies.every((dependency) => dependency.isReady());
} }
async getSpawnAction(children: App[], action_name = 'main', referencedApp?: App, referencedAction?: Action, cwd?: string): Promise<SpawnAction> { async getSpawnAction(children: App[], action_name = 'main', referencedApp?: App, referencedAction?: Action, cwd?: string, argsTemplate?: any): Promise<SpawnAction> {
const appCwd = (<AppLocal>this.local).path; const appCwd = (<AppLocal>this.local).path;
if(!cwd) { if(!cwd) {
cwd = appCwd; cwd = appCwd;
...@@ -301,23 +309,31 @@ export class App { ...@@ -301,23 +309,31 @@ export class App {
if (action.open) { if (action.open) {
const np2 = action.open; const np2 = action.open;
const openAction = await np2.getSpawnAction([], 'main', this, action, cwd); const openAction = await np2.getSpawnAction([], 'main', this, action, cwd, argsTemplate);
args = args.concat(openAction.args); args = args.concat(openAction.args);
args.push(action.execute); args.push(action.execute);
execute = openAction.execute; execute = openAction.execute;
cwd = openAction.cwd; cwd = openAction.cwd;
} }
args = args.concat(action.args); args = args.concat(action.args);
if (argsTemplate) {
for (let i = 0; i < args.length; ++i) {
if (typeof args[i] !== 'string') {
continue;
}
args[i] = Mustache.render(args[i], argsTemplate, null, { escape: (v) => v });
}
}
env = Object.assign(env, action.env); env = Object.assign(env, action.env);
return { return {
execute, execute,
args, args,
env, env,
cwd cwd
} };
} }
async spawnApp(children: App[], action_name = 'main') { async spawnApp(children: App[], action_name = 'main', argsTemplate?: any) {
if (this.id === 'th123') { if (this.id === 'th123') {
let th105 = <App>this.references.get('th105'); let th105 = <App>this.references.get('th105');
...@@ -333,9 +349,44 @@ export class App { ...@@ -333,9 +349,44 @@ export class App {
} }
const appCwd = (<AppLocal>this.local).path; const appCwd = (<AppLocal>this.local).path;
const {execute, args, env, cwd} = await this.getSpawnAction(children, action_name); const {execute, args, env, cwd} = await this.getSpawnAction(children, action_name, null, null, null, argsTemplate);
console.log(execute, args, env, cwd, appCwd); console.log(execute, args, env, cwd, appCwd);
return child_process.spawn(execute, args, {env: env, cwd: cwd || appCwd}); return child_process.spawn(execute, args, {env: env, cwd: cwd || appCwd});
} }
get isYGOPro(): boolean {
return !!this.ygoproDistroData;
}
get ygoproDistroData(): YGOProDistroData {
if(!this.data) {
return null;
}
return this.data.ygopro || null;
}
get ygoproDeckPath(): string {
const distroData = this.ygoproDistroData;
if(!distroData) {
return null;
}
return path.join(this.local!.path, distroData.deckPath);
}
get ygoproReplayPath(): string {
const distroData = this.ygoproDistroData;
if(!distroData || !distroData.replayPath) {
return null;
}
return path.join(this.local!.path, distroData.replayPath);
}
get systemConfPath(): string {
const distroData = this.ygoproDistroData;
if(!distroData || !distroData.systemConf) {
return null;
}
return path.join(this.local!.path, distroData.systemConf);
}
} }
...@@ -19,9 +19,8 @@ import {LoginService} from './login.service'; ...@@ -19,9 +19,8 @@ import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices'; import {SettingsService} from './settings.sevices';
import {ComparableSet} from './shared/ComparableSet'; import {ComparableSet} from './shared/ComparableSet';
import {AppsJson} from './apps-json-type'; import {AppsJson} from './apps-json-type';
import Timer = NodeJS.Timer;
import ReadableStream = NodeJS.ReadableStream;
import * as os from 'os'; import * as os from 'os';
import Timer = NodeJS.Timer;
const Logger = { const Logger = {
info: (...message: any[]) => { info: (...message: any[]) => {
......
...@@ -23,7 +23,7 @@ $.fn.init = new Proxy($.fn.init, { ...@@ -23,7 +23,7 @@ $.fn.init = new Proxy($.fn.init, {
window['jQuery'] = $; window['jQuery'] = $;
import {Component, ViewEncapsulation, OnInit, Input, OnChanges, SimpleChanges, ElementRef} from '@angular/core'; import {Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation} from '@angular/core';
import {LoginService} from './login.service'; import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices'; import {SettingsService} from './settings.sevices';
import {App} from './app'; import {App} from './app';
......
/** /**
* Created by weijian on 2016/10/26. * Created by weijian on 2016/10/26.
*/ */
import {Injectable, NgZone, EventEmitter} from '@angular/core'; import {EventEmitter, Injectable, NgZone} from '@angular/core';
import {Http} from '@angular/http'; import {Http} from '@angular/http';
// import {error} from 'util'; // import {error} from 'util';
// import Timer = NodeJS.Timer; // import Timer = NodeJS.Timer;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Created by zh99998 on 2017/6/1. * Created by zh99998 on 2017/6/1.
*/ */
import * as Raven from 'raven-js'; import * as Raven from 'raven-js';
import { ErrorHandler } from '@angular/core'; import {ErrorHandler} from '@angular/core';
Raven Raven
.config('https://2c5fa0d0f13c43b5b96346f4eff2ea60@sentry.io/174769') .config('https://2c5fa0d0f13c43b5b96346f4eff2ea60@sentry.io/174769')
...@@ -12,4 +12,4 @@ export class RavenErrorHandler implements ErrorHandler { ...@@ -12,4 +12,4 @@ export class RavenErrorHandler implements ErrorHandler {
handleError(err: any): void { handleError(err: any): void {
Raven.captureException(err.originalError || err); Raven.captureException(err.originalError || err);
} }
} }
\ No newline at end of file
import {TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID} from '@angular/core'; import {LOCALE_ID, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
import {remote} from 'electron'; import {remote} from 'electron';
export async function getTranslationProviders (): Promise<Object[]> { export async function getTranslationProviders (): Promise<Object[]> {
......
import {App} from './app'; import {App} from './app';
import * as path from 'path'; import * as path from 'path';
/** /**
* Created by weijian on 2016/10/24. * Created by weijian on 2016/10/24.
*/ */
......
...@@ -42,6 +42,15 @@ ...@@ -42,6 +42,15 @@
</a> </a>
</li> </li>
</ul> </ul>
<span i18n *ngIf="grouped_apps.ygopro">YGOPro 各发行版</span>
<ul *ngIf="grouped_apps.recommend" class="nav nav-pills flex-column">
<li *ngFor="let app of grouped_apps.ygopro" class="nav-item">
<a (click)="$event.preventDefault(); chooseApp(app)" [href]="'https://mycard.moe/' + app.id" class="nav-link" [class.active]="app===currentApp">
<img *ngIf="app.icon" class="icon" [src]="app.icon">
{{app.name}}
</a>
</li>
</ul>
<span i18n *ngIf="grouped_apps.mysterious">迷之物体</span> <span i18n *ngIf="grouped_apps.mysterious">迷之物体</span>
<ul *ngIf="grouped_apps.mysterious" class="nav nav-pills flex-column"> <ul *ngIf="grouped_apps.mysterious" class="nav nav-pills flex-column">
<li *ngFor="let app of grouped_apps.mysterious" class="nav-item"> <li *ngFor="let app of grouped_apps.mysterious" class="nav-item">
...@@ -95,4 +104,4 @@ ...@@ -95,4 +104,4 @@
</div> </div>
</div> </div>
<div id="right-shadow"></div> <div id="right-shadow"></div>
\ No newline at end of file
/** /**
* Created by zh99998 on 16/9/2. * Created by zh99998 on 16/9/2.
*/ */
import { ChangeDetectorRef, Component, ElementRef, OnInit, ViewChild } from '@angular/core'; import {ChangeDetectorRef, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { AppsService } from './apps.service'; import {AppsService} from './apps.service';
import { LoginService } from './login.service'; import {LoginService} from './login.service';
import { App, Category } from './app'; import {App, Category} from './app';
import { shell } from 'electron'; import {shell} from 'electron';
import { SettingsService } from './settings.sevices'; import {SettingsService} from './settings.sevices';
const ReconnectingWebSocket = require('reconnecting-websocket'); const ReconnectingWebSocket = require('reconnecting-websocket');
// import 'typeahead.js'; // import 'typeahead.js';
...@@ -168,25 +169,27 @@ export class LobbyComponent implements OnInit { ...@@ -168,25 +169,27 @@ export class LobbyComponent implements OnInit {
let contains = ['game', 'music', 'book'].map((value) => Category[value]); let contains = ['game', 'music', 'book'].map((value) => Category[value]);
let result = {runtime: []}; let result = {runtime: []};
for (let app of this.apps.values()) { for (let app of this.apps.values()) {
let tag: string; let tags: string[];
if (contains.includes(app.category)) { if (contains.includes(app.category)) {
if (app.isInstalled()) { if (app.isInstalled()) {
tag = 'installed'; tags = ['installed'];
} else { } else {
tag = app.tags ? app.tags[0] : 'test'; tags = app.tags || ['test'];
} }
} else { } else {
if (app.isInstalled()) { if (app.isInstalled()) {
tag = 'runtime_installed'; tags = ['runtime_installed'];
} else { } else {
tag = 'runtime'; tags = ['runtime'];
} }
} }
if (!result[tag]) { for (const tag of tags) {
result[tag] = []; if (!result[tag]) {
result[tag] = [];
}
result[tag].push(app);
} }
result[tag].push(app);
} }
return result; return result;
} }
......
/** /**
* Created by zh99998 on 16/9/2. * Created by zh99998 on 16/9/2.
*/ */
import { Component } from '@angular/core'; import {Component} from '@angular/core';
import { LoginService } from './login.service'; import {LoginService} from './login.service';
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import { shell } from 'electron'; import {shell} from 'electron';
@Component({ @Component({
moduleId: module.id, moduleId: module.id,
......
import { ChangeDetectorRef, Component, ElementRef, OnInit, Renderer, ViewChild } from '@angular/core'; import {ChangeDetectorRef, Component, ElementRef, OnInit, Renderer, ViewChild} from '@angular/core';
import 'bootstrap'; import 'bootstrap';
import { remote, shell } from 'electron'; import {remote, shell} from 'electron';
import * as $ from 'jquery'; import * as $ from 'jquery';
import * as Tether from 'tether'; import * as Tether from 'tether';
import { LoginService } from './login.service'; import {LoginService} from './login.service';
import { SettingsService } from './settings.sevices'; import {SettingsService} from './settings.sevices';
window['Tether'] = Tether; window['Tether'] = Tether;
const autoUpdater: Electron.AutoUpdater = remote.getGlobal('autoUpdater'); const autoUpdater: Electron.AutoUpdater = remote.getGlobal('autoUpdater');
......
import { ErrorHandler, LOCALE_ID, NgModule, NO_ERRORS_SCHEMA } from '@angular/core'; import {LOCALE_ID, NgModule, NO_ERRORS_SCHEMA} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import { HttpModule } from '@angular/http'; import {HttpModule} from '@angular/http';
import { MyCardComponent } from './mycard.component'; import {MyCardComponent} from './mycard.component';
import { LoginComponent } from './login.component'; import {LoginComponent} from './login.component';
import { StoreComponent } from './store.component'; import {StoreComponent} from './store.component';
import { LobbyComponent } from './lobby.component'; import {LobbyComponent} from './lobby.component';
import { AppDetailComponent } from './app-detail.component'; import {AppDetailComponent} from './app-detail.component';
import { RosterComponent } from './roster.component'; import {RosterComponent} from './roster.component';
import { YGOProComponent } from './ygopro.component'; import {YGOProComponent} from './ygopro.component';
import { AppsService } from './apps.service'; import {AppsService} from './apps.service';
import { SettingsService } from './settings.sevices'; import {SettingsService} from './settings.sevices';
import { LoginService } from './login.service'; import {LoginService} from './login.service';
import { DownloadService } from './download.service'; import {DownloadService} from './download.service';
import { AboutComponent } from './about.component'; import {AboutComponent} from './about.component';
import { CandyComponent } from './candy.component'; import {CandyComponent} from './candy.component';
import { RavenErrorHandler } from './error-handler'; import {NetworkComponent} from './network.component';
import { NetworkComponent } from './network.component';
export function settingsService_getLocale(settingsService: SettingsService) { export function settingsService_getLocale(settingsService: SettingsService) {
return settingsService.getLocale(); return settingsService.getLocale();
......
import { ChangeDetectorRef, Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges, Injectable } from '@angular/core'; import {Component, Injectable, Input} from '@angular/core';
import { AppsService } from './apps.service'; import {AppsService} from './apps.service';
import {App} from './app'; import {App} from './app';
@Component({ @Component({
......
/** /**
* Created by zh99998 on 16/9/2. * Created by zh99998 on 16/9/2.
*/ */
import {Component, Input, EventEmitter, Output, OnInit, OnChanges} from '@angular/core'; import {Component, EventEmitter, Input, OnChanges, OnInit, Output} from '@angular/core';
@Component({ @Component({
moduleId: module.id, moduleId: module.id,
selector: 'roster', selector: 'roster',
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Created by zh99998 on 16/9/2. * Created by zh99998 on 16/9/2.
*/ */
import {Component} from '@angular/core'; import {Component} from '@angular/core';
@Component({ @Component({
moduleId: module.id, moduleId: module.id,
selector: 'store', selector: 'store',
......
...@@ -3,11 +3,8 @@ ...@@ -3,11 +3,8 @@
*/ */
import {ChangeDetectorRef, Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild} from '@angular/core'; import {ChangeDetectorRef, Component, ElementRef, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild} from '@angular/core';
import {Headers, Http} from '@angular/http'; import {Headers, Http} from '@angular/http';
import * as child_process from 'child_process';
import {clipboard, remote, shell} from 'electron'; import {clipboard, remote, shell} from 'electron';
import * as fs from 'fs-extra'; import * as fs from 'fs-extra';
import * as ini from 'ini';
import {EncodeOptions} from 'ini';
import * as $ from 'jquery'; import * as $ from 'jquery';
import * as path from 'path'; import * as path from 'path';
import 'rxjs/Rx'; import 'rxjs/Rx';
...@@ -18,6 +15,7 @@ import {LoginService} from './login.service'; ...@@ -18,6 +15,7 @@ import {LoginService} from './login.service';
import {SettingsService} from './settings.sevices'; import {SettingsService} from './settings.sevices';
import Timer = NodeJS.Timer; import Timer = NodeJS.Timer;
import WillNavigateEvent = Electron.WillNavigateEvent; import WillNavigateEvent = Electron.WillNavigateEvent;
import _ = require('lodash');
interface SystemConf { interface SystemConf {
use_d3d: string; use_d3d: string;
...@@ -95,8 +93,16 @@ export interface Points { ...@@ -95,8 +93,16 @@ export interface Points {
ratio: number; ratio: number;
} }
interface YGOProDistroData {
deckPath: string;
replayPath: string;
systemConf?: string;
lastDeckFormat?: string;
}
interface YGOProData { interface YGOProData {
servers: Server[] ygopro: YGOProDistroData;
servers: Server[];
} }
...@@ -140,7 +146,7 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -140,7 +146,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
selectableServers: Server[]; selectableServers: Server[];
//selectingServerId: string; // selectingServerId: string;
currentServer: Server; currentServer: Server;
/*reloadCurrentServer() { /*reloadCurrentServer() {
...@@ -150,6 +156,8 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -150,6 +156,8 @@ export class YGOProComponent implements OnInit, OnDestroy {
// tslint:disable-next-line:member-ordering // tslint:disable-next-line:member-ordering
rooms_loading = true; rooms_loading = true;
lastDeckFormat: RegExp;
default_options: Options = { default_options: Options = {
mode: 1, mode: 1,
rule: this.settingsService.getLocale().startsWith('zh') ? 0 : 1, rule: this.settingsService.getLocale().startsWith('zh') ? 0 : 1,
...@@ -270,11 +278,27 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -270,11 +278,27 @@ export class YGOProComponent implements OnInit, OnDestroy {
}); });
} }
getYGOProData(app: App) {
const ygoproData = <YGOProData>app.data;
for (const child of this.appsService.findChildren(app)) {
if (child.isYGOPro) {
const childData = this.getYGOProData(child);
_.mergeWith(ygoproData, childData, (objValue, srcValue) => {
if (_.isArray(objValue)) {
return objValue.concat(srcValue);
}
});
}
}
return ygoproData;
}
async ngOnInit() { async ngOnInit() {
this.servers = (<YGOProData>this.app.data).servers; const ygoproData = this.getYGOProData(this.app);
this.servers = ygoproData.servers;
this.selectableServers = this.servers.filter(s => !s.hidden); this.selectableServers = this.servers.filter(s => !s.hidden);
this.currentServer = this.selectableServers[0]; this.currentServer = this.selectableServers[0];
//this.reloadCurrentServer(); // this.reloadCurrentServer();
let locale: string; let locale: string;
if (this.settingsService.getLocale().startsWith('zh')) { if (this.settingsService.getLocale().startsWith('zh')) {
...@@ -283,8 +307,14 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -283,8 +307,14 @@ export class YGOProComponent implements OnInit, OnDestroy {
locale = 'en-US'; locale = 'en-US';
} }
this.system_conf = path.join(this.app.local!.path, 'system.conf'); if (ygoproData.ygopro.lastDeckFormat) {
await this.refresh(); // console.log(`Deck format pattern: ${ygoproData.ygopro.lastDeckFormat}`)
this.lastDeckFormat = new RegExp(ygoproData.ygopro.lastDeckFormat);
}
this.system_conf = this.app.systemConfPath;
console.log(`Will load system conf file from ${this.system_conf}`);
await this.refresh(true);
let modal = $('#game-list-modal'); let modal = $('#game-list-modal');
...@@ -387,7 +417,7 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -387,7 +417,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
let watchDropdownMenu = $('#watch-filter'); let watchDropdownMenu = $('#watch-filter');
watchDropdownMenu.on("change", "input[type='checkbox']", (event) => { watchDropdownMenu.on("change", "input[type='checkbox']", (event) => {
//$(event.target).closest("label").toggleClass("active", (<HTMLInputElement> event.target).checked); // $(event.target).closest("label").toggleClass("active", (<HTMLInputElement> event.target).checked);
this.refresh_replay_rooms(); this.refresh_replay_rooms();
}); });
...@@ -408,14 +438,31 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -408,14 +438,31 @@ export class YGOProComponent implements OnInit, OnDestroy {
} }
async refresh() { async refresh(init?: boolean) {
this.decks = await this.get_decks(); this.decks = await this.get_decks();
let system_conf = await this.load_system_conf(); if (this.lastDeckFormat) {
const systemConfString = await this.load_system_conf();
let lastDeck: string;
if (systemConfString) {
// console.log(`System conf string: ${systemConfString}`);
const lastDeckMatch = systemConfString.match(this.lastDeckFormat);
if (lastDeckMatch) {
lastDeck = lastDeckMatch[1];
// console.log(`Last deck ${lastDeck} read from ${this.system_conf}.`);
} else {
// console.error(`Deck pattern not found from pattern ${this.system_conf}: ${lastDeckMatch}`);
}
} else {
// console.error(`System conf ${this.system_conf} not found.`);
}
if (this.decks.includes(system_conf.lastdeck)) { if (lastDeck && this.decks.includes(lastDeck)) {
this.current_deck = system_conf.lastdeck; // console.log(`Got last deck ${lastDeck}.`);
} else { this.current_deck = lastDeck;
this.current_deck = this.decks[0]; } else if (init) {
this.current_deck = this.decks[0];
}
} }
this.replays = await this.get_replays(); this.replays = await this.get_replays();
...@@ -437,18 +484,43 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -437,18 +484,43 @@ export class YGOProComponent implements OnInit, OnDestroy {
async get_decks(): Promise<string[]> { async get_decks(): Promise<string[]> {
try { try {
let files: string[] = await fs.readdir(path.join(this.app.local!.path, 'deck')); /*
const deckPath = this.app.ygoproDeckPath;
let result: string[] = [];
const files: string[] = await fs.readdir(deckPath);
for (const file of files) {
if (file.startsWith('.git')) { // fuck
continue;
}
if (path.extname(file) === '.ydk') {
result.push(path.basename(file, '.ydk'));
} else {
const fullPath = path.join(deckPath, file);
const stat = await fs.stat(fullPath);
if (stat.isDirectory()) {
const innerDecks = (await fs.readdir(fullPath))
.filter((iFile) => path.extname(iFile) === '.ydk')
.map((iFile) => path.join(file, path.basename(iFile, '.ydk')));
result = result.concat(innerDecks);
}
}
}
return result;
*/
let files: string[] = await fs.readdir(this.app.ygoproDeckPath);
return files.filter(file => path.extname(file) === '.ydk').map(file => path.basename(file, '.ydk')); return files.filter(file => path.extname(file) === '.ydk').map(file => path.basename(file, '.ydk'));
} catch (error) { } catch (error) {
console.error(`Load deck fail: ${error.toString()}`);
return []; return [];
} }
} }
async get_replays(): Promise<string[]> { async get_replays(): Promise<string[]> {
try { try {
let files: string[] = await fs.readdir(path.join(this.app.local!.path, 'replay')); let files: string[] = await fs.readdir(this.app.ygoproReplayPath);
return files.filter(file => path.extname(file) === '.yrp').map(file => path.basename(file, '.yrp')); return files.filter(file => path.extname(file) === '.yrp').map(file => path.basename(file, '.yrp'));
} catch (error) { } catch (error) {
console.error(`Load replay fail: ${error.toString()}`);
return []; return [];
} }
} }
...@@ -464,13 +536,14 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -464,13 +536,14 @@ export class YGOProComponent implements OnInit, OnDestroy {
async delete_deck(deck: string) { async delete_deck(deck: string) {
if (confirm('确认删除?')) { if (confirm('确认删除?')) {
try { try {
await fs.unlink(path.join(this.app.local!.path, 'deck', deck + '.ydk')); await fs.unlink(path.join(this.app.ygoproDeckPath, deck + '.ydk'));
} catch (error) { } catch (error) {
} }
return this.refresh(); return this.refresh();
} }
} }
/*
async fix_fonts(data: SystemConf) { async fix_fonts(data: SystemConf) {
if (!await this.get_font([data.numfont])) { if (!await this.get_font([data.numfont])) {
let font = await this.get_font(this.numfont); let font = await this.get_font(this.numfont);
...@@ -485,16 +558,25 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -485,16 +558,25 @@ export class YGOProComponent implements OnInit, OnDestroy {
data['textfont'] = `${font} 14`; data['textfont'] = `${font} 14`;
} }
} }
}; };*/
async load_system_conf(): Promise<SystemConf> { async load_system_conf(): Promise<string> {
let data = await fs.readFile(this.system_conf, {encoding: 'utf-8'}); if (!this.system_conf) {
return <any>ini.parse(data); return null;
}
try {
// console.log(`Loading system conf from ${this.system_conf}`)
let data = await fs.readFile(this.system_conf, {encoding: 'utf-8'});
return data;
} catch(e) {
return null;
}
}; };
/*
save_system_conf(data: SystemConf) { save_system_conf(data: SystemConf) {
return fs.writeFile(this.system_conf, ini.unsafe(ini.stringify(data, <EncodeOptions>{whitespace: true}))); return fs.writeFile(this.system_conf, ini.unsafe(ini.stringify(data, <EncodeOptions>{whitespace: true})));
}; };*/
async join(name: string, server: Server) { async join(name: string, server: Server) {
/*let system_conf = await this.load_system_conf(); /*let system_conf = await this.load_system_conf();
...@@ -506,7 +588,8 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -506,7 +588,8 @@ export class YGOProComponent implements OnInit, OnDestroy {
system_conf.roompass = name; system_conf.roompass = name;
system_conf.nickname = this.loginService.user.username; system_conf.nickname = this.loginService.user.username;
await this.save_system_conf(system_conf);*/ await this.save_system_conf(system_conf);*/
return this.start_game(['-h', server.address, '-p', server.port.toString(), '-w', name, '-n', this.loginService.user.username, '-d', this.current_deck, '-j']); // return this.start_game(['-h', server.address, '-p', server.port.toString(), '-w', name, '-n', this.loginService.user.username, '-d', this.current_deck, '-j']);
return this.start_game('main', {server, password: name, username: this.loginService.user.username, deck: this.current_deck});
}; };
async edit_deck(deck: string) { async edit_deck(deck: string) {
...@@ -514,14 +597,16 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -514,14 +597,16 @@ export class YGOProComponent implements OnInit, OnDestroy {
await this.fix_fonts(system_conf); await this.fix_fonts(system_conf);
system_conf.lastdeck = deck; system_conf.lastdeck = deck;
await this.save_system_conf(system_conf);*/ await this.save_system_conf(system_conf);*/
return this.start_game(['-d', deck]); // return this.start_game(['-d', deck]);
return this.start_game('deck', { deck })
} }
async watch_replay(replay: string) { async watch_replay(replay: string) {
/*let system_conf = await this.load_system_conf(); /*let system_conf = await this.load_system_conf();
await this.fix_fonts(system_conf); await this.fix_fonts(system_conf);
await this.save_system_conf(system_conf);*/ await this.save_system_conf(system_conf);*/
return this.start_game(['-r', path.join('replay', replay + '.yrp')]); // return this.start_game(['-r', path.join('replay', replay + '.yrp')]);
return this.start_game('replay', { replay: path.join(this.app.ygoproReplayPath, `${replay}.yrp`) });
} }
join_windbot(name?: string) { join_windbot(name?: string) {
...@@ -531,7 +616,7 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -531,7 +616,7 @@ export class YGOProComponent implements OnInit, OnDestroy {
return this.join('AI#' + name, this.currentServer); return this.join('AI#' + name, this.currentServer);
} }
async start_game(args: string[]) { async start_game(action: string, param: any) {
let data: any; let data: any;
let start_time: string; let start_time: string;
let exp_rank_ex: number; let exp_rank_ex: number;
...@@ -539,11 +624,9 @@ export class YGOProComponent implements OnInit, OnDestroy { ...@@ -539,11 +624,9 @@ export class YGOProComponent implements OnInit, OnDestroy {
let win = remote.getCurrentWindow(); let win = remote.getCurrentWindow();
win.minimize(); win.minimize();
await new Promise((resolve, reject) => { await new Promise(async (resolve, reject) => {
let child = child_process.spawn(path.join(this.app.local!.path, this.app.actions.get('main')!.execute), args, { const children = this.appsService.findChildren(this.app);
cwd: this.app.local!.path, let child = await this.app.spawnApp(children, action, param);
stdio: 'inherit'
});
child.on('error', (error) => { child.on('error', (error) => {
reject(error); reject(error);
win.restore(); win.restore();
......
{ {
"name": "mycard", "name": "mycard",
"version": "3.0.48", "version": "3.0.51",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"version": "3.0.48", "version": "3.0.51",
"hasInstallScript": true, "hasInstallScript": true,
"license": "UNLICENSED", "license": "UNLICENSED",
"dependencies": { "dependencies": {
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
"ini": "1.3.4", "ini": "1.3.4",
"jquery": "2.2.4", "jquery": "2.2.4",
"marked": "0.3.6", "marked": "0.3.6",
"mustache": "^4.2.0",
"raven-js": "3.16.1", "raven-js": "3.16.1",
"raw-socket": "latest", "raw-socket": "latest",
"reconnecting-websocket": "3.0.7", "reconnecting-websocket": "3.0.7",
...@@ -57,6 +58,7 @@ ...@@ -57,6 +58,7 @@
"@types/jquery": "^2.0.47", "@types/jquery": "^2.0.47",
"@types/lodash": "^4.14.172", "@types/lodash": "^4.14.172",
"@types/marked": "latest", "@types/marked": "latest",
"@types/mustache": "^4.1.2",
"@types/node": "^14.0.1", "@types/node": "^14.0.1",
"@types/tether": "latest", "@types/tether": "latest",
"@types/typeahead": "latest", "@types/typeahead": "latest",
...@@ -564,6 +566,12 @@ ...@@ -564,6 +566,12 @@
"integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==", "integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==",
"dev": true "dev": true
}, },
"node_modules/@types/mustache": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/@types/mustache/-/mustache-4.1.2.tgz",
"integrity": "sha512-c4OVMMcyodKQ9dpwBwh3ofK9P6U9ZktKU9S+p33UqwMNN1vlv2P0zJZUScTshnx7OEoIIRcCFNQ904sYxZz8kg==",
"dev": true
},
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "14.0.1", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.1.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.1.tgz",
...@@ -3539,6 +3547,14 @@ ...@@ -3539,6 +3547,14 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}, },
"node_modules/mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==",
"bin": {
"mustache": "bin/mustache"
}
},
"node_modules/nan": { "node_modules/nan": {
"version": "2.14.2", "version": "2.14.2",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz",
...@@ -5904,6 +5920,12 @@ ...@@ -5904,6 +5920,12 @@
"integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==", "integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==",
"dev": true "dev": true
}, },
"@types/mustache": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/@types/mustache/-/mustache-4.1.2.tgz",
"integrity": "sha512-c4OVMMcyodKQ9dpwBwh3ofK9P6U9ZktKU9S+p33UqwMNN1vlv2P0zJZUScTshnx7OEoIIRcCFNQ904sYxZz8kg==",
"dev": true
},
"@types/node": { "@types/node": {
"version": "14.0.1", "version": "14.0.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.1.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.1.tgz",
...@@ -8269,6 +8291,11 @@ ...@@ -8269,6 +8291,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
}, },
"mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="
},
"nan": { "nan": {
"version": "2.14.2", "version": "2.14.2",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz",
......
...@@ -70,6 +70,8 @@ System.config({ ...@@ -70,6 +70,8 @@ System.config({
// other node.js libraries // other node.js libraries
"electron": "@node/electron", "electron": "@node/electron",
"ini": "@node/ini", "ini": "@node/ini",
"mustache": "@node/mustache",
"lodash": "@node/lodash",
"mkdirp": "@node/mkdirp", "mkdirp": "@node/mkdirp",
"aria2": "@node/aria2", "aria2": "@node/aria2",
"electron-sudo": "@node/electron-sudo", "electron-sudo": "@node/electron-sudo",
......
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