VsConvertEscapeCharacters - Custom escape characters
VsConvertEscapeCharacters + 1.1.0VsRpgDev
Introduction
This plugin allows you to register custom escape characters, which lets you, for example, access custom values from your plugin, trigger methods, draw images, etc., when a text message is displayed.
Additionally, you can use convertEscapeCharacters from anywhere in the code through the static class VsConvertEscapeCharacters.
Readme
Features
[*]registerEscapeCharacter
registers a new escaped character
[*]registerProcessEscapeCharacter
register a new escaped character (gets handled later then registerEscapeCharacter)
[*]convertEscapeCharacters
converts escaped characters in a text
How to Use
registerEscapeCharacter
JavaScript:
// arrow functions -------------
VsConvertEscapeCharacters.registerEscapeCharacter("X",(text)=> {
return "your text was "+text;
});
// old style -------------------
function ReplaceText(text)
{
return "your text was "+text;
}
VsConvertEscapeCharacters.registerEscapeCharacter("X",ReplaceText);
registerProcessEscapeCharacter
JavaScript:
// arrow functions -------------
VsConvertEscapeCharacters.registerProcessEscapeCharacter("X",(currentWindow, textState, param)=> {
//do whatever you like
//example draw icon
currentWindow.processDrawIcon(param, textState);
});
// old style -------------------
function CustomMethod(currentWindow, textState, param)
{
return "your text was "+text;
//do whatever you like
//example draw icon
currentWindow.processDrawIcon(param, textState);
}
VsConvertEscapeCharacters.registerProcessEscapeCharacter("X",CustomMethod);
convertEscapeCharacters - get escaped character from wherever you want
JavaScript:
finalText = VsConvertEscapeCharacters.convertEscapeCharacters(text);
Plugin Commands / Script Calls
JavaScript:
declare class VsConvertEscapeCharacters
{
static convertEscapeCharacters(text: string) : string;
static actorName(n: string) : string;
static partyMemberName (n:string) : string;
/**
* register a new escape character
* @param char escape character to use
* @param method callback method which gets the paramter from within the brackets [] and should return the replacement text
*/
static registerEscapeCharacter(char : string, method: (string)=>string) : string;
/**
* retursn all registered escape characters
*/
static get CustomEscapeCharacters() :{ :(string)=>string; };
/**
* register process escape character, these get processed character by character when the textbox draws the message text
* @param char scape character to use
* @param method callback method which gets the the current windows, the textstate and paramter from within the brackets [] and should return the replacement text
*/
static registerProcessEscapeCharacter(char : string, method: (windowBase:Window_Base, state: TextState, param: string)=>void) : string;
static get ProcessEscapeCharacter() :{ : (windowBase:Window_Base, state: TextState, param: string)=>void; };
}
Changes to the core script
[*]rmmz_windows.js
[*]Window_Base
[*] convertEscapeCharacters: overrides,original gets called after
[*] processEscapeCharacter: overrides,original gets called after
The plugin should work with all other plugins as long as convertEscapeCharacters and processEscapeCharacter are still called.
Demo
demo.js
Download
VsConvertEscapeCharacters.js (Plugin)
Github Repository
Terms and Credits
VsConvertEscapeCharacters is marked with CC0 1.0 Universal. To view a copy of this license, visit https://creativecommons.org/publicdomain/zero/1.0/
This plugin can be used in any project, commercial or otherwise. no credit needed.
本贴来自国际rpgmaker官方论坛作者:VsRpgDev处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/vsconvertescapecharacters-custom-escape-characters.174963/
页:
[1]