From 67e7e195d95e6a526b59ba0460e651e30d33474f Mon Sep 17 00:00:00 2001 From: Beha Date: Mon, 5 Aug 2019 09:10:08 -0400 Subject: [PATCH] Add inventory:setList(list) and inventory:getList() to set the inventory list name. (#56) * Add inventory:setList(list) and inventory:getList() to inventory element. This allows multiple inventory elements with the same list name but different inventory locations. Example: the "main" list in a chest and the player's "main" list. --- docs/API.md | 2 ++ smartfs.lua | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/API.md b/docs/API.md index 081cd78..9897f8c 100644 --- a/docs/API.md +++ b/docs/API.md @@ -148,6 +148,8 @@ * element:useDetached( name ) - use a detached inventory with the given name * element:usePlayer( name ) - use a player inventory other than the current player * element:getLocation() - returns the inventory location (default: current_player) +* element:setList( list ) - set a custom inventory list name or nil for the default (the element's name) +* element:getList() - returns the list name (defaults to the element's name) * element:setIndex( index ) - set the inventory starting index * element:getIndex() - returns the inventory starting index diff --git a/smartfs.lua b/smartfs.lua index cf5d059..4719b15 100644 --- a/smartfs.lua +++ b/smartfs.lua @@ -1416,12 +1416,15 @@ smartfs.element("inventory", { assert(self.data.pos and self.data.pos.x and self.data.pos.y, "list needs valid pos") assert(self.data.size and self.data.size.w and self.data.size.h, "list needs valid size") assert(self.name, "list needs name") + + -- Default the list name to the element name. + self.data.list = self.name end, build = function(self) return "list[".. (self.data.invlocation or "current_player") .. ";".. - self.name.. --no namespacing + self.data.list .. ";".. self.data.pos.x..","..self.data.pos.y.. ";".. @@ -1451,6 +1454,12 @@ smartfs.element("inventory", { useDetached = function(self, name) self.data.invlocation = "detached:" .. name end, + setList = function(self, list) + self.data.list = list or self.name + end, + getList = function(self) + return self.data.list + end, setIndex = function(self,index) self.data.index = index end,