From 02a1b5bd0730fa78c8387a768ae69072050c211b Mon Sep 17 00:00:00 2001 From: rlcevg <514675+rlcevg@users.noreply.github.com> Date: Mon, 9 Sep 2024 17:06:34 +0300 Subject: [PATCH] Custom AI profiles --- .../configs/gameConfig/byar/aiCustomData.lua | 53 +++++++++++++++++++ .../configs/gameConfig/byar/mainConfig.lua | 4 +- .../chobby/components/aioptions_window.lua | 9 ++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 LuaMenu/configs/gameConfig/byar/aiCustomData.lua diff --git a/LuaMenu/configs/gameConfig/byar/aiCustomData.lua b/LuaMenu/configs/gameConfig/byar/aiCustomData.lua new file mode 100644 index 000000000..9618c3da3 --- /dev/null +++ b/LuaMenu/configs/gameConfig/byar/aiCustomData.lua @@ -0,0 +1,53 @@ +local customProfiles = { +-- ['BARb stable'] = { +-- { +-- key = 'example', -- must conform to directory name +-- name = 'Not so Hard', -- human readable name displayed in a list +-- -- desc kept for consistency with AIOptions.lua +-- desc = 'Alas desc doesn\'t work - no way to display tooltip on a list item', +-- }, +-- }, +} + +local blacklistProfiles = { +-- ['BARb stable'] = { +-- dev = true, +-- hard = true, +-- }, +} + +local function ArrayRemove(t, fnKeep) + local j, n = 1, #t; + + for i=1,n do + if (fnKeep(t, i, j)) then + -- Move i's kept value to j's position, if it's not already there. + if (i ~= j) then + t[j] = t[i]; + t[i] = nil; + end + j = j + 1; -- Increment position of where we'll place the next kept value. + else + t[i] = nil; + end + end + + return t; +end + +function CustomAiProfiles(name, items) + local customs = customProfiles[name] + if customs then + for _, v in ipairs(customs) do + table.insert(items, v) + end + end + local filter = blacklistProfiles[name] + if filter then + ArrayRemove(items, function(t, i, j) return not filter[t[i].key] end) + end +end + +return { + CustomAiProfiles = CustomAiProfiles +} diff --git a/LuaMenu/configs/gameConfig/byar/mainConfig.lua b/LuaMenu/configs/gameConfig/byar/mainConfig.lua index fbaea7d40..05b671240 100644 --- a/LuaMenu/configs/gameConfig/byar/mainConfig.lua +++ b/LuaMenu/configs/gameConfig/byar/mainConfig.lua @@ -3,6 +3,7 @@ local shortname = "byar" local sidedata = VFS.Include(LUA_DIRNAME .. "configs/gameConfig/" .. shortname .. "/sidedata.lua") local aiBlacklist = VFS.Include(LUA_DIRNAME .. "configs/gameConfig/" .. shortname .. "/aiBlacklist.lua") local aiSimpleNames = VFS.Include(LUA_DIRNAME .. "configs/gameConfig/" .. shortname .. "/aiSimpleName.lua") +local aiCustomData = VFS.Include(LUA_DIRNAME .. "configs/gameConfig/" .. shortname .. "/aiCustomData.lua") local singleplayerConfig = VFS.Include(LUA_DIRNAME .. "configs/gameConfig/" .. shortname .. "/singleplayerMenu.lua") local helpSubmenuConfig = VFS.Include(LUA_DIRNAME .. "configs/gameConfig/" .. shortname .. "/helpSubmenuConfig.lua") local skirmishDefault = VFS.Include(LUA_DIRNAME .. "configs/gameConfig/" .. shortname .. "/skirmishDefault.lua") @@ -80,10 +81,11 @@ local externalFuncAndData = { defaultChatChannels = {"main"}, sayPrivateSelectAndActivateChatTab = sayPrivateSelectAndActivateChatTab, aiBlacklist = aiBlacklist, - unversionedGameAis = {"SimpleAI","SimpleDefenderAI", "SimpleConstructorAI", "ScavengersAI", "RaptorsAI"}, + unversionedGameAis = {"SimpleAI","SimpleDefenderAI", "SimpleConstructorAI", "ScavengersAI", "RaptorsAI"}, GetAiSimpleName = aiSimpleNames.GetAiSimpleName, simpleAiOrder = aiSimpleNames.simpleAiOrder, aiTooltip = aiSimpleNames.aiTooltip, + CustomAiProfiles = aiCustomData.CustomAiProfiles, mapDetails = mapDetails, mapStartBoxes = mapStartBoxes, useDefaultStartBoxes = useDefaultStartBoxes, diff --git a/LuaMenu/widgets/chobby/components/aioptions_window.lua b/LuaMenu/widgets/chobby/components/aioptions_window.lua index db9505e05..f5e3a245b 100644 --- a/LuaMenu/widgets/chobby/components/aioptions_window.lua +++ b/LuaMenu/widgets/chobby/components/aioptions_window.lua @@ -26,6 +26,7 @@ function AiOptionsWindow:init(displayName, optionsPath, successFunc) -- AIOptions local options = VFS.Include(optionsPath) + self:CustomizeProfiles(displayName, options) for i = #options, 1, -1 do self:AddEntry(options[i], i) end @@ -223,3 +224,11 @@ function AiOptionsWindow:MakeString(data) } } end + +function AiOptionsWindow:CustomizeProfiles(displayName, options) + for _, data in ipairs(options) do + if data.type == "list" and data.key == "profile" then + WG.Chobby.Configuration.gameConfig.CustomAiProfiles(displayName, data.items) -- in place + end + end +end