HollowBond/Public/ecma/Models/ChunkModel.ecma.js

96 lines
3.1 KiB
JavaScript

"use strict";
const ChunkModel = (function(){
const ChunkModel = function(hollow_bond, inputs = {}, callback = null){
const self = this;
// Coordenadas enteras del Chunk en la rejilla macro
this.x = Common.get_value(["x", "cx"], inputs, 0);
this.y = Common.get_value(["y", "cy"], inputs, 0);
this.z = Common.get_value(["z", "cz"], inputs, 0);
this.id = `chunk_${self.x}_${self.y}_${self.z}`;
// Límites espaciales absolutos: From (xf, yf, zf) -> To (xt, yt, zt)
this.xf = this.x * hollow_bond.chunk_size;
this.yf = this.y * hollow_bond.chunk_size;
this.zf = this.z * hollow_bond.chunk_size;
this.xt = this.xf + hollow_bond.chunk_size;
this.yt = this.yf + hollow_bond.chunk_size;
this.zt = this.zf + hollow_bond.chunk_size;
// Colecciones lógicas contenidas en este Chunk
this.rooms = {};
this.frames = {};
this.holes = {};
this.stairs = {};
this.elevators = {};
this.neighbors = Common.get_value("neighbors", inputs, {
north : false,
south : false,
east : false,
west : false,
up : false,
down : false
});
// Índice de coordenadas discretas ocupadas por marcos
// this.frames_by_position = {};
// Lista de cajas de ocupación (AABB) registradas
this.occupancy = [];
const constructor = () => {
hollow_bond.builders.frames.generate_seam(self);
hollow_bond.builders.holes.generate_seam(self);
hollow_bond.builders.holes.generate_internal(self);
hollow_bond.builders.elevators.generate_seam(self);
hollow_bond.builders.elevators.generate_internal(self);
if(callback)
hollow_bond.builders.rooms.generate_asyncronous(self, callback);
else
hollow_bond.builders.rooms.generate(self);
};
this.is_occupied = (xf, yf, zf, xt, yt, zt) => {
for(const box of self.occupancy)
if(
xf < box.xt && xt > box.xf &&
yf < box.yt && yt > box.yf &&
zf < box.zt && zt > box.zf
)
return true;
return false;
};
this.occupy = (xf, yf, zf, xt, yt, zt, type, id) => {
self.occupancy.push({
xf : xf,
yf : yf,
zf : zf,
xt : xt,
yt : yt,
zt : zt,
type : type,
id : id
});
};
// const get_position_key = (key, x, y, z) => `${key}_${x}_${y}_${z}`;
// this.has_frame_at = (x, y, z) => !!self.frames_by_position[FrameModel.get_id(x, y, z)];
// this.get_frame_at = (x, y, z) => self.frames_by_position[FrameModel.get_id(x, y, z)] || null;
constructor();
};
// ChunkModel.get_position_key = (key, x, y, z) => `${key}_${x}_${y}_${z}`;
return ChunkModel;
})();