Skip to content

Commit

Permalink
style: 格式化代码,删除flow变量
Browse files Browse the repository at this point in the history
  • Loading branch information
duan602728596 committed Apr 14, 2019
1 parent f088f24 commit 81b3869
Show file tree
Hide file tree
Showing 33 changed files with 431 additions and 545 deletions.
8 changes: 3 additions & 5 deletions app/src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
import * as React from 'react';
import ReactDOM from 'react-dom';
import React from 'react';
import { render } from 'react-dom';
import { HashRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import Routers from './router/Routers';
Expand All @@ -10,14 +9,13 @@ import { storeFactory } from './store/store';
import './components/upgradeDetection/upgradeDetection';

/* app */
ReactDOM.render(
render(
<Provider store={ storeFactory(window.__INITIAL_STATE__ || {}) }>
<LocaleProvider locale={ zhCN }>
<HashRouter>
<Routers />
</HashRouter>
</LocaleProvider>
</Provider>,
// $FlowFixMe
document.getElementById('app')
);
6 changes: 2 additions & 4 deletions app/src/assembly/SwitchLoading/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/**
* 异步加载时显示loading
*
* @flow
*/
import * as React from 'react';
import React from 'react';
import { Spin } from 'antd';
import style from './style.sass';

function SwitchLoading(props: Object): React.Node {
function SwitchLoading(props) {
return (
<div className={ style.loading }>
<Spin size="large" tip="Loading..." />
Expand Down
10 changes: 5 additions & 5 deletions app/src/components/callback/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kd48Cb from '../kd48listerer/kd48Cb';
import customCb from '../custom/customCb';
import helpCb from '../help/helpCb';

function fn(command: string[], qq: CoolQ, dataJson: Object): void {
function fn(command, qq, dataJson) {
switch (command[0]) {
// 摩点判断
case '摩点':
Expand Down Expand Up @@ -38,12 +38,12 @@ function fn(command: string[], qq: CoolQ, dataJson: Object): void {
}
}

function callback(dataJson: Object, qq: CoolQ): void {
const content: string = dataJson?.raw_message || dataJson.message;
const command: string[] = content.split(/\s+/);
function callback(dataJson, qq) {
const content = dataJson?.raw_message || dataJson.message;
const command = content.split(/\s+/);

// 格式化去掉空字符串
for (let i: number = command.length - 1; i >= 0; i--) {
for (let i = command.length - 1; i >= 0; i--) {
if (command[i] === '') {
command.splice(i, 1);
}
Expand Down
18 changes: 9 additions & 9 deletions app/src/components/chouka/bestCards.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* 查询最好的卡片 */

function bestCards(cards: Object, len: number): string {
const result: [] = [];
function bestCards(cards, len) {
const result = [];

for (const key: string in cards) {
const item: Object = cards[key];
for (const key in cards) {
const item = cards[key];

if (result.length === 0) {
result.push(item);
continue;
}

for (let i: number = 0, j: number = result.length; i < j; i++) {
const item2: Object = result[i];
for (let i = 0, j = result.length; i < j; i++) {
const item2 = result[i];

if (item.levelNum > item2.levelNum) {
result.splice(i, 0, item);
Expand All @@ -24,10 +24,10 @@ function bestCards(cards: Object, len: number): string {
}

// 返回数据
const str: string[] = [];
const str = [];

for (let i: number = 0, j: number = len > result.length ? result.length : len; i < j; i++) {
const item: Object = result[i];
for (let i = 0, j = len > result.length ? result.length : len; i < j; i++) {
const item = result[i];

str.push(`[CQ:image,file=${ item.image }]`);
}
Expand Down
27 changes: 11 additions & 16 deletions app/src/components/chouka/bukaCb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,28 @@ import * as storagecard from './storagecard';
import { chouka } from './chouka';
import bestCards from './bestCards';

async function bukaCb(command: string[], qq: CoolQ, dataJson: Object): Promise<void> {
const { basic }: { basic: Object } = qq.option;
async function bukaCb(command, qq, dataJson) {
const { basic } = qq.option;

if (!basic.isChouka || !qq.bukaQQNumber.includes(dataJson.user_id) || !command[1] || !/^[0-9]+$/.test(command[1])) {
return void 0;
}

try {
const { cards, money, multiple, db }: {
cards: Array;
money: number;
multiple: number;
db: Object;
} = qq.choukaJson;
const { cards, money, multiple, db } = qq.choukaJson;

const choukaStr: string[] = [];
let cqImage: string = '';
const choukaStr = [];
let cqImage = '';

// 把卡存入数据库
const kaResult: [] = await storagecard.query(db, command[1]);
const record: Object = kaResult.length === 0 ? {} : JSON.parse(kaResult[0].record);
const kaResult = await storagecard.query(db, command[1]);
const record = kaResult.length === 0 ? {} : JSON.parse(kaResult[0].record);

const choukaResult: Object = chouka(cards, money, null, multiple, command[2] ? Number(command[2]) : 1);
const choukaResult = chouka(cards, money, null, multiple, command[2] ? Number(command[2]) : 1);

for (const key: string in choukaResult) {
const item2: Object = choukaResult[key];
const str: string = `【${ item2.level }${ item2.name } * ${ item2.length }`;
for (const key in choukaResult) {
const item2 = choukaResult[key];
const str = `【${ item2.level }${ item2.name } * ${ item2.length }`;

choukaStr.push(str);

Expand Down
25 changes: 11 additions & 14 deletions app/src/components/chouka/chakaCb.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
/* 查卡 */
import * as storagecard from './storagecard';

async function chakaCb(command: string[], qq: CoolQ): Promise<void> {
const { basic }: { basic: Object } = qq.option;
async function chakaCb(command, qq) {
const { basic } = qq.option;

if (!basic.isChouka || !command[1]) {
return void 0;
}

const { db, cards }: {
db: Object;
cards: Array;
} = qq.choukaJson;
const kaResult: [] = await storagecard.query2(db, command[1]);
const { db, cards } = qq.choukaJson;
const kaResult = await storagecard.query2(db, command[1]);

if (kaResult.length === 0) {
await qq.sendMessage(`[${ command[1] }]:暂无卡片。`);

return void 0;
}

const record: Object = JSON.parse(kaResult[0].record);
const strArr: string[] = [];
const record = JSON.parse(kaResult[0].record);
const strArr = [];

for (let i: number = cards.length - 1; i >= 0; i--) {
const item: Object = cards[i];
const strData: string[] = [];
let str: string = `【${ item.level }】:`;
for (let i = cards.length - 1; i >= 0; i--) {
const item = cards[i];
const strData = [];
let str = `【${ item.level }】:`;

for (const item2: Object of item.data) {
for (const item2 of item.data) {
if (item2.id in record && record[item2.id] > 0) {
strData.push(`${ item2.name } * ${ record[item2.id] }`);
}
Expand Down
60 changes: 18 additions & 42 deletions app/src/components/chouka/chouka.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
/* 抽卡方法 */

type CardsInformation = Array<{
level: string;
length: number;
data: Array<{
id: string;
name: string;
image: string;
}>;
}>;

/**
* 生成随机数
* @param { number } len: 长度
*/
function random(len: number): number {
function random(len) {
return Math.floor(Math.random() * len);
}

function randomCards(cardsInformation: CardsInformation): Array {
const result: [] = [];
function randomCards(cardsInformation) {
const result = [];

for (let i: number = 0, j: number = cardsInformation.length; i < j; i++) {
const { level = '', length = 0, data }: {
level: string;
length: number;
data: [];
} = cardsInformation[i];
const len: number = data.length;
for (let i = 0, j = cardsInformation.length; i < j; i++) {
const { level = '', length = 0, data } = cardsInformation[i];
const len = data.length;

if (!(data && Array.isArray(data) && data.length > 0)) {
break;
}

// 生成每个等级的卡组
for (let i1: number = 0; i1 < length; i1++) {
for (let i1 = 0; i1 < length; i1++) {
result.push({
...data[random(len)],
level,
Expand All @@ -44,10 +30,10 @@ function randomCards(cardsInformation: CardsInformation): Array {
}

// 对卡组进行打乱
const kazu: [] = [];
const kazu = [];

while (result.length > 0) {
const index: number = random(result.length);
const index = random(result.length);

kazu.push(result[index]);
result.splice(index, 1);
Expand All @@ -63,39 +49,29 @@ function randomCards(cardsInformation: CardsInformation): Array {
* @param { number } multiple : 多抽倍数
* @param { ?number } buka : 补卡次数
*/
export function chouka(
cardsInformation: CardsInformation,
choukaMoney: number,
money: number,
multiple: number = 0,
buka: ?number = null
): Object {
export function chouka(cardsInformation, choukaMoney, money, multiple = 0, buka = null) {
// 是否为补卡
const isBuKa: boolean = !(buka === null || buka === undefined);
const isBuKa = !(buka === null || buka === undefined);

// 正常抽卡次数
const zhengchangchouka: number = isBuKa ? buka : Math.floor(money / choukaMoney);
const zhengchangchouka = isBuKa ? buka : Math.floor(money / choukaMoney);

// 多抽卡次数
let duochoukacishu: number = 0;
let duochoukacishu = 0;

if (!isBuKa && multiple > 0 && zhengchangchouka >= multiple) {
duochoukacishu = Math.floor(zhengchangchouka / multiple);
}

// 总抽卡次数
const allchouka: number = zhengchangchouka + duochoukacishu;
const allchouka = zhengchangchouka + duochoukacishu;

// 抽卡
const result: Object = {};

for (let i: number = 0, rc: [] = randomCards(cardsInformation); i < allchouka; i++) {
// 5的倍数时重新随机卡组
if (i % 5 === 0 && i !== 0) {
rc = randomCards(cardsInformation);
}
const result = {};

const item: Object = {
for (let i = 0; i < allchouka; i++) {
const rc = randomCards(cardsInformation);
const item = {
...rc[random(rc.length)]
};

Expand Down
Loading

0 comments on commit 81b3869

Please sign in to comment.