mirror of
https://gitea.com/SweetSea-ButImNotSweet/tromi_mobile.git
synced 2025-01-08 17:33:09 +08:00
Sorting code
This commit is contained in:
@@ -149,8 +149,7 @@ function GameMode:readGradeHistory()
|
|||||||
self.grade = self.grade_history[1]
|
self.grade = self.grade_history[1]
|
||||||
self.starting_grade = self.grade
|
self.starting_grade = self.grade
|
||||||
if self.grade > 1 then
|
if self.grade > 1 then
|
||||||
temp_grade = copy(self.grade_history)
|
local temp_grade = copy(self.grade_history); temp_grade[2] = 0
|
||||||
temp_grade[2] = 0
|
|
||||||
bitser.dumpLoveFile(SAVE_DIR..self.player_name.."_grade_history.sav", temp_grade)
|
bitser.dumpLoveFile(SAVE_DIR..self.player_name.."_grade_history.sav", temp_grade)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -279,7 +278,7 @@ function GameMode:initialize(ruleset)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function GameMode:saveInputs()
|
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
|
for frame, input_set in pairs(self.recorded_inputs) do
|
||||||
input_string = input_string..string.format('%03d', tostring(input_set))
|
input_string = input_string..string.format('%03d', tostring(input_set))
|
||||||
end
|
end
|
||||||
@@ -288,28 +287,56 @@ function GameMode:saveInputs()
|
|||||||
inputfile:close()
|
inputfile:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function GameMode:storeInput(input_set)
|
function GameMode:storeInput(input_set)
|
||||||
input_right = 1
|
self.recorded_inputs[self.frames] = bit.bor(
|
||||||
input_rotright2 = 2
|
input_set['right'] and 1 or 0,
|
||||||
input_up = 4
|
input_set['rotate_right2'] and 2 or 0,
|
||||||
input_rotleft = 8
|
input_set['up'] and 4 or 0,
|
||||||
input_left = 16
|
input_set['rotate_left'] and 8 or 0,
|
||||||
input_down = 32
|
input_set['left'] and 16 or 0,
|
||||||
input_rotright = 64
|
input_set['down'] and 32 or 0,
|
||||||
input_rotleft2 = 128
|
input_set['rotate_right'] and 64 or 0,
|
||||||
if not input_set['right'] then input_right = 0 end
|
input_set['rotate_left2'] and 128 or 0
|
||||||
if not input_set['rotate_right2'] then input_rotright2 = 0 end
|
)
|
||||||
if not input_set['up'] then input_up = 0 end
|
end
|
||||||
if not input_set['rotate_left'] then input_rotleft = 0 end
|
function GameMode:getReplayInputs(input_file)
|
||||||
if not input_set['left'] then input_left = 0 end
|
local i = 1
|
||||||
if not input_set['down'] then input_down = 0 end
|
local replay_inputs = {}
|
||||||
if not input_set['rotate_right'] then input_rotright = 0 end
|
local reached_inputs = false
|
||||||
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)
|
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
|
end
|
||||||
|
|
||||||
function GameMode:getInputPieceSeq(input_file)
|
function GameMode:getInputPieceSeq(input_file)
|
||||||
local seed = ''
|
local seed = ''
|
||||||
|
local string_start
|
||||||
if string.sub(input_file, 1, 3) == 'NEW' then
|
if string.sub(input_file, 1, 3) == 'NEW' then
|
||||||
string_start = 4
|
string_start = 4
|
||||||
self.old_replay = false
|
self.old_replay = false
|
||||||
@@ -318,7 +345,7 @@ function GameMode:getInputPieceSeq(input_file)
|
|||||||
self.old_replay = true
|
self.old_replay = true
|
||||||
end
|
end
|
||||||
for i = string_start, #input_file do
|
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
|
if c == ';' then break
|
||||||
else seed = seed..c
|
else seed = seed..c
|
||||||
end
|
end
|
||||||
@@ -326,44 +353,6 @@ function GameMode:getInputPieceSeq(input_file)
|
|||||||
return seed
|
return seed
|
||||||
end
|
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)
|
function GameMode:update(inputs, ruleset)
|
||||||
if self.input_playback and self.replay_inputs[self.frames] ~= nil then
|
if self.input_playback and self.replay_inputs[self.frames] ~= nil then
|
||||||
inputs = self.replay_inputs[self.frames]
|
inputs = self.replay_inputs[self.frames]
|
||||||
|
|||||||
Reference in New Issue
Block a user