77using Intersect . Client . General ;
88using Intersect . Core ;
99using Intersect . Enums ;
10+ using Intersect . Framework . Core . GameObjects . Animations ;
1011using Intersect . Framework . Core . GameObjects . Resources ;
1112using Intersect . Network . Packets . Server ;
1213using Microsoft . Extensions . Logging ;
@@ -25,6 +26,7 @@ public partial class Resource : Entity, IResource
2526 private ResourceStateDescriptor ? _currentState ;
2627 private ResourceDescriptor ? _descriptor ;
2728 private IAnimation ? _activeAnimation ;
29+ private IAnimation ? _stateAnimation ;
2830
2931 private readonly int _tileWidth = Options . Instance . Map . TileWidth ;
3032 private readonly int _tileHeight = Options . Instance . Map . TileHeight ;
@@ -87,20 +89,49 @@ private void ReloadSpriteTexture()
8789 return ;
8890 }
8991
90- if ( _currentState ? . TextureType == ResourceTextureSource . Tileset )
92+ switch ( _currentState ? . TextureType )
9193 {
92- if ( GameContentManager . Current . TilesetsLoaded )
93- {
94- Texture = GameContentManager . Current . GetTexture ( TextureType . Tileset , _sprite ) ;
95- }
96- else
97- {
98- _waitingForTilesets = true ;
99- }
100- }
101- else
102- {
103- Texture = GameContentManager . Current . GetTexture ( TextureType . Resource , _sprite ) ;
94+ case ResourceTextureSource . Tileset :
95+ if ( GameContentManager . Current . TilesetsLoaded )
96+ {
97+ Texture = GameContentManager . Current . GetTexture ( TextureType . Tileset , _sprite ) ;
98+ }
99+ else
100+ {
101+ _waitingForTilesets = true ;
102+ }
103+ break ;
104+
105+ case ResourceTextureSource . Resource :
106+ Texture = GameContentManager . Current . GetTexture ( TextureType . Resource , _sprite ) ;
107+ break ;
108+
109+ case ResourceTextureSource . Animation :
110+ if ( _stateAnimation ? . Descriptor ? . Id == _currentState . AnimationId )
111+ {
112+ return ;
113+ }
114+
115+ _stateAnimation ? . Dispose ( ) ;
116+ _stateAnimation = null ;
117+
118+ if ( MapInstance is not { } mapInstance )
119+ {
120+ return ;
121+ }
122+
123+ if ( ! AnimationDescriptor . TryGet ( _currentState . AnimationId , out var animationDescriptor ) )
124+ {
125+ return ;
126+ }
127+
128+ var animation = mapInstance . AddTileAnimation ( animationDescriptor , X , Y , Direction . Up ) ;
129+ if ( animation is { IsDisposed : false } )
130+ {
131+ animation . InfiniteLoop = true ;
132+ }
133+ _stateAnimation = animation ;
134+ break ;
104135 }
105136
106137 if ( Texture == default )
0 commit comments