From a175aa93e7185d929a471ac0ec4173e78be564cf Mon Sep 17 00:00:00 2001 From: CaitSith2 Date: Fri, 26 Aug 2022 01:31:30 -0700 Subject: [PATCH] Factorio: Detect if more than one AP factorio mod is loaded. (#964) --- worlds/factorio/data/mod_template/settings.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/worlds/factorio/data/mod_template/settings.lua b/worlds/factorio/data/mod_template/settings.lua index 7703ebe2..73e131a6 100644 --- a/worlds/factorio/data/mod_template/settings.lua +++ b/worlds/factorio/data/mod_template/settings.lua @@ -1,3 +1,21 @@ +-- Find out if more than one AP mod is loaded, and if so, error out. +function mod_is_AP(str) + -- lua string.match is way more restrictive than regex. Regex would be "^AP-W?\d{20}-P[1-9]\d*-.+$" + local result = string.match(str, "^AP%-W?%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%-P[1-9]%d-%-.+$") + if result ~= nil then + log("Archipelago Mod: " .. result .. " is loaded.") + end + return result ~= nil +end +local ap_mod_count = 0 +for name, _ in pairs(mods) do + if mod_is_AP(name) then + ap_mod_count = ap_mod_count + 1 + if ap_mod_count > 1 then + error("More than one Archipelago Factorio mod is loaded.") + end + end +end data:extend({ { type = "bool-setting",