Replays are now fully functional.
parent
81ab7cd4de
commit
febd1de0ef
|
@ -1,3 +1,5 @@
|
||||||
|
local Sequence = require 'tetris.randomizers.fixed_sequence'
|
||||||
|
|
||||||
local ReplayScene = Scene:extend()
|
local ReplayScene = Scene:extend()
|
||||||
|
|
||||||
ReplayScene.title = "Replay"
|
ReplayScene.title = "Replay"
|
||||||
|
@ -6,7 +8,10 @@ function ReplayScene:new(replay, game_mode, ruleset, inputs)
|
||||||
self.secret_inputs = inputs
|
self.secret_inputs = inputs
|
||||||
self.game = game_mode(self.secret_inputs)
|
self.game = game_mode(self.secret_inputs)
|
||||||
self.ruleset = ruleset(self.game)
|
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 = {
|
self.inputs = {
|
||||||
left=false,
|
left=false,
|
||||||
right=false,
|
right=false,
|
||||||
|
|
|
@ -74,7 +74,8 @@ function GameMode:new(secret_inputs)
|
||||||
self.section_times = { [0] = 0 }
|
self.section_times = { [0] = 0 }
|
||||||
self.secondary_section_times = { [0] = 0 }
|
self.secondary_section_times = { [0] = 0 }
|
||||||
self.replay_inputs = {}
|
self.replay_inputs = {}
|
||||||
self.replay_pieces = {}
|
self.replay_pieces = ""
|
||||||
|
self.save_replay = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameMode:getARR() return 1 end
|
function GameMode:getARR() return 1 end
|
||||||
|
@ -89,7 +90,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()
|
||||||
self.replay_pieces[#self.replay_pieces + 1] = shape
|
self.replay_pieces = self.replay_pieces..shape
|
||||||
return {
|
return {
|
||||||
skin = self:getSkin(),
|
skin = self:getSkin(),
|
||||||
shape = shape,
|
shape = shape,
|
||||||
|
@ -114,7 +115,18 @@ function GameMode:initialize(ruleset)
|
||||||
for i = 1, math.max(self.next_queue_length, 1) do
|
for i = 1, math.max(self.next_queue_length, 1) do
|
||||||
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
||||||
end
|
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]
|
self.lock_on_hard_drop = ({ruleset.harddrop_lock, self.instant_hard_drop, true, false})[config.gamesettings.manlock]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -361,6 +373,7 @@ function GameMode:onGameOver()
|
||||||
local animation_length = 120
|
local animation_length = 120
|
||||||
if self.game_over_frames == 1 then
|
if self.game_over_frames == 1 then
|
||||||
alpha = 1
|
alpha = 1
|
||||||
|
if self.save_replay then
|
||||||
-- Save replay.
|
-- Save replay.
|
||||||
local replay = {}
|
local replay = {}
|
||||||
replay["inputs"] = self.replay_inputs
|
replay["inputs"] = self.replay_inputs
|
||||||
|
@ -391,6 +404,7 @@ 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))
|
||||||
|
end
|
||||||
elseif self.game_over_frames < animation_length then
|
elseif self.game_over_frames < animation_length then
|
||||||
-- Show field for a bit, then fade out.
|
-- Show field for a bit, then fade out.
|
||||||
alpha = math.pow(2048, self.game_over_frames/animation_length - 1)
|
alpha = math.pow(2048, self.game_over_frames/animation_length - 1)
|
||||||
|
|
Loading…
Reference in New Issue