1 |
21 |
Thurallor-7095 |
Sequence = class(); |
2 |
13 |
Thurallor-7095 |
|
3 |
16 |
Thurallor-7095 |
function Sequence:Constructor(bar, info) |
4 |
|
Thurallor-7095 |
self.bar = bar; |
5 |
|
Thurallor-7095 |
self.manager = bar.manager; |
6 |
|
Thurallor-7095 |
self.visibleItems = {}; |
7 |
|
Thurallor-7095 |
|
8 |
|
Thurallor-7095 |
-- Callbacks |
9 |
|
Thurallor-7095 |
self.ItemChanged = nil; |
10 |
13 |
Thurallor-7095 |
|
11 |
16 |
Thurallor-7095 |
if (not info) then |
12 |
|
Thurallor-7095 |
info = {}; |
13 |
|
Thurallor-7095 |
end |
14 |
|
Thurallor-7095 |
self:SetInfo(info); |
15 |
13 |
Thurallor-7095 |
end |
16 |
|
Thurallor-7095 |
|
17 |
16 |
Thurallor-7095 |
function Sequence:SetInfo(newInfo) |
18 |
|
Thurallor-7095 |
self.slots = {}; |
19 |
|
Thurallor-7095 |
self.events = {}; |
20 |
|
Thurallor-7095 |
self.slotIndexMap = {}; |
21 |
|
Thurallor-7095 |
self.includes = {}; |
22 |
|
Thurallor-7095 |
|
23 |
|
Thurallor-7095 |
for i = 1, #newInfo, 1 do |
24 |
|
Thurallor-7095 |
self.i = i; |
25 |
|
Thurallor-7095 |
local info = newInfo[i]; |
26 |
|
Thurallor-7095 |
self:ProcessInfoItem(info); |
27 |
|
Thurallor-7095 |
end |
28 |
|
Thurallor-7095 |
|
29 |
|
Thurallor-7095 |
self:ProcessConditionals(); |
30 |
13 |
Thurallor-7095 |
end |
31 |
|
Thurallor-7095 |
|
32 |
16 |
Thurallor-7095 |
function Sequence:ProcessInfoItem(info) |
33 |
|
Thurallor-7095 |
local slot = Slot(info); |
34 |
|
Thurallor-7095 |
slot.i = self.i; |
35 |
|
Thurallor-7095 |
slot.info = info; |
36 |
|
Thurallor-7095 |
if ((type(info) ~= "table") or not info.class) then |
37 |
|
Thurallor-7095 |
-- Empty slot; discard |
38 |
|
Thurallor-7095 |
elseif ((info.class == "Turbine.UI.Control") and (info.type == "Include")) then |
39 |
|
Thurallor-7095 |
if (info.include ~= self.bar:GetID()) then |
40 |
|
Thurallor-7095 |
if (not self:IncludeSequence(info.include)) then |
41 |
|
Thurallor-7095 |
info.include = nil; |
42 |
|
Thurallor-7095 |
self.bar:SaveSettings(false); |
43 |
|
Thurallor-7095 |
end |
44 |
|
Thurallor-7095 |
end |
45 |
|
Thurallor-7095 |
else |
46 |
|
Thurallor-7095 |
table.insert(self.slots, slot); |
47 |
|
Thurallor-7095 |
self.slotIndexMap[self.i] = #self.slots; |
48 |
|
Thurallor-7095 |
if (info.class ~= "Turbine.UI.Control") then |
49 |
|
Thurallor-7095 |
-- Standard quickslot; no further handling necessary |
50 |
|
Thurallor-7095 |
else |
51 |
|
Thurallor-7095 |
if (info.type == "GenerateEvent") then |
52 |
|
Thurallor-7095 |
self.events[info.eventName] = 0; |
53 |
|
Thurallor-7095 |
end |
54 |
|
Thurallor-7095 |
if (info.action) then |
55 |
|
Thurallor-7095 |
slot.actionFunc = loadstring(info.action); |
56 |
|
Thurallor-7095 |
end |
57 |
|
Thurallor-7095 |
end |
58 |
|
Thurallor-7095 |
end |
59 |
|
Thurallor-7095 |
end |
60 |
|
Thurallor-7095 |
|
61 |
|
Thurallor-7095 |
function Sequence:IncludeSequence(barID) |
62 |
|
Thurallor-7095 |
local otherSettings = self.manager.settings.bars[barID]; |
63 |
|
Thurallor-7095 |
if (otherSettings and not otherSettings.deleted) then |
64 |
|
Thurallor-7095 |
table.insert(self.includes, barID); |
65 |
|
Thurallor-7095 |
local otherInfo = otherSettings.sequenceItemInfo; |
66 |
|
Thurallor-7095 |
for i = 1, #otherInfo, 1 do |
67 |
|
Thurallor-7095 |
local info = otherInfo[i]; |
68 |
|
Thurallor-7095 |
self:ProcessInfoItem(info); |
69 |
|
Thurallor-7095 |
end |
70 |
|
Thurallor-7095 |
return true; |
71 |
|
Thurallor-7095 |
else |
72 |
|
Thurallor-7095 |
return false; |
73 |
|
Thurallor-7095 |
end |
74 |
|
Thurallor-7095 |
end |
75 |
|
Thurallor-7095 |
|
76 |
|
Thurallor-7095 |
function Sequence:GetIncludes() |
77 |
|
Thurallor-7095 |
return self.includes; |
78 |
|
Thurallor-7095 |
end |
79 |
|
Thurallor-7095 |
|
80 |
|
Thurallor-7095 |
-- Returns the new index of a slot after empty slots are removed |
81 |
|
Thurallor-7095 |
function Sequence:GetNewIndex(oldIndex) |
82 |
|
Thurallor-7095 |
return self.slotIndexMap[oldIndex]; |
83 |
|
Thurallor-7095 |
end |
84 |
|
Thurallor-7095 |
|
85 |
|
Thurallor-7095 |
function Sequence:GetOldIndex(newIndex) |
86 |
|
Thurallor-7095 |
return self.slots[newIndex].i; |
87 |
|
Thurallor-7095 |
end |
88 |
|
Thurallor-7095 |
|
89 |
|
Thurallor-7095 |
function Sequence:GetSlots() |
90 |
|
Thurallor-7095 |
return self.slots; |
91 |
|
Thurallor-7095 |
end |
92 |
|
Thurallor-7095 |
|
93 |
|
Thurallor-7095 |
function Sequence:GetSlot(index) |
94 |
|
Thurallor-7095 |
return self.slots[index]; |
95 |
|
Thurallor-7095 |
end |
96 |
|
Thurallor-7095 |
|
97 |
|
Thurallor-7095 |
function Sequence:GetEvents() |
98 |
|
Thurallor-7095 |
return self.events; |
99 |
|
Thurallor-7095 |
end |
100 |
|
Thurallor-7095 |
|
101 |
|
Thurallor-7095 |
-- Populate the 'ifSlot', 'elseSlot', and 'endIfSlot' members of slots. |
102 |
|
Thurallor-7095 |
function Sequence:ProcessConditionals() |
103 |
|
Thurallor-7095 |
local stack = { {} }; |
104 |
|
Thurallor-7095 |
local parentIfSlot, parentElseSlot = nil, nil; |
105 |
|
Thurallor-7095 |
for s = 1, #self.slots, 1 do |
106 |
|
Thurallor-7095 |
local slot = self.slots[s]; |
107 |
|
Thurallor-7095 |
local info = slot.info; |
108 |
|
Thurallor-7095 |
slot.parentIfSlot, slot.parentElseSlot = parentIfSlot, parentElseSlot; |
109 |
|
Thurallor-7095 |
if (info.type == "If") then |
110 |
|
Thurallor-7095 |
slot.ifSlot, slot.elseSlot, slot.endIfSlot = nil, nil, nil; |
111 |
|
Thurallor-7095 |
-- Do argument substitutions |
112 |
|
Thurallor-7095 |
slot.condExpr = info.condExpr; |
113 |
|
Thurallor-7095 |
if (info.condArgs) then |
114 |
|
Thurallor-7095 |
for name, value in pairs(info.condArgs) do |
115 |
20 |
Thurallor-7095 |
slot.condExpr = string.gsub(slot.condExpr, "<" .. name .. ">", tostring(value)); |
116 |
16 |
Thurallor-7095 |
end |
117 |
|
Thurallor-7095 |
end |
118 |
|
Thurallor-7095 |
slot.condFunc = loadstring(slot.condExpr); |
119 |
|
Thurallor-7095 |
table.insert(stack, { info.type, s }); |
120 |
|
Thurallor-7095 |
parentIfSlot = s; |
121 |
|
Thurallor-7095 |
parentElseSlot = nil; |
122 |
|
Thurallor-7095 |
elseif (info.type == "Else") then |
123 |
|
Thurallor-7095 |
local lastType, lastLoc = unpack(table.remove(stack)); |
124 |
|
Thurallor-7095 |
if (lastType == "If") then |
125 |
|
Thurallor-7095 |
local ifItem = self.slots[lastLoc]; |
126 |
|
Thurallor-7095 |
ifItem.elseSlot = s; |
127 |
|
Thurallor-7095 |
slot.ifSlot, slot.elseSlot, slot.endIfSlot = lastLoc, nil, nil; |
128 |
|
Thurallor-7095 |
table.insert(stack, { info.type, s }); |
129 |
|
Thurallor-7095 |
slot.parentIfSlot, slot.parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot; |
130 |
|
Thurallor-7095 |
parentIfSlot = nil; |
131 |
|
Thurallor-7095 |
parentElseSlot = s; |
132 |
|
Thurallor-7095 |
else -- Syntax error: Unmatched braces |
133 |
|
Thurallor-7095 |
Puts("Error: \"Else\" at slot " .. tostring(slot.i) .. " has no matching \"If\"."); |
134 |
|
Thurallor-7095 |
table.insert(stack, { lastType, lastLoc }); |
135 |
|
Thurallor-7095 |
end |
136 |
|
Thurallor-7095 |
elseif (info.type == "EndIf") then |
137 |
|
Thurallor-7095 |
local lastType, lastLoc = unpack(table.remove(stack)); |
138 |
|
Thurallor-7095 |
if (lastType == "If") then |
139 |
|
Thurallor-7095 |
local ifItem = self.slots[lastLoc]; |
140 |
|
Thurallor-7095 |
ifItem.endIfSlot = s; |
141 |
|
Thurallor-7095 |
slot.ifSlot, slot.elseSlot, slot.endIfSlot = lastLoc, nil, nil; |
142 |
|
Thurallor-7095 |
slot.parentIfSlot, slot.parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot; |
143 |
|
Thurallor-7095 |
parentIfSlot, parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot; |
144 |
|
Thurallor-7095 |
elseif (lastType == "Else") then |
145 |
|
Thurallor-7095 |
local elseItem = self.slots[lastLoc]; |
146 |
|
Thurallor-7095 |
local ifItem = self.slots[elseItem.ifSlot]; |
147 |
|
Thurallor-7095 |
ifItem.endIfSlot = s; |
148 |
|
Thurallor-7095 |
elseItem.endIfSlot = s; |
149 |
|
Thurallor-7095 |
slot.ifSlot, slot.elseSlot, slot.endIfSlot = elseItem.ifSlot, lastLoc, nil; |
150 |
|
Thurallor-7095 |
slot.parentIfSlot, slot.parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot; |
151 |
|
Thurallor-7095 |
parentIfSlot, parentElseSlot = ifItem.parentIfSlot, ifItem.parentElseSlot; |
152 |
|
Thurallor-7095 |
else -- Syntax error: Unmatched braces |
153 |
|
Thurallor-7095 |
Puts("Error: \"EndIf\" at slot " .. tostring(slot.i) .. " has no matching \"If\"."); |
154 |
|
Thurallor-7095 |
table.insert(stack, { lastType, lastLoc }); |
155 |
|
Thurallor-7095 |
end |
156 |
|
Thurallor-7095 |
end |
157 |
|
Thurallor-7095 |
end |
158 |
|
Thurallor-7095 |
while (#stack > 1) do |
159 |
|
Thurallor-7095 |
local t, s = unpack(table.remove(stack)); |
160 |
|
Thurallor-7095 |
local slot = self.slots[s]; |
161 |
|
Thurallor-7095 |
Puts("Error: \"" .. t .. "\" at slot " .. tostring(slot.i) .. " has no matching \"EndIf\"."); |
162 |
|
Thurallor-7095 |
end |
163 |
|
Thurallor-7095 |
--for s = 1, #self.slots, 1 do |
164 |
|
Thurallor-7095 |
-- local slot = self.slots[s]; |
165 |
|
Thurallor-7095 |
-- Puts(tostring(s) .. ". parentIfSlot/parentElseSlot/ifSlot/elseSlot/endIfSlot = " .. tostring(slot.parentIfSlot) .. "/" .. tostring(slot.parentElseSlot) .. "/" .. tostring(slot.ifSlot) .. "/" .. tostring(slot.elseSlot) .. "/" .. tostring(slot.endIfSlot) .. "; condExpr = " .. tostring(slot.info.condExpr) .. "; condFunc = " .. tostring(slot.condFunc)); |
166 |
|
Thurallor-7095 |
--end |
167 |
|
Thurallor-7095 |
end |
168 |
|
Thurallor-7095 |
|
169 |
|
Thurallor-7095 |
function Sequence:UnfoldAllSlots() |
170 |
|
Thurallor-7095 |
for s = 1, #self.slots, 1 do |
171 |
|
Thurallor-7095 |
self.slots[s].condResult = nil; |
172 |
|
Thurallor-7095 |
end |
173 |
|
Thurallor-7095 |
end |
174 |
|
Thurallor-7095 |
|
175 |
|
Thurallor-7095 |
function Sequence:SlotIsFolded(s) |
176 |
|
Thurallor-7095 |
local slot = self.slots[s]; |
177 |
|
Thurallor-7095 |
if (slot.parentIfSlot) then |
178 |
|
Thurallor-7095 |
local ifSlot = self.slots[slot.parentIfSlot]; |
179 |
|
Thurallor-7095 |
return self:SlotIsFolded(slot.parentIfSlot) or (ifSlot.condResult == false); |
180 |
|
Thurallor-7095 |
elseif (slot.parentElseSlot) then |
181 |
|
Thurallor-7095 |
local elseSlot = self.slots[slot.parentElseSlot]; |
182 |
|
Thurallor-7095 |
local ifSlot = self.slots[elseSlot.ifSlot]; |
183 |
|
Thurallor-7095 |
return self:SlotIsFolded(slot.parentElseSlot) or (ifSlot.condResult == true); |
184 |
|
Thurallor-7095 |
else |
185 |
|
Thurallor-7095 |
return false; |
186 |
|
Thurallor-7095 |
end |
187 |
|
Thurallor-7095 |
end |