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: "数値をテキストに"
_numberToString: _numberToString:
arg1: "数値" arg1: "数値"
splitStrByLine: "テキストを行で分割"
_splitStrByLine:
arg1: "テキスト"
ref: "変数" ref: "変数"
fn: "関数" fn: "関数"
_fn: _fn:

View file

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