summaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-04-06 09:52:29 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-04-06 10:52:29 +0200
commit91615f9588420fd716978552fdacf1323b8df11c (patch)
tree951b1c139c09056d0d31bc4b8e0d13fd2d69c8bb /games
parent7e3f88f539109955b21a129e4203a1cadb913483 (diff)
downloadminetest-91615f9588420fd716978552fdacf1323b8df11c.tar.gz
minetest-91615f9588420fd716978552fdacf1323b8df11c.tar.bz2
minetest-91615f9588420fd716978552fdacf1323b8df11c.zip
Add player:get_meta(), deprecate player attributes (#7202)
* Add player:get_meta(), deprecate player attributes
Diffstat (limited to 'games')
-rw-r--r--games/minimal/mods/test/init.lua34
1 files changed, 31 insertions, 3 deletions
diff --git a/games/minimal/mods/test/init.lua b/games/minimal/mods/test/init.lua
index b08ddfa94..9b826bce6 100644
--- a/games/minimal/mods/test/init.lua
+++ b/games/minimal/mods/test/init.lua
@@ -13,7 +13,7 @@ assert(pseudo:next() == 13854)
-- HP Change Reasons
--
local expect = nil
-minetest.register_on_joinplayer(function(player)
+local function run_hpchangereason_tests(player)
expect = { type = "set_hp", from = "mod" }
player:set_hp(3)
assert(expect == nil)
@@ -25,8 +25,7 @@ minetest.register_on_joinplayer(function(player)
expect = { df = 3458973454, type = "fall", from = "mod" }
player:set_hp(10, { type = "fall", df = 3458973454 })
assert(expect == nil)
-end)
-
+end
minetest.register_on_player_hpchange(function(player, hp, reason)
for key, value in pairs(reason) do
assert(expect[key] == value)
@@ -38,3 +37,32 @@ minetest.register_on_player_hpchange(function(player, hp, reason)
expect = nil
end)
+
+
+
+local function run_player_meta_tests(player)
+ local meta = player:get_meta()
+ meta:set_string("foo", "bar")
+ assert(meta:get_string("foo") == "bar")
+
+ local meta2 = player:get_meta()
+ assert(meta2:get_string("foo") == "bar")
+ assert(meta:equals(meta2))
+ assert(player:get_attribute("foo") == "bar")
+
+ meta:set_string("bob", "dillan")
+ assert(meta:get_string("foo") == "bar")
+ assert(meta:get_string("bob") == "dillan")
+ assert(meta2:get_string("foo") == "bar")
+ assert(meta2:get_string("bob") == "dillan")
+ assert(meta:equals(meta2))
+ assert(player:get_attribute("foo") == "bar")
+ assert(player:get_attribute("bob") == "dillan")
+end
+
+local function run_player_tests(player)
+ run_hpchangereason_tests(player)
+ run_player_meta_tests(player)
+ minetest.chat_send_all("All tests pass!")
+end
+minetest.register_on_joinplayer(run_player_tests)