- Joined
- Apr 6, 2008
- Messages
- 760
Im trying out Unitevent. I really dont know how to use this system. I looked thru the demo code and did the same for remove. It wont trigger when i remove a unit that is registered.
So what i need is this system to unregister the unit that is removed
So what i need is this system to unregister the unit that is removed
JASS:
library KMS uses UnitIndexer, Table, UnitEvent
private struct Data extends array
readonly UnitIndex Unit
static Table T
private static integer instanceCount = 0
private static thistype recycle = 0
private thistype recycleNext
static method create takes unit u returns thistype
local thistype this
if (recycle == 0) then
set instanceCount = instanceCount + 1
set this = instanceCount
else
set this = recycle
set recycle = recycle.recycleNext
endif
set Unit = GetUnitId(u)
if Unit != 0 then
call Unit.lock()
else
call this.destroy()
return 0
endif
set T[GetUnitId(u)] = this
call BJDebugMsg("registered")
return this
endmethod
static method Unregister takes unit u returns nothing
local thistype this = T[GetUnitId(u)]
call Unit.unlock()
call T.remove(GetUnitId(u))
call BJDebugMsg("unregistered")
call .destroy()
endmethod
method destroy takes nothing returns nothing
set recycleNext = recycle
set recycle = this
endmethod
static method onInit takes nothing returns nothing
set T = Table.create()
endmethod
// This wont trigger
private method remove takes nothing returns nothing
call Unregister(unit)
endmethod
// This wont trigger neither
private static method filter takes unit u returns boolean
call BJDebugMsg("Filter")
return T.has(GetUnitId(u))
endmethod
implement UnitEventStruct
endstruct
public function RegisterUnitOutputs takes unit u returns nothing
call Data.create(u)
endfunction
public function UnregisterUnitOutputs takes unit u returns nothing
call Data.Unregister(u)
endfunction
public function GetUnitTable takes unit u returns Data
return Data.T[GetUnitId(u)]
endfunction
endlibrary