Replays are now fully functional.

pull/48/head
BoatsandJoes 2021-12-05 22:17:44 -06:00
parent 81ab7cd4de
commit febd1de0ef
2 changed files with 50 additions and 31 deletions

View File

@ -1,3 +1,5 @@
local Sequence = require 'tetris.randomizers.fixed_sequence'
local ReplayScene = Scene:extend()
ReplayScene.title = "Replay"
@ -6,7 +8,10 @@ function ReplayScene:new(replay, game_mode, ruleset, inputs)
self.secret_inputs = inputs
self.game = game_mode(self.secret_inputs)
self.ruleset = ruleset(self.game)
self.game:initialize(self.ruleset)
-- Replace piece randomizer with replay piece sequence
local randomizer = Sequence(table.keys(ruleset.colourscheme))
randomizer.sequence = replay["pieces"]
self.game:initializeReplay(self.ruleset, randomizer)
self.inputs = {
left=false,
right=false,

View File

@ -74,7 +74,8 @@ function GameMode:new(secret_inputs)
self.section_times = { [0] = 0 }
self.secondary_section_times = { [0] = 0 }
self.replay_inputs = {}
self.replay_pieces = {}
self.replay_pieces = ""
self.save_replay = true
end
function GameMode:getARR() return 1 end
@ -89,7 +90,7 @@ function GameMode:getGravity() return 1/64 end
function GameMode:getNextPiece(ruleset)
local shape = self.used_randomizer:nextPiece()
self.replay_pieces[#self.replay_pieces + 1] = shape
self.replay_pieces = self.replay_pieces..shape
return {
skin = self:getSkin(),
shape = shape,
@ -114,7 +115,18 @@ function GameMode:initialize(ruleset)
for i = 1, math.max(self.next_queue_length, 1) do
table.insert(self.next_queue, self:getNextPiece(ruleset))
end
self.lock_on_soft_drop = ({ruleset.softdrop_lock, self.instant_soft_drop, false, true })[config.gamesettings.manlock]
self.lock_on_soft_drop = ({ruleset.softdrop_lock, self.instant_soft_drop, false, true})[config.gamesettings.manlock]
self.lock_on_hard_drop = ({ruleset.harddrop_lock, self.instant_hard_drop, true, false})[config.gamesettings.manlock]
end
function GameMode:initializeReplay(ruleset, randomizer)
self.used_randomizer = randomizer
self.save_replay = false
self.ruleset = ruleset
for i = 1, math.max(self.next_queue_length, 1) do
table.insert(self.next_queue, self:getNextPiece(ruleset))
end
self.lock_on_soft_drop = ({ruleset.softdrop_lock, self.instant_soft_drop, false, true})[config.gamesettings.manlock]
self.lock_on_hard_drop = ({ruleset.harddrop_lock, self.instant_hard_drop, true, false})[config.gamesettings.manlock]
end
@ -361,6 +373,7 @@ function GameMode:onGameOver()
local animation_length = 120
if self.game_over_frames == 1 then
alpha = 1
if self.save_replay then
-- Save replay.
local replay = {}
replay["inputs"] = self.replay_inputs
@ -391,6 +404,7 @@ function GameMode:onGameOver()
end
end
love.filesystem.write("replays/"..replay_number..".rply", binser.serialize(replay))
end
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)