Various fixes
This commit is contained in:
parent
376a4c8795
commit
e1b879320c
@ -282,15 +282,27 @@ local function delete_record(db, uid)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local methods =
|
||||||
|
{
|
||||||
|
get = effect_set_get,
|
||||||
|
effects = effect_set_effects,
|
||||||
|
insert = insert_record,
|
||||||
|
delete = delete_record,
|
||||||
|
with_index = effect_set_index_set,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
local function add_methods(eset)
|
local function add_methods(eset)
|
||||||
eset.get = effect_set_get
|
for name, method in pairs(methods) do
|
||||||
eset.effects = effect_set_effects
|
eset[name] = method
|
||||||
eset.insert = insert_record
|
end
|
||||||
eset.delete = delete_record
|
end
|
||||||
eset.size = function(self)
|
|
||||||
return #(self.uid_table)
|
|
||||||
|
local function del_methods(eset)
|
||||||
|
for name, method in pairs(methods) do
|
||||||
|
eset.name = nil
|
||||||
end
|
end
|
||||||
eset.with_index = effect_set_index_set
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -322,22 +334,29 @@ end
|
|||||||
local function serialize_effect_set(eset)
|
local function serialize_effect_set(eset)
|
||||||
local serialize_this = shallow_copy(eset.uid_table)
|
local serialize_this = shallow_copy(eset.uid_table)
|
||||||
|
|
||||||
serialize_this.get = nil
|
del_methods(eset)
|
||||||
serialize_this.effects = nil
|
|
||||||
serialize_this.tables = nil
|
|
||||||
|
|
||||||
return minetest.serialize(serialize_this)
|
return minetest.serialize(serialize_this)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function deserialize_effect_set(str)
|
local function deserialize_effect_set(str)
|
||||||
local deserialized = minetest.deserialize(str)
|
local uid_table = minetest.deserialize(str)
|
||||||
|
local deserialized = {uid_table = uid_table, tables = {}}
|
||||||
|
|
||||||
if (deserialized == nil) then
|
local tables = {}
|
||||||
|
|
||||||
|
for i, table_name in ipairs(table_names) do
|
||||||
|
tables[table_name] = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
deserialized.tables = tables
|
||||||
|
|
||||||
|
if (uid_table == nil) then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
for k, v in pairs(deserialized) do
|
for k, v in pairs(uid_table) do
|
||||||
insert_record_with_uid(k, deserialized, v)
|
insert_record_with_uid(k, deserialized, v)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user