36 lines
974 B
JavaScript
36 lines
974 B
JavaScript
// The map-mode picker: a small popover of radio options anchored above the
|
|
// Map modes button. It only reports the chosen mode; the game screen applies
|
|
// it, so the modal stays free of map state.
|
|
|
|
export class MapModesModal {
|
|
constructor() {
|
|
this.$popover = $("#map-modes-popover");
|
|
this.onMode = () => {};
|
|
this.$popover.on("change", "input[name='map-mode']", (event) => {
|
|
const mode = $(event.currentTarget).val();
|
|
this.close();
|
|
this.onMode(mode);
|
|
});
|
|
}
|
|
|
|
isShowing() {
|
|
return this.$popover.length > 0 && !this.$popover.hasClass("hidden");
|
|
}
|
|
|
|
show(current) {
|
|
const $inputs = this.$popover.find("input[name='map-mode']");
|
|
$inputs.prop("checked", false);
|
|
$inputs.filter(`[value='${current}']`).prop("checked", true);
|
|
this.$popover.removeClass("hidden");
|
|
}
|
|
|
|
toggle(current) {
|
|
if (this.isShowing()) this.close();
|
|
else this.show(current);
|
|
}
|
|
|
|
close() {
|
|
this.$popover.addClass("hidden");
|
|
}
|
|
}
|