1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-12 16:53:07 +00:00

formatting

This commit is contained in:
Variable 2024-10-15 17:18:28 +05:00
parent 8990ff2816
commit d34c7739fb
5 changed files with 17 additions and 29 deletions

View file

@ -749,6 +749,7 @@ func update_grids(grids_data: Dictionary):
for grid_idx in grids_data.size(): for grid_idx in grids_data.size():
Grid.new(grids_data[grid_idx]) # gets auto added to grids array Grid.new(grids_data[grid_idx]) # gets auto added to grids array
func _initialize_keychain() -> void: func _initialize_keychain() -> void:
Keychain.config_file = config_cache Keychain.config_file = config_cache
Keychain.actions = { Keychain.actions = {

View file

@ -1,20 +1,11 @@
extends GridContainer extends GridContainer
var grid_preferences: Array[GridPreference] = [ var grid_preferences: Array[GridPreference] = [
GridPreference.new( GridPreference.new("grid_type", "GridType", "selected", Global.GridTypes.CARTESIAN),
"grid_type", "GridType", "selected", Global.GridTypes.CARTESIAN
),
GridPreference.new("grid_size", "GridSizeValue", "value", Vector2i(2, 2)), GridPreference.new("grid_size", "GridSizeValue", "value", Vector2i(2, 2)),
GridPreference.new( GridPreference.new("isometric_grid_size", "IsometricGridSizeValue", "value", Vector2i(16, 8)),
"isometric_grid_size", "IsometricGridSizeValue", "value", Vector2i(16, 8)
),
GridPreference.new("grid_offset", "GridOffsetValue", "value", Vector2i.ZERO), GridPreference.new("grid_offset", "GridOffsetValue", "value", Vector2i.ZERO),
GridPreference.new( GridPreference.new("grid_draw_over_tile_mode", "GridDrawOverTileMode", "button_pressed", false),
"grid_draw_over_tile_mode",
"GridDrawOverTileMode",
"button_pressed",
false
),
GridPreference.new("grid_color", "GridColor", "color", Color.BLACK), GridPreference.new("grid_color", "GridColor", "color", Color.BLACK),
] ]
@ -67,9 +58,7 @@ func _ready() -> void:
var node := get_node(pref.node_path) var node := get_node(pref.node_path)
var restore_default_button := RestoreDefaultButton.new() var restore_default_button := RestoreDefaultButton.new()
restore_default_button.pressed.connect( restore_default_button.pressed.connect(
_on_Grid_Pref_value_changed.bind( _on_Grid_Pref_value_changed.bind(pref.default_value, pref, restore_default_button)
pref.default_value, pref, restore_default_button
)
) )
restore_default_button.setting_name = pref.prop_name restore_default_button.setting_name = pref.prop_name
restore_default_button.value_type = pref.value_type restore_default_button.value_type = pref.value_type
@ -82,9 +71,7 @@ func _ready() -> void:
match pref.value_type: match pref.value_type:
"button_pressed": "button_pressed":
node.toggled.connect( node.toggled.connect(_on_Grid_Pref_value_changed.bind(pref, restore_default_button))
_on_Grid_Pref_value_changed.bind(pref, restore_default_button)
)
"value": "value":
node.value_changed.connect( node.value_changed.connect(
_on_Grid_Pref_value_changed.bind(pref, restore_default_button) _on_Grid_Pref_value_changed.bind(pref, restore_default_button)
@ -101,7 +88,6 @@ func _ready() -> void:
grid_selected = 0 grid_selected = 0
func _on_Grid_Pref_value_changed(value, pref: GridPreference, button: RestoreDefaultButton) -> void: func _on_Grid_Pref_value_changed(value, pref: GridPreference, button: RestoreDefaultButton) -> void:
var grids: Dictionary = Global.config_cache.get_value( var grids: Dictionary = Global.config_cache.get_value(
"preferences", "grids", {0: create_default_properties()} "preferences", "grids", {0: create_default_properties()}
@ -117,9 +103,7 @@ func _on_Grid_Pref_value_changed(value, pref: GridPreference, button: RestoreDef
if typeof(value) == TYPE_COLOR: if typeof(value) == TYPE_COLOR:
disable = value.is_equal_approx(default_value) disable = value.is_equal_approx(default_value)
disable_restore_default_button(button, disable) disable_restore_default_button(button, disable)
Global.config_cache.set_value( Global.config_cache.set_value("preferences", "grids", grids)
"preferences", "grids", grids
)
func _on_grids_count_value_changed(value: float) -> void: func _on_grids_count_value_changed(value: float) -> void:
@ -162,7 +146,7 @@ func add_remove_select_button(grid_idx: int, remove := false):
var select_button = Button.new() var select_button = Button.new()
select_button.text = str(grid_idx) select_button.text = str(grid_idx)
grids_select_container.add_child(select_button) grids_select_container.add_child(select_button)
select_button.pressed.connect(func() : grid_selected = grid_idx) select_button.pressed.connect(func(): grid_selected = grid_idx)
else: else:
if grid_idx < grids_select_container.get_child_count(): if grid_idx < grids_select_container.get_child_count():
grids_select_container.get_child(grid_idx).queue_free() grids_select_container.get_child(grid_idx).queue_free()

View file

@ -149,7 +149,9 @@ func snap_position(pos: Vector2) -> Vector2:
pos = grid_point.floor() pos = grid_point.floor()
if Global.snap_to_rectangular_grid_center: if Global.snap_to_rectangular_grid_center:
var grid_center := pos.snapped(Global.grids[0].grid_size) + Vector2(Global.grids[0].grid_size / 2) var grid_center := (
pos.snapped(Global.grids[0].grid_size) + Vector2(Global.grids[0].grid_size / 2)
)
grid_center += Vector2(Global.grids[0].grid_offset) grid_center += Vector2(Global.grids[0].grid_offset)
# keeping grid_center as is would have been fine but this adds extra accuracy as to # keeping grid_center as is would have been fine but this adds extra accuracy as to
# which snap point (from the list below) is closest to mouse and occupy THAT point # which snap point (from the list below) is closest to mouse and occupy THAT point

View file

@ -113,10 +113,12 @@ func _snap_position(pos: Vector2) -> Vector2:
if !Global.current_project.has_selection: if !Global.current_project.has_selection:
var move_offset := Vector2.ZERO var move_offset := Vector2.ZERO
move_offset.x = ( move_offset.x = (
_start_pos.x - (_start_pos.x / Global.grids[0].grid_size.x) * Global.grids[0].grid_size.x _start_pos.x
- (_start_pos.x / Global.grids[0].grid_size.x) * Global.grids[0].grid_size.x
) )
move_offset.y = ( move_offset.y = (
_start_pos.y - (_start_pos.y / Global.grids[0].grid_size.y) * Global.grids[0].grid_size.y _start_pos.y
- (_start_pos.y / Global.grids[0].grid_size.y) * Global.grids[0].grid_size.y
) )
pos += move_offset pos += move_offset

View file

@ -3,6 +3,7 @@ extends Node2D
var unique_rect_lines := PackedVector2Array() var unique_rect_lines := PackedVector2Array()
var unique_iso_lines := PackedVector2Array() var unique_iso_lines := PackedVector2Array()
func _ready() -> void: func _ready() -> void:
Global.project_switched.connect(queue_redraw) Global.project_switched.connect(queue_redraw)
@ -67,9 +68,7 @@ func _draw_isometric_grid(grid_index: int, target_rect: Rect2i) -> void:
var cell_size: Vector2 = grid.isometric_grid_size var cell_size: Vector2 = grid.isometric_grid_size
var max_cell_count: Vector2 = Vector2(target_rect.size) / cell_size var max_cell_count: Vector2 = Vector2(target_rect.size) / cell_size
var origin_offset: Vector2 = Vector2(grid.grid_offset - target_rect.position).posmodv( var origin_offset: Vector2 = Vector2(grid.grid_offset - target_rect.position).posmodv(cell_size)
cell_size
)
# lines ↗↗↗ (from bottom-left to top-right) # lines ↗↗↗ (from bottom-left to top-right)
var per_cell_offset: Vector2 = cell_size * Vector2(1, -1) var per_cell_offset: Vector2 = cell_size * Vector2(1, -1)