Commit b884a9ec authored by 神楽坂玲奈's avatar 神楽坂玲奈

reformat code

parent ba81af1e
......@@ -5,12 +5,10 @@
padding: 1rem;
}
.list-group {
width: 20rem;
}
.news-block {
padding: 0;
}
......@@ -27,6 +25,7 @@ progress {
#news h3 {
font-size: 1.5rem;
}
#news p {
margin-bottom: 0;
}
......@@ -42,12 +41,12 @@ progress {
width: 300px;
}
#network .input-group-btn>.btn:not(:last-child):not(.dropdown-toggle){
#network .input-group-btn > .btn:not(:last-child):not(.dropdown-toggle) {
border-bottom-right-radius: 0;
border-top-right-radius: 0;
}
#network .input-group-btn>.dropdown-toggle{
#network .input-group-btn > .dropdown-toggle {
border-bottom-left-radius: 0;
border-top-left-radius: 0;
}
\ No newline at end of file
......@@ -3,20 +3,17 @@
<li *ngFor="let app of grouped_apps.installed" [class.active]="app===appsService.currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
<span *ngIf="grouped_apps.yugioh">游戏王</span>
</ul><span *ngIf="grouped_apps.yugioh">游戏王</span>
<ul *ngIf="grouped_apps.yugioh" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.yugioh" [class.active]="app===appsService.currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
<span *ngIf="grouped_apps.touhou">东方 Project</span>
</ul><span *ngIf="grouped_apps.touhou">东方 Project</span>
<ul *ngIf="grouped_apps.touhou" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.touhou" [class.active]="app===appsService.currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
</li>
</ul>
<span *ngIf="grouped_apps.touhou_pc98">东方旧作</span>
</ul><span *ngIf="grouped_apps.touhou_pc98">东方旧作</span>
<ul *ngIf="grouped_apps.touhou_pc98" class="nav nav-sidebar">
<li *ngFor="let app of grouped_apps.touhou_pc98" [class.active]="app===appsService.currentApp">
<a (click)="chooseApp(app)" href="#">{{app.name}}</a>
......
......@@ -2,10 +2,11 @@
* Created by zh99998 on 16/9/2.
*/
import { Component } from '@angular/core';
import {Component} from "@angular/core";
@Component({
selector: 'community',
templateUrl: 'app/community.component.html',
styleUrls: ['app/community.component.css'],
})
export class CommunityComponent { }
export class CommunityComponent {
}
......@@ -4,6 +4,4 @@
<app-detail *ngIf="appsService._currentApp"></app-detail>
<roster></roster>
</div>
<webview id="candy"
[src]="candy_url"
nodeintegration></webview>
\ No newline at end of file
<webview id="candy" [src]="candy_url" nodeintegration></webview>
\ No newline at end of file
:host {
display: flex;
}
webview {
flex-grow: 1;
}
\ No newline at end of file
......@@ -4,7 +4,6 @@
import {Injectable} from "@angular/core";
import {Http} from "@angular/http";
interface User {
admin: boolean;
avatar_url: string;
......
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { MyCard } from './mycard.module';
import {enableProdMode} from '@angular/core';
import {platformBrowserDynamic} from "@angular/platform-browser-dynamic";
import {MyCard} from "./mycard.module";
//enableProdMode();
platformBrowserDynamic().bootstrapModule(MyCard);
......@@ -18,11 +18,9 @@
</ul>
<div class="navbar-right">
<div id="user" *ngIf="loginService.user">
<a href="#forum" class="require-login profile">
<img id="avatar" [src]="loginService.user.avatar_url" alt="image">
</a>
<a href="#forum" class="require-login profile item" id="username"></a>
<a (click)="loginService.logout()" href="#ygopro" id="logout" class="require-login item">切换账号</a>
<a class="require-login profile"><img id="avatar" [src]="loginService.user.avatar_url" alt="image"></a>
<a class="require-login profile item" id="username"></a>
<a (click)="loginService.logout()" id="logout" class="require-login item">切换账号</a>
<!--<a (click)="refresh()" href="#ygopro" id="refresh" class="item">刷新</a>-->
</div>
<div id="window-buttons" [hidden]="platform == 'darwin'">
......@@ -33,9 +31,7 @@
</div>
</div>
</nav>
<login class="page" *ngIf="!loginService.user"></login>
<store class="page" *ngIf="loginService.user" [hidden]="currentPage != 'store'"></store>
<lobby class="page" *ngIf="loginService.user" [hidden]="currentPage != 'lobby'"></lobby>
<webview id="community" class="page" *ngIf="loginService.user" [hidden]="currentPage != 'community'"
src="https://ygobbs.com"></webview>
\ No newline at end of file
<webview id="community" class="page" *ngIf="loginService.user" [hidden]="currentPage != 'community'" src="https://ygobbs.com"></webview>
\ No newline at end of file
/**
* Created by zh99998 on 16/9/2.
*/
import { Component } from '@angular/core';
import {Component} from "@angular/core";
@Component({
selector: 'roster',
templateUrl: 'app/roster.component.html',
styleUrls: ['app/roster.component.css'],
})
export class RosterComponent { }
export class RosterComponent {
}
/**
* Created by zh99998 on 16/9/2.
*/
import { Component } from '@angular/core';
import {Component} from "@angular/core";
@Component({
selector: 'store',
templateUrl: 'app/store.component.html',
styleUrls: ['app/store.component.css'],
})
export class StoreComponent { }
export class StoreComponent {
}
......@@ -3,10 +3,12 @@
overflow-y: auto;
height: 21.5rem;
}
#game-list-modal thead {
position: relative;
display: block;
}
#game-list-modal tr {
width: 100%;
display: table;
......@@ -15,6 +17,7 @@
#game-list-modal .table {
margin-bottom: 0;
}
#game-list-modal .avatar {
width: 25px;
height: 25px;
......@@ -31,10 +34,12 @@
top: 15px;
right: 15px;
}
#game-list-modal .modal-header {
padding-left: 0;
padding-right: 0;
}
#game-list-modal .modal-header th {
line-height: 36px;
padding-top: 0;
......@@ -42,16 +47,17 @@
border: none;
}
#game-list-modal .modal-body {
padding: 0;
height: 21.4rem;
}
#game-list-modal .modal-body tr:first-child td{
#game-list-modal .modal-body tr:first-child td {
border-top: none;
}
#game-list-modal .modal-body tr:last-child td{
#game-list-modal .modal-body tr:last-child td {
border-bottom: none;
}
......@@ -59,12 +65,15 @@
#game-list-modal .title {
width: 25%;
}
#game-list-modal .users {
width: 20%;
}
#game-list-modal .mode {
width: 20%;
}
#game-list-modal .extra {
width: 35%;
}
......
......@@ -18,8 +18,7 @@
<button type="button" class="btn btn-secondary" data-toggle="modal" data-target="#game-create-windbot">单人模式</button>
</div>
<div class="modal fade" id="game-create-windbot" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal fade" id="game-create-windbot" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
......@@ -31,8 +30,7 @@
<div class="modal-body">
<label>选择对手</label>
<div id="windbot" class="list-group">
<a *ngFor="let name of windbot" href="#" class="list-group-item"
(click)="join_windbot(name)">{{name}}</a>
<a *ngFor="let name of windbot" href="#" class="list-group-item" (click)="join_windbot(name)">{{name}}</a>
</div>
</div>
<div class="modal-footer">
......@@ -42,8 +40,7 @@
</div>
</div>
<div class="modal fade" id="game-create-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal fade" id="game-create-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
......@@ -57,8 +54,7 @@
<div class="form-group row">
<label for="game-create-title" class="col-sm-2 form-control-label">游戏标题</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="game-create-title" name="title"
[(ngModel)]="room.title">
<input type="text" class="form-control" id="game-create-title" name="title" [(ngModel)]="room.title">
</div>
</div>
<div class="form-group row">
......@@ -88,25 +84,19 @@
<div class="row">
<label for="game-create-start-lp" class="col-sm-6 form-control-label">初始 LP</label>
<div class="col-sm-6">
<input name="start_lp" type="number" value="8000" min="1" max="65536"
class="form-control form-control-sm game-create-extra"
id="game-create-start-lp" [(ngModel)]="room.start_lp">
<input name="start_lp" type="number" value="8000" min="1" max="65536" class="form-control form-control-sm game-create-extra" id="game-create-start-lp" [(ngModel)]="room.start_lp">
</div>
</div>
<div class="row">
<label for="game-create-start-hand" class="col-sm-6 form-control-label">初始手牌数</label>
<div class="col-sm-6">
<input name="start_hand" type="number" value="5" min="0" max="16"
class="form-control form-control-sm game-create-extra"
id="game-create-start-hand" [(ngModel)]="room.start_hand">
<input name="start_hand" type="number" value="5" min="0" max="16" class="form-control form-control-sm game-create-extra" id="game-create-start-hand" [(ngModel)]="room.start_hand">
</div>
</div>
<div class="row">
<label for="game-create-draw-count" class="col-sm-6 form-control-label">每回合抽卡</label>
<div class="col-sm-6">
<input name="draw_count" type="number" value="1" min="0" max="16"
class="form-control form-control-sm game-create-extra"
id="game-create-draw-count" [(ngModel)]="room.draw_count">
<input name="draw_count" type="number" value="1" min="0" max="16" class="form-control form-control-sm game-create-extra" id="game-create-draw-count" [(ngModel)]="room.draw_count">
</div>
</div>
</div>
......@@ -117,8 +107,7 @@
</label>
</div>
<div class="checkbox">
<label>
<input name="no_check_deck" type="checkbox" [(ngModel)]="room.no_check_deck">不检查卡组
<label> <input name="no_check_deck" type="checkbox" [(ngModel)]="room.no_check_deck">不检查卡组
</label>
</div>
<div class="checkbox">
......@@ -140,8 +129,7 @@
</div>-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary float-left" data-dismiss="modal" data-toggle="modal"
data-target="#game-list-modal">查看房间
<button type="button" class="btn btn-secondary float-left" data-dismiss="modal" data-toggle="modal" data-target="#game-list-modal">查看房间
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-primary">创建</button>
......@@ -149,10 +137,8 @@
</form>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="game-list-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
</div><!-- Modal -->
<div class="modal fade" id="game-list-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<table class="table table-striped table-hover">
......@@ -169,8 +155,7 @@
<tr *ngFor="let room of rooms" class="room" (click)="join_room(room)">
<td class="title">{{room.title}}</td>
<td class="users">
<img *ngFor="let user of room.users" class="avatar"
[src]="'https://ygobbs.com/user_avatar/ygobbs.com/' + user.username + '/25/1.png'">
<img *ngFor="let user of room.users" class="avatar" [src]="'https://ygobbs.com/user_avatar/ygobbs.com/' + user.username + '/25/1.png'">
</td>
<td class="mode">{{{'0': '单局模式', '1': '比赛模式', '2': 'TAG'}[room.mode]}}</td>
<td class="extra">
......@@ -188,8 +173,7 @@
<span aria-hidden="true">&times;</span>
</button>
<div class="modal-footer">
<button type="button" class="btn btn-secondary float-left" data-dismiss="modal" data-toggle="modal"
data-target="#game-create-modal">创建房间
<button type="button" class="btn btn-secondary float-left" data-dismiss="modal" data-toggle="modal" data-target="#game-create-modal">创建房间
</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
</div>
......
......@@ -10,9 +10,57 @@ import * as child_process from "child_process";
import {remote} from "electron";
import * as ini from "ini";
import {EncodeOptions} from "ini";
import {LoginService} from "./login.service";
declare var $;
interface SystemConf {
use_d3d: string
antialias: string
errorlog: string
nickname: string
gamename: string
lastdeck: string
textfont: string
numfont: string
serverport: string
lastip: string
lastport: string
autopos: string
randompos: string
autochain: string
waitchain: string
mute_opponent: string
mute_spectators: string
hide_setname: string
hide_hint_button: string
control_mode: string
draw_field_spell: string
separate_clear_button: string
roompass: string
}
interface Server {
id: string
url: string
address: string
port: number
}
interface Room {
id?: string
title?: string
server?: Server
mode: number,
rule: number,
start_lp: number,
start_hand: number,
draw_count: number,
enable_priority: boolean,
no_check_deck: boolean,
no_shuffle_deck: boolean
}
@Component({
selector: 'ygopro',
templateUrl: 'app/ygopro.component.html',
......@@ -20,8 +68,8 @@ declare var $;
})
export class YGOProComponent implements OnInit {
app = this.appsService.searchApp('ygopro');
decks = [];
current_deck;
decks: string[] = [];
current_deck: string;
system_conf = path.join(this.app.local.path, 'system.conf');
numfont = {'darwin': ['/System/Library/Fonts/PingFang.ttc']};
......@@ -29,12 +77,15 @@ export class YGOProComponent implements OnInit {
windbot = ["琪露诺", "谜之剑士LV4", "复制植物", "尼亚"];
servers = [{id: 'tiramisu', url: 'wss://tiramisu.mycard.moe:7923', address: "112.124.105.11", port: 7911}];
servers: Server[] = [{
id: 'tiramisu',
url: 'wss://tiramisu.mycard.moe:7923',
address: "112.124.105.11",
port: 7911
}];
user = {external_id: 1, username: 'zh99998'}; // for test
default_options = {
default_options: Room = {
mode: 1,
rule: 0,
start_lp: 8000,
......@@ -45,13 +96,13 @@ export class YGOProComponent implements OnInit {
no_shuffle_deck: false
};
room = Object.assign({title: this.user.username + '的房间'}, this.default_options);
room: Room = Object.assign({title: this.loginService.user.username + '的房间'}, this.default_options);
rooms = [];
rooms: Room[] = [];
connections = [];
connections: WebSocket[] = [];
constructor(private appsService: AppsService, private ref: ChangeDetectorRef) {
constructor(private appsService: AppsService, private loginService: LoginService, private ref: ChangeDetectorRef) {
this.refresh();
}
......@@ -94,16 +145,15 @@ export class YGOProComponent implements OnInit {
});
}
refresh = () => {
this.get_decks().then((decks)=> {
this.decks = decks;
if (!(this.current_deck in this.decks)) {
this.current_deck = decks[0];
}
})
async refresh() {
let decks = await this.get_decks();
this.decks = decks;
if (!(this.current_deck in this.decks)) {
this.current_deck = decks[0];
}
};
get_decks(): Promise<[string]> {
get_decks(): Promise<string[]> {
return new Promise((resolve, reject)=> {
fs.readdir(path.join(this.app.local.path, 'deck'), (error, files)=> {
if (error) {
......@@ -115,48 +165,37 @@ export class YGOProComponent implements OnInit {
})
}
get_font(files: string[]) {
return new Promise((resolve, reject)=> {
files.reduce((promise, file: string) => {
return promise.then(()=>file).then(()=>new Promise((resolve, reject)=> {
fs.access(file, fs.constants.R_OK, (error) => {
error ? resolve(`can't find fonts ${files[process.platform]}`) : reject(file)
});
}));
}, Promise.resolve()).then(reject, resolve);
})
async get_font(files: string[]): Promise<string> {
for (let file in files) {
let found = await new Promise((resolve)=>fs.access(file, fs.constants.R_OK, error=>resolve(!error)));
if (found) {
return file;
}
}
}
edit_deck(deck) {
this.load_system_conf()
.then(this.fix_fonts)
.then(data => {
data['lastdeck'] = deck;
return data
})
.then(this.save_system_conf)
.then(()=>['-d'])
.then(this.start_game)
.catch(reason=>console.log(reason))
async delete_deck(deck) {
await new Promise(resolve => fs.unlink(path.join(this.app.local.path, 'deck', deck + '.ydk'), resolve));
return this.refresh()
}
delete_deck(deck) {
return new Promise((resolve, reject) => {
fs.unlink(path.join(this.app.local.path, 'deck', deck + '.ydk'), resolve)
}).then(this.refresh)
}
async fix_fonts(data) {
if (!await this.get_font([data.numfont])) {
let font = await this.get_font(this.numfont[process.platform]);
if (font) {
data['numfont'] = font
}
}
fix_fonts = (data) => {
return this.get_font([data.numfont])
.catch(() => this.get_font(this.numfont[process.platform]).then(font => data['numfont'] = font))
.catch(null)
.then(() => this.get_font([data.textfont.split(' ', 2)[0]]))
.catch(() => this.get_font(this.textfont[process.platform]).then(font => data['textfont'] = `${font} 14`))
.catch(null)
.then(() => data)
if (!await this.get_font([data.textfont.split(' ', 2)[0]])) {
let font = await this.get_font(this.textfont[process.platform]);
if (font) {
data['textfont'] = `${font} 14`
}
}
};
load_system_conf = () => {
load_system_conf(): Promise<SystemConf> {
return new Promise((resolve, reject)=> {
fs.readFile(this.system_conf, {encoding: 'utf-8'}, (error, data) => {
if (error) return reject(error);
......@@ -165,7 +204,7 @@ export class YGOProComponent implements OnInit {
})
};
save_system_conf = (data) => {
save_system_conf(data: SystemConf) {
return new Promise((resolve, reject)=> {
fs.writeFile(this.system_conf, ini.stringify(data, <EncodeOptions>{whitespace: true}), (error) => {
if (error) return reject(error);
......@@ -174,29 +213,31 @@ export class YGOProComponent implements OnInit {
})
};
join(name, server) {
this.load_system_conf()
.then(this.fix_fonts)
.then(data => {
data['lastdeck'] = this.current_deck;
data['lastip'] = server.address;
data['lastport'] = server.port;
data['roompass'] = name;
data['nickname'] = this.user.username;
console.log(data);
return data
})
.then(this.save_system_conf)
.then(()=>['-j'])
.then(this.start_game)
.catch(reason=>alert(reason))
async join(name, server) {
let system_conf = await this.load_system_conf();
await this.fix_fonts(system_conf);
system_conf.lastdeck = this.current_deck;
system_conf.lastip = server.address;
system_conf.lastport = server.port;
system_conf.roompass = name;
system_conf.nickname = this.loginService.user.username;
await this.save_system_conf(system_conf);
return this.start_game(['-j']);
};
async edit_deck(deck: string) {
let system_conf = await this.load_system_conf();
await this.fix_fonts(system_conf);
system_conf.lastdeck = deck;
await this.save_system_conf(system_conf);
return this.start_game(['-d']);
}
join_windbot(name) {
this.join('AI#' + name, this.servers[0])
return this.join('AI#' + name, this.servers[0])
}
start_game = (args) => {
start_game(args) {
let win = remote.getCurrentWindow();
win.minimize();
return new Promise((resolve, reject)=> {
......@@ -207,7 +248,7 @@ export class YGOProComponent implements OnInit {
});
child.on('exit', (code, signal)=> {
// error 触发之后还可能会触发exit,但是Promise只承认首次状态转移,因此这里无需重复判断是否已经error过。
resolve(code);
resolve();
win.restore()
})
})
......@@ -226,13 +267,13 @@ export class YGOProComponent implements OnInit {
}
options_buffer.writeUInt8(checksum & 0xFF, 0);
let secret = this.user.external_id % 65535 + 1;
let secret = this.loginService.user.external_id % 65535 + 1;
for (let i = 0; i < options_buffer.length; i += 2) {
options_buffer.writeUInt16LE(options_buffer.readUInt16LE(i) ^ secret, i)
}
let password = options_buffer.toString('base64') + options.title.replace(/\s/, String.fromCharCode(0xFEFF));
let room_id = crypto.createHash('md5').update(password + this.user.username).digest('base64').slice(0, 10).replace('+', '-').replace('/', '_');
let room_id = crypto.createHash('md5').update(password + this.loginService.user.username).digest('base64').slice(0, 10).replace('+', '-').replace('/', '_');
this.join(password, this.servers[0]);
}
......@@ -246,7 +287,7 @@ export class YGOProComponent implements OnInit {
}
options_buffer.writeUInt8(checksum & 0xFF, 0);
let secret = this.user.external_id % 65535 + 1;
let secret = this.loginService.user.external_id % 65535 + 1;
for (i = 0; i < options_buffer.length; i += 2) {
options_buffer.writeUInt16LE(options_buffer.readUInt16LE(i) ^ secret, i)
}
......
let apps = require('./apps.json')
let apps = require('./apps.json');
let result = apps.map((app)=>{
console.error(app.id)
let result = {}
result.id = app.id
result.name = app.name
result.description = app.description
let parent = apps.find(a=>app.id.startsWith(a.id+'-'));
if(parent){
result.category = "module"
result.parent = parent.id
result.tags = ["language"]
} else {
result.category = "game"
result.tags = app.tags
}
result.dependency = {
"win32": [],
"darwin": ['wine']
let result = apps.map((app)=> {
console.error(app.id);
let result = {};
result.id = app.id;
result.name = app.name;
result.description = app.description;
let parent = apps.find(a=>app.id.startsWith(a.id + '-'));
if (parent) {
result.category = "module";
result.parent = parent.id;
result.tags = ["language"]
} else {
result.category = "game";
result.tags = app.tags
}
let references = apps.filter(a=>a.id.startsWith(app.id+'-')).map(a=>a.id)
result.dependency = {
"win32": [],
"darwin": ['wine']
};
let references = apps.filter(a=>a.id.startsWith(app.id + '-')).map(a=>a.id);
result.references = {
"win32": references,
"darwin": references
}
result.author = app.author
result.homepage = app.homepage
result.locales = app.locales
result.actions = app.actions
result.version = app.version
result.download = app.download
result.news = app.news
"win32": references,
"darwin": references
};
result.author = app.author;
result.homepage = app.homepage;
result.locales = app.locales;
result.actions = app.actions;
result.version = app.version;
result.download = app.download;
result.news = app.news;
return result
return result
})
.sort((a, b)=>a.id < b.id ? -1 : 1)
.sort((a, b)=>a.id < b.id ? -1 : 1);
for (let app of result){
console.error(app.id)
for (let app of result) {
console.error(app.id)
}
console.log(JSON.stringify(result))
\ No newline at end of file
console.log(JSON.stringify(result));
\ No newline at end of file
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