Add splitStrByLine function

This commit is contained in:
syuilo 2019-05-01 16:33:54 +09:00
parent ca6fc9cd79
commit 3444b9c9c8
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
2 changed files with 36 additions and 31 deletions

View File

@ -2053,6 +2053,9 @@ pages:
numberToString: "数値をテキストに"
_numberToString:
arg1: "数値"
splitStrByLine: "テキストを行で分割"
_splitStrByLine:
arg1: "テキスト"
ref: "変数"
fn: "関数"
_fn:

View File

@ -83,6 +83,7 @@ const funcDefs = {
join: { in: ['stringArray', 'string'], out: 'string', category: 'text', icon: faQuoteRight, },
stringToNumber: { in: ['string'], out: 'number', category: 'convert', icon: faExchangeAlt, },
numberToString: { in: ['number'], out: 'string', category: 'convert', icon: faExchangeAlt, },
splitStrByLine: { in: ['string'], out: 'stringArray', category: 'convert', icon: faExchangeAlt, },
rannum: { 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, },
@ -502,6 +503,7 @@ export class AiScript {
join: (texts, separator) => texts.join(separator || ''),
stringToNumber: (a) => parseInt(a),
numberToString: (a) => a.toString(),
splitStrByLine: (a) => a.split('\n'),
random: (probability) => Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * 100) < probability,
rannum: (min, max) => min + Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * (max - min + 1)),
randomPick: (list) => list[Math.floor(seedrandom(`${this.opts.randomSeed}:${block.id}`)() * list.length)],