-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTrail.cs
83 lines (71 loc) · 2.42 KB
/
Trail.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using Terraria.DataStructures;
namespace OriMod;
/// <summary>
/// Class for containing and updating all <see cref="TrailSegment"/>s on an <see cref="OriPlayer"/>.
/// </summary>
public class Trail {
/// <summary>
/// Create an instance of <see cref="Trail"/> that will belong to <paramref name="oPlayer"/>.
/// </summary>
/// <param name="oPlayer">The <see cref="OriPlayer"/> this <see cref="Trail"/> will belong to.</param>
/// <exception cref="ArgumentNullException"><paramref name="oPlayer"/> is <see langword="null"/>.</exception>
internal Trail(OriPlayer oPlayer) {
ArgumentNullException.ThrowIfNull(oPlayer);
_segments = new TrailSegment[Count];
int i = 0;
while (i < Count) {
_segments[i++] = new TrailSegment(oPlayer);
}
}
/// <summary>
/// Sets <see cref="_index"/> to the next index in <see cref="_segments"/>, and returns the value.
/// </summary>
/// <returns>The updated value of <see cref="_index"/>.</returns>
private int NextIndex() {
_index = (_index + 1) % _segments.Length;
return _index;
}
/// <summary>
/// All <see cref="TrailSegment"/>s in this <see cref="Trail"/>.
/// </summary>
private readonly TrailSegment[] _segments;
/// <summary>
/// Current <see cref="_segments"/> index. Used for <see cref="TrailSegment.Reset"/>.
/// </summary>
private int _index;
internal bool hasDrawnThisFrame;
/// <summary>
/// Number of segments in a trail.
/// </summary>
public static int Count => 26;
/// <summary>
/// Call <see cref="TrailSegment.Tick"/> on each <see cref="TrailSegment"/>.
/// <para>This keeps the opacity of the trail appearing consistent.</para>
/// </summary>
public void UpdateSegments() {
foreach (TrailSegment segment in _segments) {
segment.Tick();
}
}
/// <summary>
/// <see cref="IEnumerable{T}"/> of all <see cref="DrawData"/>s from this trail.
/// </summary>
public IEnumerable<DrawData> TrailDrawDatas => _segments.Select(segment => segment.GetDrawData());
/// <summary>
/// Calls <see cref="TrailSegment.Reset"/> on the next segment.
/// </summary>
internal void ResetNextSegment() {
_segments[NextIndex()].Reset();
}
/// <summary>
/// Call to wipe player's trail completely
/// </summary>
public void DecayAllSegments() {
foreach (TrailSegment segment in _segments) {
segment.Decay();
}
}
}