aboutsummaryrefslogtreecommitdiff
path: root/gamemode/inventorysystem
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/inventorysystem')
-rw-r--r--gamemode/inventorysystem/equipment/cl_equipment.lua1
-rw-r--r--gamemode/inventorysystem/equipment/sh_equipment.lua1
-rw-r--r--gamemode/inventorysystem/shapedinventory/cl_shaped.lua16
-rw-r--r--gamemode/inventorysystem/shapedinventory/sh_shaped.lua50
4 files changed, 39 insertions, 29 deletions
diff --git a/gamemode/inventorysystem/equipment/cl_equipment.lua b/gamemode/inventorysystem/equipment/cl_equipment.lua
index 74152dc..57a07ad 100644
--- a/gamemode/inventorysystem/equipment/cl_equipment.lua
+++ b/gamemode/inventorysystem/equipment/cl_equipment.lua
@@ -181,6 +181,7 @@ inv.DrawOnDPanel = function(self,panel)
for k,v in pairs(pn:GetChildren()) do
v:Remove()
end
+ if pn.Entity then pn.Entity:Remove() end
end
return prox
end
diff --git a/gamemode/inventorysystem/equipment/sh_equipment.lua b/gamemode/inventorysystem/equipment/sh_equipment.lua
index be930e0..0cd62e9 100644
--- a/gamemode/inventorysystem/equipment/sh_equipment.lua
+++ b/gamemode/inventorysystem/equipment/sh_equipment.lua
@@ -120,6 +120,7 @@ inv.DeSerialize = function(self,data)
for k,v in pairs(tbl) do
cpy.equiped[k] = itm.GetItemFromData(v)
end
+ return cpy
else
return table.Copy(self)
end
diff --git a/gamemode/inventorysystem/shapedinventory/cl_shaped.lua b/gamemode/inventorysystem/shapedinventory/cl_shaped.lua
index 051f0bc..746a37a 100644
--- a/gamemode/inventorysystem/shapedinventory/cl_shaped.lua
+++ b/gamemode/inventorysystem/shapedinventory/cl_shaped.lua
@@ -18,8 +18,8 @@ end
--[[
-local function calcposition(dimx,dimy,x,y)
- return (y * dimx) + x
+local function calcposition(width,height,x,y)
+ return (y * width) + x
end
]]
@@ -49,7 +49,7 @@ local function drawitemat(self,x,y,item)
print("Drawing item at ",x,y)
local tp = self.gridpanels[x][y]
if tp == nil then
- error("Unable to continue")
+ error("Unable to continue, could not find item at (" .. x .. "," .. y .. ")")
end
tp:Droppable("item")
runonshape(self,item.Shape,x,y,function(panel)
@@ -100,7 +100,7 @@ inv.DrawOnDPanel = function(self,panel)
local grid = vgui.Create( "DGrid", DScrollPanel )
grid:SetPos(0, 0)
- grid:SetCols(self.dimx)
+ grid:SetCols(self.width)
grid:SetColWide(iconsize)
grid:SetRowHeight(iconsize)
self.grid = grid
@@ -108,8 +108,8 @@ inv.DrawOnDPanel = function(self,panel)
self.gridpanels = {}
--Create the full grid of dpanels
- for x = 1, self.dimx do
- for y = 1, self.dimy do
+ for x = 1, self.width do
+ for y = 1, self.height do
local dp = vgui.Create("DModelPanel")
function dp:LayoutEntity( Entity ) return end -- disables default rotation
dp:SetSize(iconsize,iconsize)
@@ -131,8 +131,8 @@ inv.DrawOnDPanel = function(self,panel)
--Go through the items, and set the dpanels appropriately.
for k,v in pairs(self.tracker) do
if type(v) == "table" then
- local px = k % self.dimx
- local py = math.floor(k / self.dimy)
+ local px = k % self.width
+ local py = math.ceil(k / self.height)
drawitemat(self,px,py,v)
end
end
diff --git a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua
index b77f378..09668e2 100644
--- a/gamemode/inventorysystem/shapedinventory/sh_shaped.lua
+++ b/gamemode/inventorysystem/shapedinventory/sh_shaped.lua
@@ -1,5 +1,6 @@
--[[
An inventory, with a shape!
+ Items are stored in a 1-d array, array is 1-indexed
]]
local reg = nrequire("inventory/inventory.lua")
@@ -9,19 +10,20 @@ if CLIENT then inv = nrequire("cl_shaped.lua") end
inv.Name = "Shaped Inventory"
inv.tracker = {}
-inv.dimx = 5
-inv.dimy = 5
+inv.width = 5
+inv.height = 5
-local function calcposition(dimx,dimy,x,y)
- return ((x-1) * dimx) + y
+local function calcposition(width,height,row,col)
+ return ((row-1) * width) + col
end
-local function canfitin(self,x,y,shape)
+local function canfitin(self,arow,acol,shape)
for rn,row in ipairs(shape) do
for cn,col in ipairs(row) do
- local absx,absy = x + rn - 1, y + cn - 1
- local slot = calcposition(self.dimx,self.dimy,absx,absy)
- if col and ((self.tracker[slot] ~= nil) or (absx > self.dimx) or (absy > self.dimy)) then
+ local absrow,abscol = arow + rn - 1, acol + cn - 1
+ print("absrow was",absrow,"abscol was",abscol)
+ local slot = calcposition(self.width,self.height,absrow,abscol)
+ if col and ((self.tracker[slot] ~= nil) or (absrow > self.width) or (abscol > self.height)) then
return false
end
end
@@ -30,10 +32,10 @@ local function canfitin(self,x,y,shape)
end
function inv:FindPlaceFor(item)
- for x = 1, self.dimx do
- for y = 1, self.dimy do
- if canfitin(self,x,y,item.Shape) then
- return {x,y}
+ for row = 1, self.height do
+ for col = 1, self.width do
+ if canfitin(self,row,col,item.Shape) then
+ return {row,col}
end
end
end
@@ -54,14 +56,16 @@ function inv:Put(tbl,item)
for rn,row in ipairs(item.Shape) do
for cn,col in ipairs(row) do
if col then
- local slot = calcposition(self.dimx,self.dimy,tbl[1] + rn - 1,tbl[2] + cn - 1)
+ local slot = calcposition(self.width,self.height,tbl[1] + rn - 1,tbl[2] + cn - 1)
self.tracker[slot] = 1
end
end
end
--Now set the item in the correct slot
- local slot = calcposition(self.dimx,self.dimy,tbl[1],tbl[2])
+ print("Put item at ",tbl[1],tbl[2])
+ local slot = calcposition(self.width,self.height,tbl[1],tbl[2])
+ print("Slot is",slot)
self.tracker[slot] = item
end
@@ -74,22 +78,24 @@ function inv:Has(ptr)
end
for k,v in pairs(self.tracker) do
if type(v) == "table" and compare_func(v) then
- local x = math.floor(k / self.dimx)
- local y = k % self.dimx
- return {x,y}
+ local row = math.ceil(k / self.width)
+ local col = k % self.width
+ print("Has is retuning",row,col)
+ return {row,col}
end
end
return nil
end
function inv:Remove(tbl)
- local slot = calcposition(self.dimx,self.dimy,tbl[1],tbl[2])
+ local slot = calcposition(self.width,self.height,tbl[1],tbl[2])
+ print("Slot is",slot)
local item = self.tracker[slot]
self.tracker[slot] = nil
for rn,row in ipairs(item.Shape) do
for cn,col in ipairs(row) do
if col then
- slot = calcposition(self.dimx,self.dimy,tbl[1] + rn - 1,tbl[2] + cn - 1)
+ slot = calcposition(self.width,self.height,tbl[1] + rn - 1,tbl[2] + cn - 1)
self.tracker[slot] = nil
end
end
@@ -97,7 +103,7 @@ function inv:Remove(tbl)
end
function inv:Get(tbl)
- local slot = calcposition(self.dimx,self.dimy,tbl[1],tbl[2])
+ local slot = calcposition(self.width,self.height,tbl[1],tbl[2])
return self.tracker[slot]
end
@@ -114,13 +120,15 @@ end
function inv:DeSerialize(str)
--TODO:Implement
+ local ret = table.Copy(self)
local tbl = util.JSONToTable(str)
for k,v in pairs(tbl) do
local name = k
local pos = v[1]
local data = v[2]
- self.tracker[pos] = itm.GetItemFromData(name,data)
+ ret.tracker[pos] = itm.GetItemFromData(name,data)
end
+ return ret
end