forked from FAForever/fa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates_factory.lua
More file actions
88 lines (77 loc) · 2.72 KB
/
templates_factory.lua
File metadata and controls
88 lines (77 loc) · 2.72 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
local Prefs = import('/lua/user/prefs.lua')
local templates = Prefs.GetFromCurrentProfile('build_templates_factory') or {}
local UIUtil = import('/lua/ui/uiutil.lua')
-- Utils
function GetInitialName()
local nextNum = 0
for _, template in templates do
local pStart, pEnd = string.find(template.name, '%(%d+%)')
if pStart == 1 and pEnd == string.len(template.name) then
local prevNum = tonumber(string.sub(template.name, 2, pEnd - 1))
if nextNum < prevNum then
nextNum = prevNum
end
end
end
local name = '(' .. nextNum + 1 .. ')'
return name
end
function GetInitialIcon(buildQueue)
for _, entry in buildQueue do
if type(entry) == 'table' and UIUtil.UIFile('/icons/units/' .. entry.id .. '_icon.dds', true) then
return entry.id -- Original or modded unit found
end
end
return 'default' -- If we don't find a valid IconName; return string 'default'
end
-- Main functions
function CreateBuildTemplate(buildQueue)
if buildQueue and not table.empty(buildQueue) then
PlaySound(Sound({Bank = 'Interface', Cue = 'UI_Tab_Click_02'}))
table.insert(templates, {templateData = buildQueue, name = GetInitialName(), icon = GetInitialIcon(buildQueue)})
Prefs.SetToCurrentProfile('build_templates_factory', templates)
import('/lua/ui/game/construction.lua').RefreshUI()
else
PlaySound(Sound({Cue = 'UI_Menu_Error_01', Bank = 'Interface',}))
end
end
function GetTemplates()
return Prefs.GetFromCurrentProfile('build_templates_factory')
end
-- Options menu
function RemoveTemplate(templateID)
table.remove(templates, templateID)
Prefs.SetToCurrentProfile('build_templates_factory', templates)
end
function RenameTemplate(templateID, name)
templates[templateID].name = name
Prefs.SetToCurrentProfile('build_templates_factory', templates)
end
function SetTemplateIcon(templateID, iconPath)
templates[templateID].icon = iconPath
Prefs.SetToCurrentProfile('build_templates_factory', templates)
end
function SendTemplate(templateID, armyIndex)
WARN("Not implemented yet. Shhhh.")
end
function SetTemplateKey(templateID, key)
local used = false
for i, template in templates do
if i == templateID then continue end
if template.key and template.key == key then
used = true
break
end
end
if used then
return false
else
templates[templateID].key = key
Prefs.SetToCurrentProfile('build_templates_factory', templates)
return true
end
end
function ClearTemplateKey(templateID)
templates[templateID].key = nil
Prefs.SetToCurrentProfile('build_templates_factory', templates)
end