mirror of
https://github.com/beestat/app.git
synced 2025-05-24 02:14:03 -04:00
Clamped rooms, walls, and points to the grid bounds
This commit is contained in:
parent
db6cb0d1f4
commit
6b9fd70b6c
@ -264,6 +264,7 @@ beestat.component.floor_plan.prototype.set_draggable_ = function() {
|
||||
// Deselect when clicking on the background.
|
||||
if (
|
||||
self.parent_.contains(e.target) &&
|
||||
self.drag_start_mouse_ !== undefined &&
|
||||
e.clientX === self.drag_start_mouse_.x &&
|
||||
e.clientY === self.drag_start_mouse_.y
|
||||
) {
|
||||
|
@ -121,7 +121,7 @@ beestat.component.floor_plan_entity.point.prototype.set_room = function(room) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the x and y positions of this entity.
|
||||
* Set the x and y positions of this entity. Clamps to the edges of the grid.
|
||||
*
|
||||
* @param {number} x The x position of this entity.
|
||||
* @param {number} y The y position of this entity.
|
||||
@ -129,12 +129,19 @@ beestat.component.floor_plan_entity.point.prototype.set_room = function(room) {
|
||||
* @return {beestat.component.floor_plan_entity.point} This.
|
||||
*/
|
||||
beestat.component.floor_plan_entity.point.prototype.set_xy = function(x, y) {
|
||||
let clamped_x = x + this.room_.get_x();
|
||||
let clamped_y = y + this.room_.get_y();
|
||||
|
||||
if (x !== null) {
|
||||
this.point_.x = Math.round(x);
|
||||
clamped_x = Math.min(clamped_x, (this.floor_plan_.get_grid_pixels() / 2));
|
||||
clamped_x = Math.max(clamped_x, -(this.floor_plan_.get_grid_pixels() / 2));
|
||||
this.point_.x = Math.round(clamped_x - this.room_.get_x());
|
||||
}
|
||||
|
||||
if (y !== null) {
|
||||
this.point_.y = Math.round(y);
|
||||
clamped_y = Math.min(clamped_y, (this.floor_plan_.get_grid_pixels() / 2));
|
||||
clamped_y = Math.max(clamped_y, -(this.floor_plan_.get_grid_pixels() / 2));
|
||||
this.point_.y = Math.round(clamped_y - this.room_.get_y());
|
||||
}
|
||||
|
||||
this.update_rect_();
|
||||
|
@ -354,7 +354,7 @@ beestat.component.floor_plan_entity.room.prototype.set_group = function(group) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the x and y positions of this entity.
|
||||
* Set the x and y positions of this entity. Clamps to the edges of the grid.
|
||||
*
|
||||
* @param {number} x The x position of this entity.
|
||||
* @param {number} y The y position of this entity.
|
||||
@ -362,10 +362,32 @@ beestat.component.floor_plan_entity.room.prototype.set_group = function(group) {
|
||||
* @return {beestat.component.floor_plan_entity} This.
|
||||
*/
|
||||
beestat.component.floor_plan_entity.room.prototype.set_xy = function(x, y) {
|
||||
this.room_.x = Math.round(x);
|
||||
this.room_.y = Math.round(y);
|
||||
let clamped_x = x;
|
||||
let clamped_y = y;
|
||||
|
||||
return beestat.component.floor_plan_entity.prototype.set_xy.apply(this, arguments);
|
||||
let min_x = 0;
|
||||
let max_x = 0;
|
||||
let min_y = 0;
|
||||
let max_y = 0;
|
||||
this.room_.points.forEach(function(point) {
|
||||
max_x = Math.max(max_x, point.x);
|
||||
max_y = Math.max(max_y, point.y);
|
||||
});
|
||||
clamped_x = Math.min(x, (this.floor_plan_.get_grid_pixels() / 2) - max_x);
|
||||
clamped_y = Math.min(y, (this.floor_plan_.get_grid_pixels() / 2) - max_y);
|
||||
clamped_x = Math.max(clamped_x, -(this.floor_plan_.get_grid_pixels() / 2) + min_x);
|
||||
clamped_y = Math.max(clamped_y, -(this.floor_plan_.get_grid_pixels() / 2) + min_y);
|
||||
|
||||
this.room_.x = Math.round(clamped_x);
|
||||
this.room_.y = Math.round(clamped_y);
|
||||
|
||||
return beestat.component.floor_plan_entity.prototype.set_xy.apply(
|
||||
this,
|
||||
[
|
||||
clamped_x,
|
||||
clamped_y
|
||||
]
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -299,7 +299,7 @@ beestat.component.floor_plan_entity.wall.prototype.set_room = function(room) {
|
||||
|
||||
/**
|
||||
* Set the x and y positions of this entity. This just updates the points as
|
||||
* the entity itself is not translated.
|
||||
* the entity itself is not translated. Clamps to the edges of the grid.
|
||||
*
|
||||
* @param {number} x The x position of this entity.
|
||||
* @param {number} y The y position of this entity.
|
||||
@ -307,14 +307,23 @@ beestat.component.floor_plan_entity.wall.prototype.set_room = function(room) {
|
||||
* @return {beestat.component.floor_plan_entity.wall} This.
|
||||
*/
|
||||
beestat.component.floor_plan_entity.wall.prototype.set_xy = function(x, y) {
|
||||
let clamped_x = x + this.room_.get_x();
|
||||
let clamped_y = y + this.room_.get_y();
|
||||
|
||||
if (x !== null) {
|
||||
this.point_1_.x = Math.round(x);
|
||||
this.point_2_.x = Math.round(x);
|
||||
clamped_x = Math.min(clamped_x, (this.floor_plan_.get_grid_pixels() / 2));
|
||||
clamped_x = Math.max(clamped_x, -(this.floor_plan_.get_grid_pixels() / 2));
|
||||
|
||||
this.point_1_.x = Math.round(clamped_x - this.room_.get_x());
|
||||
this.point_2_.x = Math.round(clamped_x - this.room_.get_x());
|
||||
}
|
||||
|
||||
if (y !== null) {
|
||||
this.point_1_.y = Math.round(y);
|
||||
this.point_2_.y = Math.round(y);
|
||||
clamped_y = Math.min(clamped_y, (this.floor_plan_.get_grid_pixels() / 2));
|
||||
clamped_y = Math.max(clamped_y, -(this.floor_plan_.get_grid_pixels() / 2));
|
||||
|
||||
this.point_1_.y = Math.round(clamped_y - this.room_.get_y());
|
||||
this.point_2_.y = Math.round(clamped_y - this.room_.get_y());
|
||||
}
|
||||
|
||||
return this;
|
||||
|
Loading…
x
Reference in New Issue
Block a user