[REQUEST] Plugin to utilize furigana

Status
Not open for further replies.

AkarouKamimaruno

Villager
Member
Joined
Mar 19, 2018
Messages
6
Reaction score
0
First Language
English
Primarily Uses
RMMV
I was wondering if there is anyone willing to write a plugin to implement furigana in a project that I'm working in Japanese.

For those that don't know what furigana is:

Furigana (Japanese: 振り仮名), often alternatively referred to as ruby text, is a phonetic gloss that appears above the base text (when writing horizontally) or to the right (when writing vertically). It is usually in hiragana and indicates how the base text should be read. For example, a term from a light novel series I'm writing has the base text "古いシステムの解放者", which is normally read as 'furui shisutemu no kaihōsha', but has "システム・リベレータ" which is read as 'shisutemu riberēta', indicating that it should be read as 'System Liberator' instead of 'Liberator of the Old System'. Again this explanation was for those who don't know what furigana is. Now you know.

Now that I've briefly explained what furigana is, I need a plugin that will let me input furigana, especially when introducing new characters.

If anyone doesn't want to take up this request, I perfectly understand.

Many thanks in advance!
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
147
Reaction score
166
First Language
Danish
Primarily Uses
RMMV
Hi, I have made something. However, it is in no way perfect. I am not too experienced in changing the message system yet.
I have only done a few tests and it seem to work. Something to notice is that I have made it so there is more space between each line. This means that 3 lines takes up 4 lines of space.

The plugin is relatively easy to use just add the text code \furi[BASETEXT, FURIGANA] to add the furigana to be above the base text. I hope I have done it right as I am not completely sure about the rules for furigana.

If you encounter any problems with the plugin feel free to message me :)

Code:
//=============================================================================
// Furigana
// MRP_Furigana.js
// By Magnus0808 || Magnus Rubin Peterson
//=============================================================================

/*:
 * @plugindesc Adds Furigana Utilization.
 * @author Magnus0808
 *
 * @help Use the Text Code \furi[BASETEXT, FURIGANA] to add the furigana above
 * the base text.
 *
 
 */
 
 var Imported = Imported || {};
 Imported.MRP_Furigana = true;
 
 var MRP = MRP || {};
 MRP.Furigana = MRP.Furigana ||{};
 
(function() {
       
    //-----------------------------------------------------------------------------
    // Window_Base
    //
    // Changes to Window_Base
   
    Window_Base.prototype.processNewLine = function(textState) {
        textState.x = textState.left;
        var arr = /^\n((?!\n).)*(\x1bfuri).*?/.exec(textState.text.slice(textState.index));
        if(arr) {
            textState.y += textState.height * 1.5;          
        } else {
            textState.y += textState.height;      
        }
        textState.height = this.calcTextHeight(textState, false);
       
        textState.index++;
    };
   
    MRP.Furigana.Window_Base_processEscapeCharacter = Window_Base.prototype.processEscapeCharacter;
    Window_Base.prototype.processEscapeCharacter = function(code, textState) {
        console.log("process");
        MRP.Furigana.Window_Base_processEscapeCharacter.call(this, code, textState);
        switch (code) {
        case 'FURI':
            var arr = this.obtainFuriParam(textState);
            var normText = arr[0];
            var furiText = arr[1];
           
            var w = this.textWidth(normText);
           
            this.makeFontSmaller();
            var furiW = this.textWidth(furiText);
            var spaceLength = (w - furiW)/(furiText.length + 1);
           
            var furiStart = textState.x + spaceLength;
            for(var i = 0; i < furiText.length; i++){
                var c = furiText.charAt(i);
                this.contents.drawText(c, furiStart + spaceLength * i, textState.y - textState.height/1.5, w * 2, textState.height);
                furiStart += furiW/furiText.length;
            }
           
            this.makeFontBigger();
            this.contents.drawText(normText, textState.x, textState.y, w * 2, textState.height);
            textState.x += w;
            break;
        }
    };
   
    Window_Base.prototype.obtainFuriParam = function(textState) {
        var arr = /^\[(.+?), *(.+?)\]/.exec(textState.text.slice(textState.index));
        if (arr) {
            textState.index += arr[0].length;
            return arr.slice(1);
        } else {
            return '';
        }
    };
   
    //-----------------------------------------------------------------------------
    // Window_Message
    //
    // Changes to Window_Message
   
    MRP.Furigana.Window_Message_newPage = Window_Message.prototype.newPage
    Window_Message.prototype.newPage = function(textState) {
        MRP.Furigana.Window_Message_newPage.call(this, textState);
        var arr = /^((?!\n).)*(\x1bfuri).*?/.exec(textState.text.slice(textState.index));
        if(arr) {
            textState.y = textState.height * 0.5;          
        } else {
            textState.y = 0;      
        }
    };
   
})();
 

Attachments

Last edited:

AkarouKamimaruno

Villager
Member
Joined
Mar 19, 2018
Messages
6
Reaction score
0
First Language
English
Primarily Uses
RMMV
Unfortunately, I do have a problem.

For some reason that I can't explain, the text code "\furi" isn't doing what you and I hoped it would do. I'll have a screenshot for you shortly.


Here's a gander at the event page. The event in question is already highlighted.


[EDIT]
kuso~. How do I keep the images from appearing like they didn't load properly?
Edited 2019/4/17, 07:42 JST.
[/EDIT]

And about the rules for furigana... unfortunately the rules governing it's usage are rather complicated (there are things about it I don't quite understand either, so don't feel bad.) Although, I don't think I can provide an explanation that is easy to understand... sorry.
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
147
Reaction score
166
First Language
Danish
Primarily Uses
RMMV
Hi, I did encounter a bug myself that I am currently trying to fix. (If the furigana is on the first line it does not work correctly).
Could you try to upload the screenshots again? All I can see is IMG
 

AkarouKamimaruno

Villager
Member
Joined
Mar 19, 2018
Messages
6
Reaction score
0
First Language
English
Primarily Uses
RMMV
Okay... give me a moment.

考え物.png

イベント019.png

I didn't notice the "Upload a file" button, so my bad about that. Hopefully these help:yswt:!?
 

Magnus0808

Software Developer
Veteran
Joined
Feb 2, 2019
Messages
147
Reaction score
166
First Language
Danish
Primarily Uses
RMMV
Okay try it now. I have fixed some bugs. I even made it so it only uses extra space if the next line contains furigana (hopefully that works correctly).
The bug you encounted yourself occured because I forgot to make a regex lazy... so \furi[a, b] \furi[c, d] was seen as a = "a" and b = "b] \furi[c, d"...
Well I have fixed it now. I have updated my original reply
 

AkarouKamimaruno

Villager
Member
Joined
Mar 19, 2018
Messages
6
Reaction score
0
First Language
English
Primarily Uses
RMMV
Unfortunately, it still isn't working. I don't know if it's something that we're overlooking or if it's MV being a pain (which I doubt, but is possible), and I even tried it without Yanfly's Message Core turned on.

考え物 (1).png

イベント019 (1).png

I'm sure this problem is getting on your nerves, being the one actually writing the code (I'm still having trouble with JavaScript myself, I wouldn't know what would be the best way to make a plugin.), while it most certainly getting on my nerves because I'm testing it (not saying you're bad at what you do, because I think you might be better at it than I ever would be (^_^).) I just hope it isn't something we're overlooking...

[EDIT]
Also, you wouldn't mind if I start addressing you as "Magnus-san", would you? I don't want to sound rude or anything of the sort by never referring to you by name. (-san is actually a very common honorific in Japanese; also, referring the person you're speaking with using 'you' often carries a accusatory connotation in Japanese, so sorry if I sounded rude by asking.
Edited 2019/4/17, 09:02 JST
[/EDIT]
 
Last edited:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,381
Reaction score
8,537
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,050
Messages
1,018,548
Members
137,835
Latest member
yetisteven
Top