Added indexed function
This commit is contained in:
parent
a47e14ffca
commit
fd1e314ec9
1 changed files with 12 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ require 'makegrid'
|
||||||
---@field current integer
|
---@field current integer
|
||||||
LevelHandler = {
|
LevelHandler = {
|
||||||
levels = {
|
levels = {
|
||||||
'test3', 'test2', 'test'
|
'test2', 'test', 'test3'
|
||||||
},
|
},
|
||||||
current = 1,
|
current = 1,
|
||||||
}
|
}
|
||||||
|
|
@ -18,13 +18,22 @@ function LevelHandler:next()
|
||||||
if self.current > #self.levels then
|
if self.current > #self.levels then
|
||||||
self.current = 1
|
self.current = 1
|
||||||
end
|
end
|
||||||
local levelPath = string.format('levels/%s', self.levels[self.current])
|
local levelPath = 'levels/' .. self.levels[self.current]
|
||||||
return MakeGrid( require( levelPath ) )
|
return MakeGrid( require( levelPath ) )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns first level
|
-- Returns first level
|
||||||
---@return Grid
|
---@return Grid
|
||||||
function LevelHandler:first()
|
function LevelHandler:first()
|
||||||
local levelPath = string.format('levels/%s', self.levels[1])
|
local levelPath = 'levels/' .. self.levels[1]
|
||||||
|
return MakeGrid( require( levelPath ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns level by its index in table
|
||||||
|
---@param i number
|
||||||
|
---@return Grid
|
||||||
|
function LevelHandler:indexed(i)
|
||||||
|
self.current = i
|
||||||
|
local levelPath = 'levels/' .. self.levels[self.current]
|
||||||
return MakeGrid( require( levelPath ) )
|
return MakeGrid( require( levelPath ) )
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue