Skip to content

Commit

Permalink
Merge pull request #10 from jodokus31/support_jetpack
Browse files Browse the repository at this point in the history
Support jetpack
  • Loading branch information
jodokus31 authored Apr 21, 2023
2 parents 2fc49ad + eae817e commit 2abfacc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
---------------------------------------------------------------------------------------------------
Version: 0.5.5
Date: 2023-04-21
Changes:
- Support Jetpack mod, that the visual construction area doesn't get cleared on jetpack de/-activation
---------------------------------------------------------------------------------------------------
Version: 0.5.4
Date: 2023-01-13
Bugfixes:
Expand Down
32 changes: 32 additions & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ local function change_visual_area(player, state, opacity)
state.visual_area_id = nil
end

-- player.print("enable_visual_area ".. (state.enable_visual_area and "true" or "false"))
-- player.print("opacity ".. (opacity or "nil"))
-- player.print("player.character "..serpent.block(player.character))
-- player.print("build_distance "..(state.build_distance or "nil"))

if not state.enable_visual_area then return end
if not opacity or opacity <= 0 then return end
if not player.character then return end
Expand All @@ -52,6 +57,33 @@ local function change_visual_area(player, state, opacity)
})
end

-- on_character_swapped_event
-- params: event
-- new_unit_number
-- old_unit_number
-- new_character
-- old_character
function on_character_swapped_event(event)
-- attach visual area to the new character
local player = event and event.new_character and event.new_character.player
if not player then return end
if not player.index then return end

local state = get_player_state(player.index)
if not state.visual_area_id then return end
if not state.build_distance then return end

local radius = state.build_distance + 0.5
local target = rendering.get_left_top(state.visual_area_id)
if target and target.entity and target.entity.unit_number == event.old_unit_number then
rendering.set_corners(state.visual_area_id,
event.new_character, { -radius, -radius },
event.new_character, { radius, radius })
end
end

remote.add_interface("autobuild", { on_character_swapped = on_character_swapped_event } )

local function on_load()
player_state = global.player_state
end
Expand Down
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "autobuild",
"version": "0.5.4",
"version": "0.5.5",
"factorio_version": "1.1",
"title": "Autobuild",
"author": "Therax",
Expand Down

0 comments on commit 2abfacc

Please sign in to comment.