From 1fa8180e7fbc1f1470187b997ff9ecea188df0be Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 28 Nov 2018 14:14:33 +0000 Subject: [PATCH] Add sfinv.get_page() --- game_api.txt | 1 + mods/sfinv/api.lua | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/game_api.txt b/game_api.txt index 47df8e7f..4500cac8 100644 --- a/game_api.txt +++ b/game_api.txt @@ -569,6 +569,7 @@ sfinv API by its author: https://rubenwardy.com/minetest_modding_book/en/chapter **Pages** * sfinv.set_page(player, pagename) - changes the page +* sfinv.get_page(player) - get the current page name. Will never return nil * sfinv.get_homepage_name(player) - get the page name of the first page to show to a player * sfinv.register_page(name, def) - register a page, see section below * sfinv.override_page(name, def) - overrides fields of an page registered with register_page. diff --git a/mods/sfinv/api.lua b/mods/sfinv/api.lua index b9ddb39b..cd5b5e8a 100644 --- a/mods/sfinv/api.lua +++ b/mods/sfinv/api.lua @@ -135,6 +135,11 @@ function sfinv.set_page(player, pagename) sfinv.set_player_inventory_formspec(player, context) end +function sfinv.get_page(player) + local context = sfinv.contexts[player:get_player_name()] + return context and context.page or sfinv.get_homepage_name(player) +end + minetest.register_on_joinplayer(function(player) if sfinv.enabled then sfinv.set_player_inventory_formspec(player) -- 2.25.1