Add cyrillic-support option for cyrillic codepage hack

This commit is contained in:
Mike Primm 2011-11-14 14:08:24 +08:00 committed by mikeprimm
parent e696988e34
commit bbb5db3524
5 changed files with 27 additions and 2 deletions

View File

@ -23,6 +23,7 @@ public class ClientConfigurationComponent extends Component {
s(t, "defaultzoom", c.getInteger("defaultzoom", 0));
s(t, "sidebaropened", c.getString("sidebaropened", "false"));
s(t, "dynmapversion", plugin.getDescription().getVersion());
s(t, "cyrillic", c.getBoolean("cyrillic-support", false));
DynmapWorld defaultWorld = null;
String defmap = null;

View File

@ -369,6 +369,9 @@ defaultzoom: 0
defaultworld: world
defaultmap: flat
# Option to enable workaround for incorrectly encoded unicode in Cyrillic MC/Bukkit (not good for other code pages)
#cyrillic-support: true
# NOTE: the 'templates' section is now found in the 'templates' directory
# Templates CAN still be defined in configuration.txt, as before 0.20
templates:

View File

@ -43,7 +43,7 @@ componentconstructors['chatballoon'] = function(dynmap, configuration) {
}
// Add line to balloon.
$('<div/>').addClass('balloonmessage').text(message.text).appendTo(popup.content);
$('<div/>').addClass('balloonmessage').text(chat_encoder(message)).appendTo(popup.content);
// Remove older lines when too many messages are shown.
var children = $(popup.content).children();

View File

@ -104,7 +104,7 @@ componentconstructors['chatbox'] = function(dynmap, configuration) {
var playerMessageContainer = $('<span/>')
.addClass('messagetext')
.text(message.text);
.text(chat_encoder(message));
messageRow.append(playerIconContainer,playerChannelContainer,playerNameContainer,playerMessageContainer);
addrow(messageRow);

View File

@ -31,3 +31,24 @@ function getMinecraftTime(servertime) {
night: !day
};
}
function chat_encoder(message) {
if (dynmap.options.cyrillic) {
if(message.source === 'player') {
var utftext = "";
for (var n = 0; n < message.text.length; n++) {
var c = message.text.charCodeAt(n);
if (c >= 192) {
var c = message.text.charCodeAt(n);
utftext += String.fromCharCode(c+848);
}
else if (c == 184) { utftext += String.fromCharCode(1105); }
else {
utftext += String.fromCharCode(c);
}
}
return utftext
}
}
return message.text;
}