ref: a90bb4a4ef9fac5c6185b763aa2cafba9d7c6b12
parent: 5a225bf585ba302dbae1eca567b2070c67ea2981
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sun Nov 13 09:05:55 EST 2022
js: Better handling of games without presets and/or solve Games with neither presets nor configuration (which may only be the Null Game) have been slightly broken since the introduction of hierarchical preset menus, in that the code to remove the "Type..." menu stopped being called then. My switch to using radio buttons in menus then broke them utterly because it's not possible to set the value of an empty radio group, causing a crash at startup. Fix this by detected when there's no preset menu, removing the item from the menu bar, and setting the variable that's meant to indicate this has been done. The solve button problem was more subtle, in that only the <button> was being hidden and not the <li> containing it, which led to the right border of the menu bar being two pixels thick. Switch to fully removing the <li> from the DOM, like we now do with the presets menu, since that also makes my keyboard handler (in another branch) simpler.
--- a/emcc.c
+++ b/emcc.c
@@ -974,14 +974,17 @@
if (thegame.can_configure)
js_add_preset(0, "Custom", -1);
- have_presets_dropdown = true;
+ have_presets_dropdown = npresets > 0 || thegame.can_configure;
- /*
- * Now ensure the appropriate element of the presets menu
- * starts off selected, in case it isn't the first one in the
- * list (e.g. Slant).
- */
- select_appropriate_preset();
+ if (have_presets_dropdown)
+ /*
+ * Now ensure the appropriate element of the presets menu
+ * starts off selected, in case it isn't the first one in the
+ * list (e.g. Slant).
+ */
+ select_appropriate_preset();
+ else
+ js_remove_type_dropdown();
}
/*
--- a/emcclib.js
+++ b/emcclib.js
@@ -45,7 +45,9 @@
* provides neither presets nor configurability.
*/
js_remove_type_dropdown: function() {
- gametypelist.style.display = "none";
+ var gametypeitem = gametypelist.closest("li");
+ if (gametypeitem === null) return;
+ gametypeitem.parentNode.removeChild(gametypeitem);
},
/*
@@ -55,7 +57,11 @@
* time if the game doesn't support an in-game solve function.
*/
js_remove_solve_button: function() {
- document.getElementById("solve").style.display = "none";
+ var solvebutton = document.getElementById("solve");
+ if (solvebutton === null) return;
+ var solveitem = solvebutton.closest("li");
+ if (solveitem === null) return;
+ solveitem.parentNode.removeChild(solveitem);
},
/*