Module:RestrictionChecker: Difference between revisions
From Terra Invicta Official Wiki
No edit summary |
No edit summary |
||
| Line 53: | Line 53: | ||
end | end | ||
for i = 0, 100 do | for i = 0, 100 do | ||
if inList then | |||
break | |||
end | |||
local entry = '' | local entry = '' | ||
if found[1] then | if found[1] then | ||
| Line 61: | Line 64: | ||
if found[2] then | if found[2] then | ||
for j = 0, 100 do | for j = 0, 100 do | ||
if inList then | |||
break | |||
end | |||
entry = sreplace(entry,'{j}',j) | entry = sreplace(entry,'{j}',j) | ||
if found[3] then | if found[3] then | ||
for k = 0, 100 do | for k = 0, 100 do | ||
if inList then | |||
break | |||
end | |||
entry = sreplace(entry,'{k}',k) | entry = sreplace(entry,'{k}',k) | ||
if not dataRow[entry] or dataRow[entry] == '' then | if not dataRow[entry] or dataRow[entry] == '' then | ||
| Line 69: | Line 78: | ||
elseif dataRow[entry] == restrictionsRow[3] then | elseif dataRow[entry] == restrictionsRow[3] then | ||
inList = true | inList = true | ||
break | |||
end | end | ||
end | end | ||
| Line 76: | Line 86: | ||
elseif dataRow[entry] == restrictionsRow[3] then | elseif dataRow[entry] == restrictionsRow[3] then | ||
inList = true | inList = true | ||
break | |||
end | end | ||
end | end | ||
| Line 84: | Line 95: | ||
elseif dataRow[entry] == restrictionsRow[3] then | elseif dataRow[entry] == restrictionsRow[3] then | ||
inList = true | inList = true | ||
break | |||
end | end | ||
end | end | ||
| Line 92: | Line 104: | ||
elseif restrictionsRow[1] == 'Not In List' then | elseif restrictionsRow[1] == 'Not In List' then | ||
local inList = false | local inList = false | ||
local found = {} | |||
if sfind(restrictionsRow[2],'{i}',1,true) then | |||
found[1] = true | |||
end | |||
if sfind(restrictionsRow[2],'{j}',1,true) then | |||
found[2] = true | |||
end | |||
if sfind(restrictionsRow[2],'{k}',1,true) then | |||
found[3] = true | |||
end | |||
for i = 0, 100 do | for i = 0, 100 do | ||
if inList then | |||
break | |||
end | |||
local entry = '' | local entry = '' | ||
if | if found[1] then | ||
entry = sreplace(restrictionsRow[2],'{i}',i) | entry = sreplace(restrictionsRow[2],'{i}',i) | ||
else | else | ||
entry = restrictionsRow[2] .. '/' .. i | entry = restrictionsRow[2] .. '/' .. i | ||
end | end | ||
if not dataRow[entry] or dataRow[entry] == '' then | if found[2] then | ||
break | for j = 0, 100 do | ||
if inList then | |||
break | |||
end | |||
entry = sreplace(entry,'{j}',j) | |||
if found[3] then | |||
for k = 0, 100 do | |||
if inList then | |||
break | |||
end | |||
entry = sreplace(entry,'{k}',k) | |||
if not dataRow[entry] or dataRow[entry] == '' then | |||
break | |||
elseif dataRow[entry] == restrictionsRow[3] then | |||
inList = true | |||
break | |||
end | |||
end | |||
else | |||
if not dataRow[entry] or dataRow[entry] == '' then | |||
break | |||
elseif dataRow[entry] == restrictionsRow[3] then | |||
inList = true | |||
break | |||
end | |||
end | |||
end | |||
else | |||
if not dataRow[entry] or dataRow[entry] == '' then | |||
break | |||
elseif dataRow[entry] == restrictionsRow[3] then | |||
inList = true | |||
break | |||
end | |||
end | end | ||
end | end | ||
Revision as of 00:46, 27 January 2026
Documentation for this module may be created at Module:RestrictionChecker/doc
-- Helper Module for checking restrictions
local p = {}
local CommaSplitModule = require('Module:CommaSplit')
local StringReplaceModule = require('Module:StringReplace')
local sreplace = StringReplaceModule.replace
local slen = string.len
local sfind = string.find
local ssub = string.sub
---@param restrictionsTable is a table of restrictions
---@dataRow is the row from the data table to check the restrictions against.
---@return true if all restrictions pass
function p.AllPass(restrictionsTable, dataRow)
local passesAllRestrictions = true
for _, restrictionsRowText in ipairs(restrictionsTable) do -- Consider each restrictionsTable row one by one:
local restrictionsRow = CommaSplitModule.CommaSplit(restrictionsRowText)
restrictionsRow[3] = mw.text.trim(restrictionsRow[3])
if restrictionsRow[1] == 'Match' then
if dataRow[restrictionsRow[2]] ~= restrictionsRow[3] then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'Match Any' then
local foundMatch = false
for i = 3, 100 do
if dataRow[restrictionsRow[2]] == restrictionsRow[i] then
foundMatch = true
end
end
if not foundMatch then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'Not Match' then
if dataRow[restrictionsRow[2]] == restrictionsRow[3] then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'Contains' then
if not sfind(dataRow[restrictionsRow[2]], restrictionsRow[3], 1, true) then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'In List' then
local inList = false
local found = {}
if sfind(restrictionsRow[2],'{i}',1,true) then
found[1] = true
end
if sfind(restrictionsRow[2],'{j}',1,true) then
found[2] = true
end
if sfind(restrictionsRow[2],'{k}',1,true) then
found[3] = true
end
for i = 0, 100 do
if inList then
break
end
local entry = ''
if found[1] then
entry = sreplace(restrictionsRow[2],'{i}',i)
else
entry = restrictionsRow[2] .. '/' .. i
end
if found[2] then
for j = 0, 100 do
if inList then
break
end
entry = sreplace(entry,'{j}',j)
if found[3] then
for k = 0, 100 do
if inList then
break
end
entry = sreplace(entry,'{k}',k)
if not dataRow[entry] or dataRow[entry] == '' then
break
elseif dataRow[entry] == restrictionsRow[3] then
inList = true
break
end
end
else
if not dataRow[entry] or dataRow[entry] == '' then
break
elseif dataRow[entry] == restrictionsRow[3] then
inList = true
break
end
end
end
else
if not dataRow[entry] or dataRow[entry] == '' then
break
elseif dataRow[entry] == restrictionsRow[3] then
inList = true
break
end
end
end
if not inList then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'Not In List' then
local inList = false
local found = {}
if sfind(restrictionsRow[2],'{i}',1,true) then
found[1] = true
end
if sfind(restrictionsRow[2],'{j}',1,true) then
found[2] = true
end
if sfind(restrictionsRow[2],'{k}',1,true) then
found[3] = true
end
for i = 0, 100 do
if inList then
break
end
local entry = ''
if found[1] then
entry = sreplace(restrictionsRow[2],'{i}',i)
else
entry = restrictionsRow[2] .. '/' .. i
end
if found[2] then
for j = 0, 100 do
if inList then
break
end
entry = sreplace(entry,'{j}',j)
if found[3] then
for k = 0, 100 do
if inList then
break
end
entry = sreplace(entry,'{k}',k)
if not dataRow[entry] or dataRow[entry] == '' then
break
elseif dataRow[entry] == restrictionsRow[3] then
inList = true
break
end
end
else
if not dataRow[entry] or dataRow[entry] == '' then
break
elseif dataRow[entry] == restrictionsRow[3] then
inList = true
break
end
end
end
else
if not dataRow[entry] or dataRow[entry] == '' then
break
elseif dataRow[entry] == restrictionsRow[3] then
inList = true
break
end
end
end
if inList then
passesAllRestrictions = false
end
end
end
return passesAllRestrictions
end
return p


