Add more checks & Other fixes

- Rename Check:Resolutions to Check:Regular
- Add check for virtual offset
- Add check if specific mod settings are changed
- Revert scope of resolution mod settings to "runtime"
- Add restart request message
- Set virtual and internal resolutions to default if no custom resolution is defined
This commit is contained in:
David Vogel 2022-07-28 22:34:56 +02:00
parent 98f663f200
commit 63dd11fd2d
5 changed files with 51 additions and 13 deletions

View File

@ -38,9 +38,9 @@ function Check:Startup()
end end
end end
---Runs a list of checks for everything resolution related. ---Regularly runs a list of checks.
---@param interval integer -- Check interval in frames. ---@param interval integer -- Check interval in frames.
function Check:Resolutions(interval) function Check:Regular(interval)
interval = interval or 60 interval = interval or 60
self.Counter = (self.Counter or 0) - 1 self.Counter = (self.Counter or 0) - 1
if self.Counter > 0 then return end if self.Counter > 0 then return end
@ -62,27 +62,43 @@ function Check:Resolutions(interval)
if config["fullscreen"] then if config["fullscreen"] then
local expected = tonumber(config["fullscreen"]) local expected = tonumber(config["fullscreen"])
if expected ~= Coords.FullscreenMode then if expected ~= Coords.FullscreenMode then
Message:ShowSetNoitaSettings(Modification.AutoSet, string.format("Expected fullscreen mode %s. But got %s.", expected, Coords.FullscreenMode)) Message:ShowSetNoitaSettings(Modification.AutoSet, string.format("Fullscreen mode %s. Expected %s.", Coords.FullscreenMode, expected))
end end
end end
if config["window_w"] and config["window_h"] then if config["window_w"] and config["window_h"] then
local expected = Vec2(tonumber(config["window_w"]), tonumber(config["window_h"])) local expected = Vec2(tonumber(config["window_w"]), tonumber(config["window_h"]))
if expected ~= Coords.WindowResolution then if expected ~= Coords.WindowResolution then
Message:ShowSetNoitaSettings(Modification.AutoSet, string.format("Expected window resolution is %s. But got %s.", expected, Coords.WindowResolution)) Message:ShowSetNoitaSettings(Modification.AutoSet, string.format("Window resolution is %s. Expected %s.", Coords.WindowResolution, expected))
end end
end end
if config["internal_size_w"] and config["internal_size_h"] then if config["internal_size_w"] and config["internal_size_h"] then
local expected = Vec2(tonumber(config["internal_size_w"]), tonumber(config["internal_size_h"])) local expected = Vec2(tonumber(config["internal_size_w"]), tonumber(config["internal_size_h"]))
if expected ~= Coords.InternalResolution then if expected ~= Coords.InternalResolution then
Message:ShowSetNoitaSettings(Modification.AutoSet, string.format("Expected internal resolution is %s. But got %s.", expected, Coords.InternalResolution)) Message:ShowSetNoitaSettings(Modification.AutoSet, string.format("Internal resolution is %s. Expected %s.", Coords.InternalResolution, expected))
end end
end end
-- Magic numbers stuff doesn't need a forced restart, just a normal restart by the user.
if magic["VIRTUAL_RESOLUTION_X"] and magic["VIRTUAL_RESOLUTION_Y"] then if magic["VIRTUAL_RESOLUTION_X"] and magic["VIRTUAL_RESOLUTION_Y"] then
local expected = Vec2(tonumber(magic["VIRTUAL_RESOLUTION_X"]), tonumber(magic["VIRTUAL_RESOLUTION_Y"])) local expected = Vec2(tonumber(magic["VIRTUAL_RESOLUTION_X"]), tonumber(magic["VIRTUAL_RESOLUTION_Y"]))
if expected ~= Coords.VirtualResolution then if expected ~= Coords.VirtualResolution then
Message:ShowSetNoitaSettings(Modification.AutoSet, string.format("Expected virtual resolution is %s. But got %s.", expected, Coords.VirtualResolution)) Message:ShowRequestRestart(string.format("Virtual resolution is %s. Expected %s.", Coords.VirtualResolution, expected))
end
end
if magic["VIRTUAL_RESOLUTION_OFFSET_X"] and magic["VIRTUAL_RESOLUTION_OFFSET_Y"] then
local expected = Vec2(tonumber(magic["VIRTUAL_RESOLUTION_OFFSET_X"]), tonumber(magic["VIRTUAL_RESOLUTION_OFFSET_Y"]))
if expected ~= Coords.VirtualOffset then
Message:ShowRequestRestart(string.format("Virtual offset is %s. Expected %s.", Coords.VirtualOffset, expected))
end
end
-- Request a restart if the user has changed specific mod settings.
local restartModSettings = {"disable-background", "disable-physics", "disable-postfx", "disable-shaders-gui-ai"}
for i, v in ipairs(restartModSettings) do
local settingID = "noita-mapcap." .. v
if ModSettingGetNextValue(settingID) ~= ModSettingGet(settingID) then
Message:ShowRequestRestart(string.format("Setting %s got changed from %s to %s.", v, tostring(ModSettingGet(settingID)), tostring(ModSettingGetNextValue(settingID))))
end end
end end
-- TODO: Check virtual resolution offset
end end

View File

@ -74,7 +74,6 @@ function Message:ShowSetNoitaSettings(callback, desc)
desc or "", desc or "",
" ", " ",
"Press the button at the bottom to set up and close Noita automatically.", "Press the button at the bottom to set up and close Noita automatically.",
"Alternatively disable `Use custom resolution` in the mod settings.",
" ", " ",
"You can always reset any custom settings by right clicking the `start capture`", "You can always reset any custom settings by right clicking the `start capture`",
"button at the top left.", "button at the top left.",
@ -85,6 +84,22 @@ function Message:ShowSetNoitaSettings(callback, desc)
} }
end end
---Request the user to restart Noita.
---@param desc string -- What's wrong.
function Message:ShowRequestRestart(desc)
self.List = self.List or {}
self.List["RequestRestart"] = {
Type = "warning",
Lines = {
"It seems that not all requested settings are applied to Noita:",
desc or "",
" ",
"To resolve this issue, restart the game.",
},
}
end
---Request the user to let the addon automatically set Noita settings based on the given callback. ---Request the user to let the addon automatically set Noita settings based on the given callback.
---@param callback function ---@param callback function
---@param desc string -- What's wrong. ---@param desc string -- What's wrong.

View File

@ -83,6 +83,12 @@ function Modification.RequiredChanges()
config["backbuffer_height"] = config["window_h"] config["backbuffer_height"] = config["window_h"]
magic["VIRTUAL_RESOLUTION_X"] = tostring(Vec2(ModSettingGet("noita-mapcap.virtual-resolution")).x) magic["VIRTUAL_RESOLUTION_X"] = tostring(Vec2(ModSettingGet("noita-mapcap.virtual-resolution")).x)
magic["VIRTUAL_RESOLUTION_Y"] = tostring(Vec2(ModSettingGet("noita-mapcap.virtual-resolution")).y) magic["VIRTUAL_RESOLUTION_Y"] = tostring(Vec2(ModSettingGet("noita-mapcap.virtual-resolution")).y)
else
-- Only reset some stuff that is independent to the users chosen resolution.
config["internal_size_w"] = "1280"
config["internal_size_h"] = "720"
magic["VIRTUAL_RESOLUTION_X"] = "427"
magic["VIRTUAL_RESOLUTION_Y"] = "242"
end end
-- Set virtual offset to be pixel perfect. -- Set virtual offset to be pixel perfect.

View File

@ -113,7 +113,8 @@ function OnWorldPostUpdate()
-- !!! DISABLE THIS LINE AND THE CORRESPONDING REQUIRE BEFORE COMMITTING !!! -- !!! DISABLE THIS LINE AND THE CORRESPONDING REQUIRE BEFORE COMMITTING !!!
--LiveReload:Reload("mods/noita-mapcap/", 60) --LiveReload:Reload("mods/noita-mapcap/", 60)
Check:Resolutions(60) -- Run checks every 60 frames.
Check:Regular(60)
-- Draw UI after coroutines have been resumed. -- Draw UI after coroutines have been resumed.
UI:Draw() UI:Draw()

View File

@ -171,7 +171,7 @@ modSettings = {
ui_description = "Size of the window in screen pixels.\n \nDefault: 1024,1024", ui_description = "Size of the window in screen pixels.\n \nDefault: 1024,1024",
value_default = "1024,1024", value_default = "1024,1024",
allowed_characters = "0123456789,", allowed_characters = "0123456789,",
scope = MOD_SETTING_SCOPE_RUNTIME_RESTART, scope = MOD_SETTING_SCOPE_RUNTIME,
show_fn = function() show_fn = function()
return (not modSettings:Get("advanced.settings.custom-resolution-live.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-live")) return (not modSettings:Get("advanced.settings.custom-resolution-live.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-live"))
or (not modSettings:Get("advanced.settings.custom-resolution-other.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-other")) or (not modSettings:Get("advanced.settings.custom-resolution-other.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-other"))
@ -183,7 +183,7 @@ modSettings = {
ui_description = "Size of the viewport in screen pixels.\nIdeally set to the window resolution.\n \nDefault: 1024,1024", ui_description = "Size of the viewport in screen pixels.\nIdeally set to the window resolution.\n \nDefault: 1024,1024",
value_default = "1024,1024", value_default = "1024,1024",
allowed_characters = "0123456789,", allowed_characters = "0123456789,",
scope = MOD_SETTING_SCOPE_RUNTIME_RESTART, scope = MOD_SETTING_SCOPE_RUNTIME,
show_fn = function() show_fn = function()
return (not modSettings:Get("advanced.settings.custom-resolution-live.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-live")) return (not modSettings:Get("advanced.settings.custom-resolution-live.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-live"))
or (not modSettings:Get("advanced.settings.custom-resolution-other.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-other")) or (not modSettings:Get("advanced.settings.custom-resolution-other.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-other"))
@ -195,7 +195,7 @@ modSettings = {
ui_description = "Size of the viewport in world pixels.\nIdeally set to the window resolution.\n \nDefault: 1024,1024", ui_description = "Size of the viewport in world pixels.\nIdeally set to the window resolution.\n \nDefault: 1024,1024",
value_default = "1024,1024", value_default = "1024,1024",
allowed_characters = "0123456789,", allowed_characters = "0123456789,",
scope = MOD_SETTING_SCOPE_RUNTIME_RESTART, scope = MOD_SETTING_SCOPE_RUNTIME,
show_fn = function() show_fn = function()
return (not modSettings:Get("advanced.settings.custom-resolution-live.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-live")) return (not modSettings:Get("advanced.settings.custom-resolution-live.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-live"))
or (not modSettings:Get("advanced.settings.custom-resolution-other.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-other")) or (not modSettings:Get("advanced.settings.custom-resolution-other.hidden") and modSettings:GetNextValue("advanced.settings.custom-resolution-other"))