じ☆ve冰风 发表于 4 小时前

bsb notetag parser

bsb notetag parser 1.0.0
briarsweetbriar​

Introduction
it slices, it dices, it parses notetags.

Features

[*]searches text for single-line, multi-line, and js notetags
[*]parses notetags into js primitives (eg strings, numbers, booleans)
[*]also parses nested data into arrays and objects
[*]adds a new function to game battlers that aggregates all instances of a tag on that battler, searching their character, class, states, and equips

How to Use
install plugin as usual by adding it to `/js/plugins/`. you can then access its commands w/ `BSB.NP.<command>`.

Plugin Commands / Script Calls

BSB.NP.getMultiLineTags(note, tagName)

returns an array of all instances of that multi-line tag in the note.

BSB.NP.getMultiLineTag(note, tagName)

same as `getMultiLineTags` but only returns the first instance of the tag.

BSB.NP.getTags(note, tagName)

returns an array of all instances of that single-line tag in the note.

BSB.NP.getTag(note, tagName)

same as `getTags` but only returns the first instance of the tag.

BSB.NP.getJSTags(note, tagName)

returns an array of all instances of that js tag in the note.

BSB.NP.getJSTag(note, tagName)

same as `getJSTags` but only returns the first instance of the tag.

battler.getMultiLineTags(tagName)

returns all instances of a tag on a particular battler. for actors, the tag is searched for on the character, class, equips, and states. for enemies, the tag is searched for on the enemy and states.

                JavaScript:       
// getMultiLineTags/getMultiLineTag

let note = `
<Foo>
    boolean: true
    number: 8.88
    string: other value
    array:
    object: { boo: 1 }
    nestedStuff: [{ boo: 1, baz: 2 }, { boo: 3, baz: 99 }]
</Foo>
<Foo>
    anotherVal: 123
</Foo>
<Bar>
    something: else
</Bar>
`

BSB.NP.getMultiLineTags(note, "Foo");
=> [{
boolean: true,
number: 8.88,
string: 'other value',
array: ,
object: { boo: 1 },
nestedStuff: [{ boo: 1, baz: 2 }, { boo: 3, baz: 99 }]
}, {
anotherVal: 123
}]

BSB.NP.getMultiLineTag(note, "Foo");
=> {
boolean: true,
number: 8.88,
string: 'other value',
array: ,
object: { boo: 1 },
nestedStuff: [{ boo: 1, baz: 2 }, { boo: 3, baz: 99 }]
}

// getTags/getTag

BSB.NP.getTags('<Foo: 1, true, bar>', "Foo");
=> []

BSB.NP.getTags('<Foo: 1, true, bar> <Foo: baz> <Bar>', "Foo");
=> [, ['baz']]

BSB.NP.getTags('<Foo>', "Foo");
=> [[]]

BSB.NP.getTags('<Foo>', "Bar");
=> []

BSB.NP.getTag('<Foo: 1, true, bar> <Foo: baz> <Bar>', "Foo");
=>

BSB.NP.getTag('<Foo>', "Foo");
=> []

BSB.NP.getTag('<Foo>', "Bar");
=> undefined

// getJSTags/getJsTag

let jsNote = `
<Foo>
let a = 'foo bar';
let b = 'baz';
console.log(.join(' '));
</Foo>
`

let jsTags = BSB.NP.getJSTags(jsNote, "Foo");
jsTags.forEach((tag) => eval(tag));
=> foo bar baz

let jsTag = BSB.NP.getJSTag(jsNote, "Foo");
eval(jsTag);
=> foo bar baz


Download
https://raw.githubusercontent.com/briarsweetbriar/draw-that-circle-tight/master/js/plugins/BSB_0_NotetagParser.js

Terms and Credits
MIT license. feel free to use in commercial games, adult-themed games, whatever. feel free to use it in your own plugins too, including commercial plugins. if you use it in your plugin, please credit me and link to this thread. if you use it in your game, no need to credit.


本贴来自国际rpgmaker官方论坛作者:briarsweetbriar处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/bsb-notetag-parser.135617/
页: [1]
查看完整版本: bsb notetag parser