"use strict"; const ElevatorModel = (function(){ const DIRECTIONS = { north : {x : 0, z : -1}, south : {x : 0, z : 1}, east : {x : 1, z : 0}, west : {x : -1, z : 0} }; const ElevatorModel = function(hollow_bond, inputs = {}){ const self = this; this.id = ElevatorModel.get_id(inputs.x, inputs.y, inputs.z); this.group_id = Common.get_value("group_id", inputs, ""); this.x = Common.get_value("x", inputs, 0) | 0; this.y = Common.get_value("y", inputs, 0) | 0; this.z = Common.get_value("z", inputs, 0) | 0; this.floor = Common.get_value("floor", inputs, 0) | 0; this.width = hollow_bond.elevator_size; this.height = hollow_bond.elevator_height; this.depth = hollow_bond.elevator_size; this.padding = hollow_bond.elevator_padding; // Orientación de la puerta: "north", "south", "east", "west" this.facing = Common.get_value("facing", inputs, "north"); // Rango de pisos y habitaciones asociadas this.floors_from = Common.get_value("floors_from", inputs, 0) | 0; this.floors_count = Common.get_value("floors_count", inputs, 1) | 0; this.rooms = Common.get_value("rooms", inputs, []); this.room = null; /** * Obtiene la habitación asociada al piso destino mediante indexado relativo. * @param {number} floor_number * @returns {RoomModel|null} */ this.get_room_at_floor = floor_number => { const index = floor_number - self.floors_from; return (index >= 0 && index < self.rooms.length) ? self.rooms[index] : null; }; /** * Devuelve las coordenadas de la casilla frente a la puerta del ascensor. */ this.get_door_threshold = () => { const direction = DIRECTIONS[self.facing] || DIRECTIONS.north; return { x : self.x + (direction.x > 0 ? self.width : (direction.x < 0 ? -1 : 0)), z : self.z + (direction.z > 0 ? self.depth : (direction.z < 0 ? -1 : 0)), facing : self.facing }; }; }; ElevatorModel.get_id = (x, y, z) => `elevator_${x}_${y}_${z}`; return ElevatorModel; })();