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/prayers/cl_prayers.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'gamemode/inventorysystem/prayers/cl_prayers.lua') diff --git a/gamemode/inventorysystem/prayers/cl_prayers.lua b/gamemode/inventorysystem/prayers/cl_prayers.lua index afea1cc..e28db63 100644 --- a/gamemode/inventorysystem/prayers/cl_prayers.lua +++ b/gamemode/inventorysystem/prayers/cl_prayers.lua @@ -8,7 +8,7 @@ function pray:DrawOnDPanel(panel) --Active grid local agrid = vgui.Create("DGrid",panel) agrid:SetCols(4) - local w = ((ScrW()/4) - 10) / 4 + local w = ((ScrW() / 4) - 10) / 4 agrid:SetHeight(w) agrid:SetColWide(w) agrid:SetRowHeight(w) @@ -17,14 +17,19 @@ function pray:DrawOnDPanel(panel) rec:SetText("F"..i) rec:SetSize(w,w) rec.DoClick = function(s) - local ap = self.activeprayers[i] + local ap = pray.activeprayers[i] explain:SetText(ap ~= nil and ap.Description or "Select a prayer") end rec:Receiver("prayer",function(s,tbl,dropped,mi,x,y) if not dropped then return end - self.activeprayers[i] = tbl.item - if tbl.item.DoOnPanel then - tbl.item.DoOnPanel(s) + pray.activeprayers[i] = tbl[1].item + if tbl[1].item == nil then + print("Failed to get item, tbl was") + PrintTable(tbl) + error("Failed to get item") + end + if tbl[1].item.DoOnPanel then + tbl[1].item:DoOnPanel(rec) end end,{}) agrid:AddItem(rec) @@ -64,6 +69,7 @@ function pray:DrawOnDPanel(panel) local observer = {} observer.Put = function(obs,pos,item) print("Prayer observer got request to put") + debug.Trace() drawprayer(item) end observer.Remove = function(obs,pos,item) @@ -79,12 +85,12 @@ local prayerhooks = { ["gm_showspare1"] = 3, ["gm_showspare2"] = 4 } -hook.Add("PlayerBindPress", function( ply, bind, pressed ) +hook.Add("PlayerBindPress", "pray_hook", function( ply, bind, pressed ) local phn = prayerhooks[bind] if phn == nil then return end local pap = pray.activeprayers[phn] if pap == nil then return end - pap:pray() + pap:Pray() end) return pray -- cgit v1.2.3-70-g09d2