diff --git a/changelog.txt b/changelog.txt index 7e8df43..c9c73d4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,9 @@ --------------------------------------------------------------------------------------------------- +Version: 0.5.4 +Date: 26. 12. 2025 + Changes: + - Allow rotation. +--------------------------------------------------------------------------------------------------- Version: 0.5.3 Date: XX. 07. 2025 Changes: diff --git a/control.lua b/control.lua index e2292e6..312600e 100644 --- a/control.lua +++ b/control.lua @@ -5,6 +5,12 @@ function init_globals() storage.objects = storage.objects or {} end +-- Resets rotation and flip to default +local function reset_rotation(entity) + entity.direction = defines.direction.north + entity.mirroring = false +end + -- Creates a table entry for this force if necessary local function check_state(force) if not storage.teams[force.index] then @@ -299,6 +305,21 @@ local function OnEntityCreated(event) radio_tune(entity) check_channels() end + + -- lock rotation after building + local name = entity.name == "entity-ghost" and entity.ghost_name or entity.name + if name == "shortwave-radio" or name == "shortwave-port" then + reset_rotation(entity) + entity.rotatable = false + end +end + +local function OnEntityRotated(event) + local entity = event.entity + local name = entity.name == "entity-ghost" and entity.ghost_name or entity.name + if name == "shortwave-radio" or name == "shortwave-port" then + reset_rotation(entity) + end end local function OnEntityRemoved(event) @@ -431,6 +452,10 @@ script.on_event(defines.events.on_entity_cloned, OnEntityCreated, built_filters) script.on_event(defines.events.script_raised_revive, OnEntityCreated, built_filters) script.on_event(defines.events.on_space_platform_built_entity, OnEntityCreated, built_filters) +-- When Radios (or links) are rotated, revert it to default rotation +script.on_event(defines.events.on_player_rotated_entity, OnEntityRotated) +script.on_event(defines.events.on_player_flipped_entity, OnEntityRotated) + -- When radios (or links) are destroyed and raise an event, respond immediately local mined_filters = {{filter="name", name="shortwave-radio"}, {filter="name", name="shortwave-link"}} script.on_event(defines.events.on_player_mined_entity, OnEntityRemoved, mined_filters) @@ -488,7 +513,7 @@ commands.add_command("shortwave-dump", "Dump storage to log", function() log(ser commands.add_command("shortwave-debug", "Dump storage to console", function() game.print(serpent.block(storage)) end) -require("__gvv__.gvv")() +if script.active_mods["gvv"] then require("__gvv__.gvv")() end ------------------------------------------------------------------------------------ -- FIND LOCAL VARIABLES THAT ARE USED GLOBALLY -- diff --git a/data.lua b/data.lua index 003b1b0..a22117d 100644 --- a/data.lua +++ b/data.lua @@ -22,7 +22,6 @@ data:extend{ "player-creation", "not-flammable", "not-blueprintable", - "not-rotatable", "not-deconstructable", "placeable-off-grid" }, @@ -42,7 +41,6 @@ data:extend{ flags = { "player-creation", "not-flammable", - "not-rotatable", "not-deconstructable", "hide-alt-info", }, @@ -80,7 +78,6 @@ data:extend{ flags = { "player-creation", "not-flammable", - "not-rotatable", }, max_health = cc.max_health, selectable_in_game = true, diff --git a/info.json b/info.json index 83ef3e5..d20d92c 100644 --- a/info.json +++ b/info.json @@ -1,6 +1,6 @@ { "name": "shortwave_fix", - "version": "0.5.3", + "version": "0.5.4", "factorio_version": "2.0", "title": "Shortwave for 2.0", "author": "robot256", diff --git a/migrations/0.5.4-lock-rotation.lua b/migrations/0.5.4-lock-rotation.lua new file mode 100644 index 0000000..c81d48c --- /dev/null +++ b/migrations/0.5.4-lock-rotation.lua @@ -0,0 +1,10 @@ +for _,surface in pairs(game.surfaces) do + for _,entity in pairs(surface.find_entities_filtered{name="shortwave-radio"}) do + entity.rotatable = false + end + for _,entity in pairs(surface.find_entities_filtered{name="shortwave-port"}) do + entity.rotatable = false + end +end + +