diff --git a/js/base-engine.js b/js/base-engine.js index 8e67e8c0..0ed67815 100644 --- a/js/base-engine.js +++ b/js/base-engine.js @@ -125,8 +125,8 @@ function d20plusEngine () { }; d20plus.engine.swapTemplates = () => { - const oldToolbar = document.getElementById("floatingtoolbar"); - d20plus.isOptedInNewUI = !oldToolbar; + const $betaSwitch = $("#new-toolbar-toggle"); + d20plus.betaFeaturesEnabled = $betaSwitch.prop("checked"); d20plus.ut.log("Swapping templates..."); $("#tmpl_charactereditor").html($(d20plus.html.characterEditor).html()); @@ -199,7 +199,8 @@ function d20plusEngine () { }).addTouch(); } - if (!d20plus.isOptedInNewUI) { + if (!d20plus.betaFeaturesEnabled) { // Jan 2024 beta features include the new Page Toolbar + // this should be executed only for the old Page Toolbar overwriteDraggables(); $(`#page-toolbar`).css("top", "calc(-90vh + 40px)"); @@ -217,7 +218,7 @@ function d20plusEngine () { debouncedOverwrite(); } } else { - $(`#page-toolbar`).hide(); + $(`#page-toolbar`).hide(); // hide the old Page Toolbar that pops with b20 styling } $(`body`).on("mouseup", "li.dl", (evt) => { @@ -243,7 +244,7 @@ function d20plusEngine () { }).on("click", ".pagedetails_navigation .nav-tabs--beta", () => { d20plus.engine._populatePageCustomOptions(); }).on("click keyup", ".weather input, .weather .slider", () => { - d20plus.engine._updateCustomOptions(); + d20plus.engine._updatePageCustomOptions(); }); }; @@ -333,17 +334,17 @@ function d20plusEngine () { $overlay.remove(); } $saveBtn.before(templateApply); - $(`.btn-apply`).on("click", d20plus.engine.applySettings); + $(`.btn-apply`).on("click", d20plus.engine.applyPageSettings); } // process options within open dialog if ($dialog[0]) { const $pageTitle = $dialog.find(`.ui-dialog-title:visible`); - d20plus.engine._preserveCustomOptions(page); - d20plus.engine._populateCustomOptions(page, $dialog.find(`.dialog .tab-content`)); + d20plus.engine._preservePageCustomOptions(page); + d20plus.engine._populatePageCustomOptions(page, $dialog.find(`.dialog .tab-content`)); if ($pageTitle[0] && !$(".ui-dialog-pagename:visible")[0]) { $pageTitle.after(`${page.get("name")}`); $saveBtn.off("click"); - $saveBtn.on("click", d20plus.engine.applySettings); + $saveBtn.on("click", d20plus.engine.applyPageSettings); // closed editors behave strangely, so replace Close with Cancel $dialog.find(`.ui-dialog-titlebar-close:visible`).on("mousedown", () => { $dialog.find(`.ui-dialog-buttonpane .btn:not(.btn-apply):not(.btn-primary)`).click(); @@ -362,7 +363,7 @@ function d20plusEngine () { } } - d20plus.engine.applySettings = (evt) => { + d20plus.engine.applyPageSettings = (evt) => { evt.stopPropagation(); evt.preventDefault(); const page = d20.Campaign.pages.get(d20plus.engine._lastSettingsPageId); @@ -375,8 +376,8 @@ function d20plusEngine () { const activeTabScroll = $dialog.find(`.ui-dialog-content`).scrollTop(); const $settings = $dialog.find(`.dialog .tab-content`); - d20plus.engine._saveCustomOptions(page); - d20plus.engine._saveNativeOptions(page, $settings); + d20plus.engine._savePageCustomOptions(page); + d20plus.engine._savePageNativeOptions(page, $settings); page.save(); @@ -387,7 +388,7 @@ function d20plusEngine () { // page.save resets current dialog, so we need to restore status quo $(`.nav-tabs:visible [data-tab=${activeTab}]`).click(); $(`.ui-dialog-content:visible`).scrollTop(activeTabScroll); - d20plus.engine._populateCustomOptions(); + d20plus.engine._populatePageCustomOptions(); } } @@ -427,7 +428,7 @@ function d20plusEngine () { lightglobalillum: {class: ".lightglobalillum"}, }; - d20plus.engine._saveNativeOptions = (page, dialog) => { + d20plus.engine._savePageNativeOptions = (page, dialog) => { if (!page || !page.get) return; const getSlider = (el) => { if (el.style.left?.search("%") > 0) return el.style.left.slice(0, -1) / 100; @@ -452,23 +453,23 @@ function d20plusEngine () { }); } - d20plus.engine._preserveCustomOptions = (page) => { + d20plus.engine._preservePageCustomOptions = (page) => { if (!page || !page.get) return; - d20plus.engine._customOptions = d20plus.engine._customOptions || {}; - d20plus.engine._customOptions[page.id] = { _defaults: {} }; + d20plus.engine._customPageOptions = d20plus.engine._customPageOptions || {}; + d20plus.engine._customPageOptions[page.id] = { _defaults: {} }; [ "weather", ].forEach(category => Object.entries(d20plus[category].props).forEach(([name, deflt]) => { - d20plus.engine._customOptions[page.id][name] = page.get(`bR20cfg_${name}`) || deflt; - d20plus.engine._customOptions[page.id]._defaults[name] = deflt; + d20plus.engine._customPageOptions[page.id][name] = page.get(`bR20cfg_${name}`) || deflt; + d20plus.engine._customPageOptions[page.id]._defaults[name] = deflt; })); } d20plus.engine._populatePageCustomOptions = (page, dialog) => { dialog = dialog || $(`.pagedetails_navigation:visible`).closest(".ui-dialog"); page = page || d20.Campaign.pages.get(d20plus.engine._lastSettingsPageId); - if (!d20plus.engine._customOptions[page.id]) return; - Object.entries(d20plus.engine._customOptions[page.id]).forEach(([name, val]) => { + if (!d20plus.engine._customPageOptions[page.id]) return; + Object.entries(d20plus.engine._customPageOptions[page.id]).forEach(([name, val]) => { dialog.find(`[name="${name}"]`).each((i, e) => { const $e = $(e); if ($e.is(":checkbox")) { @@ -482,24 +483,24 @@ function d20plusEngine () { }); }); // ensure all Select elements will update options on change - $(".weather select").each((a, b) => { b.onchange = () => d20plus.engine._updateCustomOptions() }); + $(".weather select").each((a, b) => { b.onchange = () => d20plus.engine._updatePageCustomOptions() }); } - d20plus.engine._updateCustomOptions = (page, dialog) => { + d20plus.engine._updatePageCustomOptions = (page, dialog) => { dialog = dialog || $(`.pagedetails_navigation:visible`).closest(".ui-dialog"); page = page || d20.Campaign.pages.get(d20plus.engine._lastSettingsPageId); - if (!d20plus.engine._customOptions[page.id]) return; - Object.entries(d20plus.engine._customOptions[page.id]).forEach(([name, val]) => { + if (!d20plus.engine._customPageOptions[page.id]) return; + Object.entries(d20plus.engine._customPageOptions[page.id]).forEach(([name, val]) => { dialog.find(`[name="${name}"]`).each((i, e) => { const $e = $(e); const val = $e.is(":checkbox") ? !!$e.prop("checked") : $e.val(); - d20plus.engine._customOptions[page.id][name] = val; + d20plus.engine._customPageOptions[page.id][name] = val; }); }); } - d20plus.engine._saveCustomOptions = (page) => { - const values = d20plus.engine._customOptions[page.id]; + d20plus.engine._savePageCustomOptions = (page) => { + const values = d20plus.engine._customPageOptions[page.id]; Object.entries(values).forEach(([name, val]) => { if (name === "_defaults") return; if (val && val !== values._defaults[name]) { @@ -693,43 +694,39 @@ function d20plusEngine () { /* eslint-disable */ // BEGIN ROLL20 CODE - window.Markdown.parse = function(e) { - { - var t = e - , n = [] - , i = []; - -1 != t.indexOf("\r\n") ? "\r\n" : -1 != t.indexOf("\n") ? "\n" : "" - } - return t = t.replace(/{{{([\s\S]*?)}}}/g, function(e) { - return n.push(e.substring(3, e.length - 3)), - "{{{}}}" + window.Markdown.parse = function(x) { + var g = x, l, t = [], m = [], v = g.indexOf(`\r\n`) != -1 ? `\r\n` : g.indexOf(`\n`) != -1 ? `\n` : ""; + return g = g.replace(/{{{([\s\S]*?)}}}/g, function(h) { + return t.push(h.substring(3, h.length - 3)), + "{{{}}}" }), - t = t.replace(new RegExp("
([\\s\\S]*?)
","gi"), function(e) { - return i.push(e.substring(5, e.length - 6)), - "
"
-				}),
-				// BEGIN MOD
-				t = t.replace(/~~(.*?)~~/g, OUT_STRIKE),
-				// END MOD
-				t = t.replace(/\*\*(.*?)\*\*/g, "$1"),
-				t = t.replace(/\*(.*?)\*/g, "$1"),
-				t = t.replace(/``(.*?)``/g, "$1"),
-				t = t.replace(/\[([^\]]+)\]\(([^)]+(\.png|\.gif|\.jpg|\.jpeg))\)/g, '$1'),
-				t = t.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'),
-				t = t.replace(new RegExp("
","g"), function() {
-					return "
" + i.shift() + "
" - }), - t = t.replace(/{{{}}}/g, function() { - return n.shift() - }) - }; + g = g.replace(new RegExp("
([\\s\\S]*?)
","gi"), function(h) { + return m.push(h.substring(5, h.length - 6)), + "
"
+			}),
+			// BEGIN MOD
+			g = g.replace(/~~(.*?)~~/g, OUT_STRIKE),
+			// END MOD
+			g = g.replace(/\*\*(.*?)\*\*/g, "$1"),
+			g = g.replace(/\*(.*?)\*/g, "$1"),
+			g = g.replace(/``(.*?)``/g, "$1"),
+			g = g.replace(/\[([^\]]+)\]\(([^)]+(\.png|\.gif|\.jpg|\.jpeg))\)/g, '$1'),
+			g = g.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1'),
+			g = g.replace(new RegExp("
","g"), function(h) {
+				return "
" + m.shift() + "
" + }), + g = g.replace(/{{{}}}/g, function(h) { + return t.shift() + }), + g + }, // END ROLL20 CODE /* eslint-enable */ // after a short delay, replace any old content in the chat setTimeout(() => { - $(`.message`).each(function () { + $(`.message.general`).each(function () { $(this).html($(this).html().replace(/~~(.*?)~~/g, OUT_STRIKE)) }) }, 2500); @@ -846,7 +843,7 @@ function d20plusEngine () { }; d20plus.engine.fixPolygonTool = () => { - if (d20plus.isOptedInNewUI) return; + if (!d20plus.newUIDisabled) return; // as of January 2024 newUI is always ON, so the below block is not needed $("#editor-wrapper").on("pointerdown", x => { d20plus.engine.leftClicked = x.which === 1 }); $("#editor-wrapper").on("pointerup", x => { d20plus.engine.leftClicked = false }); d20plus.ut.injectCode(d20.engine, "finishCurrentPolygon", (finishDrawing, params) => { diff --git a/js/base-util.js b/js/base-util.js index f4f65d34..a2b5ddfc 100644 --- a/js/base-util.js +++ b/js/base-util.js @@ -137,9 +137,10 @@ function baseUtil () { } else { d20plus.ut.showHardDickMessage(scriptName); } - d20plus.isOptedInNewUI && !isStreamer && d20plus.ut.sendHackerChat(` - betteR20 does not support the new UI preview at this moment! - Using it will make some betteR20 functionality unavailable. + d20plus.betaFeaturesEnabled && !isStreamer && d20plus.ut.sendHackerChat(` + betteR20 does not support the beta UI preview at this moment! + Using it will make some betteR20 or roll20 functionality unavailable. + If you experience problems with Page Settings, disable roll20 Beta Features. `); $boringProgress .before(`>all systems operational`)