Skip to content

Commit

Permalink
issue deprecation message once per MAI **squash
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsc committed Jun 27, 2022
1 parent bf9be47 commit 6d92fa7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions data/ai/micro_ais/micro_ai_helper.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
local T = wml.tag
local MAIUV = wesnoth.require "ai/micro_ais/micro_ai_unit_variables.lua"

local showed_deprecation_message = false
local showed_deprecation_message = {}

local function show_deprecation_message()
if (not showed_deprecation_message) then
wesnoth.deprecated_message('The old syntax how required and optional parameters are defined when creating a Micro AIs', 3, '1.19', "instead of { 'parameter' } it is now { parameter = 'parameter_type' }. See data/ai/micro_ai/mai-defs/ for examples." )
showed_deprecation_message = true
local function show_deprecation_message(ai_type)
if (not showed_deprecation_message[ai_type]) then
wesnoth.deprecated_message('[micro_ai] tag (' .. ai_type .. '): The old syntax for required and optional parameters when creating a Micro AIs', 3, '1.19', "instead of { 'parameter' } it is now { parameter = 'parameter_type' }. See data/ai/micro_ai/mai-defs/ for examples." )
showed_deprecation_message[ai_type] = true
end
end

Expand Down Expand Up @@ -249,7 +249,7 @@ function micro_ai_helper.micro_ai_setup(cfg, CA_parms, required_keys, optional_k
end
CA_cfg[k_type] = cfg[k_type]
end
show_deprecation_message()
show_deprecation_message(cfg.ai_type)
elseif (k_type == 'tag') then
-- Check that this is not a scalar parameter
if cfg[k_name] then
Expand Down Expand Up @@ -282,7 +282,7 @@ function micro_ai_helper.micro_ai_setup(cfg, CA_parms, required_keys, optional_k
else
CA_cfg[k_type] = cfg[k_type]
end
show_deprecation_message()
show_deprecation_message(cfg.ai_type)
elseif (k_type == 'tag') then
-- Check that this is not a scalar parameter
if cfg[k_name] then
Expand All @@ -299,7 +299,7 @@ function micro_ai_helper.micro_ai_setup(cfg, CA_parms, required_keys, optional_k

-- Check whether there are invalid keys in the [micro_ai] tag
for k in pairs(cfg) do
if (not showed_deprecation_message) -- otherwise this produces false positives
if (not showed_deprecation_message[cfg.ai_type]) -- otherwise this produces false positives
and (k ~= 'side') and (k ~= 'ai_type') and (k ~= 'action')
and (k ~= 'ca_id') and (k ~= 'ca_score') and (type(k) ~= 'number')
then
Expand Down Expand Up @@ -330,7 +330,7 @@ function micro_ai_helper.micro_ai_setup(cfg, CA_parms, required_keys, optional_k
for _,t in ipairs(cfg) do
-- [filter] is always added to [micro_ai] tags inside a unit's [ai] tag,
-- whether the specific MAI supports it or not
if (not showed_deprecation_message) and (t[1] ~= 'filter') then
if (not showed_deprecation_message[cfg.ai_type]) and (t[1] ~= 'filter') then
local is_invalid = true
for k_name in pairs(required_keys) do
if (t[1] == k_name) then
Expand Down

0 comments on commit 6d92fa7

Please sign in to comment.