MisskeyPagesにリストから選択関数を追加

This commit is contained in:
syuilo 2019-05-05 20:31:15 +09:00
parent 17b373ac07
commit ca2949fbb4
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
3 changed files with 8 additions and 0 deletions

View file

@ -1941,6 +1941,7 @@ pages:
fn: "関数" fn: "関数"
text: "テキスト操作" text: "テキスト操作"
convert: "変換" convert: "変換"
list: "リスト"
blocks: blocks:
text: "テキスト" text: "テキスト"
multiLineText: "テキスト(複数行)" multiLineText: "テキスト(複数行)"
@ -2062,6 +2063,10 @@ pages:
DRPWPM: "確率付きリストからランダムに選択 (ユーザーごとに日替わり)" DRPWPM: "確率付きリストからランダムに選択 (ユーザーごとに日替わり)"
_DRPWPM: _DRPWPM:
arg1: "テキストのリスト" arg1: "テキストのリスト"
pick: "リストから選択"
_pick:
arg1: "リスト"
arg2: "位置"
number: "数値" number: "数値"
stringToNumber: "テキストを数値に" stringToNumber: "テキストを数値に"
_stringToNumber: _stringToNumber:

View file

@ -169,6 +169,7 @@ export class ASEvaluator {
stringToNumber: (a: string) => parseInt(a), stringToNumber: (a: string) => parseInt(a),
numberToString: (a: number) => a.toString(), numberToString: (a: number) => a.toString(),
splitStrByLine: (a: string) => a.split('\n'), splitStrByLine: (a: string) => a.split('\n'),
pick: (list: any[], i: number) => list[i - 1],
random: (probability: number) => Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * 100) < probability, random: (probability: number) => Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * 100) < probability,
rannum: (min: number, max: number) => min + Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * (max - min + 1)), rannum: (min: number, max: number) => min + Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * (max - min + 1)),
randomPick: (list: any[]) => list[Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * list.length)], randomPick: (list: any[]) => list[Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * list.length)],

View file

@ -23,6 +23,7 @@ import {
faSortNumericUp, faSortNumericUp,
faExchangeAlt, faExchangeAlt,
faRecycle, faRecycle,
faIndent,
} from '@fortawesome/free-solid-svg-icons'; } from '@fortawesome/free-solid-svg-icons';
import { faFlag } from '@fortawesome/free-regular-svg-icons'; import { faFlag } from '@fortawesome/free-regular-svg-icons';
@ -72,6 +73,7 @@ export const funcDefs: Record<string, { in: any[]; out: any; category: string; i
stringToNumber: { in: ['string'], out: 'number', category: 'convert', icon: faExchangeAlt, }, stringToNumber: { in: ['string'], out: 'number', category: 'convert', icon: faExchangeAlt, },
numberToString: { in: ['number'], out: 'string', category: 'convert', icon: faExchangeAlt, }, numberToString: { in: ['number'], out: 'string', category: 'convert', icon: faExchangeAlt, },
splitStrByLine: { in: ['string'], out: 'stringArray', category: 'convert', icon: faExchangeAlt, }, splitStrByLine: { in: ['string'], out: 'stringArray', category: 'convert', icon: faExchangeAlt, },
pick: { in: [null], out: null, category: 'list', icon: faIndent, },
rannum: { in: ['number', 'number'], out: 'number', category: 'random', icon: faDice, }, rannum: { in: ['number', 'number'], out: 'number', category: 'random', icon: faDice, },
dailyRannum: { in: ['number', 'number'], out: 'number', category: 'random', icon: faDice, }, dailyRannum: { in: ['number', 'number'], out: 'number', category: 'random', icon: faDice, },
seedRannum: { in: [null, 'number', 'number'], out: 'number', category: 'random', icon: faDice, }, seedRannum: { in: [null, 'number', 'number'], out: 'number', category: 'random', icon: faDice, },