You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (commandDescription==nilortype(commandDescription) ~="table") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription]") end
15
+
if (commandDescription.type==nilortype(commandDescription.type) ~="number") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.type]") end
16
+
if (commandDescription.name==nilortype(commandDescription.name ) ~="string") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.name]") end
17
+
if (commandDescription.cursor==nilortype(commandDescription.cursor) ~="string") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.cursor]") end
18
+
if (commandDescription.action==nilortype(commandDescription.action) ~="string") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.action]") end
19
+
if (commandDescription.tooltip==nilortype(commandDescription.tooltip) ~="string") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.tooltip]") end
20
+
if (commandDescription.hidden==nilortype(commandDescription.hidden) ~="boolean") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.hidden]") end
21
+
22
+
-- NOTA UI mandatory
23
+
if (commandDescription.UIoverride==nilortype(commandDescription.UIoverride) ~="table") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.UIoverride]") end
24
+
25
+
-- optional for Spring
26
+
if (commandDescription.texture~=nilandtype(commandDescription.texture) ~="string") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.texture]") end
27
+
if (commandDescription.queueing~=nilandtype(commandDescription.queueing) ~="boolean") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.queueing]") end
28
+
if (commandDescription.disabled~=nilandtype(commandDescription.disabled) ~="boolean") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.disabled]") end
29
+
if (commandDescription.showUnique~=nilandtype(commandDescription.showUnique) ~="boolean") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.showUnique]") end
30
+
if (commandDescription.onlyTexture~=nilandtype(commandDescription.onlyTexture) ~="boolean") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.onlyTexture]") end
31
+
if (commandDescription.params~=nilandtype(commandDescription.params) ~="table") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [RegisterCustomCommand] with wrong parameter for [commandDescription.params]") end
32
+
33
+
-- optional
34
+
if (commandDescription.whitelist~=nilandtype(commandDescription.whitelist) ~="table") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [registerCustomCommand] with wrong parameter for [commandDescription.whitelist]") end
if (commandName==nilortype(commandName) ~="string") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [DeregisterCustomCommand] with wrong parameter for [commandName]") end
if (cmdID==nilortype(cmdID) ~="number") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [CustomCommandUpdate] with wrong parameter for [cmdID]") end
if (cmdName==nilortype(cmdName) ~="string") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [CustomCommandRegistered] with wrong parameter for [cmdName]") end
20
+
if (cmdID==nilortype(cmdID) ~="number") thenSpring.Echo("[" ..moduleInfo.name.."]" .."WARNING: Attempt to send message [CustomCommandRegistered] with wrong parameter for [cmdID]") end
message.SendSyncedInfoTeamPacked("CustomCommandsNameToID", encodedCustomCommandsNameToID , teamID) -- save mapping to global variable so any widget can reload it from there
message.SendSyncedInfoTeamPacked("CustomCommandsIDToOverride", encodedCustomCommandsIDToOverride, teamID) -- save override info to global variable so any widget can reload it from there
117
+
sendCustomMessage.CustomCommandUpdate(cmdID) -- event like notification for any widget
118
+
sendCustomMessage.CustomCommandRegistered(cmdName, cmdID) -- notify all widgets about registration (no matter if new or overriden)
119
+
120
+
-- construct valid commandDescription which does not contain invalid key=>value pairs
Spring.Echo("[customCommands] Command [" ..cmdName.."] was not registered because 1) limit reached or 2) trying to register command with already used name and you are not its owner")
157
+
end
158
+
end,
159
+
160
+
-- FAKE DEREGISTRAION :)
161
+
-- @description We just remove given command from all places where it was deployed
162
+
-- @privacy private to customCommands module
163
+
-- @argument internalCmdName [string] name of the command we want to deregister
164
+
-- @argument playerID [number] Spring playerID
165
+
-- @comment WARNING: the commandID is still occupied in engine!
if (cmdDesc~=nilandcmdDesc.id~=nilandcustomCommandsNameToPlayerID[internalCmdName] ==playerID) then-- only registrator can remove all instances of his own command from all units
171
+
for_, unitIDinpairs(Spring.GetTeamUnits(teamID)) do
customCommandsDescriptions[internalCmdName] =nil-- registration and internalCmdName => cmdID mapping is kept, but cmdDescription is deleted
178
+
end
179
+
end,
180
+
181
+
-- PUBLIC MODULE FUNCTIONS
182
+
183
+
-- @description handler API used for getting unit by any means which (re)sets the system to proper state once called (by adding, removing or updating available commands)
184
+
-- @argument unitID [number] Spring unitID
185
+
-- @argument unitDefID [number] Spring unitDefID
186
+
-- @argument teamID [number] Spring teamID
187
+
-- @argument builderID [number] Spring unitID of builder of given unit
0 commit comments