Skip to content

Commit

Permalink
Fixed move offsets (#713)
Browse files Browse the repository at this point in the history
* Fixed move offsets

* Formatting

* More formatting

* Some more Formatting
  • Loading branch information
Variable-ind authored Jul 3, 2022
1 parent 8a922a2 commit feb68a2
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/Tools/Move.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func _input(event: InputEvent) -> void:
if Global.current_project.has_selection:
var prev_pos = selection_node.big_bounding_rectangle.position
selection_node.big_bounding_rectangle.position = prev_pos.snapped(grid_size)
# The First time transform_snap_grid is enabled then _snap_position() is not called
# and selection had wrong offset so i chose to do selection offsetting here
var grid_offset = Vector2(Global.grid_offset_x, Global.grid_offset_y)
grid_offset = Vector2(
fmod(grid_offset.x, grid_size.x), fmod(grid_offset.y, grid_size.y)
)
selection_node.big_bounding_rectangle.position += grid_offset
selection_node.marching_ants_outline.offset += (
selection_node.big_bounding_rectangle.position
- prev_pos
Expand Down Expand Up @@ -97,9 +104,19 @@ func _snap_position(position: Vector2) -> Vector2:
if _snap_to_grid: # Snap to grid
var grid_size := Vector2(Global.grid_width, Global.grid_height)
position = position.snapped(grid_size)
var grid_offset = Vector2(Global.grid_offset_x, Global.grid_offset_y)
grid_offset = Vector2(fmod(grid_offset.x, grid_size.x), fmod(grid_offset.y, grid_size.y))
position += grid_offset
# The part below only corrects the offset for situations when there is no selection
# Offsets when there is selection is controlled in _input() function
if !Global.current_project.has_selection:
var move_offset := Vector2.ZERO
move_offset.x = (
_start_pos.x
- int(_start_pos.x / Global.grid_width) * Global.grid_width
)
move_offset.y = (
_start_pos.y
- int(_start_pos.y / Global.grid_height) * Global.grid_height
)
position += move_offset

return position

Expand Down

0 comments on commit feb68a2

Please sign in to comment.