"use strict"; const DifficultySelectView = (function(){ const DifficultySelectView = function(xgravity){ const self = this; let view_element = null; this.close = () => { if(view_element && view_element.parentNode){ view_element.parentNode.removeChild(view_element); view_element = null; } }; this.go = () => { self.close(); const is_game_active = xgravity.views.game && typeof xgravity.views.game.is_active === "function" ? xgravity.views.game.is_active() : false; const presets = xgravity.settings.get("difficulty_presets", null, {}); const current_diff = xgravity.settings.get("current_difficulty", null, "average"); // Lista ordenada de niveles const diff_keys = ["training", "newbie", "lazy", "average", "hard", "berserk", "insane"]; const diff_buttons = []; for(let i = 0; i < diff_keys.length; i++){ const key = diff_keys[i]; const preset = presets[key]; if(!preset) continue; const is_selected = (key === current_diff); diff_buttons.push([ "button", { class : `xg-btn xg-btn-diff ${is_selected ? "xg-btn-selected" : ""}`, "data-i18n" : preset.label_i18n || `diff_${key}`, onclick : () => { // 1. Guardar la dificultad seleccionada xgravity.settings.add({ current_difficulty : key }); // 2. Desmontar esta vista self.close(); // 3. Iniciar la partida limpia if(xgravity.views.game){ if(is_game_active){ xgravity.views.game.stop(); } xgravity.views.game.go(); } } } ]); } // Botón Volver (cierra esta vista y regresa al Menú Principal) diff_buttons.push([ "button", { class : "xg-btn xg-btn-back", "data-i18n" : "btn_back", onclick : () => { self.close(); if(xgravity.views.main_menu){ xgravity.views.main_menu.go(); } } } ]); const nodes = xgravity.html(xgravity.item_self, [ "div", { class : "xg-view xg-difficulty-select" }, [ ["h2", { class : "xg-subtitle", "data-i18n" : "opt_difficulty" }], ["div", { class : "xg-menu-list" }, diff_buttons] ] ]); view_element = nodes[0]; xgravity.i18n.update(); }; }; return DifficultySelectView; })();