Skip to content

Commit 622fb2d

Browse files
Fix notes overlay test
1 parent 104e02b commit 622fb2d

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

test/overlay/notes.lua

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ local function install_notes_overlay(options)
2828
end
2929

3030
local overlay_state = overlay.get_state()
31+
3132
return overlay_state.db['notes.map_notes'].widget
3233
end
3334

@@ -86,16 +87,24 @@ end
8687
function get_visible_map_center()
8788
local viewport = guidm.Viewport.get()
8889

89-
local half_x = math.max(
90-
math.floor((viewport.x1 + viewport.x2) / 2),
91-
2
90+
local map_width, map_height = dfhack.maps.getTileSize()
91+
local world_rect = gui.mkdims_wh(0, 0, map_width, map_height)
92+
-- find center of visible part of the map
93+
local map_rect = gui.ViewRect{rect=world_rect}:viewport(viewport)
94+
95+
local half_x = math.floor((map_rect.clip_x1 + map_rect.clip_x2) / 2)
96+
local normalized_half_x = math.min(
97+
math.max(half_x, map_rect.clip_x1),
98+
map_rect.clip_x2
9299
)
93-
local half_y = math.max(
94-
math.floor((viewport.y1 + viewport.y2) / 2),
95-
2
100+
101+
local half_y = math.floor((map_rect.clip_y1 + map_rect.clip_y2) / 2)
102+
local normalized_half_y = math.min(
103+
math.max(half_y, map_rect.clip_y1),
104+
map_rect.clip_y2
96105
)
97106

98-
return half_x, half_y, viewport.z
107+
return normalized_half_x, normalized_half_y, viewport.z
99108
end
100109

101110
function test.load_notes_overlay()

0 commit comments

Comments
 (0)