Replace every single `io.open into fs.read()`

This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-04-11 10:25:56 +07:00
parent 3c88b8241b
commit e4b9ef4e51
2 changed files with 11 additions and 11 deletions

View File

@@ -17,7 +17,7 @@ local GameMode = Object:extend()
function GameMode:new(player_name, input_file, replay_grade)
if player_name == nil then self.training = true else self.training = false end
if input_file ~= nil then
input_file = io.open(REPLAY_DIR..input_file, 'rb'):read('a')
input_file = love.filesystem.newFile(REPLAY_DIR..input_file, 'r'):read()
input_file = lualzw.decompress(input_file)
seed = self:getInputPieceSeq(input_file)
self.replay_inputs = self:getReplayInputs(input_file)
@@ -141,7 +141,7 @@ function GameMode:new(player_name, input_file, replay_grade)
end
function GameMode:readGradeHistory()
outfile = io.open(SAVE_DIR..self.player_name.."_grade_history.sav", 'rb')
outfile = love.filesystem.newFile(SAVE_DIR..self.player_name.."_grade_history.sav", 'r')
if outfile ~= nil then
self.grade_history = binser.deserialize(outfile:read('a'))[1]
outfile:close()
@@ -153,16 +153,16 @@ function GameMode:readGradeHistory()
if self.grade > 1 then
temp_grade = copy(self.grade_history)
temp_grade[2] = 0
gradefile = io.open(SAVE_DIR..self.player_name.."_grade_history.sav", 'wb')
gradefile = love.filesystem.newFile(SAVE_DIR..self.player_name.."_grade_history.sav", 'w')
gradefile:write(binser.serialize(temp_grade))
gradefile:close()
end
end
function GameMode:readHiScores()
outfile = io.open(HIscoreFILE, 'rb')
outfile = love.filesystem.newFile(HIscoreFILE, 'r')
if outfile ~= nil then
self.hi_scores = binser.deserialize(outfile:read('a'))[1]
self.hi_scores = binser.deserialize(outfile:read())[1]
outfile:close()
else
self.hi_scores = {"TRO",0,"MIT",0,"ROM",0,"ITR",0,"OMI",0}
@@ -231,7 +231,7 @@ function GameMode:updateHiScores()
self.hi_scores[score_position] = self.grade_score
hiscore_pos = {score_position-1, score_position}
end
local scoresfile = io.open(HIscoreFILE, 'wb')
local scoresfile = love.filesystem.newFile(HIscoreFILE, 'w')
scoresfile:write(binser.serialize(self.hi_scores))
scoresfile:close()
return hiscore_pos
@@ -293,7 +293,7 @@ function GameMode:saveInputs()
for frame, input_set in pairs(self.recorded_inputs) do
input_string = input_string..string.format('%03d', tostring(input_set))
end
local inputfile = love.fileSystem.newFile(REPLAY_DIR..tostring(os.time()).."_"..self.player_name.."_"..self.starting_grade.."_"..self.grade_score.."_replay"..'.sav', 'wb')
local inputfile = love.filesystem.newFile(REPLAY_DIR..tostring(os.time()).."_"..self.player_name.."_"..self.starting_grade.."_"..self.grade_score.."_replay"..'.sav', 'w')
inputfile:write(lualzw.compress(input_string))
inputfile:close()
end
@@ -718,7 +718,7 @@ function GameMode:onGameOver()
self.grade_score = self.grade_score + self.speed_level
promo_string = self:updateGradeHistory()
hiscore_pos = self:updateHiScores()
gradefile = io.open(SAVE_DIR..self.player_name.."_grade_history.sav", 'wb')
gradefile = love.filesystem.newFile(SAVE_DIR..self.player_name.."_grade_history.sav", 'w')
gradefile:write(binser.serialize(self.grade_history))
gradefile:close()
self.did_grades = true

View File

@@ -30,9 +30,9 @@ function NameEntryScene:new()
self.name_entry = {config['last_entry']:sub(1,1),config['last_entry']:sub(2,2),config['last_entry']:sub(3,3)}
self.entry_pos = 3
end
score_file = io.open(HIscoreFILE, 'rb')
score_file = love.filesystem.newFile(HIscoreFILE, 'r')
if score_file ~= nil then
self.hi_scores = binser.deserialize(score_file:read('a'))[1]
self.hi_scores = binser.deserialize(score_file:read())[1]
else
self.hi_scores = {"TRO",0,"MIT",0,"ROM",0,"ITR",0,"OMI",0}
end
@@ -122,7 +122,7 @@ function NameEntryScene:onInputPress(e)
else
if self.entry_pos == 3 then
name = string.lower(self.name_entry[1]..self.name_entry[2]..self.name_entry[3])
grade_history = io.open(SAVE_DIR..name.."_grade_history.sav", 'rb')
grade_history = love.filesystem.newFile(SAVE_DIR..name.."_grade_history.sav", 'r')
if grade_history ~= nil then
grade_history = binser.deserialize(grade_history:read())[1]
self.grade = grade_history[1]