1-
21using System ;
32using System . Collections . Generic ;
43using System . Threading ;
@@ -21,18 +20,11 @@ public struct ActiveAnimation {
2120 public C7Animation anim ;
2221 }
2322
24- public Dictionary < string , ActiveAnimation > activeAnims = new Dictionary < string , ActiveAnimation > ( ) ;
23+ private Dictionary < ID , ActiveAnimation > activeAnims = new Dictionary < ID , ActiveAnimation > ( ) ;
2524
2625 public long getCurrentTimeMS ( ) => DateTime . Now . Ticks / TimeSpan . TicksPerMillisecond ;
2726
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 )
3628 {
3729 long currentTimeMS = getCurrentTimeMS ( ) ;
3830 long animDurationMS = ( long ) ( 1000.0 * anim . getDuration ( ) ) ;
@@ -55,30 +47,30 @@ private void startAnimation(string id, C7Animation anim, AutoResetEvent completi
5547
5648 public void startAnimation ( MapUnit unit , MapUnit . AnimatedAction action , AutoResetEvent completionEvent , AnimationEnding ending )
5749 {
58- startAnimation ( unit . guid , civ3AnimData . forUnit ( unit . unitType , action ) , completionEvent , ending ) ;
50+ startAnimation ( unit . id , civ3AnimData . forUnit ( unit . unitType , action ) , completionEvent , ending ) ;
5951 }
6052
6153 public void startAnimation ( Tile tile , AnimatedEffect effect , AutoResetEvent completionEvent , AnimationEnding ending )
6254 {
63- startAnimation ( getTileID ( tile ) , civ3AnimData . forEffect ( effect ) , completionEvent , ending ) ;
55+ startAnimation ( tile . id , civ3AnimData . forEffect ( effect ) , completionEvent , ending ) ;
6456 }
6557
6658 public void endAnimation ( MapUnit unit )
6759 {
6860 ActiveAnimation aa ;
69- if ( activeAnims . TryGetValue ( unit . guid , out aa ) ) {
61+ if ( activeAnims . TryGetValue ( unit . id , out aa ) ) {
7062 if ( aa . completionEvent != null )
7163 aa . completionEvent . Set ( ) ;
72- activeAnims . Remove ( unit . guid ) ;
64+ activeAnims . Remove ( unit . id ) ;
7365 }
7466 }
7567
7668 public bool hasCurrentAction ( MapUnit unit )
7769 {
78- return activeAnims . ContainsKey ( unit . guid ) ;
70+ return activeAnims . ContainsKey ( unit . id ) ;
7971 }
8072
81- public ( MapUnit . AnimatedAction , float ) getCurrentActionAndProgress ( string id )
73+ public ( MapUnit . AnimatedAction , float ) getCurrentActionAndProgress ( ID id )
8274 {
8375 ActiveAnimation aa = activeAnims [ id ] ;
8476
@@ -97,18 +89,18 @@ public bool hasCurrentAction(MapUnit unit)
9789
9890 public ( MapUnit . AnimatedAction , float ) getCurrentActionAndProgress ( MapUnit unit )
9991 {
100- return getCurrentActionAndProgress ( unit . guid ) ;
92+ return getCurrentActionAndProgress ( unit . id ) ;
10193 }
10294
10395 public ( MapUnit . AnimatedAction , float ) getCurrentActionAndProgress ( Tile tile )
10496 {
105- return getCurrentActionAndProgress ( getTileID ( tile ) ) ;
97+ return getCurrentActionAndProgress ( tile . id ) ;
10698 }
10799
108100 public void update ( )
109101 {
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 > ( ) ;
112104 foreach ( var guidAAPair in activeAnims . Where ( guidAAPair => guidAAPair . Value . endTimeMS <= currentTimeMS ) ) {
113105 var ( id , aa ) = ( guidAAPair . Key , guidAAPair . Value ) ;
114106 if ( aa . completionEvent is not null ) {
@@ -155,6 +147,6 @@ public MapUnit.Appearance getUnitAppearance(MapUnit unit)
155147 public C7Animation getTileEffect ( Tile tile )
156148 {
157149 ActiveAnimation aa ;
158- return activeAnims . TryGetValue ( getTileID ( tile ) , out aa ) ? aa . anim : null ;
150+ return activeAnims . TryGetValue ( tile . id , out aa ) ? aa . anim : null ;
159151 }
160152}
0 commit comments