-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
textures.lua
127 lines (111 loc) · 3.56 KB
/
textures.lua
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
local actions = require 'actions';
local util = require 'util';
local mgr = AshitaCore:GetResourceManager();
local textures = {};
local buttons = require 'buttons';
local spirit_buttons = require 'spirit_buttons';
local ja_buttons = require 'ja_buttons';
local pet_buttons = nil; -- updated on pet change
local function load_texture(name, size)
local path = string.format('%s/' .. size .. '/%s.png', _addon.path, name):gsub("[%?']", '_');
local res, texture = ashita.d3dx.CreateTextureFromFileA(path);
if (res ~= 0) then
-- Get the error information..
local _, err = ashita.d3dx.GetErrorStringA(res);
print(string.format('[Error] Failed to load background texture for slot: %s - Error: (%08X) %s', path, res, err));
return nil;
end
return texture;
end
function textures:Load()
for _, textures in ipairs({ buttons, spirit_buttons, ja_buttons }) do
for _, texture in ipairs(textures) do
if (textures == ja_buttons) then
texture.texture = load_texture(texture.command, 48);
local action, ability = actions:GetJaAction(texture.command, texture.target);
texture.action = action;
texture.ability = ability;
else
texture.texture = load_texture(texture.name, 64);
texture.action = actions:Get(texture.name);
end
if (texture.texture) then
texture.ptr = texture.texture:Get();
end
for _, command in ipairs(texture.commands or {}) do
if (command.command) then
command.texture = load_texture(command.command, 48);
if (command.texture ~= nil) then
command.ptr = command.texture:Get();
end
end
end
end
end
end
function textures:Unload()
for _, textures in ipairs({ buttons, spirit_buttons, ja_buttons }) do
for _, texture in ipairs(textures) do
texture.texture:Release();
texture.texture = nil;
texture.ptr = nil;
texture.action = nil;
for _, command in ipairs(texture.commands or {}) do
if (command.texture ~= nil) then
command.texture:Release();
command.texture = nil;
end
command.ptr = nil;
command.action = nil;
end
end
end
end
function textures:Buttons()
return buttons;
end
function textures:SpiritButtons()
return spirit_buttons;
end
function textures:JaButtons()
return ja_buttons;
end
function textures:PetButtons()
local pet, lastpet = util:PetName();
if (not util:HasPet() or pet == nil) then
pet_buttons = nil;
return pet_buttons;
end
if (pet == lastpet) then return pet_buttons end -- use the table we generated last time to save time
-- assemble new table of actions for the current pet and save it off for next render
pet_buttons = {};
local commands = nil;
local spirit = pet:lower():match('(.+)spirit');
if (spirit) then
pet = spirit .. ' spirit' -- there's no space in the ashita name
end
for _, button in ipairs(spirit == nil and buttons or spirit_buttons) do
if (button.name == pet:lower()) then
commands = button.commands;
break;
end
end
if (commands == nil) then
for _, button in ipairs(spirit_buttons) do
if (button.name == pet:lower()) then
commands = button.commands;
break;
end
end
end
commands = commands or {};
for i, command in ipairs(commands) do
local action, ability = actions:GetPetAction(command.command, command.ranks, command.target);
if (action ~= nil) then
command.action = action;
command.ability = ability;
table.insert(pet_buttons, command);
end
end
end
return textures;