-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtfreshModel.lua
More file actions
71 lines (62 loc) · 2.4 KB
/
Copy pathtfreshModel.lua
File metadata and controls
71 lines (62 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
local FOLDER_NAME,tfresh=...;
local validConditions = {"target", "combat", "alt", "shift", "ctrl"};
local resetDelimeter = "/";
tfresh.isValidResetConditions = function(resetParam)
local resetList, resetCount = tfresh.split(resetParam, resetDelimeter);
local dupeCheck = tfresh.copy(validConditions);
dupeCheck["seconds"] = false;
for _, cond in ipairs(resetList) do
resetList[cond] = false;
end
for _, condition in ipairs(resetList) do
if not tonumber(condition) then
local isValid = false;
for _, vc in pairs(validConditions) do
if condition == vc then
if dupeCheck[vc] == false then
isValid, dupeCheck[vc] = true, true;
else
print("(TFresh) Duplicate reset condition:"..condition);
return false;
end
end
end
if not isValid then
print("(TFresh) Bad reset condition: "..condition);
print("Lis of valid conditions: default, "..table.concat(validConditions, ", ")..", <seconds>.")
return false;
end
else
local seconds = tonumber(condition)
if seconds == nil or seconds ~= math.floor(tonumber(condition)) or seconds < 0 then
print("(TFresh) Bad reset condition: "..condition);
print("Seconds must be in whole number.");
return false;
elseif dupeCheck["seconds"] == true then
print("(TFresh) Duplicate reset condition:"..condition);
return false;
elseif seconds == 0 and resetCount > 1 then
print("(Tfresh) 0 can't be combined, it's short-hand for no condition.")
return false;
else
dupeCheck["seconds"] = true;
end
end
end
return true;
end
tfresh.validateAndGetParams = function(paramStr)
if paramStr == "0" then -- shortcut for no reset condition
return "";
end
a, count = string.gsub(paramStr,"%s","");
if count > 0 then
print("(TFresh) Bad params: /tfresh "..paramStr);
print("Reset conditions are separated by forward-slash '/'.");
return nil;
end
if not tfresh.isValidResetConditions(paramStr) then
return nil;
end
return paramStr;
end