Refactor WIP
This commit is contained in:
parent
bbc1a88571
commit
11568f7fb2
2 changed files with 16 additions and 25 deletions
|
@ -12,7 +12,7 @@ public class Door : Interactable
|
||||||
|
|
||||||
public Door(Vector2 position) : base(position)
|
public Door(Vector2 position) : base(position)
|
||||||
{
|
{
|
||||||
graphicsComponent.actionOfAnimationEnd += _ => { isOpened = !isOpened; };
|
graphicsComponent.OnAnimationEnd += _ => { isOpened = !isOpened; };
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnInteraction()
|
public override void OnInteraction()
|
||||||
|
|
|
@ -16,17 +16,16 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
public class GraphicsComponent
|
public class GraphicsComponent
|
||||||
{
|
{
|
||||||
public Rectangle ObjectDrawRectangle;
|
public Rectangle ObjectDrawRectangle;
|
||||||
|
public event Action<string> OnAnimationEnd;
|
||||||
|
|
||||||
|
|
||||||
public event Action<string> actionOfAnimationEnd;
|
|
||||||
private List<AnimationContainer> animations;
|
private List<AnimationContainer> animations;
|
||||||
private List<Texture2D> textures;
|
private List<Texture2D> textures;
|
||||||
public List<string> texturesNames; //rethink public and following that errors
|
public List<string> texturesNames; //rethink public and following that errors
|
||||||
private AnimationContainer currentAnimation;
|
private AnimationContainer currentAnimation;
|
||||||
static public int scaling = 1;
|
static public int scaling = 1;
|
||||||
public int parentId;
|
private bool reverse;
|
||||||
public bool reverse;
|
|
||||||
|
//TODO: remove
|
||||||
|
/*
|
||||||
public AnimationContainer CurrentAnimation
|
public AnimationContainer CurrentAnimation
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -39,28 +38,20 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
{
|
{
|
||||||
get { return currentAnimation.Id; }
|
get { return currentAnimation.Id; }
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
private AnimationContainer neitralAnimation;
|
private AnimationContainer idleAnimation;
|
||||||
//private SpriteBatch _spriteBatch;
|
|
||||||
|
|
||||||
private int currentFrame;
|
private int currentFrame;
|
||||||
public int CurrentFrame
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return currentFrame;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private int interval;
|
private int interval;
|
||||||
private int lastInterval;
|
private int lastInterval;
|
||||||
private Rectangle sourceRectangle;
|
private Rectangle sourceRectangle;
|
||||||
public GraphicsComponent(List<string> animationsId, string neitralAnimationId)
|
public GraphicsComponent(List<string> animationsId, string neitralAnimationId)
|
||||||
{
|
{
|
||||||
//this._spriteBatch = _spriteBatch;
|
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
lastInterval = 1;
|
lastInterval = 1;
|
||||||
LoadAnimations(animationsId, neitralAnimationId);
|
LoadAnimations(animationsId, neitralAnimationId);
|
||||||
currentAnimation = neitralAnimation;
|
currentAnimation = idleAnimation;
|
||||||
SetInterval();
|
SetInterval();
|
||||||
buildSourceRectangle();
|
buildSourceRectangle();
|
||||||
}
|
}
|
||||||
|
@ -90,7 +81,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
animationContainer.FrameTime = new List<Tuple<int, int>>() { new Tuple<int, int>(0, 10) };
|
animationContainer.FrameTime = new List<Tuple<int, int>>() { new Tuple<int, int>(0, 10) };
|
||||||
animationContainer.Id = texture.Name;
|
animationContainer.Id = texture.Name;
|
||||||
currentAnimation = animationContainer;
|
currentAnimation = animationContainer;
|
||||||
neitralAnimation = animationContainer;
|
idleAnimation = animationContainer;
|
||||||
animations.Add(animationContainer);
|
animations.Add(animationContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +93,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
animations.Add(AppManager.Instance.animationBuilder.Animations.Find(x => x.Id == id));
|
animations.Add(AppManager.Instance.animationBuilder.Animations.Find(x => x.Id == id));
|
||||||
if (id == neitralAnimationId)
|
if (id == neitralAnimationId)
|
||||||
{
|
{
|
||||||
neitralAnimation = animations.Last();
|
idleAnimation = animations.Last();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +146,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
{
|
{
|
||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
interval = 0;
|
interval = 0;
|
||||||
currentAnimation = neitralAnimation;
|
currentAnimation = idleAnimation;
|
||||||
buildSourceRectangle();
|
buildSourceRectangle();
|
||||||
SetInterval();
|
SetInterval();
|
||||||
}
|
}
|
||||||
|
@ -164,11 +155,11 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
{
|
{
|
||||||
if (!currentAnimation.IsCycle)
|
if (!currentAnimation.IsCycle)
|
||||||
{
|
{
|
||||||
if (actionOfAnimationEnd != null)
|
if (OnAnimationEnd != null)
|
||||||
{
|
{
|
||||||
actionOfAnimationEnd(currentAnimation.Id);
|
OnAnimationEnd(currentAnimation.Id);
|
||||||
}
|
}
|
||||||
currentAnimation = neitralAnimation;
|
currentAnimation = idleAnimation;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +262,7 @@ namespace ZoFo.GameCore.ZoFo_graphics
|
||||||
sourceRectangle = new Rectangle();
|
sourceRectangle = new Rectangle();
|
||||||
if (currentAnimation == null)
|
if (currentAnimation == null)
|
||||||
{
|
{
|
||||||
currentAnimation = neitralAnimation;
|
currentAnimation = idleAnimation;
|
||||||
}
|
}
|
||||||
sourceRectangle.X = currentAnimation.StartSpriteRectangle.X + currentFrame *
|
sourceRectangle.X = currentAnimation.StartSpriteRectangle.X + currentFrame *
|
||||||
(currentAnimation.StartSpriteRectangle.Width + currentAnimation.TextureFrameInterval);
|
(currentAnimation.StartSpriteRectangle.Width + currentAnimation.TextureFrameInterval);
|
||||||
|
|
Loading…
Add table
Reference in a new issue