Skip to content

Commit 0d07e38

Browse files
committed
Build preview fixes: cursor skip by preview accounts for rotations and special case offshore pump toi have the right dimensions
1 parent 0a41fea commit 0d07e38

2 files changed

Lines changed: 19 additions & 49 deletions

File tree

control.lua

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ local function apply_skip_by_preview_size(pindex, direction)
17051705

17061706
--Check the moved count against the dimensions of the preview in hand
17071707
local stack = p.cursor_stack
1708-
local width, height = BuildDimensions.get_stack_build_dimensions(stack, dirs.north)
1708+
local width, height = BuildDimensions.get_stack_build_dimensions(stack, vp:get_hand_direction())
17091709

17101710
--Default to cursor size if not something else
17111711
if not width or not height or (width + height <= 2) then
@@ -2063,60 +2063,22 @@ local function read_coords(pindex, start_phrase)
20632063

20642064
--If there is a build preview, give its dimensions and which way they extend
20652065
local stack = game.get_player(pindex).cursor_stack
2066+
local p_width, p_height = BuildDimensions.get_stack_build_dimensions(stack, vp:get_hand_direction())
20662067

2067-
if
2068-
stack
2069-
and stack.valid_for_read
2070-
and stack.valid
2071-
and stack.prototype.place_result ~= nil
2072-
and (stack.prototype.place_result.tile_height > 1 or stack.prototype.place_result.tile_width > 1)
2073-
then
2068+
-- Tiles are always 1x1, so tile case still triggers.
2069+
if p_width and p_height and (p_width > 1 or p_height > 1) then
20742070
local vp = Viewpoint.get_viewpoint(pindex)
20752071
local dir = vp:get_hand_direction()
20762072
turn_to_cursor_direction_cardinal(pindex)
20772073
local p_dir = storage.players[pindex].player_direction
20782074

20792075
message:fragment({ "fa.build-preview-intro" })
2080-
2081-
-- Width dimension
2082-
local width_tiles
2083-
if dir == dirs.north or dir == dirs.south then
2084-
width_tiles = stack.prototype.place_result.tile_width
2085-
else
2086-
width_tiles = stack.prototype.place_result.tile_height
2087-
end
2088-
message:fragment({ "fa.build-preview-wide", tostring(width_tiles) })
2089-
2076+
message:fragment({ "fa.build-preview-wide", tostring(p_width) })
20902077
-- Width direction
2091-
if p_dir == dirs.east or p_dir == dirs.south or p_dir == dirs.north then
2092-
message:fragment({ "fa.build-preview-east" })
2093-
elseif p_dir == dirs.west then
2094-
message:fragment({ "fa.build-preview-west" })
2095-
end
2096-
2078+
message:fragment({ "fa.build-preview-east" })
20972079
message:fragment({ "fa.build-preview-and" })
2098-
2099-
-- Height dimension
2100-
local height_tiles
2101-
if dir == dirs.north or dir == dirs.south then
2102-
height_tiles = stack.prototype.place_result.tile_height
2103-
else
2104-
height_tiles = stack.prototype.place_result.tile_width
2105-
end
2106-
message:fragment({ "fa.build-preview-high", tostring(height_tiles) })
2107-
2108-
-- Height direction
2109-
if p_dir == dirs.east or p_dir == dirs.south or p_dir == dirs.west then
2110-
message:fragment({ "fa.build-preview-south" })
2111-
elseif p_dir == dirs.north then
2112-
message:fragment({ "fa.build-preview-north" })
2113-
end
2114-
elseif stack and stack.valid_for_read and stack.valid and stack.is_blueprint and stack.is_blueprint_setup() then
2115-
--Blueprints have their own data
2116-
local vp = Viewpoint.get_viewpoint(pindex)
2117-
local dir = vp:get_hand_direction()
2118-
local width, height = BuildDimensions.get_stack_build_dimensions(stack, dir)
2119-
message:fragment({ "fa.blueprint-preview", tostring(width), tostring(height) })
2080+
message:fragment({ "fa.build-preview-high", tostring(p_height) })
2081+
message:fragment({ "fa.build-preview-south" })
21202082
elseif stack and stack.valid_for_read and stack.valid and stack.prototype.place_as_tile_result ~= nil then
21212083
--Paving preview size
21222084
local size = vp:get_cursor_size() * 2 + 1

scripts/build-dimensions.lua

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
local mod = {}
55

6+
-- Special cases where we cannot compute off the game's datga, but where we can do the right thing by hardcoding.
7+
local SPECIAL_CASES = {
8+
["offshore-pump"] = { width = 3, height = 2 },
9+
}
10+
611
---Analyze blueprint to determine base dimensions (before rotation)
712
---@param stack LuaItemStack The blueprint stack
813
---@return integer|nil width The width in tiles (north orientation)
@@ -64,15 +69,18 @@ function mod.get_stack_build_dimensions(stack, direction)
6469

6570
local width, height
6671

67-
--Blueprints: analyze constituent entities
68-
if stack.is_blueprint then
72+
if SPECIAL_CASES[stack.name] then
73+
width = SPECIAL_CASES[stack.name].width
74+
height = SPECIAL_CASES[stack.name].height
75+
elseif stack.is_blueprint then
76+
--Blueprints: analyze constituent entities
6977
width, height = analyze_blueprint_base_dimensions(stack)
7078
--Entities: get dimensions from prototype
7179
elseif stack.prototype.place_result then
7280
width = stack.prototype.place_result.tile_width
7381
height = stack.prototype.place_result.tile_height
74-
--Tiles: always 1x1
7582
elseif stack.prototype.place_as_tile_result then
83+
--Tiles: always 1x1
7684
width = 1
7785
height = 1
7886
else

0 commit comments

Comments
 (0)