Skip to content

Commit 7979b40

Browse files
committed
3.1.0, improving API to be robust on sharing units [https://trello.com/c/tg1OcR80/]
1 parent d2751e6 commit 7979b40

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

customCommands.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,21 @@ customCommands = {
205205
end
206206
end
207207
end,
208+
209+
-- @description handler API used for removing unit by any means which (re)sets the system to proper state once called (by removing)
210+
-- @argument unitID [number] Spring unitID
211+
-- @argument unitDefID [number] Spring unitDefID
212+
-- @argument teamID [number] Spring teamID
213+
-- @comment IMPORTANT NOTE: this funciton removes units commands regards CURRENT team. If supposed to be called to remove commands to solve sharing units cleanup, it should be called with oldTeamID.
214+
["UnitRemoved"] = function(unitID, unitDefID, teamID)
215+
unitName = UnitDefs[unitDefID].name
216+
for internalCmdName, cmdDesc in pairs(customCommandsDescriptions) do
217+
if (customCommandsNameToTeamID[internalCmdName] == teamID) then -- if not owned by proper team
218+
local index = Spring.FindUnitCmdDesc(unitID, cmdDesc.id)
219+
if (index ~= nil) then
220+
Spring.RemoveUnitCmdDesc(unitID, index)
221+
end
222+
end
223+
end
224+
end,
208225
}

readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
customCommands 3.0.2
1+
customCommands 3.1.0
22
===
33

44
This module allows you to
@@ -8,6 +8,11 @@ This module allows you to
88
* registration/unregistration of commands
99
* informing rest of the game synced way about changes and stored synced list of all commands readable by their owners
1010
* informing unsynced modules (UI, custom widgets) about changes via unsynced handlers
11+
12+
Important compatibility notes
13+
---
14+
15+
* since 3.1.x should provide tools to be robust on units sharing
1116

1217

1318
Actual development references

0 commit comments

Comments
 (0)