From 3571c0bd6a268921287c14a812aa133e9eebbcfa Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Mon, 21 Aug 2017 21:21:36 -0400 Subject: Fixed a bug with shaped inventory Shaped inventory was not saveing data correctly. --- gamemode/inventorysystem/shapedinventory/sh_shaped.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'gamemode/inventorysystem') diff --git a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua index 7c171c3..bb35d2d 100644 --- a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua +++ b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua @@ -51,6 +51,7 @@ function inv:CanFitIn(tbl,item) end function inv:Put(tbl,item) + print("Calling put") --Set the item's shape to true for rn,row in ipairs(item.Shape) do @@ -112,22 +113,29 @@ function inv:Serialize() local ret = {} for k,v in pairs(self.tracker) do if type(v) == "table" then - ret[v.Name] = {k,v:Serialize()} + local row = math.ceil(k / self.width) + local col = (k % self.width) + ret[v.Name] = {{row,col},v:Serialize()} end end return util.TableToJSON(ret) end function inv:DeSerialize(str) - --TODO:Implement + print("Deserialize str is", str) local ret = table.Copy(self) local tbl = util.JSONToTable(str) + print("unjsoned is",tbl,type(tbl)) + PrintTable(tbl) for k,v in pairs(tbl) do local name = k local pos = v[1] local data = v[2] local item = itm.GetItemFromData(name,data) - self:Put(pos,item) + print("Got item",item) + PrintTable(item) + print("got pos",pos) + ret:Put(pos,item) --ret.tracker[pos] = itm.GetItemFromData(name,data) end return ret -- cgit v1.2.3-70-g09d2