local ReplaySelectScene = SCENE:extend() ReplaySelectScene.title = "Replay" local replay_list local buttonList = { BUTTON.new{ text = "↑\nUP", font = FONT_big, x = 425, y = 80, w = 80, h = 80, codeWhenPressed = function() SCENE:onInputPress {input = "up"} end, codeWhenReleased = function() SCENE:onInputRelease{input = "up"} end }, BUTTON.new{ text = "↓\nDOWN", font = FONT_big, x = 425, y = 240, w = 80, h = 80, codeWhenPressed = function() SCENE:onInputPress {input = "down"} end, codeWhenReleased = function() SCENE:onInputRelease{input = "down"} end }, BUTTON.new{ text = "▶\nPLAY", font = FONT_big, x = 345, y = 160, w = 80, h = 80, codeWhenPressed = function() SCENE:onInputPress {input = "menu_decide"} end, codeWhenReleased = function() SCENE:onInputRelease{input = "menu_decide"} end }, BUTTON.new{ text = "⌂\nHOME", font = FONT_big, x = 505, y = 160, w = 80, h = 80, codeWhenPressed = function() SCENE:onInputPress {input = "menu_back"} end, codeWhenReleased = function() SCENE:onInputRelease{input = "menu_back"} end }, } function ReplaySelectScene:new() self:initList() PENTO_MODE = false end function ReplaySelectScene:initList() self.replays = {} replay_list = love.filesystem.getDirectoryItems('saves/replays/') table.sort(replay_list, function(a,b) return a > b end) self.replay_text = {} self.page_flip = 16 self.page = 1 local gradeNames = { "19k", "18k", "17k", "16k", "15k", "14k", "13k", "12k", "11k", "10k", "9k", "8k", "7k", "6k", "5k", "4k", "3k", "2k", "1k", "1D", "2D", "3D", "4D", "5D", "6D", "7D", "8D", "9D" } for i=1, #replay_list do if string.find(replay_list[i], "_replay.sav") ~= nil then table.insert(self.replays, replay_list[i]) local line_components = {} for str in string.gmatch(replay_list[i], "([^".."_".."]+)") do table.insert(line_components, str) end local player_name = line_components[2] local player_grade = gradeNames[tonumber(line_components[3])] local player_score = line_components[4] if #player_grade == 2 then player_grade = ' '..player_grade end table.insert(self.replay_text, player_name..' - '..player_grade..' - '..string.format('%6d',player_score)) end end self.replay_select = 1 self.direction = nil self.repeat_limit = 10 self.repeat_counter = self.repeat_limit-1 end function ReplaySelectScene:render() MainBackground() love.graphics.setColor(0.4, 1, 1, 0.5) love.graphics.rectangle("fill", 0, 20 + 20 * self.replay_select, 640, 22) BUTTON.draw(buttonList) drawText('Name - Grade - Score', 40, 20, 1000, "left") drawText(string.format('Page %s/%s', self.page, math.floor(#self.replays / self.page_flip) + 1), 20, 440, 1000, "left") local i, j = 1, 1 while i <= #self.replay_text do if j > self.page_flip then j = 1 elseif j < 1 then j = self.page_flip end if i > (self.page-1) * self.page_flip and i <= self.page * self.page_flip then drawText(self.replay_text[i], 40, 20 + 20 * j, 1000, "left") end j = j + 1 i = i + 1 end if self.replays[1] == nil then drawText('No replays yet!', 40, 40, 1000, "left") end end function ReplaySelectScene:update() if self.direction == "up" then if self.repeat_counter >= self.repeat_limit then self:changeOption(-1) self.repeat_counter = 0 end self.repeat_counter = self.repeat_counter + 1 elseif self.direction == "down" then if self.repeat_counter >= self.repeat_limit then self:changeOption(1) self.repeat_counter = 0 end self.repeat_counter = self.repeat_counter + 1 end end function ReplaySelectScene:changeOption(rel) local len = #self.replays self.replay_select = self.replay_select + rel if self.replay_select + ((self.page-1) * self.page_flip) > len then self.page = 1 self.replay_select = 1 elseif self.replay_select < 1 and self.page == 1 then self.page = 1+(math.floor(len / self.page_flip)) self.replay_select = len - ((self.page-1) * self.page_flip) end if self.replay_select > self.page_flip then self.page = self.page + 1 self.replay_select = 1 elseif self.replay_select < 1 then self.page = self.page - 1 self.replay_select = self.page_flip end end function ReplaySelectScene:onInputPress(e) local selected_replay = self.replays[self.replay_select + ((self.page-1) * self.page_flip)] local selected_replay_text = self.replay_text[self.replay_select + ((self.page-1) * self.page_flip)] if e.type == "touch" or e.type == "mouse" then BUTTON.press(buttonList, e.x, e.y, e.id) elseif e.input == "menu_decide" or e.input == "rotate_left" or e.scancode == "return" then if self.replays[1] == nil then SCENE = TitleScene(); return else local line_components = {} for str in string.gmatch(selected_replay_text, "([^".."-".."]+)") do table.insert(line_components, str) end local player_name = line_components[1] local player_grade = string.gsub(line_components[2], " ", "") SCENE = GameScene(player_name, selected_replay, player_grade) end -- elseif e.input == "rotate_right" then -- Will add in future, not now -- love.system.setClipboardText(love.data.encode("string", "base64", love.filesystem.read('saves/replays/'..selected_replay))) elseif e.input == "up" or e.scancode == "up" then if self.replays[1] == nil then SCENE = TitleScene(); return end self.direction = 'up' elseif e.input == "down" or e.scancode == "down" then if self.replays[1] == nil then SCENE = TitleScene(); return end self.direction = 'down' elseif e.input == "menu_back" or e.input == "rotate_right" or e.scancode == "backspace" or e.scancode == "delete" then SCENE = TitleScene() end end function ReplaySelectScene:onInputRelease(e) if e.type == "touch" or e.type == "mouse" then BUTTON.release(buttonList, e.x, e.y, e.id) elseif e.input == "up" or e.scancode == "up" or e.input == "down" or e.scancode == "down" then self.direction = nil self.repeat_counter = self.repeat_limit-1 end end function ReplaySelectScene:onInputMove(e) if e.type == "mouse" then BUTTON.checkHovering(buttonList, e.x, e.y) end end return ReplaySelectScene