summaryrefslogtreecommitdiff
path: root/NW4RTools/Models/Animation/Shared.cs
blob: 62cca94a8c3f1b34034c1fd4bf17d11152229bb4 (plain)
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
using System;

namespace NW4RTools.Models.Animation {
	public struct Keyframe {
		public float Frame, Value, Slope;
	}

	public struct KeyframeAnim {
		public bool IsConstant;

		public float ConstValue;

		public Keyframe[] Keyframes;

		// Only valid sometimes
		// This sucks but I'm not sure how else to do it atm
		public float BaseValue, Multiplier;
		public int[] Values;
		public float[] FloatValues;

		public KeyframeAnim(float cv) {
			IsConstant = true;
			ConstValue = cv;

			Keyframes = null;

			BaseValue = Multiplier = 0;
			Values = null;
			FloatValues = null;
		}


		public bool IsConstWith(float cv) {
			return (IsConstant && (ConstValue == cv));
		}


		public override bool Equals(object obj) {
			return obj is KeyframeAnim && this == (KeyframeAnim)obj;
		}

		public override int GetHashCode() {
			return
				IsConstant.GetHashCode() ^
					ConstValue.GetHashCode() ^
					BaseValue.GetHashCode() ^
					Multiplier.GetHashCode() ^
					Misc.ArrayHash(Keyframes) ^
					Misc.ArrayHash(Values) ^
					Misc.ArrayHash(FloatValues);
		}

		public static bool operator ==(KeyframeAnim x, KeyframeAnim y) {
			return
				(x.IsConstant == y.IsConstant) &&
				(x.ConstValue == y.ConstValue) &&
					(x.BaseValue == y.BaseValue) &&
					(x.Multiplier == y.Multiplier) &&
			Misc.ArrayCompare(x.Keyframes, y.Keyframes) &&
					Misc.ArrayCompare(x.Values, y.Values) &&
					Misc.ArrayCompare(x.FloatValues, y.FloatValues);
		}

		public static bool operator !=(KeyframeAnim x, KeyframeAnim y) {
			return !(x == y);
		}

		public void Dump() {
			Console.WriteLine("IsC:{0} CV:{1} KF:{2} BV:{3} M:{4} V:{5} FV:{6}", IsConstant, ConstValue, Keyframes, BaseValue, Multiplier, Values, FloatValues);
		}
	}
}