-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdatagrid.lua
49 lines (38 loc) · 893 Bytes
/
datagrid.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
DataGrid = Class(function(self, width, height)
self.grid = {}
self.width = width
self.height = height
end)
function DataGrid:Width()
return self.width
end
function DataGrid:Height()
return self.height
end
function DataGrid:GetMaxSize()
return self.width * self.height
end
function DataGrid:GetIndex(x, y)
return y * self.width + x
end
function DataGrid:GetXYFromIndex(index)
return index % self.width, math.floor(index / self.width)
end
function DataGrid:GetDataAtPoint(x, y)
return self:GetDataAtIndex(self:GetIndex(x, y))
end
function DataGrid:SetDataAtPoint(x, y, data)
return self:SetDataAtIndex(self:GetIndex(x, y), data)
end
function DataGrid:GetDataAtIndex(index)
return self.grid[index]
end
function DataGrid:SetDataAtIndex(index, data)
self.grid[index] = data
end
function DataGrid:Save()
return self.grid
end
function DataGrid:Load(grid)
self.grid = grid
end