1
-
2
1
using System ;
3
2
using System . Collections . Generic ;
4
3
using System . Threading ;
@@ -21,18 +20,11 @@ public struct ActiveAnimation {
21
20
public C7Animation anim ;
22
21
}
23
22
24
- public Dictionary < string , ActiveAnimation > activeAnims = new Dictionary < string , ActiveAnimation > ( ) ;
23
+ private Dictionary < ID , ActiveAnimation > activeAnims = new Dictionary < ID , ActiveAnimation > ( ) ;
25
24
26
25
public long getCurrentTimeMS ( ) => DateTime . Now . Ticks / TimeSpan . TicksPerMillisecond ;
27
26
28
- private string getTileID ( Tile tile )
29
- {
30
- // Generate a string to ID this tile that won't conflict with the unit GUIDs. TODO: Eventually we'll implement a common way of ID'ing
31
- // all game objects. Use that here instead.
32
- return String . Format ( "Tile.{0}.{1}" , tile . xCoordinate , tile . yCoordinate ) ;
33
- }
34
-
35
- private void startAnimation ( string id , C7Animation anim , AutoResetEvent completionEvent , AnimationEnding ending )
27
+ private void startAnimation ( ID id , C7Animation anim , AutoResetEvent completionEvent , AnimationEnding ending )
36
28
{
37
29
long currentTimeMS = getCurrentTimeMS ( ) ;
38
30
long animDurationMS = ( long ) ( 1000.0 * anim . getDuration ( ) ) ;
@@ -55,30 +47,30 @@ private void startAnimation(string id, C7Animation anim, AutoResetEvent completi
55
47
56
48
public void startAnimation ( MapUnit unit , MapUnit . AnimatedAction action , AutoResetEvent completionEvent , AnimationEnding ending )
57
49
{
58
- startAnimation ( unit . guid , civ3AnimData . forUnit ( unit . unitType , action ) , completionEvent , ending ) ;
50
+ startAnimation ( unit . id , civ3AnimData . forUnit ( unit . unitType , action ) , completionEvent , ending ) ;
59
51
}
60
52
61
53
public void startAnimation ( Tile tile , AnimatedEffect effect , AutoResetEvent completionEvent , AnimationEnding ending )
62
54
{
63
- startAnimation ( getTileID ( tile ) , civ3AnimData . forEffect ( effect ) , completionEvent , ending ) ;
55
+ startAnimation ( tile . id , civ3AnimData . forEffect ( effect ) , completionEvent , ending ) ;
64
56
}
65
57
66
58
public void endAnimation ( MapUnit unit )
67
59
{
68
60
ActiveAnimation aa ;
69
- if ( activeAnims . TryGetValue ( unit . guid , out aa ) ) {
61
+ if ( activeAnims . TryGetValue ( unit . id , out aa ) ) {
70
62
if ( aa . completionEvent != null )
71
63
aa . completionEvent . Set ( ) ;
72
- activeAnims . Remove ( unit . guid ) ;
64
+ activeAnims . Remove ( unit . id ) ;
73
65
}
74
66
}
75
67
76
68
public bool hasCurrentAction ( MapUnit unit )
77
69
{
78
- return activeAnims . ContainsKey ( unit . guid ) ;
70
+ return activeAnims . ContainsKey ( unit . id ) ;
79
71
}
80
72
81
- public ( MapUnit . AnimatedAction , float ) getCurrentActionAndProgress ( string id )
73
+ public ( MapUnit . AnimatedAction , float ) getCurrentActionAndProgress ( ID id )
82
74
{
83
75
ActiveAnimation aa = activeAnims [ id ] ;
84
76
@@ -97,18 +89,18 @@ public bool hasCurrentAction(MapUnit unit)
97
89
98
90
public ( MapUnit . AnimatedAction , float ) getCurrentActionAndProgress ( MapUnit unit )
99
91
{
100
- return getCurrentActionAndProgress ( unit . guid ) ;
92
+ return getCurrentActionAndProgress ( unit . id ) ;
101
93
}
102
94
103
95
public ( MapUnit . AnimatedAction , float ) getCurrentActionAndProgress ( Tile tile )
104
96
{
105
- return getCurrentActionAndProgress ( getTileID ( tile ) ) ;
97
+ return getCurrentActionAndProgress ( tile . id ) ;
106
98
}
107
99
108
100
public void update ( )
109
101
{
110
- long currentTimeMS = ! endAllImmediately ? getCurrentTimeMS ( ) : long . MaxValue ;
111
- var keysToRemove = new List < string > ( ) ;
102
+ long currentTimeMS = ( ! endAllImmediately ) ? getCurrentTimeMS ( ) : long . MaxValue ;
103
+ List < ID > keysToRemove = new List < ID > ( ) ;
112
104
foreach ( var guidAAPair in activeAnims . Where ( guidAAPair => guidAAPair . Value . endTimeMS <= currentTimeMS ) ) {
113
105
var ( id , aa ) = ( guidAAPair . Key , guidAAPair . Value ) ;
114
106
if ( aa . completionEvent is not null ) {
@@ -155,6 +147,6 @@ public MapUnit.Appearance getUnitAppearance(MapUnit unit)
155
147
public C7Animation getTileEffect ( Tile tile )
156
148
{
157
149
ActiveAnimation aa ;
158
- return activeAnims . TryGetValue ( getTileID ( tile ) , out aa ) ? aa . anim : null ;
150
+ return activeAnims . TryGetValue ( tile . id , out aa ) ? aa . anim : null ;
159
151
}
160
152
}
0 commit comments