diff --git a/game/gamemode.lua b/game/gamemode.lua index 4d459c8..d7f930d 100644 --- a/game/gamemode.lua +++ b/game/gamemode.lua @@ -2,8 +2,6 @@ local Object = require 'libs.classic' local bit = require("bit") local lualzw = require 'libs.lualzw' local bitser = require 'libs.bitser' -require 'funcs' -require 'settings' local playedReadySE = false local playedGoSE = false @@ -287,64 +285,55 @@ function GameMode:saveInputs() inputfile:close() end - +local GAME_input_code_list = { + right = 1 , + rotate_right2 = 2 , + up = 4 , + rotate_left = 8 , + left = 16 , + down = 32 , + rotate_right = 64 , + rotate_left2 = 128, +} function GameMode:storeInput(input_set) - local input_code_list = { - right = 1 , - rotate_right2 = 2 , - up = 4 , - rotate_left = 8 , - left = 16 , - down = 32 , - rotate_right = 64 , - rotate_left2 = 128, - } local current_frame_input = 0 - - for key, code in pairs(input_code_list) do + for key, code in pairs(GAME_input_code_list) do if input_set[key] then current_frame_input = bit.bor(current_frame_input, code) end end - self.recorded_inputs[self.frames] = current_frame_input end function GameMode:getReplayInputs(input_file) - local i = 1 local replay_inputs = {} - local reached_inputs = false + local semicolon_position = string.find(input_file, ';', 1, true) - 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 + -- 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 semicolon_position then + for i = semicolon_position + 1, #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 + for key, code in pairs(GAME_input_code_list) do + ---@diagnostic disable-next-line: param-type-mismatch + if bit.band(coded_input, code) == code then input_list[key] = true end + 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 @@ -353,13 +342,16 @@ function GameMode:getInputPieceSeq(input_file) string_start = 1 self.old_replay = true end - for i = string_start, #input_file do - local c = string.sub(input_file, i, i) - if c == ';' then break - else seed = seed..c - end - end - return seed + return string.sub( + input_file, string_start, + string.find(input_file, ';', string_start, true) - 1 + ) -- seed + -- for i = string_start, #input_file do + -- local c = string.sub(input_file, i, i) + -- if c == ';' then break + -- else seed = seed..c + -- end + -- end end function GameMode:update(inputs, ruleset)