From 5c3e7a93a7185769e06224a1f74888a5a95aa094 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 29 Feb 2020 10:24:07 -0500 Subject: [PATCH] =?UTF-8?q?Add=20Kuro-shi=20Uch=C5=AB.=20Allow=20alt-dragg?= =?UTF-8?q?ing=20to=20go=20outside=20of=20the=20world=20bounds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- macrovision.js | 30 +++- media/attribution.js | 20 +++ media/characters/kuro-shi-uchū/front.svg | 161 ++++++++++++++++++++++ presets/characters.js | 41 ++++++ 4 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 media/characters/kuro-shi-uchū/front.svg diff --git a/macrovision.js b/macrovision.js index 86d5bd30..a5c3b92b 100644 --- a/macrovision.js +++ b/macrovision.js @@ -63,6 +63,9 @@ const entities = { } function constrainRel(coords) { + if (altHeld) { + return coords; + } return { x: Math.min(Math.max(coords.x, 0), 1), y: Math.min(Math.max(coords.y, 0), 1) @@ -909,7 +912,7 @@ document.addEventListener("DOMContentLoaded", () => { scenes["Demo"](); else { try { - const data = JSON.parse(atob(param)); + const data = JSON.parse(b64DecodeUnicode(param)); if (data.entities === undefined) { return; } @@ -1324,11 +1327,34 @@ function exportScene() { return results; } +// btoa doesn't like anything that isn't ASCII +// great + +// thanks to https://stackoverflow.com/questions/30106476/using-javascripts-atob-to-decode-base64-doesnt-properly-decode-utf-8-strings +// for providing an alternative + +function b64EncodeUnicode(str) { + // first we use encodeURIComponent to get percent-encoded UTF-8, + // then we convert the percent encodings into raw bytes which + // can be fed into btoa. + return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, + function toSolidBytes(match, p1) { + return String.fromCharCode('0x' + p1); + })); +} + +function b64DecodeUnicode(str) { + // Going backwards: from bytestream, to percent-encoding, to original string. + return decodeURIComponent(atob(str).split('').map(function(c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); + }).join('')); +} + function linkScene() { loc = new URL(window.location); - window.location = loc.protocol + "//" + loc.host + loc.pathname + "?scene=" + btoa(JSON.stringify(exportScene())); + window.location = loc.protocol + "//" + loc.host + loc.pathname + "?scene=" + b64EncodeUnicode(JSON.stringify(exportScene())); } function copyScene() { const results = exportScene(); diff --git a/media/attribution.js b/media/attribution.js index 922b357d..ff88b003 100644 --- a/media/attribution.js +++ b/media/attribution.js @@ -1748,6 +1748,18 @@ const attributionData = { "bossvoss" ] }, + { + prefix: "./media/characters/kuro-shi-uchū/", + files: [ + { name: "front.svg", source: "https://media.discordapp.net/attachments/300130710671458304/682667452626239526/lugiablackholeactual2.png" }, + ], + authors: [ + "shinywark" + ], + owners: [ + "dragonshark" + ] + }, { prefix: "./media/characters/lexi/", files: [ @@ -3365,6 +3377,14 @@ const attributionData = { "name": "Mariokartsonicriders", "url": "https://www.furaffinity.net/user/mariokartsonicriders/", }, + "shinywark": { + "name": "ShinyWark", + "url": "https://twitter.com/ShinyWark", + }, + "dragonshark": { + "name": "DragonShark", + "url": "https://twitter.com/ReptileGamepley", + }, } } diff --git a/media/characters/kuro-shi-uchū/front.svg b/media/characters/kuro-shi-uchū/front.svg new file mode 100644 index 00000000..6a0e4a76 --- /dev/null +++ b/media/characters/kuro-shi-uchū/front.svg @@ -0,0 +1,161 @@ + + + + + + + + + + + + diff --git a/presets/characters.js b/presets/characters.js index 1f01800d..daa73c15 100644 --- a/presets/characters.js +++ b/presets/characters.js @@ -8,6 +8,9 @@ math.createUnit("lightyears", { definition: "9.461e15 meters", prefixes: "long" }) +math.createUnit("AU", { + definition: "149597870700 meters" +}) function makeCharacter(name, author, viewInfo, defaultSizes, defaultSize, extraInfo) { if (extraInfo === undefined) { extraInfo = {} @@ -6513,6 +6516,44 @@ characterMakers["Mira al-Cul"] = () => { ) }; +characterMakers["Kuro-shi Uchū"] = () => { + return makeCharacter( + "Kuro-shi Uchū", + "Dragon Shark", + { + front: { + height: math.unit(17 + 1/12, "feet"), + weight: math.unit(476.2*5, "lbs"), + name: "Front", + image: { + source: "./media/characters/kuro-shi-uchū/front.svg", + extra: 2329/1835 * (1 / (1 - 0.02)), + bottom: 0.02 + } + }, + }, + [ + { + name: "Micro", + height: math.unit(2, "inches") + }, + { + name: "Normal", + height: math.unit(12, "meters") + }, + { + name: "Planetary", + height: math.unit(0.00929, "AU"), + default: true + }, + { + name: "Universal", + height: math.unit(20, "gigaparsecs") + }, + ] + ) +}; + function makeCharacters() { const results = [];