-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCore.lua
More file actions
202 lines (169 loc) · 6.31 KB
/
Core.lua
File metadata and controls
202 lines (169 loc) · 6.31 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
--- Define the Rotation Builder main Object.
RotationBuilder = {
-- Technical version of rotation builder.
version = 1,
-- If we need to clean up the user installation with this revision.
needCleanUp = true,
-- serializer tool for import/export funtionality.
serializer = nil,
-- The list of rotations generator.
defaultRotationGenerator = {},
-- If we seek a multi-target rotation.
multiTargetEnabled = false,
-- TODO Vladilen : We set custom case 1 as enabled by default
customCase = {
case1 = true,
case2 = false,
},
};
--- Import a rotation.
-- Unserialize a string as a Rotation and import it.
-- @param #string serializedRotation the serialized Rotation to import.
function RotationBuilder:importRotation(serializedRotation)
if (not self.serializer) then
-- Initialize the libraries when needed.
self:initialize();
end
-- Deserialize
local hasWork, addonName, rotationName, deSerialized = self.serializer:Deserialize(serializedRotation);
-- Verify
if(hasWork and (addonName == "RotationBuilder")) then
if (not rotationName) then
-- No rotation name found.
print(RotationBuilderUtils:localize('ROB_UI_IMPORT_ERROR1'));
return
end
if (ROB_Rotations[rotationName]) then
-- A rotation with the same name already exist.
print(RotationBuilderUtils:localize('ROB_UI_IMPORT_ERROR2')..":"..rotationName);
return
end
local tempRotation = RotationBuilderUtils:restoreTable({}, deSerialized);
ROB_Rotations[rotationName] = tempRotation;
-- update rotation list
ROB_SortRotationList();
-- update the action list
ROB_ActionList_Update();
-- sort spell lists
ROB_SortSpellLists();
-- sort spells
ROB_SortSpells();
-- update the spells list
ROB_SpellList_Update();
-- update rotation modify buttons
ROB_RotationModifyButtons_UpdateUI();
-- update rotation ui stuff
ROB_Rotation_Edit_UpdateUI();
print(RotationBuilderUtils:localize('ROB_UI_IMPORT_SUCCESS')..":"..rotationName);
else
-- Not a rotation builder import.
print(RotationBuilderUtils:localize('ROB_UI_IMPORT_ERROR3'));
end
end
--- Export a rotation.
-- Serialize a Rotation as a string for export purpose.
-- @param #string rotationName the name of the rotation to export.
-- @return #string the exported rotation as a String.
function RotationBuilder:exportRotation(rotationName)
-- Verify.
-- TODO PEL : We need to localize these messages.
if ((not rotationName) or (rotationName == "")) then
print("No rotation name specified for export")
return
end
local tempRotationData = ROB_Rotations[rotationName];
if (not tempRotationData) then
print("Rotation name must be the name of an rotation build, and is case-sensitive."..rotationName)
return
end
if (not self.serializer) then
-- Initialize the libraries when needed.
self:initialize();
end
-- We must clean-up the data before serializing them.
local toSerialize = RotationBuilderUtils:copyTable(tempRotationData, true);
--@do-not-package@
-- Register export information for development purpose.
ROB_Exports[rotationName] = toSerialize;
--@end-do-not-package@
-- Serializing
local rotation = self.serializer:Serialize("RotationBuilder", rotationName, toSerialize);
return rotation;
end
--- Register a rotations generator for a class.
-- @param #string className the class for which we want to add a rotation generator.
-- @param #function method the method which will generate the rotation.
function RotationBuilder:addDefaultRotationsGenerator(className, method)
if(not className or not method) then
print("className or method is nil.");
return
end
if (self.defaultRotationGenerator[className]) then
-- TODO PEL : Localized this error message.
print("Override rotations generator for "..className);
end
-- Register the generator.
self.defaultRotationGenerator[className] = method;
end
--- Load default rotations for a class.
-- @param #String className the name of the class for which we must load default rotations.
function RotationBuilder:loadDefaultRotations(className)
if (not self.defaultRotationGenerator[className]) then
-- TODO PEL : Localized this error message.
print("No data available for "..className);
return
end
-- Load default rotations for this class.
local defaultRotation = self.defaultRotationGenerator[className]["generator"]();
for key, value in pairs(defaultRotation) do
if(not ROB_Rotations[key] or not ROB_Rotations[key]["version"] or ROB_Rotations[key]["version"] < value["version"]) then
-- The rotation don't exist or is older, then we can import the rotation.
ROB_Rotations[key] = value;
end
end
end
--- Check if this is a newer RotationBuilder add-on and upgrade default rotation if possible.
function RotationBuilder:cleanUpInstallationOnNeed()
local oldVersion = ROB_Options["version"];
local newVersion = RotationBuilder["version"];
if(not oldVersion or (oldVersion < newVersion and (RotationBuilder["needCleanUp"] or oldVersion + 1 < newVersion))) then
-- We need do clean up RotationBuilder.
ROB_Options = {};
ROB_Rotations = {};
ROB_Exports = {};
print(RotationBuilderUtils:localize('message/core/fullCleanUp'));
end
ROB_Options["version"] = newVersion;
end
--- Find a rotation by its specialization.
-- @param #Int specializationID: the specialization ID for which we seek a rotation.
-- @return #String the name of the rotation.
function RotationBuilder:findRotationBySpecializationID(specializationID)
if (not ROB_Rotations or not specializationID) then
-- If no rotation is defined, then return nil.
return nil;
end
local tmpRotation = nil;
for key, value in pairs(ROB_Rotations) do
if (value["specID"] == specializationID) then
if(value["isMultiTarget"] and RotationBuilder["multiTargetEnabled"]) then
return key;
end
if(not value["isMultiTarget"] and not RotationBuilder["multiTargetEnabled"]) then
return key;
end
tmpRotation = key;
end
end
return tmpRotation;
end
function RotationBuilder:isCustomCase1Enable()
return self.customCase.case1;
end
function RotationBuilder:isCustomCase2Enable()
return self.customCase.case2;
end
--- Initialize the RotationBuilder Object.
function RotationBuilder:initialize()
self.serializer = LibStub:GetLibrary("AceSerializer-3.0");
end