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.
This commit is contained in:
Beha 2019-08-05 09:10:08 -04:00 committed by bell07
parent d22f3f0050
commit 67e7e195d9
2 changed files with 12 additions and 1 deletions

View File

@ -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

View File

@ -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,