diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-03-23 15:20:30 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-03-23 15:20:30 -0400 |
| commit | d2868db28210b8c4debab2b70dca2833d582fdfd (patch) | |
| tree | 17ad5beb46e3b1c3c17d520a71a4c1ea12c47f51 /gamemode/inventorysystem/prayers/cl_prayers.lua | |
| parent | a7f7bed257dd96b1027c6343cd59eea4eee9fc3b (diff) | |
| download | artery-d2868db28210b8c4debab2b70dca2833d582fdfd.tar.gz artery-d2868db28210b8c4debab2b70dca2833d582fdfd.tar.bz2 artery-d2868db28210b8c4debab2b70dca2833d582fdfd.zip | |
Refactored the inventory system
Inventory system now uses flyweight pattern with metatables.
Diffstat (limited to 'gamemode/inventorysystem/prayers/cl_prayers.lua')
| -rw-r--r-- | gamemode/inventorysystem/prayers/cl_prayers.lua | 20 |
1 files changed, 13 insertions, 7 deletions
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 |
