Skip to content

Commit fbd1b73

Browse files
committed
added animation part in client
1 parent 2a7e0c2 commit fbd1b73

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

Intersect.Client.Core/Entities/Resource.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ResourceDescriptor? Descriptor
4242
set => _descriptor = value;
4343
}
4444

45-
private ResourceStateDescriptor? CurrentGraphicState
45+
public ResourceStateDescriptor? CurrentGraphicState
4646
{
4747
get
4848
{
@@ -67,6 +67,11 @@ private ResourceStateDescriptor? CurrentGraphicState
6767
return default;
6868
}
6969

70+
if (currentState.Value.GraphicType == ResourceGraphicType.Animation)
71+
{
72+
return currentState.Value;
73+
}
74+
7075
if (currentState.Key != _currentStateKey)
7176
{
7277
_currentStateKey = currentState.Key;

Intersect.Client.Core/Maps/MapInstance.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
using Intersect.Utilities;
2828
using Microsoft.Extensions.Logging;
2929
using Newtonsoft.Json;
30+
using Intersect.Framework.Core.GameObjects.Resources;
3031

3132
namespace Intersect.Client.Maps;
3233

@@ -668,6 +669,59 @@ private void UpdateMapAttributes()
668669
mAttributeCritterInstances[mapAttribute].Update();
669670
break;
670671
}
672+
case MapAttributeType.Resource:
673+
{
674+
var resource = Globals.Entities.Values
675+
.Where(e =>
676+
e.Type == EntityType.Resource &&
677+
e.X == x && e.Y == y &&
678+
e.MapInstance?.Id == Id
679+
).FirstOrDefault() as Resource;
680+
681+
if (resource?.CurrentGraphicState is not { } graphicState)
682+
{
683+
continue;
684+
}
685+
686+
if (graphicState.GraphicType != ResourceGraphicType.Animation)
687+
{
688+
continue;
689+
}
690+
691+
if (!AnimationDescriptor.TryGet(graphicState.AnimationId, out var animation))
692+
{
693+
continue;
694+
}
695+
696+
if (!mAttributeAnimInstances.ContainsKey(mapAttribute))
697+
{
698+
var animInstance = new Animation(animation, true);
699+
animInstance.SetPosition(
700+
X + x * _tileWidth + _tileHalfWidth,
701+
Y + y * _tileHeight + _tileHalfHeight, x, y, Id, 0
702+
);
703+
704+
mAttributeAnimInstances.Add(mapAttribute, animInstance);
705+
}
706+
else
707+
{
708+
var currentResourceAnimation = mAttributeAnimInstances[mapAttribute];
709+
if (currentResourceAnimation.Descriptor?.Id != animation.Id)
710+
{
711+
currentResourceAnimation.Dispose();
712+
mAttributeAnimInstances.Remove(mapAttribute);
713+
var animInstance = new Animation(animation, true);
714+
animInstance.SetPosition(
715+
X + x * _tileWidth + _tileHalfWidth,
716+
Y + y * _tileHeight + _tileHalfHeight, x, y, Id, 0
717+
);
718+
mAttributeAnimInstances.Add(mapAttribute, animInstance);
719+
}
720+
}
721+
722+
mAttributeAnimInstances[mapAttribute].Update();
723+
}
724+
break;
671725
}
672726
}
673727
}

0 commit comments

Comments
 (0)