diff --git a/CustomStackSize/data-final-fixes.lua b/CustomStackSize/data-final-fixes.lua index 29922c7..0e32a66 100644 --- a/CustomStackSize/data-final-fixes.lua +++ b/CustomStackSize/data-final-fixes.lua @@ -31,3 +31,32 @@ for _, category in pairs(stack_list) do end end end + +-- LUA doesn't have a built-in way to split strings, so... +-- Source - https://stackoverflow.com/a/7615129 +-- Posted by user973713, modified by community. See post 'Timeline' for change history +-- Retrieved 2026-08-20, License - CC BY-SA 4.0 +function strsplit(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t = {} + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + table.insert(t, str) + end + return t +end + +-- Custom user-added rules +for _, token in pairs(strsplit(settings.startup["stack-size-custom-others"].value, ";")) do + local proto_name, ssize = table.unpack(strsplit(token, "=")) + if ssize then + local size = tonumber(ssize) + if size >= 1 and size <= 100000 then + local proto = find_proto(proto_name) + if proto then + proto.stack_size = size + end + end + end +end \ No newline at end of file diff --git a/CustomStackSize/locale/en/settings.cfg b/CustomStackSize/locale/en/settings.cfg index 405aa43..5793a60 100644 --- a/CustomStackSize/locale/en/settings.cfg +++ b/CustomStackSize/locale/en/settings.cfg @@ -84,6 +84,7 @@ stack-size-metallic-asteroid-chunk=Space → Metallic asteroid chunk stack-size-carbonic-asteroid-chunk=Space → Carbonic asteroid chunk stack-size-oxide-asteroid-chunk=Space → Oxide asteroid chunk stack-size-promethium-asteroid-chunk=Space → Promethium asteroid chunk +stack-size-custom-others=Others (custom rules) [mod-setting-description] stack-size-brick=Set the stack size for stone bricks. Default is 100. Minimum is 1. Maximum is 100000. @@ -171,3 +172,4 @@ stack-size-metallic-asteroid-chunk=Set the stack size for metallic asteroid chun stack-size-carbonic-asteroid-chunk=Set the stack size for carbonic asteroid chunks. Default is 1. Minimum is 1. Maximum is 100000. stack-size-oxide-asteroid-chunk=Set the stack size for oxide asteroid chunks. Default is 1. Minimum is 1. Maximum is 100000. stack-size-promethium-asteroid-chunk=Set the stack size for promethium asteroid chunks. Default is 1. Minimum is 1. Maximum is 100000. +stack-size-custom-others=Set here any custom rules for other/modded item prototypes. Rules are divided by ";" and are in the format "my-item-prototype=". Minimum recognized value is 1. Maximum is 100000. diff --git a/CustomStackSize/settings.lua b/CustomStackSize/settings.lua index 9695fce..375481f 100644 --- a/CustomStackSize/settings.lua +++ b/CustomStackSize/settings.lua @@ -20,4 +20,14 @@ for _, category in pairs(stack_list) do end end +settings_to_add[#settings_to_add + 1] = { + type = "string-setting", + name = "stack-size-custom-others", + setting_type = "startup", + default_value = "", + allow_blank = true, + -- allow_trim = false, + order = "za", +} + data:extend(settings_to_add)