From 47a5a53e23c347e5923b0393470d6c92b0d4957f Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Thu, 9 Dec 2021 18:18:23 -0500 Subject: [PATCH] Fixed sorting replays in the replay select In addition, minor change to the default text that shows up when the game is paused --- scene/replay_select.lua | 19 ++++--------------- tetris/modes/gamemode.lua | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/scene/replay_select.lua b/scene/replay_select.lua index f37ba90..3685641 100644 --- a/scene/replay_select.lua +++ b/scene/replay_select.lua @@ -15,22 +15,11 @@ function ReplaySelectScene:new() for i=1,#replay_file_list do local data = love.filesystem.read("replays/"..replay_file_list[i]) local new_replay = binser.deserialize(data)[1] - -- Insert, sorting by date played, newest first - local start_index, mid_index, end_index = 1, 1, i - if i ~= 1 then - while start_index <= end_index do - mid_index = math.floor((start_index + end_index) / 2) - if os.difftime(replays[mid_index]["timestamp"], new_replay["timestamp"]) <= 0 then - -- search first half - end_index = mid_index - 1 - else - -- search second half - start_index = mid_index + 1 - end - end - end - table.insert(replays, mid_index, new_replay) + replays[#replays + 1] = new_replay end + table.sort(replays, function(a, b) + return a["timestamp"] > b["timestamp"] + end) self.display_error = false if table.getn(replays) == 0 then self.display_warning = true diff --git a/tetris/modes/gamemode.lua b/tetris/modes/gamemode.lua index 6cb49aa..883bfbb 100644 --- a/tetris/modes/gamemode.lua +++ b/tetris/modes/gamemode.lua @@ -1034,7 +1034,7 @@ function GameMode:drawCustom() end function GameMode:drawIfPaused() love.graphics.setFont(font_3x5_3) - love.graphics.printf("GAME PAUSED!", 64, 160, 160, "center") + love.graphics.printf("PAUSED!", 64, 160, 160, "center") end -- transforms specified in here will transform the whole screen