public EditorAnimation.EditorFrame GetFrameFromAttribute(EditorAnimation anim, AttributeValue attribute, string key = "frameID") { int frameID = -1; switch (attribute.Type) { case AttributeTypes.UINT8: frameID = entity.attributesMap[key].ValueUInt8; break; case AttributeTypes.INT8: frameID = entity.attributesMap[key].ValueInt8; break; case AttributeTypes.VAR: frameID = (int)entity.attributesMap[key].ValueVar; break; } if (frameID >= anim.Frames.Count) { frameID = (anim.Frames.Count - 1) - (frameID % anim.Frames.Count + 1); } if (frameID < 0) { frameID = 0; } if (frameID >= 0 && frameID < int.MaxValue) { return(anim.Frames[frameID % anim.Frames.Count]); } else { return(null); // Don't Render the Animation } }
public static void LoadNextAnimation(DevicePanel d, string name, bool FallBack = false) { if (AnimationCache.ContainsKey(name)) { return; } else { var Animation = new EditorAnimation(); var AssetInfo = GetAnimationPath(name, FallBack); Animation.SourcePath = AssetInfo.Item1; Animation.SourceDirectory = AssetInfo.Item2; if (AssetInfo.Item1 != string.Empty && AssetInfo.Item1 != null && File.Exists(AssetInfo.Item1)) { Animation RSDKAnim; using (var stream = File.OpenRead(AssetInfo.Item1)) { RSDKAnim = new Animation(new RSDKv5.Reader(stream)); } Animation.Animation = RSDKAnim; Animation.Spritesheets = GetAnimationSpriteSheetTextures(d, name, RSDKAnim, Animation.SourcePath, Animation.SourceDirectory, true); } else { Animation.Animation = null; Animation.Spritesheets = null; } AnimationCache.Add(name, Animation); } }
public static void RSDKv1_Load_AnimHeader(EditorAnimation BridgeHost, RSDKv1.Animation animsetv1) { for (int i = 0; i < animsetv1.SpriteSheets.Length; i++) { BridgeHost.SpriteSheets.Add(animsetv1.SpriteSheets[i]); } BridgeHost.CollisionBoxes = GetV3HitboxList(); }
public static void RSDKv1_Save_AnimHeader(EditorAnimation BridgeHost, RSDKv1.Animation animsetv1) { for (int i = 0; i < BridgeHost.SpriteSheets.Count; i++) { if (i >= 3) { break; } animsetv1.SpriteSheets[i] = BridgeHost.SpriteSheets[i]; } }
public static void RSDKvRS_Load_AnimHeader(EditorAnimation BridgeHost, RSDKvRS.Animation animsetvRS) { BridgeHost.PlayerType = animsetvRS.PlayerType; BridgeHost.Unknown = animsetvRS.Unknown; for (int i = 0; i < animsetvRS.SpriteSheets.Length; i++) { BridgeHost.SpriteSheets.Add(animsetvRS.SpriteSheets[i]); } BridgeHost.CollisionBoxes.Add("Hitbox"); }
public static void RSDKv5_Load_Animation(EditorAnimation BridgeHost, string filepath) { RSDKv5.Animation animsetv5 = new RSDKv5.Animation(new RSDKv5.Reader(filepath)); RSDKv5_Load_AnimHeader(BridgeHost, animsetv5); for (int a = 0; a < animsetv5.Animations.Count; a++) { var animset = new EditorAnimation.EditorAnimationInfo(EngineType.RSDKv5, BridgeHost); animset.LoadFrom(EngineType.RSDKv5, animsetv5.Animations[a]); BridgeHost.Animations.Add(animset); } }
public static void RSDKv5_Save_Animation(EditorAnimation BridgeHost, string filepath) { RSDKv5.Animation animsetv5 = new RSDKv5.Animation(); RSDKv5_Save_AnimHeader(BridgeHost, animsetv5); for (int a = 0; a < BridgeHost.Animations.Count; a++) { RSDKv5.Animation.AnimationEntry animv5 = new RSDKv5.Animation.AnimationEntry(); BridgeHost.Animations[a].SaveTo(EngineType.RSDKv5, animv5); animsetv5.Animations.Add(animv5); } animsetv5.Write(new RSDKv5.Writer(filepath)); }
public static void RSDKvRS_Save_AnimHeader(EditorAnimation BridgeHost, RSDKvRS.Animation animsetvRS) { animsetvRS.PlayerType = BridgeHost.PlayerType; animsetvRS.Unknown = BridgeHost.Unknown; for (int i = 0; i < BridgeHost.SpriteSheets.Count; i++) { if (i >= 3) { break; } animsetvRS.SpriteSheets[i] = BridgeHost.SpriteSheets[i]; } }
public static void RSDKv1_Save_Animation(EditorAnimation BridgeHost, string filepath) { RSDKv1.Animation animsetv1 = new RSDKv1.Animation(); RSDKv1_Save_AnimHeader(BridgeHost, animsetv1); for (int a = 0; a < BridgeHost.Animations.Count; a++) { RSDKv1.Animation.AnimationEntry animv1 = new RSDKv1.Animation.AnimationEntry(); BridgeHost.Animations[a].SaveTo(EngineType.RSDKv1, animv1); animsetv1.Animations.Add(animv1); } RSDKv1_Save_CollisionBoxes(BridgeHost, animsetv1); animsetv1.Write(new RSDKv1.Writer(filepath)); }
public static void RSDKv1_Load_CollisionBoxes(EditorAnimation BridgeHost, RSDKv1.Animation animsetv1) { var collisionBoxes = new List <EditorAnimation.EditorRetroHitBox>(); for (int i = 0; i < animsetv1.CollisionBoxes.Count; i++) { var hitboxEntry = new EditorAnimation.EditorRetroHitBox(); for (int j = 0; j < animsetv1.CollisionBoxes[i].Hitboxes.Length; j++) { hitboxEntry.Hitboxes[j].Bottom = animsetv1.CollisionBoxes[i].Hitboxes[j].Bottom; hitboxEntry.Hitboxes[j].Top = animsetv1.CollisionBoxes[i].Hitboxes[j].Top; hitboxEntry.Hitboxes[j].Left = animsetv1.CollisionBoxes[i].Hitboxes[j].Left; hitboxEntry.Hitboxes[j].Right = animsetv1.CollisionBoxes[i].Hitboxes[j].Right; } collisionBoxes.Add(hitboxEntry); } BridgeHost.RetroCollisionBoxes = collisionBoxes; }
public static void RSDKv1_Save_CollisionBoxes(EditorAnimation BridgeHost, RSDKv1.Animation animsetv1) { animsetv1.CollisionBoxes = new List <RSDKv1.Animation.sprHitbox>(8); for (int a = 0; a < BridgeHost.RetroCollisionBoxes.Count; a++) { animsetv1.CollisionBoxes.Insert(a, new RSDKv1.Animation.sprHitbox()); for (int f = 0; f < 8; f++) { if (animsetv1.CollisionBoxes[a].Hitboxes == null) { animsetv1.CollisionBoxes[a].Hitboxes = new RSDKv1.Animation.sprHitbox.HitboxInfo[8]; } animsetv1.CollisionBoxes[a].Hitboxes[f].Bottom = BridgeHost.RetroCollisionBoxes[a].Hitboxes[f].Bottom; animsetv1.CollisionBoxes[a].Hitboxes[f].Top = BridgeHost.RetroCollisionBoxes[a].Hitboxes[f].Top; animsetv1.CollisionBoxes[a].Hitboxes[f].Left = BridgeHost.RetroCollisionBoxes[a].Hitboxes[f].Left; animsetv1.CollisionBoxes[a].Hitboxes[f].Right = BridgeHost.RetroCollisionBoxes[a].Hitboxes[f].Right; } } }
public SpriteService(EditorAnimation animation, string basePath) { _animationData = animation; BasePath = basePath; }
public static void RSDKv2_Save_AnimHeader(EditorAnimation BridgeHost, RSDKv2.Animation animsetv2) { animsetv2.SpriteSheets = BridgeHost.SpriteSheets.ToList(); }
public static void RSDKv5_Save_AnimHeader(EditorAnimation BridgeHost, RSDKv5.Animation animsetv5) { animsetv5.SpriteSheets = BridgeHost.SpriteSheets.ToList(); animsetv5.CollisionBoxes = BridgeHost.CollisionBoxes; }
public void SetAnimation(EditorAnimation Anim) { LoadedAnimationFile = Anim; }
public static void RSDKv2_Load_AnimHeader(EditorAnimation BridgeHost, RSDKv2.Animation animsetv2) { BridgeHost.SpriteSheets = new System.Collections.ObjectModel.ObservableCollection <string>(animsetv2.SpriteSheets); BridgeHost.CollisionBoxes = GetV3HitboxList(); }
public static void RSDKv5_Load_AnimHeader(EditorAnimation BridgeHost, RSDKv5.Animation animsetv5) { BridgeHost.SpriteSheets = new System.Collections.ObjectModel.ObservableCollection <string>(animsetv5.SpriteSheets); BridgeHost.TotalFrameCount = animsetv5.TotalFrameCount; BridgeHost.CollisionBoxes = animsetv5.CollisionBoxes; }
public static void RSDKvRS_Load_CollisionBoxes(EditorAnimation BridgeHost, RSDKvRS.Animation animsetvRS) { }
/// <summary> /// Loads / Gets the Sprite Animation /// NOTE: /// </summary> /// <param name="name">The Name of the object</param> /// <param name="d">The DevicePanel</param> /// <param name="AnimId">The Animation ID (-1 to Load Normal)</param> /// <param name="frameId">The Frame ID for the specified Animation (-1 to load all frames)</param> /// <param name="fliph">Flip the Texture Horizontally</param> /// <param name="flipv">Flip the Texture Vertically</param> /// <returns>The fully loaded Animation</returns> public EditorAnimation LoadAnimation(string name, DevicePanel d, int AnimId, int frameId, bool fliph, bool flipv, bool rotate, bool loadImageToDX = true) { string key = $"{name}-{AnimId}-{frameId}-{fliph}-{flipv}-{rotate}"; var anim = new EditorAnimation(); if (Animations.ContainsKey(key)) { if (Animations[key].Ready) { // Use the already loaded Amination return(Animations[key]); } else { return(null); } } Animations.Add(key, anim); string path, path2; if (name == "EditorAssets" || name == "SuperSpecialRing" || name == "EditorIcons2" || name == "TransportTubes") { if (name == "EditorAssets") { path2 = Path.Combine(Environment.CurrentDirectory, "EditorAssets.bin"); if (!File.Exists(path2)) { return(null); } } else if (name == "EditorIcons2") { path2 = Path.Combine(Environment.CurrentDirectory, "EditorIcons2.bin"); if (!File.Exists(path2)) { return(null); } } else if (name == "TransportTubes") { path2 = Path.Combine(Environment.CurrentDirectory, "Global\\", "TransportTubes.bin"); if (!File.Exists(path2)) { return(null); } } else { path2 = Path.Combine(Environment.CurrentDirectory, "Global\\", "SuperSpecialRing.bin"); Debug.Print(path2); if (!File.Exists(path2)) { return(null); } } } else { if (DataDirectoryList == null) { DataDirectoryList = Directory.GetFiles(Path.Combine(Editor.DataDirectory, "Sprites"), $"*.bin", SearchOption.AllDirectories); } // Checks Global frist path = Editor.Instance.SelectedZone + "\\" + name + ".bin"; path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path; if (!File.Exists(path2)) { // Checks without last character path = path = Editor.Instance.SelectedZone.Substring(0, Editor.Instance.SelectedZone.Length - 1) + "\\" + name + ".bin"; path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path; } /*if (!File.Exists(path2)) * { * // Checks Editor Global * path2 = Environment.CurrentDirectory + "\\Global\\" + name + ".bin"; * }*/ if (!File.Exists(path2)) { // Checks Global path = "Global\\" + name + ".bin"; path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path; } if (!File.Exists(path2)) { // Checks the Stage folder foreach (string dir in Directory.GetDirectories(Path.Combine(Editor.DataDirectory, "Sprites"), $"*", SearchOption.TopDirectoryOnly)) { path = Path.GetFileName(dir) + "\\" + name + ".bin"; path2 = Path.Combine(Editor.DataDirectory, "sprites") + '\\' + path; if (File.Exists(path2)) { break; } } } if (!File.Exists(path2)) { // Seaches all around the Data directory var list = DataDirectoryList; if (list.Any(t => Path.GetFileName(t.ToLower()).Contains(name.ToLower()))) { list = list.Where(t => Path.GetFileName(t.ToLower()).Contains(name.ToLower())).ToArray(); if (list.Any(t => t.ToLower().Contains(Editor.Instance.SelectedZone))) { path2 = list.Where(t => t.ToLower().Contains(Editor.Instance.SelectedZone)).First(); } else { path2 = list.First(); } } } if (!File.Exists(path2)) { // No animation found return(null); } } using (var stream = File.OpenRead(path2)) { rsdkAnim = new Animation(); rsdkAnim.Load(new BinaryReader(stream)); } if (AnimId == -1) { if (rsdkAnim.Animations.Any(t => t.AnimName.Contains("Normal"))) { AnimId = rsdkAnim.Animations.FindIndex(t => t.AnimName.Contains("Normal")); } else { AnimId = 0; } // Use Vertical Amination if one exists if (rotate && rsdkAnim.Animations.Any(t => t.AnimName.EndsWith(" V"))) { AnimId = rsdkAnim.Animations.FindIndex(t => t.AnimName.EndsWith(" V")); } } if (AnimId >= rsdkAnim.Animations.Count) { AnimId = rsdkAnim.Animations.Count - 1; } for (int i = 0; i < rsdkAnim.Animations[AnimId].Frames.Count; ++i) { // check we don't stray outside our loaded animations/frames // if user enters a value that would take us there, just show // a valid frame instead var animiation = rsdkAnim.Animations[AnimId]; var frame = animiation.Frames[i]; if (frameId >= 0 && frameId < animiation.Frames.Count) { frame = animiation.Frames[frameId]; } Bitmap map; if (!Sheets.ContainsKey(rsdkAnim.SpriteSheets[frame.SpriteSheet])) { string targetFile; if (name == "EditorAssets" || name == "SuperSpecialRing" || name == "EditorIcons2" || name == "TransportTubes") { if (name == "EditorAssets") { targetFile = Path.Combine(Environment.CurrentDirectory, "EditorAssets.gif"); } else if (name == "EditorIcons2") { targetFile = Path.Combine(Environment.CurrentDirectory, "EditorIcons2.gif"); } else if (name == "TransportTubes") { targetFile = Path.Combine(Environment.CurrentDirectory, "Global\\", "TransportTubes.gif"); } else { targetFile = Path.Combine(Environment.CurrentDirectory, "Global\\", "SuperSpecialRing.gif"); } } else { targetFile = Path.Combine(Editor.DataDirectory, "sprites", rsdkAnim.SpriteSheets[frame.SpriteSheet].Replace('/', '\\')); } if (!File.Exists(targetFile)) { map = null; // add a Null to our lookup, so we can avoid looking again in the future Sheets.Add(rsdkAnim.SpriteSheets[frame.SpriteSheet], map); } else { map = new Bitmap(targetFile); Sheets.Add(rsdkAnim.SpriteSheets[frame.SpriteSheet], map); } } else { map = Sheets[rsdkAnim.SpriteSheets[frame.SpriteSheet]]; } if (frame.Width == 0 || frame.Height == 0) { continue; } // can't load the animation, it probably doesn't exist in the User's Sprites folder if (map == null) { return(null); } // We are storing the first colour from the palette so we can use it to make sprites transparent var colour = map.Palette.Entries[0]; // Slow map = CropImage(map, new Rectangle(frame.X, frame.Y, frame.Width, frame.Height), fliph, flipv); RemoveColourImage(map, colour, frame.Width, frame.Height); Texture texture = null; if (loadImageToDX) { texture = TextureCreator.FromBitmap(d._device, map); } var editorFrame = new EditorAnimation.EditorFrame() { Texture = texture, Frame = frame, Entry = rsdkAnim.Animations[AnimId] }; if (!loadImageToDX) { editorFrame._Bitmap = map; } anim.Frames.Add(editorFrame); if (frameId != -1) { break; } } anim.ImageLoaded = true; if (loadImageToDX) { anim.Ready = true; } Working = false; return(anim); }