Skip to content

Commit 219e7ff

Browse files
Fix notes corner case failed tests
Test failed if the cam has been in left-top corner of the map
1 parent c7d0937 commit 219e7ff

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

test/gui/notes.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,21 @@ local function cleanup(gui_notes)
6666
map_points_backup = nil
6767
end
6868

69+
function get_visible_map_center()
70+
local viewport = guidm.Viewport.get()
71+
72+
local half_x = math.max(
73+
math.floor((viewport.x1 + viewport.x2) / 2),
74+
2
75+
)
76+
local half_y = math.max(
77+
math.floor((viewport.y1 + viewport.y2) / 2),
78+
2
79+
)
80+
81+
return half_x, half_y, viewport.z
82+
end
83+
6984
function test.load_gui_notes()
7085
local gui_notes = arrange_gui_notes()
7186
expect.eq(gui_notes.visible, true)
@@ -297,8 +312,7 @@ function test.create_new_note()
297312

298313
local viewport = guidm.Viewport.get()
299314

300-
local half_x = math.floor((viewport.x1 + viewport.x2) / 2)
301-
local half_y = math.floor((viewport.y1 + viewport.y2) / 2)
315+
local half_x, half_y = get_visible_map_center()
302316

303317
local pos = {x=half_x, y=half_y, z=viewport.z}
304318
local screen_pos = viewport:tileToScreen(pos)

test/overlay/notes.lua

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ local function install_notes_overlay(options)
2323
overlay.rescan()
2424
overlay.overlay_command({'enable', 'notes.map_notes'})
2525

26-
local overlay_state = overlay.get_state()
27-
if not overlay_state.config['notes.map_notes'].enabled then
26+
if not overlay.isOverlayEnabled('notes.map_notes') then
2827
qerror('can not enable notes.map_notes overlay')
2928
end
3029

30+
local overlay_state = overlay.get_state()
3131
return overlay_state.db['notes.map_notes'].widget
3232
end
3333

@@ -83,6 +83,21 @@ function set_mouse_screen_pos(screen_pos)
8383

8484
end
8585

86+
function get_visible_map_center()
87+
local viewport = guidm.Viewport.get()
88+
89+
local half_x = math.max(
90+
math.floor((viewport.x1 + viewport.x2) / 2),
91+
2
92+
)
93+
local half_y = math.max(
94+
math.floor((viewport.y1 + viewport.y2) / 2),
95+
2
96+
)
97+
98+
return half_x, half_y, viewport.z
99+
end
100+
86101
function test.load_notes_overlay()
87102
local notes_overlay = install_notes_overlay()
88103
expect.ne(notes_overlay, nil)
@@ -108,8 +123,7 @@ function test.render_existing_notes()
108123

109124
local viewport = guidm.Viewport.get()
110125

111-
local half_x = math.floor((viewport.x1 + viewport.x2) / 2)
112-
local half_y = math.floor((viewport.y1 + viewport.y2) / 2)
126+
local half_x, half_y = get_visible_map_center()
113127

114128
local pos_1 = {x=half_x, y=half_y, z=viewport.z}
115129
local pos_2 = {x=half_x - 2, y=half_y + 2, z=viewport.z}
@@ -137,8 +151,7 @@ function test.edit_clicked_note()
137151

138152
local viewport = guidm.Viewport.get()
139153

140-
local half_x = math.floor((viewport.x1 + viewport.x2) / 2)
141-
local half_y = math.floor((viewport.y1 + viewport.y2) / 2)
154+
local half_x, half_y, z = get_visible_map_center()
142155

143156
local pos_1 = {x=half_x, y=half_y, z=viewport.z}
144157
local pos_2 = {x=half_x - 2, y=half_y + 2, z=viewport.z}
@@ -182,8 +195,7 @@ function test.delete_clicked_note()
182195

183196
local viewport = guidm.Viewport.get()
184197

185-
local half_x = math.floor((viewport.x1 + viewport.x2) / 2)
186-
local half_y = math.floor((viewport.y1 + viewport.y2) / 2)
198+
local half_x, half_y = get_visible_map_center()
187199

188200
local pos_1 = {x=half_x, y=half_y, z=viewport.z}
189201
local pos_2 = {x=half_x - 2, y=half_y + 2, z=viewport.z}
@@ -216,3 +228,4 @@ function test.delete_clicked_note()
216228

217229
cleanup(notes_overlay)
218230
end
231+

0 commit comments

Comments
 (0)