From d2868db28210b8c4debab2b70dca2833d582fdfd Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Fri, 23 Mar 2018 15:20:30 -0400 Subject: Refactored the inventory system Inventory system now uses flyweight pattern with metatables. --- gamemode/inventorysystem/shapedinventory/cl_shaped.lua | 3 +++ gamemode/inventorysystem/shapedinventory/sh_shaped.lua | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'gamemode/inventorysystem/shapedinventory') diff --git a/gamemode/inventorysystem/shapedinventory/cl_shaped.lua b/gamemode/inventorysystem/shapedinventory/cl_shaped.lua index 7c60156..d9a4a08 100644 --- a/gamemode/inventorysystem/shapedinventory/cl_shaped.lua +++ b/gamemode/inventorysystem/shapedinventory/cl_shaped.lua @@ -46,6 +46,9 @@ end --Draw the item in a position local function drawitemat(self,x,y,item) + assert(self ~= nil, "I am nil!") + assert(self.gridpanels ~= nil, "My gridpanels were nil!") + assert(self.gridpanels[x] ~= nil, "Could not find that row!") local tp = self.gridpanels[x][y] if tp == nil then error("Unable to continue, could not find item at (" .. x .. "," .. y .. ")") diff --git a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua index 5de6272..42edaa6 100644 --- a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua +++ b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua @@ -119,17 +119,18 @@ function inv:Serialize() end function inv:DeSerialize(str) - local ret = table.Copy(self) + self.tracker = {} local tbl = util.JSONToTable(str) + tbl = tbl or {} for k,v in pairs(tbl) do local name = k local pos = v[1] local data = v[2] local item = itm.GetItemFromData(name,data) - ret:Put(pos,item) + self:Put(pos,item) --ret.tracker[pos] = itm.GetItemFromData(name,data) end - return ret + return self end -- cgit v1.2.3-70-g09d2