mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 02:29:03 -06:00
Replays list is now sorted, and replays are smaller.
This commit is contained in:
parent
59c7834c9a
commit
a5750e4959
@ -14,10 +14,26 @@ function ReplaySelectScene:new()
|
|||||||
replay_file_list = love.filesystem.getDirectoryItems("replays")
|
replay_file_list = love.filesystem.getDirectoryItems("replays")
|
||||||
for i=1,#replay_file_list do
|
for i=1,#replay_file_list do
|
||||||
local data = love.filesystem.read("replays/"..replay_file_list[i])
|
local data = love.filesystem.read("replays/"..replay_file_list[i])
|
||||||
local object = binser.deserialize(data)
|
local new_replay = binser.deserialize(data)[1]
|
||||||
replays[i] = object[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)
|
||||||
|
print(start_index, mid_index, end_index)
|
||||||
|
print(replays[mid_index])
|
||||||
|
print(new_replay)
|
||||||
|
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)
|
||||||
end
|
end
|
||||||
-- TODO sort replays list
|
|
||||||
if table.getn(replays) == 0 then
|
if table.getn(replays) == 0 then
|
||||||
self.display_warning = true
|
self.display_warning = true
|
||||||
current_replay = 1
|
current_replay = 1
|
||||||
@ -87,14 +103,13 @@ function ReplaySelectScene:render()
|
|||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1, 0.5)
|
love.graphics.setColor(1, 1, 1, 0.5)
|
||||||
love.graphics.rectangle("fill", 20, 258, 500, 22)
|
love.graphics.rectangle("fill", 3, 258, 634, 22)
|
||||||
|
|
||||||
love.graphics.setFont(font_3x5_2)
|
love.graphics.setFont(font_3x5_2)
|
||||||
for idx, replay in pairs(replays) do
|
for idx, replay in ipairs(replays) do
|
||||||
if(idx >= self.menu_state.replay-9 and idx <= self.menu_state.replay+9) then
|
if(idx >= self.menu_state.replay-9 and idx <= self.menu_state.replay+9) then
|
||||||
-- TODO format timer into minutes:seconds:centiseconds
|
local display_string = os.date("%c", replay["timestamp"]).." "..replay["mode"].." "..replay["ruleset"].." Level: "..replay["level"].." Time: "..formatTime(replay["timer"])
|
||||||
local display_string = replay["mode"].." "..replay["ruleset"].." "..replay["timer"].." "..replay["level"].." "..os.date("%c", replay["timestamp"])
|
love.graphics.printf(display_string, 6, (260 - 20*(self.menu_state.replay)) + 20 * idx, 640, "left")
|
||||||
love.graphics.printf(display_string, 40, (260 - 20*(self.menu_state.replay)) + 20 * idx, 500, "left")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -89,7 +89,7 @@ function GameMode:getGravity() return 1/64 end
|
|||||||
|
|
||||||
function GameMode:getNextPiece(ruleset)
|
function GameMode:getNextPiece(ruleset)
|
||||||
local shape = self.used_randomizer:nextPiece()
|
local shape = self.used_randomizer:nextPiece()
|
||||||
table.insert(self.replay_pieces,shape)
|
self.replay_pieces[#self.replay_pieces + 1] = shape
|
||||||
return {
|
return {
|
||||||
skin = self:getSkin(),
|
skin = self:getSkin(),
|
||||||
shape = shape,
|
shape = shape,
|
||||||
@ -105,7 +105,7 @@ function GameMode:initialize(ruleset)
|
|||||||
local dummy_entry = {}
|
local dummy_entry = {}
|
||||||
dummy_entry["inputs"] = {}
|
dummy_entry["inputs"] = {}
|
||||||
dummy_entry["frames"] = 0
|
dummy_entry["frames"] = 0
|
||||||
table.insert(self.replay_inputs, dummy_entry)
|
self.replay_inputs[#self.replay_inputs + 1] = dummy_entry
|
||||||
-- generate next queue
|
-- generate next queue
|
||||||
self.used_randomizer = (
|
self.used_randomizer = (
|
||||||
table.equalvalues(
|
table.equalvalues(
|
||||||
@ -138,16 +138,19 @@ function GameMode:update(inputs, ruleset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- check if inputs have changed since last frame
|
-- check if inputs have changed since last frame
|
||||||
local last_input_index = table.maxn(self.replay_inputs)
|
if self.prev_inputs["left"] ~= inputs["left"] or self.prev_inputs["right"] ~= inputs["right"]
|
||||||
if self.replay_inputs[last_input_index]["inputs"] ~= inputs then
|
or self.prev_inputs["down"] ~= inputs["down"] or self.prev_inputs["up"] ~= inputs["up"]
|
||||||
|
or self.prev_inputs["rotate_left"] ~= inputs["rotate_left"] or self.prev_inputs["rotate_right"] ~= inputs["rotate_right"]
|
||||||
|
or self.prev_inputs["hold"] ~= inputs["hold"] or self.prev_inputs["rotate_180"] ~= inputs["rotate_180"]
|
||||||
|
or self.prev_inputs["rotate_left2"] ~= inputs["rotate_left2"] or self.prev_inputs["rotate_right2"] ~= inputs["rotate_right2"] then
|
||||||
-- insert new inputs into replay inputs table
|
-- insert new inputs into replay inputs table
|
||||||
local new_inputs = {}
|
local new_inputs = {}
|
||||||
new_inputs["inputs"] = inputs
|
new_inputs["inputs"] = inputs
|
||||||
new_inputs["frames"] = 0
|
new_inputs["frames"] = 0
|
||||||
table.insert(self.replay_inputs,new_inputs)
|
self.replay_inputs[#self.replay_inputs + 1] = new_inputs
|
||||||
else
|
else
|
||||||
-- add 1 to input frame counter
|
-- add 1 to input frame counter
|
||||||
self.replay_inputs[last_input_index]["frames"] = self.replay_inputs[last_input_index]["frames"] + 1
|
self.replay_inputs[#self.replay_inputs]["frames"] = self.replay_inputs[#self.replay_inputs]["frames"] + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
-- advance one frame
|
-- advance one frame
|
||||||
@ -357,10 +360,7 @@ function GameMode:onGameOver()
|
|||||||
switchBGM(nil)
|
switchBGM(nil)
|
||||||
local alpha = 0
|
local alpha = 0
|
||||||
local animation_length = 120
|
local animation_length = 120
|
||||||
if self.game_over_frames < animation_length then
|
if self.game_over_frames == 1 then
|
||||||
-- Show field for a bit, then fade out.
|
|
||||||
alpha = math.pow(2048, self.game_over_frames/animation_length - 1)
|
|
||||||
elseif self.game_over_frames == animation_length then
|
|
||||||
alpha = 1
|
alpha = 1
|
||||||
-- Save replay.
|
-- Save replay.
|
||||||
local replay = {}
|
local replay = {}
|
||||||
@ -392,6 +392,9 @@ function GameMode:onGameOver()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
love.filesystem.write("replays/"..replay_number..".rply", binser.serialize(replay))
|
love.filesystem.write("replays/"..replay_number..".rply", binser.serialize(replay))
|
||||||
|
elseif self.game_over_frames < animation_length then
|
||||||
|
-- Show field for a bit, then fade out.
|
||||||
|
alpha = math.pow(2048, self.game_over_frames/animation_length - 1)
|
||||||
elseif self.game_over_frames < 2 * animation_length then
|
elseif self.game_over_frames < 2 * animation_length then
|
||||||
-- Keep field hidden for a short time, then pop it back in (for screenshots).
|
-- Keep field hidden for a short time, then pop it back in (for screenshots).
|
||||||
alpha = 1
|
alpha = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user