152 lines
6.7 KiB
JavaScript
152 lines
6.7 KiB
JavaScript
"use strict";
|
|
|
|
const NewGameView = (function(){
|
|
|
|
const NewGameView = function(hollow_bond){
|
|
|
|
const self = this;
|
|
let root_element = null;
|
|
|
|
/**
|
|
* Normaliza la entrada de semilla: enteros si son puros dígitos,
|
|
* o hash determinista de 32 bits para cadenas alfanuméricas.
|
|
*/
|
|
const parse_seed = raw => {
|
|
|
|
const clean = String(raw).trim();
|
|
|
|
if(/^\d+$/.test(clean))
|
|
return parseInt(clean, 10);
|
|
|
|
let hash = 0;
|
|
|
|
for(let i = 0; i < clean.length; i++)
|
|
hash = (hash << 5) - hash + clean.charCodeAt(i) | 0;
|
|
|
|
return Math.abs(hash);
|
|
};
|
|
|
|
this.destroy = () => {
|
|
if(root_element && root_element.parentNode){
|
|
root_element.remove();
|
|
root_element = null;
|
|
}
|
|
};
|
|
|
|
this.go = () => {
|
|
self.destroy();
|
|
|
|
// const default_seed = Math.floor(Math.random() * 10000000);
|
|
// const default_seed = 7229736;
|
|
// const default_seed = 9003770; // Bug en ascensor y paredes.
|
|
// const default_seed = 1501172; // Ascensor 1ª planta. Encerrado.
|
|
const default_seed = 8030220; // Ascensor 1ª planta.
|
|
|
|
// 7229736
|
|
console.log(default_seed);
|
|
|
|
root_element = hollow_bond.html(hollow_bond.item_self, ["div", {"class" : "new-game-modal"}, [
|
|
["div", {"class" : "new-game-box"}, [
|
|
["h2", {"data-i18n" : "new_game_title"}, hollow_bond.i18n.get("new_game_title", null, "Configuración de Partida")],
|
|
|
|
// Selector de Modo de Ejecución
|
|
["div", {"class" : "field-group"}, [
|
|
["label", {"data-i18n" : "mode_label"}, hollow_bond.i18n.get("mode_label", null, "Modo de Ejecución:")],
|
|
["select", {"class" : "select-input input-game-mode"}, [
|
|
["option", {"value" : "gameplay", "selected" : "selected"}, hollow_bond.i18n.get("mode_gameplay", null, "Partida Normal (Primera Persona)")],
|
|
["option", {"value" : "inspector"}, hollow_bond.i18n.get("mode_inspector", null, "Inspector de Pruebas (Capas/Pisos)")]
|
|
]]
|
|
]],
|
|
|
|
// Selector de altura del personaje
|
|
["div", {"class" : "field-group field-player-height"}, [
|
|
["label", {}, [
|
|
["span", {"data-i18n" : "player_height_label"}, hollow_bond.i18n.get("player_height_label", null, "Altura del personaje: ")],
|
|
["span", {"class" : "height-value"}, "1.75"],
|
|
["span", {}, " m"]
|
|
]],
|
|
["input", {
|
|
"type" : "range",
|
|
"min" : "1.30",
|
|
"max" : "2.35",
|
|
"step" : "0.01",
|
|
"value" : "1.75",
|
|
"class" : "range-input",
|
|
"oninput" : input => {
|
|
input.closest(".field-group").querySelector(".height-value").textContent = parseFloat(input.value).toFixed(2);
|
|
}
|
|
}]
|
|
]],
|
|
|
|
// Campo de semilla
|
|
["div", {"class" : "field-group"}, [
|
|
["label", {"data-i18n" : "seed_label"}, hollow_bond.i18n.get("seed_label", null, "Semilla:")],
|
|
["input", {
|
|
"type" : "text",
|
|
"class" : "text-input",
|
|
"value" : String(default_seed)
|
|
}]
|
|
]],
|
|
|
|
// Campo de Chunks máximos (0 = Infinito)
|
|
["div", {"class" : "field-group"}, [
|
|
["label", {}, [
|
|
["span", {"data-i18n" : "max_chunks_label"}, hollow_bond.i18n.get("max_chunks_label", null, "Máximo de Chunks: ")],
|
|
["span", {"class" : "max-chunks-desc"}, "(0 = Infinito)"]
|
|
]],
|
|
["input", {
|
|
"type" : "number",
|
|
"min" : "0",
|
|
"step" : "1",
|
|
"value" : "0",
|
|
"class" : "number-input input-max-chunks"
|
|
}]
|
|
]],
|
|
|
|
// Acciones
|
|
["div", {"class" : "modal-actions"}, [
|
|
["button", {
|
|
"class" : "menu-button",
|
|
"data-i18n" : "btn_start",
|
|
"onclick" : button => {
|
|
const box = button.closest(".new-game-box"),
|
|
mode = box.querySelector(".input-game-mode").value,
|
|
height = parseFloat(box.querySelector(".range-input").value) || 1.75,
|
|
raw_seed = box.querySelector(".text-input").value || default_seed,
|
|
final_seed = parse_seed(raw_seed),
|
|
maximum_chunks = parseInt(box.querySelector(".input-max-chunks").value) || 0;
|
|
|
|
self.destroy();
|
|
|
|
// 1. Generar mapa determinista
|
|
hollow_bond.map.generate(final_seed, maximum_chunks, () => {
|
|
// 2. Enrutamiento según el modo seleccionado
|
|
if(mode === "inspector"){
|
|
hollow_bond.inspector && hollow_bond.inspector.start();
|
|
} else {
|
|
hollow_bond.dungeon && hollow_bond.dungeon.start(height);
|
|
}
|
|
});
|
|
|
|
}
|
|
}, hollow_bond.i18n.get("btn_start", null, "Iniciar")],
|
|
|
|
["button", {
|
|
"class" : "menu-button",
|
|
"data-i18n" : "btn_back",
|
|
"onclick" : () => {
|
|
self.destroy();
|
|
hollow_bond.views.menu.go();
|
|
}
|
|
}, hollow_bond.i18n.get("btn_back", null, "Atrás")]
|
|
]]
|
|
]]
|
|
]])[0];
|
|
|
|
return self;
|
|
};
|
|
|
|
};
|
|
|
|
return NewGameView;
|
|
})(); |