mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-27 04:33:00 +00:00
Merge branch 'develop' of https://github.com/syuilo/misskey into develop
This commit is contained in:
commit
ccf8e44acc
17 changed files with 59 additions and 25 deletions
|
@ -1,2 +0,0 @@
|
|||
const gcd = (a, b) => !b ? a : gcd(b, a % b);
|
||||
export default gcd;
|
|
@ -1,14 +1,20 @@
|
|||
<template>
|
||||
<span class="mk-acct">
|
||||
<span class="name">@{{ user.username }}</span>
|
||||
<span class="host" v-if="user.host">@{{ user.host }}</span>
|
||||
<span class="host" v-if="user.host || detail">@{{ user.host || host }}</span>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import Vue from 'vue';
|
||||
import { host } from '../../../config';
|
||||
export default Vue.extend({
|
||||
props: ['user']
|
||||
props: ['user', 'detail'],
|
||||
data() {
|
||||
return {
|
||||
host
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
import Vue from 'vue';
|
||||
import Menu from '../../../../common/views/components/menu.vue';
|
||||
import contextmenu from '../../../api/contextmenu';
|
||||
import { countIf } from '../../../../../../prelude/array';
|
||||
|
||||
export default Vue.extend({
|
||||
props: {
|
||||
|
@ -117,7 +118,7 @@ export default Vue.extend({
|
|||
toggleActive() {
|
||||
if (!this.isStacked) return;
|
||||
const vms = this.$store.state.settings.deck.layout.find(ids => ids.indexOf(this.column.id) != -1).map(id => this.getColumnVm(id));
|
||||
if (this.active && vms.filter(vm => vm.$el.classList.contains('active')).length == 1) return;
|
||||
if (this.active && countIf(vm => vm.$el.classList.contains('active'), vms) == 1) return;
|
||||
this.active = !this.active;
|
||||
},
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="title">
|
||||
<p class="name">{{ user | userName }}</p>
|
||||
<div>
|
||||
<span class="username"><mk-acct :user="user"/></span>
|
||||
<span class="username"><mk-acct :user="user" :detail="true" /></span>
|
||||
<span v-if="user.isBot" title="%i18n:@is-bot%">%fa:robot%</span>
|
||||
<span class="location" v-if="user.host === null && user.profile.location">%fa:map-marker% {{ user.profile.location }}</span>
|
||||
<span class="birthday" v-if="user.host === null && user.profile.birthday">%fa:birthday-cake% {{ user.profile.birthday.replace('-', '年').replace('-', '月') + '日' }} ({{ age }}歳)</span>
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
import Vue from 'vue';
|
||||
import * as EXIF from 'exif-js';
|
||||
import * as hljs from 'highlight.js';
|
||||
import gcd from '../../../common/scripts/gcd';
|
||||
import { gcd } from '../../../../../prelude/math';
|
||||
|
||||
export default Vue.extend({
|
||||
props: ['file'],
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
</div>
|
||||
<div class="title">
|
||||
<h1>{{ user | userName }}</h1>
|
||||
<span class="username"><mk-acct :user="user"/></span>
|
||||
<span class="username"><mk-acct :user="user" :detail="true" /></span>
|
||||
<span class="followed" v-if="user.isFollowed">%i18n:@follows-you%</span>
|
||||
</div>
|
||||
<div class="description">
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { count, countIf } from "../../prelude/array";
|
||||
|
||||
// MISSKEY REVERSI ENGINE
|
||||
|
||||
/**
|
||||
|
@ -88,8 +90,8 @@ export default class Reversi {
|
|||
//#endregion
|
||||
|
||||
// ゲームが始まった時点で片方の色の石しかないか、始まった時点で勝敗が決定するようなマップの場合がある
|
||||
if (this.canPutSomewhere(BLACK).length == 0) {
|
||||
if (this.canPutSomewhere(WHITE).length == 0) {
|
||||
if (!this.canPutSomewhere(BLACK)) {
|
||||
if (!this.canPutSomewhere(WHITE)) {
|
||||
this.turn = null;
|
||||
} else {
|
||||
this.turn = WHITE;
|
||||
|
@ -101,14 +103,14 @@ export default class Reversi {
|
|||
* 黒石の数
|
||||
*/
|
||||
public get blackCount() {
|
||||
return this.board.filter(x => x === BLACK).length;
|
||||
return count(BLACK, this.board);
|
||||
}
|
||||
|
||||
/**
|
||||
* 白石の数
|
||||
*/
|
||||
public get whiteCount() {
|
||||
return this.board.filter(x => x === WHITE).length;
|
||||
return count(BLACK, this.board);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,9 +172,9 @@ export default class Reversi {
|
|||
|
||||
private calcTurn() {
|
||||
// ターン計算
|
||||
if (this.canPutSomewhere(!this.prevColor).length > 0) {
|
||||
if (this.canPutSomewhere(!this.prevColor)) {
|
||||
this.turn = !this.prevColor;
|
||||
} else if (this.canPutSomewhere(this.prevColor).length > 0) {
|
||||
} else if (this.canPutSomewhere(this.prevColor)) {
|
||||
this.turn = this.prevColor;
|
||||
} else {
|
||||
this.turn = null;
|
||||
|
@ -204,10 +206,17 @@ export default class Reversi {
|
|||
/**
|
||||
* 打つことができる場所を取得します
|
||||
*/
|
||||
public canPutSomewhere(color: Color): number[] {
|
||||
public puttablePlaces(color: Color): number[] {
|
||||
return Array.from(this.board.keys()).filter(i => this.canPut(color, i));
|
||||
}
|
||||
|
||||
/**
|
||||
* 打つことができる場所があるかどうかを取得します
|
||||
*/
|
||||
public canPutSomewhere(color: Color): boolean {
|
||||
return this.puttablePlaces(color).length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定のマスに石を打つことができるかどうかを取得します
|
||||
* @param color 自分の色
|
||||
|
|
|
@ -4,10 +4,7 @@ const { JSDOM } = jsdom;
|
|||
import config from '../config';
|
||||
import { INote } from '../models/note';
|
||||
import { TextElement } from './parse';
|
||||
|
||||
function intersperse<T>(sep: T, xs: T[]): T[] {
|
||||
return [].concat(...xs.map(x => [sep, x])).slice(1);
|
||||
}
|
||||
import { intersperse } from '../prelude/array';
|
||||
|
||||
const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: INote['mentionedRemoteUsers']) => void } = {
|
||||
bold({ document }, { bold }) {
|
||||
|
|
3
src/prelude/README.md
Normal file
3
src/prelude/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Prelude
|
||||
このディレクトリのコードはJavaScriptの表現能力を補うためのコードです。
|
||||
Misskey固有の処理とは独立したコードの集まりですが、Misskeyのコードを読みやすくすることを目的としています。
|
11
src/prelude/array.ts
Normal file
11
src/prelude/array.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export function countIf<T>(f: (x: T) => boolean, xs: T[]): number {
|
||||
return xs.filter(f).length;
|
||||
}
|
||||
|
||||
export function count<T>(x: T, xs: T[]): number {
|
||||
return countIf(y => x === y, xs);
|
||||
}
|
||||
|
||||
export function intersperse<T>(sep: T, xs: T[]): T[] {
|
||||
return [].concat(...xs.map(x => [sep, x])).slice(1);
|
||||
}
|
3
src/prelude/math.ts
Normal file
3
src/prelude/math.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function gcd(a: number, b: number): number {
|
||||
return b === 0 ? a : gcd(b, a % b);
|
||||
}
|
|
@ -10,6 +10,7 @@ import { setResponseType } from '../activitypub';
|
|||
|
||||
import Note from '../../models/note';
|
||||
import renderNote from '../../remote/activitypub/renderer/note';
|
||||
import { countIf } from '../../prelude/array';
|
||||
|
||||
export default async (ctx: Router.IRouterContext) => {
|
||||
const userId = new mongo.ObjectID(ctx.params.user);
|
||||
|
@ -25,7 +26,7 @@ export default async (ctx: Router.IRouterContext) => {
|
|||
const page: boolean = ctx.request.query.page === 'true';
|
||||
|
||||
// Validate parameters
|
||||
if (sinceIdErr || untilIdErr || pageErr || [sinceId, untilId].filter(x => x != null).length > 1) {
|
||||
if (sinceIdErr || untilIdErr || pageErr || countIf(x => x != null, [sinceId, untilId]) > 1) {
|
||||
ctx.status = 400;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import Mute from '../../../../models/mute';
|
|||
import { pack } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import { countIf } from '../../../../prelude/array';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
@ -42,7 +43,7 @@ export default async (params: any, user: ILocalUser) => {
|
|||
if (psErr) throw psErr;
|
||||
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
|
||||
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
|
||||
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { getFriends } from '../../common/get-friends';
|
|||
import { pack } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import { countIf } from '../../../../prelude/array';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
@ -86,7 +87,7 @@ export default async (params: any, user: ILocalUser) => {
|
|||
if (psErr) throw psErr;
|
||||
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
|
||||
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
|
||||
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import Mute from '../../../../models/mute';
|
|||
import { pack } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import { countIf } from '../../../../prelude/array';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
@ -48,7 +49,7 @@ export default async (params: any, user: ILocalUser) => {
|
|||
if (psErr) throw psErr;
|
||||
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
|
||||
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
|
||||
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { getFriends } from '../../common/get-friends';
|
|||
import { pack } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import { countIf } from '../../../../prelude/array';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
@ -86,7 +87,7 @@ export default async (params: any, user: ILocalUser) => {
|
|||
if (psErr) throw psErr;
|
||||
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
|
||||
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
|
||||
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import getHostLower from '../../common/get-host-lower';
|
|||
import Note, { pack } from '../../../../models/note';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import { countIf } from '../../../../prelude/array';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
|
@ -110,7 +111,7 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
|
|||
}
|
||||
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
|
||||
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
|
||||
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue