HollowBond/Public/ecma/Models/FrameModel.ecma.js

47 lines
1.4 KiB
JavaScript

"use strict";
const FrameModel = (function(){
const FrameModel = function(hollow_bond, inputs = {}){
const self = this;
this.x = Common.get_value("x", inputs, 0);
this.y = Common.get_value("y", inputs, 0);
this.z = Common.get_value("z", inputs, 0);
this.id = FrameModel.get_id(self.x, self.y, self.z);
this.axis = Common.get_value("axis", inputs, "horizontal");
this.rooms = Common.get_value("rooms", inputs, [null, null]);
this.width = hollow_bond.frame_width;
this.height = hollow_bond.frame_height;
this.padding = hollow_bond.frame_padding + hollow_bond.room_padding;
this.size = (
this.axis == "horizontal" ? {x : self.width, z : self.padding * 2} :
{x : self.padding * 2, z : self.width});
this.connect_room = room_id => {
if(self.rooms.includes(room_id))
return;
self.rooms.some((room, i) => {
if(room === null){
self.rooms[i] = room_id;
return true;
};
return false;
});
};
this.get_world_position = () =>({
x : self.x,
y : self.y * self.height,
z : self.z
});
};
FrameModel.get_id = (x, y, z) => `frame_${x | 0}_${y | 0}_${z | 0}`;
return FrameModel;
})();