Back to Home

ESO Lua File v100020

libraries/zo_particles/zo_particle.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
--Particle
ZO_Particle = ZO_Object:Subclass()
function ZO_Particle:New(...)
    local obj = ZO_Object.New(self)
    obj:Initialize(...)
    return obj
end
function ZO_Particle:Initialize()
    self.parameters = {}
end
function ZO_Particle:GetKey()
    return self.key
end
function ZO_Particle:SetKey(key)
    self.key = key
end
function ZO_Particle:SetParameter(name, value)
    self.parameters[name] = value
end
function ZO_Particle:Start(parentControl)
    local parameters = self.parameters
    self.textureControl = PARTICLE_SYSTEM_MANAGER:AcquireTexture()
    self.textureControl:SetParent(parentControl)
    self.startTimeS = GetGameTimeMilliseconds() / 1000
    local durationS = parameters["DurationS"]
    if durationS then
        self.endTimeS = self.startTimeS + durationS
    end
    self.textureControl:SetTexture(parameters["Texture"])
    local blendMode = parameters["BlendMode"]
    self.textureControl:SetBlendMode(blendMode or TEX_BLEND_MODE_ALPHA)
    local size = parameters["Size"]
    self.hasScaleInterpolation, self.scale = self:InitializeEasedLerpParameter("StartScale", "EndScale", 1)
    self.textureControl:SetDimensions(size * self.scale, size * self.scale)
    self.hasOffsetXInterpolation, self.offsetX = self:InitializeEasedLerpParameter("StartOffsetX", "EndOffsetX", 0)
    self.hasOffsetYInterpolation, self.offsetY = self:InitializeEasedLerpParameter("StartOffsetY", "EndOffsetY", 0)
    self.hasOffsetZInterpolation, self.offsetZ = self:InitializeEasedLerpParameter("StartOffsetZ", "EndOffsetZ", 0)
    local alpha
    self.hasAlphaInterpolation, alpha = self:InitializeEasedLerpParameter("StartAlpha", "EndAlpha", 1)
    self.hasColorRInterpolation, self.colorR = self:InitializeEasedLerpParameter("StartColorR", "EndColorR", 1)
    self.hasColorGInterpolation, self.colorG = self:InitializeEasedLerpParameter("StartColorG", "EndColorG", 1)
    self.hasColorBInterpolation, self.colorB = self:InitializeEasedLerpParameter("StartColorB", "EndColorB", 1)
    self.textureControl:SetColor(self.colorR, self.colorG, self.colorB, alpha)
end
function ZO_Particle:Stop()
    PARTICLE_SYSTEM_MANAGER:ReleaseTexture(self.textureControl)
    self.textureControl = nil
end
function ZO_Particle:GetProgress(timeS)
    return zo_clamp((timeS - self.startTimeS) / (self.endTimeS - self.startTimeS), 0, 1)
end
function ZO_Particle:GetElapsedTime(timeS)
    return zo_clamp(timeS - self.startTimeS, 0, self.endTimeS - self.startTimeS)
end
function ZO_Particle:IsDone(timeS)
    return timeS > self.endTimeS
end
function ZO_Particle:InitializeEasedLerpParameter(startName, endName, defaultValue)
    local parameters = self.parameters
    local hasInterpolation = false
    local initialValue = defaultValue
    if parameters[startName] ~= nil then
        initialValue = parameters[startName]
        if parameters[endName] ~= nil then
            hasInterpolation = true
        end
    end
    return hasInterpolation, initialValue
end
local lerp = zo_lerp
function ZO_Particle:ComputedEasedLerpParameter(startName, endName, easingName, defaultValue, progress)
    local parameters = self.parameters
    local startValue = parameters[startName]
    local endValue = parameters[endName]
    local value = defaultValue
    if startValue and endValue then
        local easingFunction = parameters[easingName]
        if easingFunction then
            progress = easingFunction(progress)
        end
        value = lerp(startValue, endValue, progress)
    end
    return value
end
function ZO_Particle:OnUpdate(timeS)
    local progress = self:GetProgress(timeS)
    
    if self.hasScaleInterpolation then
        local parameters = self.parameters
        local size = parameters["Size"]
        local scale = self:ComputedEasedLerpParameter("StartScale", "EndScale", "ScaleEasing", 1, progress)
        self.textureControl:SetDimensions(size * scale, size * scale)
    end
    if self.hasOffsetXInterpolation then
        self.offsetX = self:ComputedEasedLerpParameter("StartOffsetX", "EndOffsetX", "OffsetXEasing", 0, progress)
    end
    if self.hasOffsetYInterpolation then
        self.offsetY = self:ComputedEasedLerpParameter("StartOffsetY", "EndOffsetY", "OffsetYEasing", 0, progress)
    end
    if self.hasOffsetZInterpolation then
        self.offsetZ = self:ComputedEasedLerpParameter("StartOffsetZ", "EndOffsetZ", "OffsetZEasing", 0, progress)
    end
    local r, g, b, a = self.textureControl:GetColor()
    if self.hasColorRInterpolation then
        r = self:ComputedEasedLerpParameter("StartColorR", "EndColorR", "ColorREasing", 1, progress)
    end
    if self.hasColorGInterpolation then
        g = self:ComputedEasedLerpParameter("StartColorG", "EndColorG", "ColorGEasing", 1, progress)
    end
    if self.hasColorBInterpolation then
        b = self:ComputedEasedLerpParameter("StartColorB", "EndColorB", "ColorBEasing", 1, progress)
    end
    if self.hasAlphaInterpolation then
        a = self:ComputedEasedLerpParameter("StartAlpha", "EndAlpha", "AlphaEasing", 1, progress)
    end
    self.textureControl:SetColor(r, g, b, a)
end
--Scene Graph Particle
ZO_SceneGraphParticle = ZO_Particle:Subclass()
function ZO_SceneGraphParticle:New(...)
    return ZO_Particle.New(self, ...)
end
function ZO_SceneGraphParticle:Initialize()
    ZO_Particle.Initialize(self)
end
function ZO_SceneGraphParticle:SetParentNode(parentNode)
    self.parentNode = parentNode
end
function ZO_SceneGraphParticle:Start(parentControl)
    ZO_Particle.Start(self, parentControl)
    self.parentNode:AddControl(self.textureControl, 0, 0, 0)
end
function ZO_SceneGraphParticle:Stop()
    self.parentNode:RemoveControl(self.textureControl)
    ZO_Particle.Stop(self)
end
function ZO_SceneGraphParticle:SetPosition(x, y, z)
    if z == nil then
        z = 0
    end
    self.parentNode:SetControlPosition(self.textureControl, x + self.offsetX, -(y + self.offsetY), z + self.offsetZ)
end