Sorting code

This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-05-15 18:18:55 +07:00
parent b789354299
commit 8c895221bd

View File

@@ -149,8 +149,7 @@ function GameMode:readGradeHistory()
self.grade = self.grade_history[1]
self.starting_grade = self.grade
if self.grade > 1 then
temp_grade = copy(self.grade_history)
temp_grade[2] = 0
local temp_grade = copy(self.grade_history); temp_grade[2] = 0
bitser.dumpLoveFile(SAVE_DIR..self.player_name.."_grade_history.sav", temp_grade)
end
end
@@ -279,7 +278,7 @@ function GameMode:initialize(ruleset)
end
function GameMode:saveInputs()
input_string = 'NEW'..string.format("%16d", self.randomizer.seed)..';'
local input_string = 'NEW'..string.format("%16d", self.randomizer.seed)..';'
for frame, input_set in pairs(self.recorded_inputs) do
input_string = input_string..string.format('%03d', tostring(input_set))
end
@@ -288,28 +287,56 @@ function GameMode:saveInputs()
inputfile:close()
end
function GameMode:storeInput(input_set)
input_right = 1
input_rotright2 = 2
input_up = 4
input_rotleft = 8
input_left = 16
input_down = 32
input_rotright = 64
input_rotleft2 = 128
if not input_set['right'] then input_right = 0 end
if not input_set['rotate_right2'] then input_rotright2 = 0 end
if not input_set['up'] then input_up = 0 end
if not input_set['rotate_left'] then input_rotleft = 0 end
if not input_set['left'] then input_left = 0 end
if not input_set['down'] then input_down = 0 end
if not input_set['rotate_right'] then input_rotright = 0 end
if not input_set['rotate_left2'] then input_rotleft2 = 0 end
self.recorded_inputs[self.frames] = bit.bor(input_right, input_rotright2, input_up, input_rotleft, input_left, input_down, input_rotright, input_rotleft2)
self.recorded_inputs[self.frames] = bit.bor(
input_set['right'] and 1 or 0,
input_set['rotate_right2'] and 2 or 0,
input_set['up'] and 4 or 0,
input_set['rotate_left'] and 8 or 0,
input_set['left'] and 16 or 0,
input_set['down'] and 32 or 0,
input_set['rotate_right'] and 64 or 0,
input_set['rotate_left2'] and 128 or 0
)
end
function GameMode:getReplayInputs(input_file)
local i = 1
local replay_inputs = {}
local reached_inputs = false
for _=1,1e99 do
local c = string.sub(input_file,_,_)
if c == ';' then
reached_inputs = true
i = _ + 1
end
if reached_inputs then break end
end
if reached_inputs then
while i <= #input_file - 3 do
local input_list = {right = false, rotate_right2 = false, up = false, rotate_left = false, left = false, down = false, rotate_right = false, rotate_left2 = false}
local coded_input = tonumber(string.sub(input_file, i, i+2))
if bit.band(coded_input, 1 ) == 1 then input_list["right"] = true end
if bit.band(coded_input, 2 ) == 2 then input_list["rotate_right2"] = true end
if bit.band(coded_input, 4 ) == 4 then input_list["up"] = true end
if bit.band(coded_input, 8 ) == 8 then input_list["rotate_left"] = true end
if bit.band(coded_input, 16 ) == 16 then input_list["left"] = true end
if bit.band(coded_input, 32 ) == 32 then input_list["down"] = true end
if bit.band(coded_input, 64 ) == 64 then input_list["rotate_right"] = true end
if bit.band(coded_input, 128) == 128 then input_list["rotate_left2"] = true end
table.insert(replay_inputs, input_list)
i = i + 3
end
end
return replay_inputs
end
function GameMode:getInputPieceSeq(input_file)
local seed = ''
local string_start
if string.sub(input_file, 1, 3) == 'NEW' then
string_start = 4
self.old_replay = false
@@ -318,7 +345,7 @@ function GameMode:getInputPieceSeq(input_file)
self.old_replay = true
end
for i = string_start, #input_file do
c = string.sub(input_file, i, i)
local c = string.sub(input_file, i, i)
if c == ';' then break
else seed = seed..c
end
@@ -326,44 +353,6 @@ function GameMode:getInputPieceSeq(input_file)
return seed
end
function GameMode:getReplayInputs(input_file)
input_right = 1
input_rotright2 = 2
input_up = 4
input_rotleft = 8
input_left = 16
input_down = 32
input_rotright = 64
input_rotleft2 = 128
replay_inputs = {}
reached_inputs = false
i = 1
while not reached_inputs do
c = string.sub(input_file,i,i)
if c == ';' then
reached_inputs = true
end
i = i+1
end
if reached_inputs then
while i <= #input_file - 3 do
input_list = {right = false, rotate_right2 = false, up = false, rotate_left = false, left = false, down = false, rotate_right = false, rotate_left2 = false}
coded_input = tonumber(string.sub(input_file, i, i+2))
if bit.band(coded_input, input_right) == 1 then input_list["right"] = true end
if bit.band(coded_input, input_rotright2) == 2 then input_list["rotate_right2"] = true end
if bit.band(coded_input, input_up) == 4 then input_list["up"] = true end
if bit.band(coded_input, input_rotleft) == 8 then input_list["rotate_left"] = true end
if bit.band(coded_input, input_left) == 16 then input_list["left"] = true end
if bit.band(coded_input, input_down) == 32 then input_list["down"] = true end
if bit.band(coded_input, input_rotright) == 64 then input_list["rotate_right"] = true end
if bit.band(coded_input, input_rotleft2) == 128 then input_list["rotate_left2"] = true end
table.insert(replay_inputs, input_list)
i = i + 3
end
end
return replay_inputs
end
function GameMode:update(inputs, ruleset)
if self.input_playback and self.replay_inputs[self.frames] ~= nil then
inputs = self.replay_inputs[self.frames]