- Joined
- Mar 19, 2008
- Messages
- 3,141
Simple trigger indexer created in order to give even more flexibility for user while scripting.
My RestoreTrigger required somekind of stuff like this.
My RestoreTrigger required somekind of stuff like this.
JASS:
/*****************************************************************************
*
* TriggerUserData v1.1.0.1
* by Spinnaker
*
* Enables assigning unique indexes to triggers.
*
******************************************************************************
*
* Requirements:
* Optional - Table by Bribe
* hiveworkshop.com/forums/showthread.php?t=188084
*
******************************************************************************
*
* Functions:
* function SetTriggerUserData takes trigger t, integer index returns nothing
* assigns unique index to trigger t
* function GetTriggerUserData takes trigger t returns integer
* function GetTriggerId takes trigger t returns integer
* returns assigned data to trigger
*
* function GetTriggerById takes integer index returns trigger
* retrives trigger by it's index
* function IsTriggerIndexed takes trigger t returns boolean
* checks whether trigger is indexed or not
*
*****************************************************************************/
library TriggerUserData uses optional Table
globals
private integer array next
private integer array prev
private integer ic = 0
private integer rec = 0
private trigger array trigg
endglobals
function SetTriggerUserData takes trigger t, integer index returns nothing
static if LIBRARY_Table then
set TriggerData.tt[GetHandleId(t)] = index
else
call SaveInteger(TriggerData.tt, 0, GetHandleId(t), index)
endif
endfunction
function GetTriggerUserData takes trigger t returns integer
static if LIBRARY_Table then
if TriggerData.tt.has(GetHandleId(t)) then
return TriggerData.tt[GetHandleId(t)]
endif
else
if HaveSavedInteger(TriggerData.tt, 0, GetHandleId(t)) then
return LoadInteger(TriggerData.tt, 0, GetHandleId(t))
endif
endif
return TriggerData.indexTrigger(t)
endfunction
private module TriggerUDInit
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set tt = Table.create()
endif
endmethod
endmodule
function GetTriggerById takes integer index returns trigger
return trigg[index]
endfunction
function GetTriggerId takes trigger t returns integer
return GetTriggerUserData(t)
endfunction
function IsTriggerIndexed takes trigger t returns boolean
static if LIBRARY_Table then
return TriggerData.tt.has(GetHandleId(t))
else
return HaveSavedInteger(TriggerData.tt, 0, GetHandleId(t))
endif
endfunction
struct TriggerData extends array
static boolean enabled = true
static if LIBRARY_Table then
static Table tt = 0
else
static hashtable tt = InitHashtable()
endif
static method indexTrigger takes trigger t returns integer
local integer this=0
if enabled and t!= null then
if (0==rec) then
set ic=ic+1
set this=ic
else
set this=rec
set rec=next[rec]
endif
call SetTriggerUserData(t, this)
set trigg[this]=t
set prev[this]=prev[0]
set next[prev[0]]=this
set next[this]=0
set prev[0]=this
endif
return this
endmethod
static method deindexTrigger takes trigger t returns nothing
local thistype this
if IsTriggerIndexed(t) then
set this = GetTriggerUserData(t)
set next[prev[this]]=next[this]
set prev[next[this]]=prev[this]
static if LIBRARY_Table then
call TriggerData.tt.remove(GetHandleId(t))
else
call RemoveSavedInteger(tt, 0, GetHandleId(t))
endif
set trigg[this]=null
set next[this]=rec
set rec=this
endif
endmethod
implement TriggerUDInit
endstruct
hook DestroyTrigger TriggerData.deindexTrigger
endlibrary
Last edited: