Auto: add missing table properties
This commit is contained in:
parent
5dfd32df1b
commit
c531294335
|
@ -34,7 +34,7 @@ function factions.claim_parcel(name, parcelpos)
|
||||||
factions.unclaim_parcel(otherfac_name, parcelpos)
|
factions.unclaim_parcel(otherfac_name, parcelpos)
|
||||||
factions.parcelless_check(otherfac_name)
|
factions.parcelless_check(otherfac_name)
|
||||||
end
|
end
|
||||||
local data = factions.create_claim_table()
|
local data = factions.create_parcel_table()
|
||||||
data.faction = name
|
data.faction = name
|
||||||
factions.parcels.set(parcelpos, data)
|
factions.parcels.set(parcelpos, data)
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ function factions.on_create_player_table(table)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Hook function to add or delete from the claim table.
|
-- Hook function to add or delete from the claim table.
|
||||||
function factions.on_create_claim_table(table)
|
function factions.on_create_parcel_table(table)
|
||||||
return table
|
return table
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -84,6 +84,8 @@ function factions.create_faction_table()
|
||||||
last_logon = os.time(),
|
last_logon = os.time(),
|
||||||
--! @brief how long this has been without parcels
|
--! @brief how long this has been without parcels
|
||||||
no_parcel = os.time(),
|
no_parcel = os.time(),
|
||||||
|
--! @brief access table
|
||||||
|
access = {players = {}, factions = {}},
|
||||||
}
|
}
|
||||||
return factions.on_create_faction_table(table)
|
return factions.on_create_faction_table(table)
|
||||||
end
|
end
|
||||||
|
@ -99,17 +101,17 @@ end
|
||||||
-- Create a empty player table.
|
-- Create a empty player table.
|
||||||
function factions.create_player_table()
|
function factions.create_player_table()
|
||||||
local table = {
|
local table = {
|
||||||
faction = "",
|
faction = ""
|
||||||
}
|
}
|
||||||
return factions.on_create_player_table(table)
|
return factions.on_create_player_table(table)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create a empty claim table.
|
-- Create a empty claim table.
|
||||||
function factions.create_claim_table()
|
function factions.create_parcel_table()
|
||||||
local table = {
|
local table = {
|
||||||
faction = ""
|
faction = ""
|
||||||
}
|
}
|
||||||
return factions.on_create_claim_table(table)
|
return factions.on_create_parcel_table(table)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- helper functions
|
-- helper functions
|
||||||
|
@ -138,3 +140,48 @@ function factions.remove_key(db, db_name, db_data, key, write)
|
||||||
|
|
||||||
return db_data
|
return db_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- faction data check on load
|
||||||
|
local function update_data(db, db_name, db_data, empty_table, write)
|
||||||
|
local needs_update = false
|
||||||
|
|
||||||
|
if not db_data then
|
||||||
|
db_data = db.get(db_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
for k, v in pairs(empty_table) do
|
||||||
|
if db_data[k] == nil then
|
||||||
|
db_data[k] = v
|
||||||
|
needs_update = true
|
||||||
|
minetest.log("Adding property " .. k .. " to " .. db_name .. " file.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if write and needs_update then
|
||||||
|
db.set(db_name, db_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
return db_data
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_mods_loaded(function()
|
||||||
|
minetest.log("Checking faction files.")
|
||||||
|
for k, v in factions.factions.iterate() do
|
||||||
|
update_data(factions.factions, k, nil, factions.create_faction_table(), true)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log("Checking parcel files.")
|
||||||
|
for k, v in factions.parcels.iterate() do
|
||||||
|
update_data(factions.parcels, k, nil, factions.create_parcel_table(), true)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log("Checking player files.")
|
||||||
|
for k, v in factions.players.iterate() do
|
||||||
|
update_data(factions.players, k, nil, factions.create_player_table(), true)
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log("Checking ip files.")
|
||||||
|
for k, v in factions.player_ips.iterate() do
|
||||||
|
update_data(factions.player_ips, k, nil, factions.create_ip_table(), true)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
|
@ -121,7 +121,7 @@ function factions.set_name(oldname, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
for parcel in pairs(faction.land) do
|
for parcel in pairs(faction.land) do
|
||||||
local data = factions.create_claim_table()
|
local data = factions.create_parcel_table()
|
||||||
data.faction = name
|
data.faction = name
|
||||||
factions.parcels.set(parcel, data)
|
factions.parcels.set(parcel, data)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user