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: [1, 2, 3]
    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: [1, 2, 3],
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: [1, 2, 3],
object: { boo: 1 },
nestedStuff: [{ boo: 1, baz: 2 }, { boo: 3, baz: 99 }]
}

// getTags/getTag

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

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

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

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

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

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([a, b].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

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.

Original thread: https://forums.rpgmakerweb.com/threads/bsb-notetag-parser.135617/