-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
RS_DevanagariSimplify.js
221 lines (193 loc) · 7.02 KB
/
RS_DevanagariSimplify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// ================================================================
// RS_DevanagariSimplify.js
// ---------------------------------------------------------------
// The MIT License
// Copyright (c) 2022 biud436
// ---------------------------------------------------------------
// Free for commercial and non commercial use.
// ================================================================
/*:
* @target MV
* @plugindesc This plugin is possible to show up Devanagari text simplify. <RS_DevanagariSimplify>
* @author biud436
*
* @param Message Mode
* @type select
* @desc This parameter can set the message mode.
* default : devanagari
* @default devanagari
* @option Devanagari Mode
* @value devanagari
* @option Normal Mode
* @value normal
*
* @param Devanagari Font
* @desc Specific your font that can indicate Devanagari text from your system font folder.
* @default Poppins, Hind
*
* @help
* ============================================================================
* Plugin Commands
* ============================================================================
*
* To change the text mode as Devanagari, you can use the following plugin command.
*
* DevanagariMessageMode
*
* To change the text mode is normal, you can use the following plugin command.
*
* NormalMessageMode
*
* ============================================================================
* Version Log
* ============================================================================
* 2022.06.24 (v1.0.0) - First Release.
*/
(() => {
const RS = window.RS || {};
let parameters = $plugins.filter(i =>
i.description.contains('<RS_DevanagariSimplify>')
);
parameters = parameters.length > 0 && parameters[0].parameters;
RS.DevanagariSimplify = RS.DevanagariSimplify || {};
RS.DevanagariSimplify.Params = {};
RS.DevanagariSimplify.Params.messageMode = String(
parameters['Message Mode'] || 'devanagari'
);
RS.DevanagariSimplify.Params.devanagariFont = String(
parameters['Devanagari Font'] || 'Poppins, Hind'
);
function TextUtils() {
throw new Error('This is a static class');
}
TextUtils.LEFT_TO_RIGHT_EMBEDDING = '\u202A';
TextUtils.RIGHT_TO_LEFT_EMBEDDING = '\u202B';
TextUtils.POP_DIRECTIONAL_FORMATTING = '\u202C';
TextUtils.LEFT_TO_RIGHT_OVERRIDE = '\u202D';
TextUtils.RIGHT_TO_LEFT_OVERRIDE = '\u202E';
TextUtils.LEFT_TO_RIGHT_ISOLATE = '\u2066';
TextUtils.RIGHT_TO_LEFT_ISOLATE = '\u2067';
TextUtils.FIRST_STRONG_ISOLATE = '\u2068';
TextUtils.POP_DIRECTIONAL_ISOLATE = '\u2069';
TextUtils.isArabic = function (text) {
const pattern =
/[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFD\uFE70-\uFEFF\u10E600-\u10E7E\u1EE00-\u1EEFF]/;
return pattern.test(text);
};
TextUtils.makeText = function (text) {
return String(TextUtils.LEFT_TO_RIGHT_EMBEDDING + text);
};
/**
* @class DevanagariUtils
*/
function DevanagariUtils() {
throw new Error('This is a static class');
}
DevanagariUtils.isDevanagari = function (text) {
const pattern = /[\u0900-\u097F\u0980-\u09FF]/;
return pattern.test(text);
};
DevanagariUtils.makeText = function (text) {
return String(TextUtils.LEFT_TO_RIGHT_EMBEDDING + text);
};
// ============================================================================
// Window_Base
// ============================================================================
const alias_Bitmap_drawText = Bitmap.prototype.drawText;
Bitmap.prototype.drawText = function (
text,
x,
y,
maxWidth,
lineHeight,
align
) {
if (
RS.DevanagariSimplify.Params.messageMode === 'devanagari' &&
DevanagariUtils.isDevanagari(text)
) {
text = DevanagariUtils.makeText(text);
}
alias_Bitmap_drawText.call(
this,
text,
x,
y,
maxWidth,
lineHeight,
align
);
};
// ============================================================================
// Window_Base
// ============================================================================
const alias_Window_Base_standardFontFace =
Window_Base.prototype.standardFontFace;
Window_Base.prototype.standardFontFace = function () {
if (
RS.DevanagariSimplify.Params.messageMode === 'devanagari' ||
navigator.language.match(/^hi/)
) {
return RS.DevanagariSimplify.Params.devanagariFont;
}
return alias_Window_Base_standardFontFace.call(this);
};
const alias_Window_Base_processNormalCharacter =
Window_Base.prototype.processNormalCharacter;
Window_Base.prototype.processNormalCharacter = function (textState) {
if (RS.DevanagariSimplify.Params.messageMode !== 'devanagari') {
return alias_Window_Base_processNormalCharacter.call(
this,
textState
);
}
const allLines = textState.text
// eslint-disable-next-line no-plusplus
.slice(textState.index++)
.split(/[\r\n]+/);
const currentLine = allLines[0] || '';
let currentText = '';
// eslint-disable-next-line prefer-destructuring
currentText = currentLine.split('\x1b')[0];
textState.index += currentText.length - 1;
const c = currentText;
const w = this.textWidth(c);
this.contents.drawText(
c,
textState.x,
textState.y,
w * 2,
textState.height
);
textState.x += w;
return c;
};
// ============================================================================
// Window_Message
// ============================================================================
const alias_Window_Message_standardFontFace =
Window_Message.prototype.standardFontFace;
Window_Message.prototype.standardFontFace = function () {
if (
RS.DevanagariSimplify.Params.messageMode === 'devanagari' ||
navigator.language.match(/^hi/)
) {
return RS.DevanagariSimplify.Params.devanagariFont;
}
return alias_Window_Message_standardFontFace.call(this);
};
// ============================================================================
// Game_Interpreter
// ============================================================================
const alias_Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
alias_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'DevanagariMessageMode') {
RS.DevanagariSimplify.Params.messageMode = true;
}
if (command === 'NormalMessageMode') {
RS.DevanagariSimplify.Params.messageMode = false;
}
};
})();