Back to Home

ESO Lua File v101041

ingame/particles/particles.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
ZO_WorldParticles = ZO_Object:Subclass()
function ZO_WorldParticles:New()
    local obj = ZO_Object.New(self)
    obj:Initialize()
    return obj
end
function ZO_WorldParticles:Initialize()
    self.updateParticles = {}
    EVENT_MANAGER:RegisterForUpdate("ZO_WorldParticles_Update", 0, function() self:OnUpdate() end)
end
function ZO_WorldParticles:OnUpdate()
    for i, particle in ipairs(self.updateParticles) do
        particle:OnUpdate()
    end
end
function ZO_WorldParticles:AddUpdateParticle(particle)
    table.insert(self.updateParticles, particle)
end
function ZO_WorldParticles:RemoveUpdateParticle(particle)
    for i, searchParticle in ipairs(self.updateParticles) do
        if particle == searchParticle then
            table.remove(self.updateParticles, i)
            break
        end
    end
end
local g_particles = ZO_WorldParticles:New()
ZO_WorldParticle = ZO_Object:Subclass()
function ZO_WorldParticle:New(...)
    local obj = ZO_Object.New(self)
    obj:Initialize(...)
    return obj
end
function ZO_WorldParticle:Initialize(particleId)
    self.particleId = particleId    
end
function ZO_WorldParticle:Start()
    if self.particleId then
        StartWorldParticleEffect(self.particleId)
    end
end
function ZO_WorldParticle:Stop()
    if self.particleId then
        StopWorldParticleEffect(self.particleId)
    end
end
function ZO_WorldParticle:Reset()
    self:Stop()
end
function ZO_WorldParticle:SetWorldPosition(worldX, worldY, worldZ)
    if self.particleId then
        SetWorldParticleEffectPosition(self.particleId, worldX, worldY, worldZ)
    end
end
function ZO_WorldParticle:SetWorldPositionFromLocal(control, localX, localY, localZ)
    local worldX, worldY, worldZ = control:Convert3DLocalPositionToWorldPosition(localX, localY, localZ)
    self:SetWorldPosition(worldX, worldY, worldZ)
end
function ZO_WorldParticle:SetWorldPositionFromControl(control)
    local worldX, worldY, worldZ = control:Convert3DLocalPositionToWorldPosition(0, 0, 0)
    self:SetWorldPosition(worldX, worldY, worldZ)
end
function ZO_WorldParticle:SetWorldOrientation(pitchRadians, yawRadians, rollRadians)
    if self.particleId then
        SetWorldParticleEffectOrientation(self.particleId, pitchRadians, yawRadians, rollRadians)
    end
end
function ZO_WorldParticle:SetWorldOrientationFromLocal(control, localPitchRadians, localYawRadians, localRollRadians)
    local worldPitchRadians, worldYawRadians, worldRollRadians = control:Convert3DLocalPositionToWorldPosition(localPitchRadians, localYawRadians, localRollRadians)
    self:SetWorldOrientation(worldPitchRadians, worldYawRadians, worldRollRadians)
end
function ZO_WorldParticle:SetWorldOrientationFromControl(control)
    local worldPitchRadians, worldYawRadians, worldRollRadians = control:Convert3DLocalOrientationToWorldOrientation(0, 0, 0)
    self:SetWorldOrientation(worldPitchRadians, worldYawRadians, worldRollRadians)
end
function ZO_WorldParticle:FollowControl(control)
    if self.followControl then
        self:UnfollowControl()
    end
    self.followControl = control
    g_particles:AddUpdateParticle(self)
    
end
function ZO_WorldParticle:UnfollowControl()
    if self.followControl then
        g_particles:RemoveUpdateParticle(self)
        self.followControl = nil
    end
end
function ZO_WorldParticle:UpdateFollowControl()
    self:SetWorldPositionFromControl(self.followControl)
    self:SetWorldOrientationFromControl(self.followControl)
end
function ZO_WorldParticle:OnUpdate()
    if self.followControl then
        self:UpdateFollowControl()
    end
end
function ZO_WorldParticle:SetScale(scale)
    if self.particleId then
        SetWorldParticleEffectScale(self.particleId, scale)
    end
end
function ZO_WorldParticle:Delete()
    if self.particleId then
        DeleteWorldParticleEffect(self.particleId)
        self.particleId = nil
    end
end