fix(robot): loadRobotState should set the state using onLoad result

This commit is contained in:
Guillaume ARM 2024-05-26 05:10:58 +02:00
parent 37bfb2965a
commit 6b6fcac1d1

View File

@ -73,7 +73,7 @@ local loadRobotState = function(stateFile, onLoad, onSave)
return robot.saveRobotState(stateFile, onSave)
end
return onLoad(parsedResult)
return parsedResult, onLoad(parsedResult)
end
local getAutoSave = function(config, state)
@ -93,7 +93,8 @@ api.create = function(state, givenConfig)
local config = getConfig(givenConfig)
if config.autoload then
state = loadRobotState(config.stateFilePath, config.onLoad, config.onSave)
local originalState = loadRobotState(config.stateFilePath, config.onLoad, config.onSave)
state = originalState
end
local autoSave = getAutoSave(config, state)
@ -219,7 +220,9 @@ api.create = function(state, givenConfig)
end
robot.loadState = function()
return loadRobotState(config.stateFilePath, config.onLoad, config.onSave)
local originalState, transformedState = loadRobotState(config.stateFilePath, config.onLoad, config.onSave)
state = originalState
return transformedState
end
return robot