|
|
|
@ -136,6 +136,7 @@ Mapeate.Mapas = function(mapeate, entradas){ |
|
|
|
|
tipos[clave] = { |
|
|
|
|
url : nuevos_tipos[clave].url,
|
|
|
|
|
clase : nuevos_tipos[clave].clase,
|
|
|
|
|
niveles_ocultables : nuevos_tipos[clave].niveles_ocultables,
|
|
|
|
|
datos : null,
|
|
|
|
|
ok : false |
|
|
|
|
}; |
|
|
|
@ -225,21 +226,25 @@ Mapeate.Mapas = function(mapeate, entradas){ |
|
|
|
|
cache[mapas[clave].url] = datos; |
|
|
|
|
mapa.datos = datos; |
|
|
|
|
|
|
|
|
|
construir(mapa, seleccion); |
|
|
|
|
construir(mapa, niveles, seleccion); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
else
|
|
|
|
|
construir(mapa, seleccion); |
|
|
|
|
construir(mapa, niveles, seleccion); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const construir = (datos, seleccion) => { |
|
|
|
|
const construir = (datos, niveles, seleccion) => { |
|
|
|
|
|
|
|
|
|
const juego = mapeate.si_mismo.querySelector(".juego"),
|
|
|
|
|
mapa = juego.querySelector(".mapa section"); |
|
|
|
|
mapa = juego.querySelector(".mapa section"),
|
|
|
|
|
menu = mapeate.si_mismo.querySelector(".juego .objetivos ul"); |
|
|
|
|
|
|
|
|
|
mapa.innerHTML = (` |
|
|
|
|
<div class="` + datos.nombre + `" data-clase="` + datos.clase + `">` + datos.datos + `</div> |
|
|
|
|
<div class="` + datos.nombre + `" data-clase="` + datos.clase + `"` + [0, 1, 2, 3].map(i => (
|
|
|
|
|
` data-nivel-` + i + `-ocultable="` + datos.niveles_ocultables.includes(i) + `"` +
|
|
|
|
|
` data-nivel-` + i + `="` + niveles.includes(i) + `"` |
|
|
|
|
)).join("") + `>` + datos.datos + `</div>
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
mapeate.si_mismo.querySelector(".menu-mapas").setAttribute("data-visible", false); |
|
|
|
@ -256,7 +261,31 @@ Mapeate.Mapas = function(mapeate, entradas){ |
|
|
|
|
tamano_cache.x = 0; |
|
|
|
|
tamano_cache.y = 0; |
|
|
|
|
|
|
|
|
|
svg.querySelectorAll("[data-habilitado").forEach(elemento => elemento.setAttribute("data-habilitado", seleccion.includes(elemento.getAttribute("data-objetivo")))); |
|
|
|
|
svg.querySelectorAll("[data-habilitado]").forEach(elemento => { |
|
|
|
|
|
|
|
|
|
let clon = elemento; |
|
|
|
|
const clave = elemento.getAttribute("data-objetivo"); |
|
|
|
|
|
|
|
|
|
while(clon && clon.hasAttribute){ |
|
|
|
|
if(clon.tagName.toLowerCase() == "svg") |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
const objetivo = clon.getAttribute("data-objetivo"); |
|
|
|
|
|
|
|
|
|
if(objetivo != clave && seleccion.includes(objetivo)){ |
|
|
|
|
|
|
|
|
|
const opcion = menu.querySelector("[data-clave=" + clave + "]"); |
|
|
|
|
|
|
|
|
|
opcion && opcion.remove(); |
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
}; |
|
|
|
|
clon = clon.parentNode; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
elemento.setAttribute("data-habilitado", seleccion.includes(elemento.getAttribute("data-objetivo"))) |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
mapeate.si_mismo.querySelectorAll(".juego fieldset:not(.mapa)").forEach(campo => campo.innerHTML += mapeate.vistas.coger("posicionador")); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
@ -279,6 +308,8 @@ Mapeate.Mapas = function(mapeate, entradas){ |
|
|
|
|
this.ocultar_seleccion = (elemento, evento) => mapeate.si_mismo.querySelector(".juego .elemento section").innerText = ""; |
|
|
|
|
|
|
|
|
|
this.elegir = (elemento, evento) => { |
|
|
|
|
if(elemento.getAttribute("data-habilitado") == "false") |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
const clave = elemento.getAttribute("data-objetivo"),
|
|
|
|
|
seleccionado = mapeate.si_mismo.querySelector(".juego .objetivos [data-seleccionado=true][data-ok=false]"); |
|
|
|
@ -287,7 +318,19 @@ Mapeate.Mapas = function(mapeate, entradas){ |
|
|
|
|
mapeate.alerta("Seleccionad objetivo."); |
|
|
|
|
else if(seleccionado.getAttribute("data-clave") == clave){ |
|
|
|
|
|
|
|
|
|
const siguiente = seleccionado.parentNode.querySelector("[data-seleccionado=false][data-ok=false"); |
|
|
|
|
const opciones = [...seleccionado.parentNode.querySelectorAll("li")]; |
|
|
|
|
let siguiente = null,
|
|
|
|
|
preparado = false; |
|
|
|
|
|
|
|
|
|
[0, 1].some(() => opciones.some(nuevo => { |
|
|
|
|
if(preparado){ |
|
|
|
|
if(nuevo.getAttribute("data-seleccionado") == "false" && nuevo.getAttribute("data-ok") == "false"){ |
|
|
|
|
siguiente = nuevo; |
|
|
|
|
return true; |
|
|
|
|
}; |
|
|
|
|
}else if(nuevo.getAttribute("data-clave") == clave) |
|
|
|
|
preparado = true; |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
seleccionado.setAttribute("data-seleccionado", false); |
|
|
|
|
seleccionado.setAttribute("data-ok", true); |
|
|
|
@ -296,7 +339,7 @@ Mapeate.Mapas = function(mapeate, entradas){ |
|
|
|
|
|
|
|
|
|
if(siguiente){ |
|
|
|
|
siguiente.setAttribute("data-seleccionado", true); |
|
|
|
|
seleccionado.parentNode.parentNode.scrollTop = seleccionado.offsetTop - (seleccionado.parentNode.parentNode.offsetHeight / 2); |
|
|
|
|
seleccionado.parentNode.parentNode.scrollTop = siguiente.offsetTop - (siguiente.offsetHeight / 2) - (siguiente.parentNode.parentNode.offsetHeight / 2); |
|
|
|
|
}else
|
|
|
|
|
mapeate.alerta("¡Has ganado!", () => self.volver_al_menu(elemento, evento)); |
|
|
|
|
|
|
|
|
|