From fd1e314ec96775e73dfcccf4f222c539ce554bb4 Mon Sep 17 00:00:00 2001 From: 2ndbeam <2ndbeam@disroot.org> Date: Thu, 23 Oct 2025 16:32:27 +0300 Subject: [PATCH] Added indexed function --- levelhandler.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/levelhandler.lua b/levelhandler.lua index ed7b874..8c5931c 100644 --- a/levelhandler.lua +++ b/levelhandler.lua @@ -6,7 +6,7 @@ require 'makegrid' ---@field current integer LevelHandler = { levels = { - 'test3', 'test2', 'test' + 'test2', 'test', 'test3' }, current = 1, } @@ -18,13 +18,22 @@ function LevelHandler:next() if self.current > #self.levels then self.current = 1 end - local levelPath = string.format('levels/%s', self.levels[self.current]) + local levelPath = 'levels/' .. self.levels[self.current] return MakeGrid( require( levelPath ) ) end -- Returns first level ---@return Grid 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 ) ) end