- Joined
- May 16, 2020
- Messages
- 660
Hi all,
I'm trying to use this library from PurgeandFire to play around with the vertex coloring of units, but I'm getting an error when pasting it into my map (Cold debuff with variable slow).
The error is:
"dur is not a member of VertexColor" (refers to a line almost at the end of the code)
Can someone with JASS knowledge please help fix this?
I'm trying to use this library from PurgeandFire to play around with the vertex coloring of units, but I'm getting an error when pasting it into my map (Cold debuff with variable slow).
The error is:
"dur is not a member of VertexColor" (refers to a line almost at the end of the code)
Can someone with JASS knowledge please help fix this?
JASS:
/**
A simple library to handle vertex coloring.
The most recently applied vertex color effect is the one that shows up.
When that effect expires, the next one in line appears (if any).
function RegisterDefaultVertexColor(typeId, red, green, blue, alpha)
- If a unit has a default vertex color other than (255, 255, 255, 255), then
you should use this function to register the appropriate values. You only have
to do this once per unit type, preferably on initialization.
VertexColor.create(unit, red, green, blue, alpha, duration) returns VertexColor
- Applies a vertex color effect to a unit using the given values for
'duration' seconds. If you want the effect applied indefinitely, input
a value of -1 for duration.
vertexColorInstance.destroy()
- You can destroy an instance of a vertex color at any time.
*/
library VertexColor
globals
private hashtable ht = InitHashtable()
endglobals
/**
If a unit-type has a default vertex color other than (255, 255, 255, 255),
register those values on initialization through this function.
*/
function RegisterDefaultVertexColor takes integer typeId, integer r, integer g, integer b, integer a returns nothing
call SaveInteger(ht, typeId, 0, r)
call SaveInteger(ht, typeId, 1, g)
call SaveInteger(ht, typeId, 2, b)
call SaveInteger(ht, typeId, 3, a)
endfunction
struct VertexColorEffect
private unit base
readonly integer red
readonly integer green
readonly integer blue
readonly integer alpha
readonly thistype next
readonly thistype prev
method destroy takes nothing returns nothing
local integer typeId = GetUnitTypeId(this.base)
local integer id = GetHandleId(this.base)
/* If this is the front node, we must alter vertex colors */
if this == LoadInteger(ht, id, 0) then
/* If there are no more effects, reset the color */
if this.next == 0 then
if HaveSavedInteger(ht, typeId, 0) then
call SetUnitVertexColor(this.base, LoadInteger(ht, typeId, 0), /*
[I]/ LoadInteger(ht, typeId, 1), /[/I]
[I]/ LoadInteger(ht, typeId, 2), /[/I]
*/ LoadInteger(ht, typeId, 3))
else
call SetUnitVertexColor(this.base, 255, 255, 255, 255)
endif
call RemoveSavedInteger(ht, id, 0)
else
call SetUnitVertexColor(this.base, this.next.red, this.next.green, this.next.blue, this.next.alpha)
call SaveInteger(ht, id, 0, this.next)
endif
set this.next = 0
set this.prev = 0
else
set this.next.prev = this.prev
set this.prev.next = this.next
endif
call this.deallocate()
endmethod
static method create takes unit u, integer r, integer g, integer b, integer a returns thistype
local thistype this = thistype.allocate()
local integer id = GetHandleId(u)
set this.base = u
set this.red = r
set this.green = g
set this.blue = b
set this.alpha = a
/*
Add this instance to a list.
*/
set this.next.prev = this
set this.next = LoadInteger(ht, id, 0)
call SaveInteger(ht, id, 0, this.next)
call SetUnitVertexColor(u, r, g, b, a)
return this
endmethod
endstruct
struct VertexColor
private VertexColorEffect fx
private timer time
method destroy takes nothing returns nothing
if this.time != null then
call PauseTimer(this.time)
call DestroyTimer(this.time)
set this.time = null
endif
call fx.destroy()
endmethod
private static method finish takes nothing returns nothing
local thistype this = LoadInteger(ht, GetHandleId(GetExpiredTimer()), 1)
call this.destroy()
endmethod
static method create takes unit u, integer r, integer g, integer b, integer a, real duration returns thistype
local thistype this = thistype.allocate()
set this.fx = VertexColorEffect.create(u, r, g, b, a)
set this.dur = duration
if duration == -1 then
set this.time = null
else
set this.time = CreateTimer()
call SaveInteger(ht, GetHandleId(this.time), 1, this)
call TimerStart(this.time, duration, false, function thistype.finish)
endif
return this
endmethod
endstruct
endlibrary
[/code=jass]