RMMV Coloring text inside JS plugin doesn't work

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
841
Reaction score
470
First Language
Poland
Primarily Uses
RMMV
I'm fixing some stuff in my project like removing not used resources (imgs, snds, js's) and generaly reorganizing my project and I've encountered strange thing... Very strange though...

This is my plugin allowing to obtain text from external txt file
JavaScript:
/*:
* @plugindesc v1.00 Allows to display dialouges from external txt file
* @help Requires Yanfly's Message Core for most comfortable usage
*
* @author Soulrender
*
* @param --Settings--
* @default
*
* @param Main Directory
* @parent --Settings--
* @type Text
* @desc Specify your directory for dialouges, place it in game project folder
* @default data_proto
*
* @param File name prefix
* @parent --Settings--
* @type Text
* @desc It can be any text you want, but I recommend to use very familiar word to you
* @default Map
*
* @param Use Asynchronous Requests
* @parent --Settings--
* @type boolean
* @default false
* @desc asynchronous requests should be preferred to synchronous requests for performance reasons.
*
* @param --Colors--
* @default
*
* @param Actor Name Color
* @parent --Colors--
* @type Text
* @desc Choose HEX color for actor name
* @default ffcc00
*
* @param Actor Message Color
* @parent --Colors--
* @type Text
* @desc Every message will be colored with that hex, unless you use another coloring tag inside message
* @default ffffff
*/

var soulrender = soulrender || {};
soulrender.Parameters = PluginManager.parameters('SOL_DialougesFromTxt');
soulrender.directory = String(soulrender.Parameters['Main Directory'] || "data_proto");
soulrender.filePrefix = String(soulrender.Parameters['File name prefix'] || "Map");
soulrender.asyncRequests = soulrender.Parameters['Use Asynchronous Requests'] || false;
soulrender.actorNameColor = (soulrender.Parameters['Actor Name Color'] || 'ffcc00');
soulrender.actorMsgColor = (soulrender.Parameters['Actor Message Color'] || 'ffffff');


Game_System.prototype.readFile = function(filename){
    var xhr = new XMLHttpRequest();
    xhr.async = soulrender.asyncRequests;
  
    try{
        xhr.open("GET", filename, false);
        xhr.send(null);
        var fileContent = xhr.responseText;
        return fileContent; 
    }catch(e){
        console.log(e.stack);
    }
  
}

Game_System.prototype.explode = function(txt, delim){
    try{
        var source = txt.split(delim);
        if (source){
            return source;
        }
        else return false; 
    }catch(e){
        console.log(e.stack);
    }
}

Game_System.prototype.obtainData = function(id, database){
  
    var data = this.readFile('./' + soulrender.directory + '/' + database + '.txt');
    var proto = this.explode(data, "\n");
    var item = this.explode(proto[id], "|");
    return item;
}

Game_System.prototype.getSpeechFileByMapId = function(){

    var mapId = $gameMap._mapId;
    var file = soulrender.filePrefix + mapId.padZero(3);
    return file;
}

Game_System.prototype.ShowText = function(line){
  
    var aFile = this.getSpeechFileByMapId();
    var source = this.obtainData(line - 1, aFile);
    var actorName = source[0];
    var actorSpeech = source[1];
    var displayLine = '';
  
    if (Imported.YEP_MessageCore && Imported.YEP_X_ExtMesPack1)
    {
        displayLine = "\\hc[" + String(soulrender.actorNameColor) + "]" + actorName + ": \\hc[" + String(soulrender.actorMsgColor) + "]" + actorSpeech;
    }
    else
        {
            displayLine = "\\c[6]" + actorName + ": \\c[0]" + actorSpeech;
        }
    return displayLine;
}
So... The main issue is... While I pass any string with text code (any, like \c[color]) it's not parsed if it from any JS file, final output text always looks the same, displaying broken tags (like in this image - https://prnt.sc/w0razh) and it should look like this https://prnt.sc/w0rc8s

I tried everything (starting new projects several times, all plugins where removed, I've just keeped Message Core and it's extensions and still nothing. But in backup copy wich is made on the same version of MV (1.6.2) this problem does not exists...

EDIT:\\
I'm using this method to execute JS evals in MessageBoxes:

JavaScript:
(function(){
var _sol_convertAlias = Window_Base.prototype.convertEscapeCharacters;

    Window_Base.prototype.convertEscapeCharacters = function(text) {
       text = _sol_convertAlias.call(this, text);
       text = text.replace(/\x1bjs\[".*?"\]/gi, function() {
        if(SceneManager._scene.actor===undefined)
            var a = $gameParty.leader();
             else{
        var a = SceneManager._scene.actor();
       }
             var form = arguments[0].split("[\"")[1].split("\"]")[0];
             return eval(form);
       }.bind(this));
           text = text.replace(/\x1bjsv\[".*?"\]/gi, function() {
         var v = $gameVariables._data;
             var form = arguments[0].split("[\"")[1].split("\"]")[0];
             return eval(form);
       }.bind(this));
       return text;
    };  
})();
and that way I show obtained text from file - https://prnt.sc/w0rfxk
 

Users Who Are Viewing This Thread (Users: 5, Guests: 3)

Latest Threads

Latest Posts

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,472
Members
137,822
Latest member
madelbylz
Top