diff --git a/game/engines/default/engine/Module.lua b/game/engines/default/engine/Module.lua index e25967cae5b571a70e176f0aedf4812e80448f8a..52c312ea29541e91434dcde1686c7f547c924128 100644 --- a/game/engines/default/engine/Module.lua +++ b/game/engines/default/engine/Module.lua @@ -175,7 +175,7 @@ function _M:listSavefiles(incompatible_module, moddir_filter) fs.mount(engine.homepath..fs.getPathSeparator(), "/tmp/listsaves") local steamsaves = {} - if core.steam then + if util.steamCanCloud() then local list = core.steam.listFilesEndingWith("game.teag") for _, file in ipairs(list) do local _, _, modname, char = file:find("^([^/]+)/save/([^/]+)/game%.teag$") @@ -195,9 +195,9 @@ function _M:listSavefiles(incompatible_module, moddir_filter) for i, short_name in ipairs(fs.list("/tmp/listsaves/"..mod.short_name.."/save/")) do local sdir = "/save/"..short_name local dir = "/tmp/listsaves/"..mod.short_name..sdir - if fs.exists(dir.."/game.teag") or (core.steam and core.steam.checkFile(sdir.."/game.teag")) then + if fs.exists(dir.."/game.teag") or (util.steamCanCloud() and core.steam.checkFile(sdir.."/game.teag")) then if steamsaves[mod.short_name] then steamsaves[mod.short_name][short_name:lower()] = nil end - if core.steam then core.steam.readFile(sdir.."/desc.lua") end + if util.steamCanCloud() then core.steam.readFile(sdir.."/desc.lua") end local def = self:loadSavefileDescription(dir) if def then if def.loadable and fs.exists(dir.."/cur.png") then @@ -1039,7 +1039,7 @@ function _M:setupWrite(mod, nomount) fs.setWritePath(engine.homepath) fs.mkdir(mod.short_name) fs.mkdir(mod.short_name.."/save") - if core.steam then core.steam.setFileNamespace(mod.short_name) end + if util.steamCanCloud() then core.steam.setFileNamespace(mod.short_name) end -- Enter module directory local base = engine.homepath .. fs.getPathSeparator() .. mod.short_name diff --git a/game/engines/default/engine/Savefile.lua b/game/engines/default/engine/Savefile.lua index d9bfe3fb15abc5c8d6dc21163ae4d868d30cde24..b99900969218daaef114bc39bbe069bb8097ffb0 100644 --- a/game/engines/default/engine/Savefile.lua +++ b/game/engines/default/engine/Savefile.lua @@ -77,10 +77,10 @@ end function _M:delete() for i, f in ipairs(fs.list(self.save_dir)) do fs.delete(self.save_dir..f) - if core.steam then core.steam.deleteFile(self.save_dir..f) end + if util.steamCanCloud() then core.steam.deleteFile(self.save_dir..f) end end fs.delete(self.save_dir) - if core.steam then + if util.steamCanCloud() then local namespace = core.steam.getFileNamespace() local list = core.steam.listFilesStartingWith(namespace..self.save_dir) core.steam.setFileNamespace("") @@ -243,7 +243,7 @@ function _M:saveGame(game, no_dialog) f:write(("cheat = %s\n"):format(game:isTainted() and "true" or "false")) f:write(("description = %q\n"):format(desc.description)) f:close() - if core.steam then core.steam.writeFile(self.save_dir.."desc.lua") end + if util.steamCanCloud() then core.steam.writeFile(self.save_dir.."desc.lua") end -- TODO: Replace this with saving quickhotkeys to the profile. -- Add print_doable_table to utils.lua as table.print_doable? @@ -405,7 +405,7 @@ end --- Loads a world function _M:loadWorld() - if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then core.steam.readFile(self.save_dir..self:nameLoadWorld()) end + if util.steamCanCloud() then core.steam.readFile(self.save_dir..self:nameLoadWorld()) end local path = fs.getRealPath(self.save_dir..self:nameLoadWorld()) if not path or path == "" then return nil, "no savefile" end @@ -436,7 +436,7 @@ end --- Loads a world function _M:loadWorldSize() - if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then core.steam.readFile(self.save_dir..self:nameLoadWorld()) end + if util.steamCanCloud() then core.steam.readFile(self.save_dir..self:nameLoadWorld()) end local path = fs.getRealPath(self.save_dir..self:nameLoadWorld()) if not path or path == "" then return nil, "no savefile" end @@ -455,7 +455,7 @@ end --- Loads a game function _M:loadGame() - if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then core.steam.readFile(self.save_dir..self:nameLoadGame()) end + if util.steamCanCloud() then core.steam.readFile(self.save_dir..self:nameLoadGame()) end local path = fs.getRealPath(self.save_dir..self:nameLoadGame()) if not path or path == "" then return nil, "no savefile" end @@ -489,7 +489,7 @@ end --- Loads a game function _M:loadGameSize() - if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then core.steam.readFile(self.save_dir..self:nameLoadGame()) end + if util.steamCanCloud() then core.steam.readFile(self.save_dir..self:nameLoadGame()) end local path = fs.getRealPath(self.save_dir..self:nameLoadGame()) if not path or path == "" then return nil, "no savefile" end @@ -508,7 +508,7 @@ end --- Loads a zone function _M:loadZone(zone) - if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then core.steam.readFile(self.save_dir..self:nameLoadZone(zone)) end + if util.steamCanCloud() then core.steam.readFile(self.save_dir..self:nameLoadZone(zone)) end local path = fs.getRealPath(self.save_dir..self:nameLoadZone(zone)) if not path or path == "" then return false end @@ -547,7 +547,7 @@ end --- Loads a level function _M:loadLevel(zone, level) - if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then core.steam.readFile(self.save_dir..self:nameLoadLevel(zone, level)) end + if util.steamCanCloud() then core.steam.readFile(self.save_dir..self:nameLoadLevel(zone, level)) end local path = fs.getRealPath(self.save_dir..self:nameLoadLevel(zone, level)) if not path or path == "" then return false end @@ -584,7 +584,7 @@ end --- Loads an entity function _M:loadEntity(name) - if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then core.steam.readFile(self.save_dir..self:nameLoadEntity(name)) end + if util.steamCanCloud() then core.steam.readFile(self.save_dir..self:nameLoadEntity(name)) end local path = fs.getRealPath(self.save_dir..self:nameLoadEntity(name)) if not path or path == "" then return false end @@ -638,7 +638,7 @@ end --- Checks for existence function _M:check() - if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then core.steam.readFile(self.save_dir..self:nameLoadGame()) end + if util.steamCanCloud() then core.steam.readFile(self.save_dir..self:nameLoadGame()) end return fs.exists(self.save_dir..self:nameLoadGame()) end diff --git a/game/engines/default/engine/SavefilePipe.lua b/game/engines/default/engine/SavefilePipe.lua index 22b0a1dd55f7061c9b56a38c750bf20caf6a385d..c0b783cb73215a302b762d0fd0f97deb4b6507cd 100644 --- a/game/engines/default/engine/SavefilePipe.lua +++ b/game/engines/default/engine/SavefilePipe.lua @@ -47,7 +47,7 @@ end --- Cleanup old saves in steam cloud if needed function _M:steamCleanup() - if not core.steam then return end + if not util.steamCanCloud() then return end local oldns = core.steam.getFileNamespace() core.steam.setFileNamespace("") diff --git a/game/engines/default/engine/dialogs/SteamOptions.lua b/game/engines/default/engine/dialogs/SteamOptions.lua index 1977c5b7732bceda82a3d96ca21f3158001c2cf3..e94f3bd93c3e0adce3b00011c4f24538b042587d 100644 --- a/game/engines/default/engine/dialogs/SteamOptions.lua +++ b/game/engines/default/engine/dialogs/SteamOptions.lua @@ -76,6 +76,7 @@ function _M:generateList() list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Cloud Saves#WHITE##{normal}#", status=function(item) return tostring(core.steam.isCloudEnabled(true) and "enabled" or "disabled") end, fct=function(item) + game:saveSettings("steam_cloud_choose", "steam_cloud_choose = true\n") core.steam.cloudEnable(not core.steam.isCloudEnabled(true)) self.c_list:drawItem(item) end,} diff --git a/game/engines/default/engine/init.lua b/game/engines/default/engine/init.lua index 2f0e400b5a3a285122f294a4f0afcaea7bf4f715..47c6a69ee3188739ed536be616818099b73a96c3 100644 --- a/game/engines/default/engine/init.lua +++ b/game/engines/default/engine/init.lua @@ -125,6 +125,12 @@ end fs.umount(engine.homepath) +-- Staem cloud saves, disabled until the user chooses otherwise +if core.steam and not config.settings.steam_cloud_choose then + print("[STEAM] Disabling cloud saves until the user elects to use them") + core.steam.cloudEnable(false) +end + -- Setup a default key handler local key = engine.KeyBind.new() key:setCurrent() diff --git a/game/engines/default/engine/utils.lua b/game/engines/default/engine/utils.lua index 81cb3f1a8076c31e0456b243cb0df3ff2fcbe05c..65220178f3d5b02279fa7aeecc50a721dc2da9b9 100644 --- a/game/engines/default/engine/utils.lua +++ b/game/engines/default/engine/utils.lua @@ -2409,3 +2409,7 @@ function require_first(...) end return nil end + +function util.steamCanCloud() + if core.steam and core.steam.isCloudEnabled(true) and core.steam.isCloudEnabled(false) and not savefile_pipe.disable_cloud_saves then return true end +end