From a9a66f33a88c90b027ab3b58f8e44a14c3230e74 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Sun, 13 Oct 2019 19:15:17 +0900 Subject: [PATCH] Added 'Encoding' option --- index.html | 32 ++++++++++++++++++++++++++++++++ js/client.js | 7 +++++-- js/interface.js | 9 +++++++++ js/preferences.js | 5 +++-- 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 1430524..6b19974 100644 --- a/index.html +++ b/index.html @@ -80,6 +80,38 @@ + +
diff --git a/js/client.js b/js/client.js index 3354fa4..da93ebd 100644 --- a/js/client.js +++ b/js/client.js @@ -197,8 +197,7 @@ class PalaceProtocol { connect(ip,port) { - this.textDecoder = new TextDecoder('windows-1252'); // default server encoding - this.textEncoder = new TextEncoder('windows-1252', { NONSTANDARD_allowLegacyEncoding: true }); // palace default! :\ + this.setEncoder(prefs.general.encoding); if (!port) port = '9998'; this.ip = ip.trim(); @@ -1160,6 +1159,10 @@ class PalaceProtocol { this.send(packet); } + setEncoder(encoding) { + this.textDecoder = new TextDecoder(encoding); + this.textEncoder = new TextEncoder(encoding, { NONSTANDARD_allowLegacyEncoding: true }); // palace default! :\ + } } diff --git a/js/interface.js b/js/interface.js index 64738ed..8c4088c 100644 --- a/js/interface.js +++ b/js/interface.js @@ -385,6 +385,15 @@ if (window.require) { document.getElementById('prefhomepalace').onchange = function() { setGeneralPref('home',this.value); }; + document.getElementById('prefencoding').onchange = function() { + try { + palace.setEncoder(this.value); + setGeneralPref('encoding',this.value); + } catch (error) { + logerror(error); + this.value = getGeneralPref('encoding'); + } + }; document.getElementById('prefpropbagsize').oninput = function() { // change prop bag tile size :D setGeneralPref('propBagTileSize',this.value); refreshPropBagView(true); diff --git a/js/preferences.js b/js/preferences.js index 4517e37..b060249 100644 --- a/js/preferences.js +++ b/js/preferences.js @@ -20,8 +20,8 @@ function setGeneralPref(id,value) { prefs.general[id] = value; } -function getGeneralPref(id) { - return prefs.general[id]; +function getGeneralPref(id,def) { + return prefs.general.hasOwnProperty(id) ? prefs.general[id] : def; } window.onunload = function(e) { @@ -66,4 +66,5 @@ window.onunload = function(e) { } document.getElementById('prefusername').value = getGeneralPref('userName'); document.getElementById('prefhomepalace').value = getGeneralPref('home'); + document.getElementById('prefencoding').value = getGeneralPref('encoding','windows-1252'); })();