-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy path2_groups.lua
More file actions
114 lines (87 loc) · 2.46 KB
/
2_groups.lua
File metadata and controls
114 lines (87 loc) · 2.46 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
---
--- Group Registration Plugin
--- Register the group information of the show file to use in the other plugins
---
group_all_index = 1;
group_all_name = "ALL";
group_placeholder = "[PRESS ENTER WHEN DONE]";
group_vars_groups = "group_vars_groups";
--region Group
Group = {
index = 0,
name = ""
}
--- Create a new group object for the given index and name.
---@param index number The index of the group.
---@param name string The name of the group.
---@return table Returns the new group instance.
function Group:new(index, name)
local instance = {
index = index,
name = name
}
setmetatable(instance, Groups);
self.__index = self
return instance
end
--- Create the group within grandma
function Group:create()
local index = self.index;
local name = self.name;
gma.cmd(string.format("Store Group %i /nc", index));
gma.cmd(string.format("Assign Group %i /name=\"%s\"", index, name));
end
--endregion
--region Groups
Groups = {}
--- Instantiate a new Groups instance.
---@return table Returns a new Groups instance.
function Groups:new()
local instance = {};
setmetatable(instance, Groups);
self.__index = self
return instance;
end
--- Load the groups from the show.
--- If no groups are stored in the show, and empty instance will be returned.
---@return table Returns the groups of the show.
function Groups:load()
Log:info("Loading existing groups")
local instance = Groups:new();
local savedGroups = gma.show.getvar(_G.group_vars_groups);
if (savedGroups ~= nil) then
for group in string.gmatch(savedGroups, "([^;]+)") do
end
end
return instance
end
--- Request the groups from the user.
--- This method will show an input dialog to the user.
function Groups:request()
local index = 10;
local totalGroups = 1;
local name = _G.group_placeholder;
while (true)
do
name = gma.textinput("Enter group name (" .. totalGroups .. ")", _G.group_placeholder);
if name == _G.group_placeholder or name == "" then
break ;
end
local group = Group:new(index, name);
table.insert(self, group);
index = index + 10;
totalGroups = totalGroups + 1;
end
end
--endregion
--- Plugin Entry Point
function main()
clear_all()
-- Set plugin name for logging
_G.plugin_name = "Groups";
local groups = Groups:load();
groups:request();
end
function finalize()
end
return main, finalize;