Utils

Module: Utils

The utility module contains common methods that are used during regular RPG Maker MV plugin development.
Author:
  • FeniXEngine Contributors
License:

Methods

(static) convertParameters(parameters)

Recursive method that will convert all string values in an object to a more appropriate type. In MV there are a lot of objects filled with strings of different values, a lot of times we need to convert each value manually, instead use this to quickly deep parse each value from string to the correct type.
Example
const myParams = { p1: '22', p2: 'true' }
convertParameters(myParams) // => { p1: 22, p2: true }

const myParams = { p1: '{a: 1'1, c: '2'}', p2: '[{}, {}, {}]' }
convertParameters(myParams) // => { p1: {a: 1, c: 2}, p2: [{}, {}, {}] }
Since:
  • 1.0.0
Parameters
Name Type Description
parameters object The string filled object you want converted
Returns
An object with it's string values converted

(static) extractCanvasImage(qualityopt) → {string}

Extracts the canvas data and returns base64 data generated by PIXI renderer You can use this data in combination with tryWriteFile to save a screenshot of the entire canvas.
Example
import {extractCanvasImage, tryWriteFile} from 'feni-tools'

const canvasData = extractCanvasImage()

// Now lets write the data to a file on the machine

tryWriteFile(path/to/new/file, canvasData, 'base64')
  .then('Success writing screenshot')
Since:
  • 1.0.0
Parameters
Name Type Attributes Default Description
quality number <optional>
0.1 The quality of the image to produce
Returns
returns the base64 data string.
Type
string

(static) filterText(text, regex, action) → {array}

Uses regex to recursively filter a string.
Example
import {filterText} from 'fenix-tools'

const re = /pattern/g
const matches = filterText(text, re, (match) => {
 console.log(match) // => The full match group returned from regex
 // Perform an evaluation to store specific matches
})
Since:
  • 1.0.0
Parameters
Name Type Description
text string The text you would like to filter
regex regex The regex pattern to use for filtering
action function The callback function to evaluate
Returns
An array of groups that match the evaluation
Type
array

(static) getMetaData(obj, tag) → {string}

Retrieves meta values from an RPG Maker MV object that contains the meta property. Will work with any object that contains a meta property, like $dataWeapons, $dataItems, etc
Example
import { getMetaData } from 'fenix-tools'

// $dataActors[1].meta = {myTag: 'myTagValue'}

const data = $dataActors[1]
const meta = getMetaData(data, 'myTag') // => 'myTagValue'
Since:
  • 1.0.0
Parameters
Name Type Description
obj object The meta object you want to search through.
tag string The meta tag you want to search for.
Returns
The value(s) of the notetag.
Type
string

(static) getMultiLineTag(text, tag) → {array}

Finds and extracts a notetag from a multiline string of text and returns it's value
Example
import { getMultiLineTag } from 'fenix-tools'

// $dataWeapons[1].note = '<myTag> opt1: value, opt2: value </myTag>'

const myNotes = getMultiLineTag($dataWeapons[1].note, 'myTag') // => ['opt1: value, opt2: value']
Since:
  • 1.0.0
Parameters
Name Type Description
text string The text to evaluate
tag string The tag to search for in the text
Returns
- An array of matches containing the values between the tags
Type
array

(static) getTag(text, tag) → {Array}

Finds and extracts a notetag from a string of text and returns it's values. Not much different from using getMetaData, but if you need more control over the string then use this method.
Example
import { getTag } from 'fenix-tools'

// $dataActors[1].note = '<myTag: value, value2, value3>'

const myTag = getTag($dataActors[1].note, 'myTag') // => 'value, value2, value3'
Since:
  • 1.0.0
Parameters
Name Type Description
text string The text to be evaluated
tag string The tag to search for in the text
Returns
- An array of parameters of the values within the tag
Type
Array

(static) hexToRgb(hex) → {String}

Converts hex values to rgb values
Example
import { hexToRgb } from 'fenix-tools'

hexToRgb('42f48c') // => 66,244,140'
Since:
  • 1.0.0
License:
Parameters
Name Type Description
hex Number the hex value you want to convert
Returns
A string representing the rgb value after conversion.
Type
String

(static) loadEventComments() → {object}

Scan all events on map and extract their comments. This can only be used when the map data is available upon map load. It starts by looping through all events in the current map and through each event page storing all comments.
Example
const mapEventComments = loadEventComments()
// =>  *  // { 28: [param1, param2, param3] }
          // { 29: [param1, param2, param3] }
Since:
  • 1.0.0
Returns
An object of all comments added together, sorted by eventId
Type
object

(static) tileCoords(x, y) → {object}

Converts the tile position to the stage position
Example
import { tileCoords } from 'fenix-tools'

const tileToCanvasPosition = tilePosition(7, 11) // => {x: 294, 460}
Since:
  • 1.0.0
Parameters
Name Type Description
x number the x tile position to convert.
y number the y tile position to convert.
Returns
return and object with the new x and y positions
Type
object