Skip to content

Commit fc18426

Browse files
committed
making animations working on client side
1 parent 640e1a9 commit fc18426

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

Intersect.Client.Core/Entities/Resource.cs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Intersect.Client.General;
88
using Intersect.Core;
99
using Intersect.Enums;
10+
using Intersect.Framework.Core.GameObjects.Animations;
1011
using Intersect.Framework.Core.GameObjects.Resources;
1112
using Intersect.Network.Packets.Server;
1213
using 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

Comments
 (0)