diff --git a/README.md b/README.md index bd98864..838b888 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,8 @@ them. Therefore, this mod is compatible with the Fungal Timer mod. ## Prerequisites -This mod depends on the -[https://github.com/dextercd/Noita-Dear-ImGui/releases](Noita-DearImGui) mod. -Note that the Noita-DearImGui mod must appear above Fungal Shift Query in the -mod order. +This mod depends on the Noita-DearImGui mod. Note that the Noita-DearImGui mod +must appear above Fungal Shift Query in the mod order. ## Installation diff --git a/aplc.lua b/files/aplc.lua similarity index 98% rename from aplc.lua rename to files/aplc.lua index 72f1f47..64c26dc 100644 --- a/aplc.lua +++ b/files/aplc.lua @@ -11,7 +11,7 @@ --]] --[[ Example use: --- local APLC = dofile("mods/shift_query/aplc.lua") +-- local APLC = dofile("mods/shift_query/files/aplc.lua") -- function get_aplc_data() -- local lc_combo, ap_combo, lc_prob, ap_prob = APLC.get_recipe() -- local ap_str = ("AP: %s, %s, %s (%.02f%%)"):format( diff --git a/common.lua b/files/common.lua similarity index 92% rename from common.lua rename to files/common.lua index 923726a..7837365 100644 --- a/common.lua +++ b/files/common.lua @@ -11,7 +11,7 @@ -- the "(no flask)" designation, as it's redundant. dofile_once("data/scripts/lib/utilities.lua") -dofile_once("mods/shift_query/constants.lua") +dofile_once("mods/shift_query/files/constants.lua") MOD_ID = "shift_query" K_CONFIG_LOG_ENABLE = MOD_ID .. "." .. "q_logging" @@ -123,6 +123,24 @@ function q_disable_gui() q_setting_set(SETTING_ENABLE, false) end +-- Clear the logging global if set +function logger_clear() + local value = GlobalsGetValue("shift_query.logging") or "" + if value ~= "" then + GlobalsSetValue("shift_query.logging", "") + end +end + +-- Add a component to the logging global +function logger_add(piece) + local old_log = GlobalsGetValue("shift_query.logging") or "" + local new_log = tostring(piece) + if old_log ~= "" then + new_log = old_log .. "\n" .. new_log + end + GlobalsSetValue("shift_query.logging", new_log) +end + -- Localize a material, either "name" or "$mat_name". function localize_material(material) local matid = CellFactory_GetType(material) diff --git a/constants.lua b/files/constants.lua similarity index 94% rename from constants.lua rename to files/constants.lua index b806834..67522f8 100644 --- a/constants.lua +++ b/files/constants.lua @@ -3,6 +3,8 @@ MIN_SHIFTS = -1 -- values < 0 mean "all" MAX_SHIFTS = 20 -- the game implicitly supports only 20 shifts +ALL_SHIFTS = -1 -- values < 0 mean "all" + FLAG_ON = "1" FLAG_OFF = "0" diff --git a/materials.lua b/files/materials.lua similarity index 100% rename from materials.lua rename to files/materials.lua diff --git a/query.lua b/files/query.lua similarity index 93% rename from query.lua rename to files/query.lua index 660ed68..c8fb79b 100644 --- a/query.lua +++ b/files/query.lua @@ -4,8 +4,8 @@ -- luacheck: globals pick_random_from_table_weighted random_nexti random_create -dofile("mods/shift_query/common.lua") -matinfo = dofile("mods/shift_query/materials.lua") +dofile("mods/shift_query/files/common.lua") +matinfo = dofile("mods/shift_query/files/materials.lua") MAX_SHIFTS = 20 -- maximum number of shifts according to fungal_shift.lua COOLDOWN = 60*60*5 -- post shift cooldown; five minutes diff --git a/init.lua b/init.lua index 9ad2cca..6b8f8c3 100644 --- a/init.lua +++ b/init.lua @@ -24,12 +24,12 @@ -- -- Add "fungal_shift_ui_icon" to the ImGui window. -dofile_once("mods/shift_query/common.lua") -dofile_once("mods/shift_query/materials.lua") -dofile_once("mods/shift_query/query.lua") +dofile_once("mods/shift_query/files/common.lua") +dofile_once("mods/shift_query/files/materials.lua") +dofile_once("mods/shift_query/files/query.lua") dofile_once("mods/shift_query/lib/feedback.lua") -dofile_once("mods/shift_query/constants.lua") -APLC = dofile_once("mods/shift_query/aplc.lua") +dofile_once("mods/shift_query/files/constants.lua") +APLC = dofile_once("mods/shift_query/files/aplc.lua") MAT_AP = "midas_precursor" MAT_LC = "magic_liquid_hp_regeneration_unstable" @@ -207,6 +207,32 @@ SQ = { end self._imgui.EndMenu() end + + if self._imgui.BeginMenu("Display") then + if self._imgui.BeginMenu("Prior Shifts") then + if self._imgui.MenuItem("Show All") then + q_setting_set(SETTING_PREVIOUS, tostring(ALL_SHIFTS)) + self._force_update = true + end + if self._imgui.MenuItem("Show One") then + q_setting_set(SETTING_PREVIOUS, tostring(1)) + self._force_update = true + end + self._imgui.EndMenu() + end + if self._imgui.BeginMenu("Pending Shifts") then + if self._imgui.MenuItem("Show All") then + q_setting_set(SETTING_NEXT, tostring(ALL_SHIFTS)) + self._force_update = true + end + if self._imgui.MenuItem("Show Next") then + q_setting_set(SETTING_NEXT, tostring(1)) + self._force_update = true + end + self._imgui.EndMenu() + end + self._imgui.EndMenu() + end self._imgui.EndMenuBar() end end, diff --git a/settings.lua b/settings.lua index d4bb198..a1fbd41 100644 --- a/settings.lua +++ b/settings.lua @@ -9,10 +9,14 @@ -- one-at-a-time and in bulk) -- ** Ability to override MAX_SHIFTS +--[[ +-- FIXME: previous_count and next_count display -2 .. 20 +-- FIXME: previous_count and next_count are not integers +--]] -dofile("data/scripts/lib/utilities.lua") -dofile("data/scripts/lib/mod_settings.lua") -dofile_once("mods/shift_query/constants.lua") +dofile_once("data/scripts/lib/utilities.lua") +dofile_once("data/scripts/lib/mod_settings.lua") +dofile_once("mods/shift_query/files/common.lua") -- luacheck: globals MOD_SETTING_SCOPE_RUNTIME @@ -21,11 +25,24 @@ dofile_once("mods/shift_query/constants.lua") -- ModSettingSet(setting_id, new_value) function mod_setting_changed_callback(mod_id, gui, in_main_menu, setting, old_value, new_value) - if setting == "previous_count" or setting == "next_count" then - if new_value < MIN_SHIFTS then - GamePrint(("setting %s %s outside range"):format(setting, tostring(new_value))) + --[[ TODO: enforce integer values + logger_add(("Setting %s changed from %s to %s"):format( + setting.id, tostring(old_value), tostring(new_value))) + if setting.id == "previous_count" or setting.id == "next_count" then + local final_value = math.floor(new_value) + if final_value < MIN_SHIFTS then + logger_add(("Setting %s %d below %d"):format(setting.id, new_value, final_value)) + final_value = MIN_SHIFTS + elseif final_value > MAX_SHIFTS then + logger_add(("Setting %s %d above %d"):format(setting.id, new_value, final_value)) + final_value = MAX_SHIFTS end + if new_value ~= final_value then + ModSettingSet(MOD_ID .. "." .. setting.id, final_value) + end + return final_value end + ]] end mod_settings_version = 3 @@ -71,13 +88,6 @@ mod_settings = { value_default = true, scope = MOD_SETTING_SCOPE_RUNTIME, }, - --[[{ - id = "override_ui", - ui_name = "Enable Override UI", - ui_description = "Enable use of the manual shifting UI", - value_default = false, - scope = MOD_SETTING_SCOPE_RUNTIME, - },]] { id = "include_aplc", ui_name = "Include AP / LC recipes", diff --git a/workshop_id.txt b/workshop_id.txt index 734c7ea..bda8595 100644 --- a/workshop_id.txt +++ b/workshop_id.txt @@ -1 +1 @@ -3132525756 +3132525756 \ No newline at end of file