Fix data converter
I used a old factions version and created two teams with land claims and ranks. It converted fine. Make sure you pick the same parcel size as the old save file because if they are not they don't show up in the same spot or not at all.
This commit is contained in:
parent
c069828a28
commit
bc54df4925
55
factions.lua
55
factions.lua
@ -127,8 +127,7 @@ end
|
||||
function factions.start_diplomacy(name,faction)
|
||||
for i in pairs(factions.factions) do
|
||||
if i ~= name and not (faction.neutral[i] or faction.allies[i] or faction.enemies[i]) then
|
||||
faction:new_enemy(factions.factions[i].name)
|
||||
factions.factions[i]:new_enemy(faction.name)
|
||||
faction:new_enemy(i)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -841,14 +840,16 @@ function factions.load()
|
||||
local current_version = misc_mod_data.data.factions_version
|
||||
misc_mod_data.load()
|
||||
local old_version = misc_mod_data.data.factions_version
|
||||
factions.factions = minetest.deserialize(raw_data)
|
||||
if current_version ~= old_version or factions.is_old_file(factions.factions) then
|
||||
local tabledata = minetest.deserialize(raw_data)
|
||||
file:close()
|
||||
if tabledata then
|
||||
factions.factions = tabledata
|
||||
if current_version ~= old_version or factions.is_old_file(tabledata) then
|
||||
if factions.convert(filename) then
|
||||
minetest.after(5,
|
||||
function()
|
||||
minetest.chat_send_all("Factions successfully converted.")
|
||||
end)
|
||||
factions.save()
|
||||
end
|
||||
end
|
||||
for facname, faction in pairs(factions.factions) do
|
||||
@ -882,14 +883,27 @@ function factions.load()
|
||||
if faction.no_parcel ~= -1 then
|
||||
faction.no_parcel = os.time()
|
||||
end
|
||||
if faction:count_land() > 0 then
|
||||
faction.no_parcel = -1
|
||||
end
|
||||
if faction.onlineplayers and faction.offlineplayers then
|
||||
for i, _ in pairs(faction.onlineplayers) do
|
||||
faction.offlineplayers[i] = _
|
||||
end
|
||||
else
|
||||
faction.offlineplayers = {}
|
||||
end
|
||||
faction.onlineplayers = {}
|
||||
end
|
||||
file:close()
|
||||
misc_mod_data.data.factions_version = current_version
|
||||
misc_mod_data.save()
|
||||
factions.save()
|
||||
else
|
||||
minetest.after(5,
|
||||
function()
|
||||
minetest.chat_send_all("Failed to deserialize saved file.")
|
||||
end)
|
||||
end
|
||||
end
|
||||
factions_ip.load()
|
||||
end
|
||||
@ -931,23 +945,40 @@ function factions.convert(filename)
|
||||
return false
|
||||
end
|
||||
local raw_data = file:read("*a")
|
||||
file:close()
|
||||
local data = minetest.deserialize(raw_data)
|
||||
for facname,faction in pairs(data) do
|
||||
local newfac = factions.new_faction(facname)
|
||||
local newfac = factions.new_faction(facname,true)
|
||||
for oi, ol in pairs(faction) do
|
||||
if newfac[oi] then
|
||||
newfac[oi] = ol
|
||||
end
|
||||
end
|
||||
for player, unused in pairs(newfac.players) do
|
||||
factions.players[player] = newfac.name
|
||||
if faction.players then
|
||||
newfac.players = faction.players
|
||||
end
|
||||
for land, unused in pairs(newfac.land) do
|
||||
factions.parcels[land] = newfac.name
|
||||
if faction.land then
|
||||
newfac.land = faction.land
|
||||
end
|
||||
if faction.ranks then
|
||||
newfac.ranks = faction.ranks
|
||||
end
|
||||
factions.start_diplomacy(facname,newfac)
|
||||
newfac:check_power()
|
||||
end
|
||||
-- Create runtime data.
|
||||
for facname,faction in pairs(factions.factions) do
|
||||
if faction.players then
|
||||
for player, unused in pairs(faction.players) do
|
||||
factions.players[player] = faction.name
|
||||
end
|
||||
end
|
||||
if faction.land then
|
||||
for l, unused in pairs(faction.land) do
|
||||
factions.parcels[l] = facname
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
@ -1001,7 +1032,7 @@ function(player)
|
||||
if faction:has_permission(name, "diplomacy") then
|
||||
for _ in pairs(faction.request_inbox) do minetest.chat_send_player(name,"You have diplomatic requests in the inbox.") break end
|
||||
end
|
||||
if faction.message_of_the_day ~= "" or faction.message_of_the_day ~= " " then
|
||||
if faction.message_of_the_day and (faction.message_of_the_day ~= "" or faction.message_of_the_day ~= " ") then
|
||||
minetest.chat_send_player(name,faction.message_of_the_day)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user