Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tf_util-bugfix #10

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
util = require "data/tf_util/tf_util"
--util = require "data/tf_util/tf_util"
names = require("shared")
-- require "data/hotkeys"
require "data/units/units"
Expand Down
1 change: 1 addition & 0 deletions data/shortcut.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local util = require "data/tf_util/tf_util"
local path = util.path("data/units/construction_drone/")

local icon = {
Expand Down
6 changes: 3 additions & 3 deletions data/tf_util/tf_util.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local util = require("util")
local util = table.deepcopy ( require("util") )
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit I am not very good with lua nor factorio modding, but does this not make a deepcopy only for the local variable? Or does this actually carry over to the, let's say, script/construction_drone.lua file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way tables work in Lua is that every variable with a table in it doesn't actually contain the table, it's merely a portal to the table. So every change made to it will apply to the original table, and every OTHER local variable that points at the same table as it will be able to see it. This is why you can do local belt = data.raw["transport-belt"]["express-transport-belt"]; belt.speed = 60, and it would apply to the original object held in the data table.

In the example you provide with scripts/construction_drone.lua, it never actually did see the modified tf_util table, even before I touched anything, since tf_util is executed during the DATA stage, which the script file is used during the CONTROL stage. No data beyond what factorio takes from the data table is transferred over.
The util in that file is defined in control.lua line 3.


local is_sprite_def = function(array)
return array.width and array.height and (array.filename or array.stripes or array.filenames)
Expand Down Expand Up @@ -214,7 +214,7 @@ end
util.copy = util.table.deepcopy

util.flying_unit_collision_mask = function()
return { "not-colliding-with-itself", "layer-15" }
return { "not-colliding-with-itself", "layer-15" } -- this needs to be updated to use the new collision lib
end


Expand All @@ -224,7 +224,7 @@ end


util.projectile_collision_mask = function()
return { "layer-15", "player-layer", "train-layer" }
return { "layer-15", "player-layer", "train-layer" } -- this needs to be updated to use the new collision lib
end


Expand Down
1 change: 1 addition & 0 deletions data/units/construction_drone/construction_drone.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local util = require "data/tf_util/tf_util"
local path = util.path("data/units/construction_drone/")
local name = names.units.construction_drone

Expand Down