Skip to content

Commit

Permalink
Merge pull request #760 from rlcevg/ai_custom_profile
Browse files Browse the repository at this point in the history
Custom AI profiles
  • Loading branch information
AntlerForce authored Sep 20, 2024
2 parents af46e00 + 02a1b5b commit 93908e7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
53 changes: 53 additions & 0 deletions LuaMenu/configs/gameConfig/byar/aiCustomData.lua
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 3 additions & 1 deletion LuaMenu/configs/gameConfig/byar/mainConfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions LuaMenu/widgets/chobby/components/aioptions_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 93908e7

Please sign in to comment.