Neemys wrote:Yeah i read your post and the third point suprised me so I made a test. Using only side inserter and test mod in 0.12. I used smart side inserter to load and unload thing from smart chest.
Those side smart inserter had two wire, one on the next pole, the other to the next smart chest (in 0.12).
Migrating to 0.13, the wire to the pole was kept, but not to the chest. That's not side inserter's fault but the game's because when they migrate smart chest they do not keep circuit network connection (maybe they only use JSON migration). But the wire to the pole and the condition on inserter was kept. so his script does his job. The game doesn't.
So lua migration can keep circuit network and condition if the connected entities keep the circuit network connection too.
Haven't test the two other point, but maybe they can be kept in a table and script restored after.
But free to you to do it the way you prefer, only lua (1 pass to migrate) or using JSON and lua (2 pass). You already have done great job by upgrading it for 0.13 in such short time.
Okay, it does keep filters, but here is the code from side inserters:
Code: Select all
function ReplaceInserter(ins)
local itype = "inserter"
local smart = false
local filters = {}
local fuel
if string.sub(ins.name, 1, 6) == "burner" then
if ins.get_inventory(defines.inventory.fuel).get_item_count() > 0 then
fuel = ins.get_inventory(defines.inventory.fuel)[1]
end
itype = "burner-inserter"
elseif string.sub(ins.name, 1, 4) == "fast" then
itype = "fast-inserter"
elseif string.sub(ins.name, 1, 4) == "long" then
itype = "long-handed-inserter"
elseif string.sub(ins.name, 1, 5) == "smart" then
smart = true
itype = "filter-inserter"
for i = 1,5 do
filters[i] = {index = i, name = ins.get_filter(i)}
end
end
local position = ins.position
local direction = ins.direction
local left, right
if string.match(ins.name, "left") then
direction = (direction + 6) % 8
left = true
elseif string.match(ins.name, "right") then
direction = (direction + 2) % 8
right = true
end
local near = string.match(ins.name, "near") ~= nil
local force = ins.force
local energy = ins.energy
local newins = game.surfaces[1].create_entity{
name = itype,
position = position,
direction = direction,
force = ins.force
}
newins.energy = energy
if fuel then
newins.insert(fuel)
end
if smart then
for i = 1,5 do
newins.set_filter(i, filters[i].name)
end
end
ins.destroy()
if left then
RotateLeft(newins)
elseif right then
RotateRight(newins)
end
if near then
ToggleInserterDrop(newins)
end
end
(to note: I only looked at this for ideas, and to see what was going on, I didn't actually use any of it in my own script, which you'd clearly see if you compared the 2... the one I'm not using anyway, because I decided to take a different approach, see below. if interested, here is the code I'm not going to use:)
Code: Select all
local function replace_inserter(inserter, newname)
local newinserter = game.surfaces[1].create_entity{
name = newname,
position = inserter.position,
direction = inserter.direction,
force = inserter.force
}
newinserter.pickup_position = inserter.pickup_position
newinserter.drop_position = inserter.drop_position
newinserter.energy = inserter.energy
if string.sub(newname, 1, 6) == "burner" then
if inserter.get_inventory(defines.inventory.fuel).get_item_count() > 0 then
newinserter.insert(inserter.get_inventory(defines.inventory.fuel)[1])
end
end
if string.sub(newname, 1, 6) == "filter" then
for i = 1, 5 do
newinserter.set_filter(i, inserter.get_filter(i))
end
end
newinserter.direction = inserter.direction
inserter.destroy()
end
local entities = game.surfaces[1].find_entities_filtered{area = {{-50000, -50000}, {50000, 50000}}, type= "inserter"}
for i, inserter in pairs(entities) do
if inserter.name == "long-handed-burner-inserter" then
replace_inserter(inserter, "burner-inserter")
elseif inserter.name == "fast-long-inserter" then
replace_inserter(inserter, "fast-inserter")
elseif inserter.name == "fast-near-inserter" then
replace_inserter(inserter, "fast-inserter")
elseif inserter.name == "fast-far-inserter" then
replace_inserter(inserter, "fast-inserter")
elseif inserter.name == "filter-long-inserter" then
replace_inserter(inserter, "filter-inserter")
elseif inserter.name == "filter-near-inserter" then
replace_inserter(inserter, "filter-inserter")
elseif inserter.name == "filter-far-inserter" then
replace_inserter(inserter, "filter-inserter")
elseif inserter.name == "filter-short-far-inserter" then
replace_inserter(inserter, "filter-inserter")
elseif inserter.name == "filter-short-long-inserter" then
replace_inserter(inserter, "filter-inserter")
elseif inserter.name == "filter-long-near-inserter" then
replace_inserter(inserter, "filter-inserter")
elseif inserter.name == "filter-long-short-inserter" then
replace_inserter(inserter, "filter-inserter")
elseif inserter.name == "express-long-inserter" then
replace_inserter(inserter, "express-inserter")
elseif inserter.name == "express-near-inserter" then
replace_inserter(inserter, "express-inserter")
elseif inserter.name == "express-far-inserter" then
replace_inserter(inserter, "express-inserter")
elseif inserter.name == "express-short-far-inserter" then
replace_inserter(inserter, "express-inserter")
elseif inserter.name == "express-short-long-inserter" then
replace_inserter(inserter, "express-inserter")
elseif inserter.name == "express-long-near-inserter" then
replace_inserter(inserter, "express-inserter")
elseif inserter.name == "express-long-short-inserter" then
replace_inserter(inserter, "express-inserter")
end
end
In there, I see no mention of circuit networks, logistic networks, hand contents, or logistic conditions (filters are a seperate thing)
It's those things without references that during my experiments weren't copied, and I can't see a way to copy.
Moving on... My progress so far, I have code that will save all hand positions to a global table, and code that will restore from a global table, along with the standard migration script.
The problem is, global tables are mod locked...
So... as things stand, 0.13.5 will save all hand locations to a global table, so you load the game, it creates the table, then you save the game.
update to 0.13.6, which has a .json migration script, and also iterates through the global table, and writes hand positions back to inserters.
upgrade complete.
there are no additional scripts for saving hand positions of inserters you add, or change after the initial table has been created.
And if you don't care about the hand positions, skipping 0.13.5 and going straight to 0.13.6 will work fine, the only thing is that no table of positions table will be created, so no positions will be restored.
EDIT:
Something else I've noticed that is interesting though... if you migrate an entity that hasn't had it's hand positions customised, the migrated entity moves hand positions to that of the new entity.
If you migrate an entity that has had it's hand positions customised, the new entity keeps the customised hand positions... so this might be easier to migrate than I thought... simply load and save the positions of the hands of every entity in a special "save hand positions" mod, then update, and upon migrating, the hands will be in the same positions.
Either way, blueprints would remain broken...
Further testing is required.