"use strict"; const HollowBond = (function(){ const HollowBond = function(inputs = null){ const self = this, screen = {x : 0, y : 0}; let cells = 40, thread_interval = null, ids = {}; this.item_self = document; this.fps = 60; this.seed = 0; this.render_scale = 100; this.show_fps = true; this.gravity = 9.81; this.chunk_size = 50; this.chunk_frame_probability = .91; this.chunk_frame_step = 10; this.chunk_frame_maximum_gap = 25; this.maximum_chunks = 0; this.room_minimum_size = 2; this.room_maximum_size = 25; this.room_size_decay = .94; this.room_size_grow = .91; this.room_height = 3; this.room_minimum_distance_hole = 2; this.rooms_hole_probability_same = .9; this.room_padding = .1; this.room_free_cuts_minimum = 4; this.room_free_cuts_maximum = 12; this.frame_wall_probability = .35; this.frame_wall_decay = .8; this.frame_height = 2; this.frame_width = .8; this.frame_padding = .05; this.hole_seam_tries = 5; this.hole_minimum_size = 4; this.hole_maximum_size = 20; this.hole_minimum_height = 2; this.hole_maximum_height = 25; this.hole_size_decay = .75; this.hole_height_decay = .85; this.hole_margin = 2; this.hole_floor_step = 3; this.internal_hole_probability = .55; this.elevator_minimum_floors = 3; this.elevator_maximum_floors = 70; this.elevator_floors_decay = .95; this.elevator_size = 2; this.elevator_height = 2; this.elevator_padding = .1; this.elevator_margin_border = 2; this.elevator_margin_hole = 2; this.elevator_networks_count = 3; this.stairs_length = 4; this.stairs_width = 1; this.stairs_height = 2; this.stairs_padding = -1; this.stairs_probability = .9; this.horizontal_loaded_rooms_levels = 3; this.horizontal_unloaded_rooms_level = 5; this.settings = new SettingsManager(this); this.i18n = new I18NManager(this); this.hash = new HashManager(this); this.builders = { frames : new FramesBuilder(this), stairs : new StairsBuilder(this), holes : new HolesBuilder(this), elevators : new ElevatorsBuilder(this), rooms : new RoomsBuilder(this) }; this.map = new MapManager(this); this.themes = new ThemeManager(this); this.controls = { debug : new DebugControls(self), game : new GameControls(self) }; this.inspector = new InspectorManager(this); this.dungeon = new DungeonManager(this); this.views = { menu : new MenuView(this), new_game : new NewGameView(this), options : new OptionsView(this), credits : new CreditsView(this), fps : new FpsView(this) }; const constructor = () => { const position = self.settings.get("position", null, "body"); let target, preload = setInterval(() => { if(target = document.querySelector(position)){ clearInterval(preload); self.item_self = target.appendChild(document.createElement("div")); self.item_self.className = self.item_self.id = self.settings.get("class_name", inputs, "hollow-bond"); self.item_self.setAttribute("data-cells", cells = self.settings.get("cells", inputs, cells)); thread_interval = setInterval(thread, 1000 / self.fps); build(); }; }, self.fps = self.settings.get(["frames_per_second", "fps"], inputs, self.fps)); self.render_scale = self.settings.get("render_scale", inputs, self.render_scale); self.show_fps = self.settings.get("show_fps", inputs, self.show_fps); self.chunk_size = self.settings.get("chunk_size", inputs, self.chunk_size); self.chunk_frame_probability = self.settings.get("chunk_frame_probability", inputs, self.chunk_frame_probability); self.chunk_frame_step = self.settings.get("chunk_frame_step", inputs, self.chunk_frame_step); self.chunk_frame_maximum_gap = self.settings.get("chunk_frame_maximum_gap", inputs, self.chunk_frame_maximum_gap); self.maximum_chunks = self.settings.get("maximum_chunks", inputs, self.maximum_chunks); self.room_height = self.settings.get("room_height", inputs, self.room_height); self.room_padding = self.settings.get("room_padding", inputs, self.room_padding); self.room_minimum_size = self.settings.get("room_minimum_size", inputs, self.room_minimum_size); self.room_maximum_size = self.settings.get("room_maximum_size", inputs, self.room_maximum_size); self.frame_height = self.settings.get("frame_height", inputs, self.frame_height); self.frame_width = self.settings.get("frame_width", inputs, self.frame_width); self.hole_maximum_height = self.settings.get("hole_maximum_height", inputs, self.hole_maximum_height); self.hole_minimum_height = self.settings.get("hole_minimum_height", inputs, self.hole_minimum_height); self.hole_maximum_size = self.settings.get("hole_maximum_size", inputs, self.hole_maximum_size); self.hole_minimum_size = self.settings.get("hole_minimum_size", inputs, self.hole_minimum_size); self.hole_seam_tries = self.settings.get("hole_seam_tries", inputs, self.hole_seam_tries); self.hole_size_decay = self.settings.get("hole_size_decay", inputs, self.hole_size_decay); self.hole_height_decay = self.settings.get("hole_height_decay", inputs, self.hole_height_decay); self.internal_hole_probability = self.settings.get("internal_hole_probability", inputs, self.internal_hole_probability); Common.SCSS(SCSS); }; const thread = () => { if(screen.x != self.item_self.offsetWidth || screen.y != self.item_self.offsetHeight){ screen.x = self.item_self.offsetWidth; screen.y = self.item_self.offsetHeight; self.item_self.style.fontSize = ((screen.x < screen.y ? screen.x : screen.y) / cells) + "px"; }; }; const build = () => { self.set_seed(self.settings.get("default_seed", null, null)); self.views.menu.go(); }; this.set_seed = seed => { self.seed = ( seed === null || seed === undefined ? Common.random() : typeof seed == "string" ? Common.string_to_integer(seed) : seed | 0); }; this.html = (...inputs) => { const fragment = new DocumentFragment(), master = ( inputs[0] && (inputs[0].tagName || inputs[0].nodeName) ? inputs[0] : typeof inputs[0] == "string" ? document.querySelector(inputs[0]) : null), items = []; (master ? inputs.slice(1) : inputs).forEach(subinputs => { if(subinputs && (subinputs.tagName || subinputs.nodeName)) fragment.appendChild(subinputs); else if(typeof subinputs == "string") fragment.appendChild(document.createTextNode(subinputs)); else if(subinputs instanceof Array){ const [tag, attributes, children] = subinputs.concat([null, null]).slice(0, 3), item = document.createElement(tag); attributes && attributes.constructor == Object && Object.entries(attributes).forEach(([key, value]) => { if(/^on[_\-]?/i.test(key) && typeof value == "function") item.addEventListener(key.replace(/^on[_\-]?/i, "").replace(/[^a-z0-9]+/gi, "").toLowerCase(), event => { value(item, event); }); else if(value !== null) item.setAttribute(key.replace(/[^a-z0-9]+/gi, "-"), value); }); if(children instanceof Array) self.html(...children).forEach(child => item.appendChild(child)); else if(typeof children == "string") item.innerHTML += children; fragment.appendChild(item); }; }); items.push(...fragment.childNodes); master && master.appendChild(fragment); return items; }; this.get_id = (name = "item") => `${name}_${ids[name] = (ids[name] || 0) + 1}`; constructor(); }; return HollowBond; })();