From 63dd11fd2df7e3251061f10d3a1c6eb4aef65e90 Mon Sep 17 00:00:00 2001 From: David Vogel Date: Thu, 28 Jul 2022 22:34:56 +0200 Subject: [PATCH] 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 --- files/check.lua | 32 ++++++++++++++++++++++++-------- files/message.lua | 17 ++++++++++++++++- files/modification.lua | 6 ++++++ init.lua | 3 ++- settings.lua | 6 +++--- 5 files changed, 51 insertions(+), 13 deletions(-) diff --git a/files/check.lua b/files/check.lua index 1dc7abc..fc1be2c 100644 --- a/files/check.lua +++ b/files/check.lua @@ -17,7 +17,7 @@ local Coords = require("coordinates") local ScreenCap = require("screen-capture") local Vec2 = require("noita-api.vec2") -local Utils= require("noita-api.utils") +local Utils = require("noita-api.utils") ---------- -- Code -- @@ -38,9 +38,9 @@ function Check:Startup() end end ----Runs a list of checks for everything resolution related. +---Regularly runs a list of checks. ---@param interval integer -- Check interval in frames. -function Check:Resolutions(interval) +function Check:Regular(interval) interval = interval or 60 self.Counter = (self.Counter or 0) - 1 if self.Counter > 0 then return end @@ -62,27 +62,43 @@ function Check:Resolutions(interval) if config["fullscreen"] then local expected = tonumber(config["fullscreen"]) 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 if config["window_w"] and config["window_h"] then local expected = Vec2(tonumber(config["window_w"]), tonumber(config["window_h"])) 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 if config["internal_size_w"] and config["internal_size_h"] then local expected = Vec2(tonumber(config["internal_size_w"]), tonumber(config["internal_size_h"])) 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 + + -- 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 local expected = Vec2(tonumber(magic["VIRTUAL_RESOLUTION_X"]), tonumber(magic["VIRTUAL_RESOLUTION_Y"])) 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 - -- TODO: Check virtual resolution offset end diff --git a/files/message.lua b/files/message.lua index a876bf8..5506154 100644 --- a/files/message.lua +++ b/files/message.lua @@ -74,7 +74,6 @@ function Message:ShowSetNoitaSettings(callback, desc) desc or "", " ", "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`", "button at the top left.", @@ -85,6 +84,22 @@ function Message:ShowSetNoitaSettings(callback, desc) } 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. ---@param callback function ---@param desc string -- What's wrong. diff --git a/files/modification.lua b/files/modification.lua index 6abc03e..b54560c 100644 --- a/files/modification.lua +++ b/files/modification.lua @@ -83,6 +83,12 @@ function Modification.RequiredChanges() config["backbuffer_height"] = config["window_h"] magic["VIRTUAL_RESOLUTION_X"] = tostring(Vec2(ModSettingGet("noita-mapcap.virtual-resolution")).x) 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 -- Set virtual offset to be pixel perfect. diff --git a/init.lua b/init.lua index 5f952e6..c8265a8 100644 --- a/init.lua +++ b/init.lua @@ -113,7 +113,8 @@ function OnWorldPostUpdate() -- !!! DISABLE THIS LINE AND THE CORRESPONDING REQUIRE BEFORE COMMITTING !!! --LiveReload:Reload("mods/noita-mapcap/", 60) - Check:Resolutions(60) + -- Run checks every 60 frames. + Check:Regular(60) -- Draw UI after coroutines have been resumed. UI:Draw() diff --git a/settings.lua b/settings.lua index 3d4aada..3504162 100644 --- a/settings.lua +++ b/settings.lua @@ -171,7 +171,7 @@ modSettings = { ui_description = "Size of the window in screen pixels.\n \nDefault: 1024,1024", value_default = "1024,1024", allowed_characters = "0123456789,", - scope = MOD_SETTING_SCOPE_RUNTIME_RESTART, + scope = MOD_SETTING_SCOPE_RUNTIME, show_fn = function() 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")) @@ -183,7 +183,7 @@ modSettings = { ui_description = "Size of the viewport in screen pixels.\nIdeally set to the window resolution.\n \nDefault: 1024,1024", value_default = "1024,1024", allowed_characters = "0123456789,", - scope = MOD_SETTING_SCOPE_RUNTIME_RESTART, + scope = MOD_SETTING_SCOPE_RUNTIME, show_fn = function() 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")) @@ -195,7 +195,7 @@ modSettings = { ui_description = "Size of the viewport in world pixels.\nIdeally set to the window resolution.\n \nDefault: 1024,1024", value_default = "1024,1024", allowed_characters = "0123456789,", - scope = MOD_SETTING_SCOPE_RUNTIME_RESTART, + scope = MOD_SETTING_SCOPE_RUNTIME, show_fn = function() 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"))