2016-09-19 18:54:13 +02:00
|
|
|
-- Assertion tools for Metatools
|
|
|
|
|
|
|
|
function assert_contextid(ctid)
|
2016-09-20 17:19:28 +02:00
|
|
|
return metatools.contexts[ctid] ~= nil
|
2016-09-19 18:54:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function assert_ownership(ctid, name)
|
2016-09-20 18:28:56 +02:00
|
|
|
return metatools.playerlocks[name] == ctid
|
2016-09-19 18:54:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function assert_pos(pos)
|
|
|
|
if type(pos) ~= "string" then
|
|
|
|
return pos and pos.x and pos.y and pos.z and minetest.pos_to_string(pos)
|
|
|
|
else
|
|
|
|
return minetest.string_to_pos(pos) ~= nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function assert_mode(mode)
|
|
|
|
return mode and (mode == "fields" or mode == "inventory")
|
|
|
|
end
|
|
|
|
|
|
|
|
function assert_poslock(pos)
|
|
|
|
return nodelock[minetest.pos_to_string(pos)] == nil
|
|
|
|
end
|
|
|
|
|
|
|
|
function assert_specific_mode(contextid, mode)
|
2016-09-20 17:19:28 +02:00
|
|
|
return assert_contextid(contextid) and metatools.contexts[contextid].mode == mode
|
2016-09-19 18:54:13 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function assert_field_type(ftype)
|
|
|
|
return ftype and type(ftype) == "string" and (ftype == "int" or ftype == "float" or ftype == "string")
|
|
|
|
end
|
|
|
|
|
|
|
|
function assert_integer(int)
|
|
|
|
return int and tonumber(int) and tonumber(int) % 1 == 0
|
|
|
|
end
|
|
|
|
|