Class in reactor_core.js

Utils

32 public functions in 5 groups · show internal (_) functions

Core runtime: data, input and the ReactorEvents feed.

Familiar territory. Utils keeps the RPG Maker MZ API, so existing MZ knowledge, tutorials and plugin code apply. Reactor's additions are marked with descriptions below.

The static class that defines utility methods.

@namespace
function Utils()

Quick Reference

Setup & Creation 1

loadWebFileIndex() Loads the web file index.

Getting Information 2

resolveFileCase() Resolve file case.
resolveAudioExtension() Resolves an audio URL's extension against what actually exists on disk.

Checks (True / False) 15

isOptionValid() Checks whether the option is in the query string.
isNwjs() Checks whether the platform is NW.js.
isMobileDevice() Checks whether the platform is a mobile device.
isMobileSafari() Checks whether the browser is Mobile Safari.
isAndroidChrome() Checks whether the browser is Android Chrome.
isLocal() Checks whether the browser is accessing local files.
canUseWebGL() Checks whether the browser supports WebGL.
canUseWebAudioAPI() Checks whether the browser supports Web Audio API.
canUseCssFontLoading() Checks whether the browser supports CSS Font Loading.
canUseIndexedDB() Checks whether the browser supports IndexedDB.
canPlayOgg() Checks whether the browser can play ogg files.
canPlayWebm() Checks whether the browser can play webm files.
containsArabic() Checks whether the string contains any Arabic characters.
hasEncryptedImages() Checks whether the image files in the game are encrypted.
hasEncryptedAudio() Checks whether the audio files in the game are encrypted.

Actions 4

setEncryptionInfo() Sets information related to encryption.
setWebFileIndex() Sets the web file index.
startAssetUseRecord() Starts the asset use record.
saveAssetUse() Saves the asset use.

Other 10

checkRMVersion() Checks whether the current RPG Reactor version is greater than or equal to the given version.
encodeURI() Encodes a URI component without escaping slash characters.
extractFileName() Gets the filename that does not include subfolders.
escapeHtml() Escapes special characters for HTML.
existsOnDisk() Exists on disk.
correctFileCase() Correct file case.
correctFileCaseFromIndex() Correct file case from index.
localAssetExists() Whether a relative asset file is on disk, in any letter case.
noteAssetUse() Note asset use.
decryptArrayBuffer() Decrypts encrypted data.

Setup & Creation

loadWebFileIndex

static source
Utils.loadWebFileIndex()

Loads the web file index. (Same as the RPG Maker MZ method of this name.)

Getting Information

resolveFileCase

static source
Utils.resolveFileCase(url, suffix)

Resolve file case. (Same as the RPG Maker MZ method of this name.)

resolveAudioExtension

static source
Utils.resolveAudioExtension(url, suffix)

Resolves an audio URL's extension against what actually exists on disk.

Details

Resolves an audio URL's extension against what actually exists on disk.

Audio references are stored extensionless and requested as ".ogg", but a project may ship the track as .mp3, .wav or .m4a instead. With the filesystem at hand the real extension is found before the request; on the web the load-error fallback chain covers the same ground.

@param
url string The relative URL about to be requested (no suffix).
@param
suffix string The encrypted-asset suffix, "_" or "".
@returns
string The URL with the on-disk extension, without the suffix.

Checks (True / False)

isOptionValid

static source
Utils.isOptionValid(name)

Checks whether the option is in the query string.

Details

Checks whether the option is in the query string.

@param
name string The option name.
@returns
boolean True if the option is in the query string.

isNwjs

static source
Utils.isNwjs()

Checks whether the platform is NW.js.

Details

Checks whether the platform is NW.js.

@returns
boolean True if the platform is NW.js.

isMobileDevice

static source
Utils.isMobileDevice()

Checks whether the platform is a mobile device.

Details

Checks whether the platform is a mobile device.

@returns
boolean True if the platform is a mobile device.

isMobileSafari

static source
Utils.isMobileSafari()

Checks whether the browser is Mobile Safari.

Details

Checks whether the browser is Mobile Safari.

@returns
boolean True if the browser is Mobile Safari.

isAndroidChrome

static source
Utils.isAndroidChrome()

Checks whether the browser is Android Chrome.

Details

Checks whether the browser is Android Chrome.

@returns
boolean True if the browser is Android Chrome.

isLocal

static source
Utils.isLocal()

Checks whether the browser is accessing local files.

Details

Checks whether the browser is accessing local files.

@returns
boolean True if the browser is accessing local files.

canUseWebGL

static source
Utils.canUseWebGL()

Checks whether the browser supports WebGL.

Details

Checks whether the browser supports WebGL.

@returns
boolean True if the browser supports WebGL.

canUseWebAudioAPI

static source
Utils.canUseWebAudioAPI()

Checks whether the browser supports Web Audio API.

Details

Checks whether the browser supports Web Audio API.

@returns
boolean True if the browser supports Web Audio API.

canUseCssFontLoading

static source
Utils.canUseCssFontLoading()

Checks whether the browser supports CSS Font Loading.

Details

Checks whether the browser supports CSS Font Loading.

@returns
boolean True if the browser supports CSS Font Loading.

canUseIndexedDB

static source
Utils.canUseIndexedDB()

Checks whether the browser supports IndexedDB.

Details

Checks whether the browser supports IndexedDB.

@returns
boolean True if the browser supports IndexedDB.

canPlayOgg

static source
Utils.canPlayOgg()

Checks whether the browser can play ogg files.

Details

Checks whether the browser can play ogg files.

@returns
boolean True if the browser can play ogg files.

canPlayWebm

static source
Utils.canPlayWebm()

Checks whether the browser can play webm files.

Details

Checks whether the browser can play webm files.

@returns
boolean True if the browser can play webm files.

containsArabic

static source
Utils.containsArabic(str)

Checks whether the string contains any Arabic characters.

Details

Checks whether the string contains any Arabic characters.

@returns
boolean True if the string contains any Arabic characters.

hasEncryptedImages

static source
Utils.hasEncryptedImages()

Checks whether the image files in the game are encrypted.

Details

Checks whether the image files in the game are encrypted.

@returns
boolean True if the image files are encrypted.

hasEncryptedAudio

static source
Utils.hasEncryptedAudio()

Checks whether the audio files in the game are encrypted.

Details

Checks whether the audio files in the game are encrypted.

@returns
boolean True if the audio files are encrypted.

Actions

setEncryptionInfo

static source
Utils.setEncryptionInfo(hasImages, hasAudio, key)

Sets information related to encryption.

Details

Sets information related to encryption.

@param
hasImages boolean Whether the image files are encrypted.
@param
hasAudio boolean Whether the audio files are encrypted.
@param
key string The encryption key.

setWebFileIndex

static source
Utils.setWebFileIndex(files)
Details
@param
files string[] Relative, forward-slashed paths of every file in the build.

startAssetUseRecord

static source
Utils.startAssetUseRecord(force)

Starts the asset use record. (Same as the RPG Maker MZ method of this name.)

saveAssetUse

static source
Utils.saveAssetUse()

Saves the asset use. (Same as the RPG Maker MZ method of this name.)

Other

checkRMVersion

static source
Utils.checkRMVersion(version)

Checks whether the current RPG Reactor version is greater than or equal to the given version.

Details

Checks whether the current RPG Reactor version is greater than or equal to the given version.

@param
version string The "x.x.x" format string to compare.
@returns
boolean True if the current version is greater than or equal to the given version.

encodeURI

static source
Utils.encodeURI(str)

Encodes a URI component without escaping slash characters.

Details

Encodes a URI component without escaping slash characters.

@param
str string The input string.
@returns
string Encoded string.

extractFileName

static source
Utils.extractFileName(filename)

Gets the filename that does not include subfolders.

Details

Gets the filename that does not include subfolders.

@param
filename string The filename with subfolders.
@returns
string The filename without subfolders.

escapeHtml

static source
Utils.escapeHtml(str)

Escapes special characters for HTML.

Details

Escapes special characters for HTML.

@param
str string The input string.
@returns
string Escaped string.

existsOnDisk

static source
Utils.existsOnDisk(file)

Exists on disk. (Same as the RPG Maker MZ method of this name.)

correctFileCase

static source
Utils.correctFileCase(url)

Correct file case. (Same as the RPG Maker MZ method of this name.)

correctFileCaseFromIndex

static source
Utils.correctFileCaseFromIndex(url)
Details
@param
url string The relative URL that failed to load.
@returns
?string The URL as the build's file index spells it, or null.

localAssetExists

static source
Utils.localAssetExists(url)

Whether a relative asset file is on disk, in any letter case.

Details

Whether a relative asset file is on disk, in any letter case. Known only with the filesystem at hand (NW.js): null elsewhere, where a request finds out.

@param
url string The relative URL.
@returns
?boolean

noteAssetUse

static source
Utils.noteAssetUse(url)

Note asset use. (Same as the RPG Maker MZ method of this name.)

decryptArrayBuffer

static source
Utils.decryptArrayBuffer(source)

Decrypts encrypted data.

Details

Decrypts encrypted data.

@param
source ArrayBuffer The data to be decrypted.
@returns
ArrayBuffer The decrypted data.