File bin/ChorusRaidFrameGenerator.lua changed (mode: 100644) (index 542e0ee..17c7f35) |
1 |
|
local mod = {} |
|
|
1 |
|
--[[-- |
|
2 |
|
A command line program, that takes a few arguments and prints to standard |
|
3 |
|
output ugly XML descriptors. |
|
4 |
|
|
|
5 |
|
This script parametrizes XML descriptor template for raid frame GUI widget, |
|
6 |
|
that is only useful for `chorus` project. |
|
7 |
|
|
|
8 |
|
There are several plausible configurations of the raid frame a user may |
|
9 |
|
require. At least one per instance type, that is, arena, battleground, raid and |
|
10 |
|
dungeon or party. Possibly more. The user will likely require to switch between |
|
11 |
|
those profiles frequently and automatically. |
|
12 |
|
|
|
13 |
|
The original intention of the project is to have the add-on come pre-configured |
|
14 |
|
by the developer, and not require configuration by the user. Hence the need to |
|
15 |
|
define a several useful raid frame profiles. |
|
16 |
|
|
|
17 |
|
This script is a tool involved in producing different, but uniform raid |
|
18 |
|
profiles, that are implemented by the project. The primary parameters are the |
|
19 |
|
button template and button dimensions. |
|
20 |
|
|
|
21 |
|
The unit button templates, that are hard coded in this script, are declared in |
|
22 |
|
`src/ChorusRaidFrameTemplate.xml`. The specialization of raid profiles is |
|
23 |
|
implemented in those virtual frame templates. This script only arranges the |
|
24 |
|
concrete instances of buttons in a grid using XML descriptors. |
|
25 |
|
|
|
26 |
|
The script is intended to be used by build orchestration tools, like `make` or |
|
27 |
|
`gradle` or `ant`, rather than called manually. |
|
28 |
|
|
|
29 |
|
The game engine loads XML descriptors quicker than Lua scripts. Therefore, |
|
30 |
|
complex widgets, like raid frames, benefit from being declared with XML rather |
|
31 |
|
than Lua. This does not improve responsiveness, however. This approach is |
|
32 |
|
largely an experiment. |
|
33 |
|
|
|
34 |
|
The usage shows how to execute the script on the command line. The first token |
|
35 |
|
is the Lua executable. The second token is the script itself, assuming the |
|
36 |
|
`chorus` source directory is the current working directory. The following |
|
37 |
|
tokens are arguments for the script. The order is significant. See `function |
|
38 |
|
emitRaidFrame`. Finally, the output is redirected to a file. |
|
39 |
|
|
|
40 |
|
Formatting and validation of the output XML descriptor is the responsibility of |
|
41 |
|
other tools, like `xmllint`. |
|
42 |
|
|
|
43 |
|
@see emitRaidFrame |
|
44 |
|
|
|
45 |
|
@usage lua bin/ChorusRaidFrameGenerator.lua ChorusTinyRaidFrame ChorusTinyRaidUnitFrameTemplate 64 16 > ChorusTinyRaidFrame.xml |
2 |
46 |
|
|
|
47 |
|
@script ChorusRaidFrameGenerator |
|
48 |
|
|
|
49 |
|
@alias mod |
|
50 |
|
]] |
|
51 |
|
|
|
52 |
|
ChorusRaidFrameGenerator = {} |
|
53 |
|
|
|
54 |
|
local mod = ChorusRaidFrameGenerator |
3 |
55 |
|
|
4 |
56 |
local header = [[ |
local header = [[ |
5 |
57 |
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
|
... |
... |
local footer = [[ |
49 |
101 |
</Frame> |
</Frame> |
50 |
102 |
</Ui>]] |
</Ui>]] |
51 |
103 |
|
|
|
104 |
|
--[[-- |
|
105 |
|
Print a snippet of XML, that describes a button for a single raid member. |
|
106 |
|
|
|
107 |
|
@function emitRaidButton |
|
108 |
|
|
|
109 |
|
@tparam string buttonName frame designation, expected to be globally unique |
|
110 |
|
|
|
111 |
|
@tparam string buttonTemplate virtual frame designation, all buttons in a |
|
112 |
|
specific raid frame profile are expected to be uniform and share a single |
|
113 |
|
template |
|
114 |
|
|
|
115 |
|
@tparam int buttonId positive integer and not zero, a serial number of the |
|
116 |
|
button, expected to be unique per raid frame profile |
|
117 |
|
|
|
118 |
|
@tparam number buttonX offset from origin, that is bottom left corner, to the right |
|
119 |
|
|
|
120 |
|
@tparam number buttonY offset from origin, that is bottom left corner, upwards |
|
121 |
|
|
|
122 |
|
@tparam string unitDesignation unit designation, that is a raid member, like |
|
123 |
|
`raid13`, each button is expected expected to map to units 1:1 |
|
124 |
|
|
|
125 |
|
@return nothing, the output is printed to standard output |
|
126 |
|
]] |
52 |
127 |
function mod.emitRaidButton(buttonName, buttonTemplate, buttonId, buttonX, buttonY, unitDesignation) |
function mod.emitRaidButton(buttonName, buttonTemplate, buttonId, buttonX, buttonY, unitDesignation) |
53 |
128 |
assert(buttonName ~= nil) |
assert(buttonName ~= nil) |
54 |
129 |
assert('string' == type(buttonName)) |
assert('string' == type(buttonName)) |
|
... |
... |
function mod.emitRaidGroup(raidFrameName, buttonTemplate, buttonWidth, |
173 |
248 |
end |
end |
174 |
249 |
end |
end |
175 |
250 |
|
|
|
251 |
|
--[[-- |
|
252 |
|
Print to standard output a valid XML descriptor for a raid frame profile, with |
|
253 |
|
given arguments. |
|
254 |
|
|
|
255 |
|
A raid frame consists by default of forty buttons arranged in a grid. First |
|
256 |
|
button is the bottom left most corner of the grid, growing to the right and up. |
|
257 |
|
|
|
258 |
|
A raid frame can be split into two blocks of twenty buttons, instead of one |
|
259 |
|
block of forty. See the notes in the source code. |
|
260 |
|
|
|
261 |
|
@function emitRaidFrame |
|
262 |
|
|
|
263 |
|
@tparam string raidFrameName raid frame designation token, expected to be |
|
264 |
|
globally unique |
|
265 |
|
|
|
266 |
|
@tparam string buttonTemplate virtual frame template designation token, that |
|
267 |
|
every button in the raid frame profile will inherit from |
|
268 |
|
|
|
269 |
|
@tparam number buttonWidth positive and not zero integer, width of a single button |
|
270 |
|
|
|
271 |
|
@tparam number buttonWidth positive and not zero integer, width of a single button |
|
272 |
|
|
|
273 |
|
@return nothing, the output is printed to standard output |
|
274 |
|
]] |
176 |
275 |
function mod.emitRaidFrame(raidFrameName, buttonTemplate, buttonWidth, buttonHeight) |
function mod.emitRaidFrame(raidFrameName, buttonTemplate, buttonWidth, buttonHeight) |
177 |
276 |
assert(raidFrameName ~= nil) |
assert(raidFrameName ~= nil) |
178 |
277 |
assert('string' == type(raidFrameName)) |
assert('string' == type(raidFrameName)) |
|
... |
... |
function mod.emitRaidFrame(raidFrameName, buttonTemplate, buttonWidth, buttonHei |
203 |
302 |
|
|
204 |
303 |
local groupQuantity = math.ceil(raidSizeMax / groupSizeMax) |
local groupQuantity = math.ceil(raidSizeMax / groupSizeMax) |
205 |
304 |
|
|
206 |
|
--[[ The table of raid buttons grows vertically from bottom left to top |
|
207 |
|
right, indefinitely. However, when the limit of rows is reached, the |
|
208 |
|
vertical position of the cursor is reset, and horizonal position is |
|
209 |
|
offset, as to allow the table to grow horizontally. The purpose is to |
|
210 |
|
save visual screen space for the end user. ]]-- |
|
211 |
|
|
|
212 |
|
--[[ Effectively, by default, the raid frame is split into two blocks |
|
213 |
|
of 4 groups x 5 members. ]]-- |
|
|
305 |
|
--[[ Effectively, when `blockQuantity = 2`, the raid frame is split |
|
306 |
|
into two blocks of 4 groups x 5 members. ]]-- |
214 |
307 |
|
|
215 |
308 |
local blockQuantity = 1 |
local blockQuantity = 1 |
216 |
309 |
assert(blockQuantity > 0) |
assert(blockQuantity > 0) |
217 |
310 |
blockQuantity = math.ceil(math.abs(blockQuantity)) |
blockQuantity = math.ceil(math.abs(blockQuantity)) |
218 |
311 |
|
|
|
312 |
|
--[[ Margin to leave space for group number labels. ]]-- |
|
313 |
|
|
219 |
314 |
local marginLeft = 16 |
local marginLeft = 16 |
220 |
315 |
local padding = 6 |
local padding = 6 |
221 |
316 |
assert(padding >= 0) |
assert(padding >= 0) |
|
... |
... |
function mod.emitRaidFrame(raidFrameName, buttonTemplate, buttonWidth, buttonHei |
258 |
353 |
print(footer) |
print(footer) |
259 |
354 |
end |
end |
260 |
355 |
|
|
261 |
|
function mod.main(...) |
|
262 |
|
mod.emitRaidFrame(...) |
|
263 |
|
end |
|
264 |
|
|
|
265 |
|
ChorusRaidFrameGenerator = mod |
|
|
356 |
|
--[[-- |
|
357 |
|
Process command line arguments with builtin global variable `arg`. |
266 |
358 |
|
|
267 |
|
do |
|
|
359 |
|
@function mod.main |
|
360 |
|
@see emitRaidFrame |
|
361 |
|
@return nothing, prints to standard output |
|
362 |
|
]] |
|
363 |
|
function mod.main() |
268 |
364 |
if arg ~= nil and 'table' == type(arg) then |
if arg ~= nil and 'table' == type(arg) then |
269 |
|
mod.main(unpack(arg)) |
|
|
365 |
|
return mod.emitRaidFrame(unpack(arg)) |
270 |
366 |
end |
end |
|
367 |
|
end |
271 |
368 |
|
|
|
369 |
|
do |
|
370 |
|
mod.main() |
272 |
371 |
return mod |
return mod |
273 |
372 |
end |
end |