64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
|
|
namespace SheetPlayer {
|
|
public class animationObject : ICloneable {
|
|
//srcData
|
|
private string srcPath;
|
|
private long lastModificTime = 0;
|
|
public string metaData = "48f1";
|
|
public Point position;
|
|
public int size = 1;
|
|
|
|
//precalculatedData
|
|
public Bitmap spriteSheet;
|
|
private List<Rectangle> animationFrames = new List<Rectangle>();
|
|
|
|
public Rectangle currentFrame {
|
|
get {
|
|
return animationFrames[mainForm.globalFrameCounter % animationFrames.Count];
|
|
}
|
|
}
|
|
|
|
public animationObject(string draggedImage, Point dropPosition) {
|
|
srcPath = draggedImage;
|
|
checkForModification();
|
|
updateMetaData();
|
|
position = dropPosition;
|
|
}
|
|
|
|
public object Clone() {
|
|
return this.MemberwiseClone();
|
|
}
|
|
|
|
public void checkForModification() {
|
|
try {
|
|
long currentModificTime = File.GetLastWriteTime(srcPath).Ticks;
|
|
if (lastModificTime != currentModificTime) {
|
|
var binary = File.ReadAllBytes(srcPath);
|
|
var memoryStream = new MemoryStream(binary);
|
|
spriteSheet = (Bitmap)Image.FromStream(memoryStream);
|
|
lastModificTime = currentModificTime;
|
|
}
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
public void updateMetaData() {
|
|
animationFrames.Add(new Rectangle(0, 0, 48, 48));
|
|
animationFrames.Add(new Rectangle(48, 0, 48, 48));
|
|
animationFrames.Add(new Rectangle(96, 0, 48, 48));
|
|
animationFrames.Add(new Rectangle(96, 0, 48, 48));
|
|
animationFrames.Add(new Rectangle(144, 0, 48, 48));
|
|
foreach (char c in metaData.ToCharArray(0, metaData.Length)) {
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|