HandToolFlashlight
HandToolFlashlight
Description
The hand tool specialisation for hand tools that shine a light from a node.
Functions
- onDelete
- onHeldEnd
- onLoad
- onUpdate
- prerequisitesPresent
- registerEventListeners
- registerFunctions
- registerXMLPaths
- setFlashlightIsActive
- updateTransform
onDelete
Description
Definition
onDelete()
Code
function HandToolFlashlight:onDelete()
local spec = self.spec_flashlight
if spec.lightNode ~ = nil then
-- The light node comes with the i3d file, but is relinked to the root node, so must be manually deleted.
delete(spec.lightNode)
spec.lightNode = nil
end
g_soundManager:deleteSamples(spec.samples)
if spec.lightNodeParent ~ = nil then
delete(spec.lightNodeParent)
spec.lightNodeParent = nil
end
end
onHeldEnd
Description
Definition
onHeldEnd()
Code
function HandToolFlashlight:onHeldEnd()
self:setFlashlightIsActive( false , true )
end
onLoad
Description
Definition
onLoad()
Arguments
| any | xmlFile |
|---|
Code
function HandToolFlashlight:onLoad(xmlFile)
local spec = self.spec_flashlight
spec.isActive = false
self.isFlashlight = true
-- The light node.
spec.lightNode = xmlFile:getValue( "handTool.flashlight.light#node" , nil , self.components, self.i3dMappings)
spec.lightMeshNode = xmlFile:getValue( "handTool.flashlight.light#mesh" , nil , self.components, self.i3dMappings)
spec.lightNodeParent = getParent(spec.lightNode)
spec.lightNodeOffsetX, spec.lightNodeOffsetY, spec.lightNodeOffsetZ = getTranslation(spec.lightNode)
spec.lightNodeForwardX, spec.lightNodeForwardY, spec.lightNodeForwardZ = localDirectionToLocal(spec.lightNode, spec.lightNodeParent, 0 , 0 , 1 )
-- Link the light node to the root node, so that it does not get hidden with the main hand tool.
link(getRootNode(), spec.lightNode)
-- The parameters.
spec.distance = xmlFile:getValue( "handTool.flashlight.light#distance" , 100 )
spec.coneAngle = xmlFile:getValue( "handTool.flashlight.light#coneAngle" , 60 )
spec.color = Color.fromVector(xmlFile:getValue( "handTool.flashlight.light#color" , { 1 , 1 , 1 , 1 } , true ))
spec.dropOff = xmlFile:getValue( "handTool.flashlight.light#dropOff" , 5 )
if spec.lightNode = = nil then
Logging.xmlError(xmlFile, "Flashlight's light node could not be resolved!" )
return
end
-- Set the light parameters.
setLightRange(spec.lightNode, spec.distance)
setLightColor(spec.lightNode, spec.color.r, spec.color.g, spec.color.b)
setLightDropOff(spec.lightNode, spec.dropOff)
setLightConeAngle(spec.lightNode, spec.coneAngle)
local iesProfileFilename = xmlFile:getValue( "handTool.flashlight.light#iesProfile" )
if iesProfileFilename ~ = nil then
iesProfileFilename = Utils.getFilename(iesProfileFilename, self.baseDirectory)
setLightIESProfile(spec.lightNode, iesProfileFilename)
end
if self.isClient then
spec.samples = { }
spec.samples.toggle = g_soundManager:loadSampleFromXML(xmlFile, "handTool.flashlight.sounds" , "toggle" , self.baseDirectory, self.components, 1 , AudioGroup.VEHICLE, self.i3dMappings, self )
end
-- Start with the light off.
self:setFlashlightIsActive( false , true )
end
onUpdate
Description
Definition
onUpdate()
Arguments
| any | dt |
|---|
Code
function HandToolFlashlight:onUpdate(dt)
self:updateTransform( self:getIsHeld())
self:raiseActive()
end
prerequisitesPresent
Description
Definition
prerequisitesPresent()
Arguments
| any | specializations |
|---|
Code
function HandToolFlashlight.prerequisitesPresent(specializations)
return true
end
registerEventListeners
Description
Definition
registerEventListeners()
Arguments
| any | handToolType |
|---|
Code
function HandToolFlashlight.registerEventListeners(handToolType)
SpecializationUtil.registerEventListener(handToolType, "onLoad" , HandToolFlashlight )
SpecializationUtil.registerEventListener(handToolType, "onDelete" , HandToolFlashlight )
SpecializationUtil.registerEventListener(handToolType, "onUpdate" , HandToolFlashlight )
SpecializationUtil.registerEventListener(handToolType, "onHeldEnd" , HandToolFlashlight )
end
registerFunctions
Description
Definition
registerFunctions()
Arguments
| any | handToolType |
|---|
Code
function HandToolFlashlight.registerFunctions(handToolType)
SpecializationUtil.registerFunction(handToolType, "setFlashlightIsActive" , HandToolFlashlight.setFlashlightIsActive)
SpecializationUtil.registerFunction(handToolType, "updateTransform" , HandToolFlashlight.updateTransform)
end