library Track /* v3.0.0.0
*******************************************************************
*
* Manages trackable objects, allowing for easy event
* registrations, data retrieval, and adds the capability of
* retrieving which player interacted with the trackable.
*
*******************************************************************
*
* */uses/*
*
* */ Table /* hiveworkshop.com/forums/jass-functions-413/snippet-new-table-188084/
*
*******************************************************************
*
* SETTINGS
*/
globals
private constant integer PLATFORM = 'Otip'
endglobals
/*
*******************************************************************
*
* FUNCTIONS
*
* function CreateTrack takes string modelPath, real x, real y, real z, real facing returns Track
*
* - Creates a trackable of "modelPath" at the coordinates
* (x, y, z) with "facing" in degrees.
*
* function CreateTrackForPlayer takes string modelPath, real x, real y, real z, real facing returns Track
*
* - Same as above, but for only one player to interact with.
*
* function RegisterAnyClickEvent takes code c returns nothing
*
* - The function input will be called whenever a trackable
* is clicked.
*
* function RegisterAnyHoverEvent takes code c returns nothing
*
* - The function input will be called whenever a player
* hovers over a trackable.
*
* function RegisterClickEvent takes Track obj, code c returns nothing
*
* - The code will be executed every time a trackable of the
* instance 'obj' is clicked.
*
* function RegisterHoverEvent takes Track obj, code c returns nothing
*
* - The code will be executed every time a trackable of the
* instance 'obj' is hovered over.
*
* function EnableTrackInstance takes Track obj, boolean flag returns nothing
*
* - Enables trackable events for the instance.
* - All instances are enabled by default.
*
* function IsTrackInstanceEnabled takes Track obj returns boolean
*
* - Returns whether or not an instance has its events enabled.
*
* EVENT RESPONSES
*
* function GetTriggerTrackInstance takes nothing returns Track
*
* - Returns the Track instance that had a player interaction.
*
* function GetTriggerTrackable takes nothing returns trackable
*
* - Returns the trackable object that had a player interaction.
*
* function GetTriggerTrackablePlayer takes nothing returns player
*
* - Returns the player that had interacted with the trackable object.
*
*******************************************************************
*
* struct Track
*
* static Track instance
*
* - The triggering instance of the event.
*
* static trackable object
*
* - The triggering trackable object of the event.
*
* static player tracker
*
* - The player who interacted with the trackable object of the event.
*
* readonly real x
* readonly real y
* readonly real z
*
* - The coordinates (x, y, z) of the trackable object.
*
* readonly real facing
*
* - The facing angle of the trackable object.
*
* readonly string model
*
* - The string path of the trackable object.
*
* method operator enabled takes nothing returns boolean
*
* static method create takes string modelPath, real x, real y, real z, real facing returns Track
*
* static method createForPlayer takes string modelPath, real x, real y, real z, real facing, player p returns Track
*
*
* static method registerAnyClick takes code c returns nothing
*
* static method registerAnyHover takes code c returns nothing
*
* method registerOnClick takes code c returns nothing
*
* method registerOnHover takes code c returns nothing
*
* method enable takes nothing returns nothing
*
* method disable takes nothing returns nothing
*
* - All of the above are the struct interface equivalents of the functions.
*
********************************************************************
*
* Credits
* - Azlier for Trackable2
*
********************************************************************/
private module Init
private static method onInit takes nothing returns nothing
set thistype.TrackTable = Table.create()
endmethod
endmodule
struct Track extends array
private static Table TrackTable = 0
static thistype instance = 0
static trackable object = null
static player tracker = null
private static integer ic = 0
private static integer ir = 0
private thistype rn
readonly real x
readonly real y
readonly real z
readonly real facing
readonly string model
private boolean flag
private trigger reg
private trigger onClick
private trigger onHover
static method registerAnyClick takes code c returns nothing
endmethod
static method registerAnyHover takes code c returns nothing
endmethod
method registerClick takes code c returns nothing
if .onClick == null then
endif
endmethod
method registerHover takes code c returns nothing
if .onHover == null then
endif
endmethod
method destroy takes nothing returns nothing
set .rn = ir
set ir = this
endmethod
method enable takes nothing returns nothing
set this.flag = true
endmethod
method disable takes nothing returns nothing
set this.flag = false
endmethod
method operator enabled takes nothing returns boolean
return this.flag
endmethod
private static method onInteract takes nothing returns boolean
local thistype temp = instance
local trackable tr = object
local player p = tracker
if instance.flag then
else
endif
endif
set instance = temp
set tracker = p
set object = tr
set tr = null
set p = null
return false
endmethod
private static method createTrack takes string modelPath, real x, real y, real z, real facing, player j returns thistype
local destructable dest = null
local thistype this = ir
local integer i = 11
local trackable tr
local player p
local string s
if this == 0 then
set ic = ic + 1
set this = ic
else
set ir = .rn
endif
if z != 0 then
endif
if j != null then
endif
set .x = x
set .y = y
set .z = z
set .flag = true
set .facing = facing
set .model = modelPath
set .onClick = null
set .onHover = null
loop
set s = modelPath
else
set s = ""
endif
if j != null then
exitwhen true
endif
endif
exitwhen i == 0
set i = i - 1
endloop
if dest != null then
set dest = null
endif
set p = null
set tr = null
return this
endmethod
static method create takes string modelPath, real x, real y, real z, real facing returns thistype
return thistype.createTrack(modelPath, x, y, z, facing, null)
endmethod
static method createForPlayer takes string modelPath, real x, real y, real z, real facing, player p returns thistype
return 0
endif
return thistype.createTrack(modelPath, x, y, z, facing, p)
endmethod
implement Init
endstruct
function CreateTrack takes string modelPath, real x, real y, real z, real facing returns Track
return Track.create(modelPath, x, y, z, facing)
endfunction
function CreateTrackForPlayer takes string modelPath, real x, real y, real z, real facing, player who returns Track
return Track.createForPlayer(modelPath, x, y, z, facing, who)
endfunction
function EnableTrackInstance takes Track instance, boolean flag returns nothing
if flag then
call instance.enable()
else
call instance.disable()
endif
endfunction
function IsTrackInstanceEnabled takes Track instance returns boolean
return instance.enabled
endfunction
function RegisterAnyClickEvent takes code c returns nothing
call Track.registerAnyClick(c)
endfunction
function RegisterAnyHoverEvent takes code c returns nothing
call Track.registerAnyHover(c)
endfunction
function RegisterClickEvent takes Track obj, code c returns nothing
call obj.registerClick(c)
endfunction
function RegisterHoverEvent takes Track obj, code c returns nothing
call obj.registerHover(c)
endfunction
function GetTriggerTrackInstance takes nothing returns Track
return Track.instance
endfunction
function GetTriggerTrackable takes nothing returns trackable
return Track.object
endfunction
function GetTriggerTrackablePlayer takes nothing returns player
return Track.tracker
endfunction
endlibrary