feat: assistant - ability to toggle assistant

This commit is contained in:
Azgaar 2024-09-01 16:40:51 +02:00
parent cb34491a17
commit f45c8040e1
2 changed files with 12 additions and 3 deletions

14
main.js
View file

@ -317,7 +317,7 @@ async function generateMapOnLoad() {
applyPreset(); // apply saved layers preset
fitMapToScreen();
focusOn(); // based on searchParams focus on point, cell or burg from MFCG
loadAssistant();
toggleAssistant();
}
// focus on coordinates, cell or burg provided in searchParams
@ -367,9 +367,17 @@ function focusOn() {
}
}
function loadAssistant() {
let isAssistantLoaded = false;
function toggleAssistant() {
const assistantContainer = byId("chat-widget-container");
const showAssistant = byId("azgaarAssistant").value === "show";
if (showAssistant) import("./libs/openwidget.min.js");
if (showAssistant) {
if (isAssistantLoaded) assistantContainer.style.display = "block";
else import("./libs/openwidget.min.js").then(() => (isAssistantLoaded = true));
} else if (isAssistantLoaded) {
assistantContainer.style.display = "none";
}
}
// find burg for MFCG and focus on it

View file

@ -148,6 +148,7 @@ optionsContent.addEventListener("change", event => {
else if (id === "yearInput") changeYear();
else if (id === "eraInput") changeEra();
else if (id === "stateLabelsModeInput") options.stateLabelsMode = value;
else if (id === "azgaarAssistant") toggleAssistant();
});
optionsContent.addEventListener("click", event => {