static void sprite_anim(string name, string texture_root, int start_frame, int end_frame, int frame_length, bool reverse_at_end) { AnimationData_Texture sprite_anim = null; sprite_anim = new AnimationData_Texture(texture_root, start_frame, end_frame); // Set speed based on how long each frame is. sprite_anim.Anims[0].Speed = 1f / frame_length; // Add new sprite animation to the texture wad. Tools.TextureWad.Add(sprite_anim, name); }
/// <summary> /// Read tileset info from a file. /// </summary> public void Read(String path) { MyPath = path; _Start(); // Find path Tools.UseInvariantCulture(); FileStream stream = null; string original_path = path; try { stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None); } catch { try { path = Path.Combine(Globals.ContentDirectory, original_path); stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None); } catch { try { path = Path.Combine(Globals.ContentDirectory, Path.Combine("DynamicLoad", original_path)); stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.None); } catch { Tools.Log(string.Format("Attempting to load a .tileset file. Path <{0}> not found.")); } } } StreamReader reader = new StreamReader(stream); String line; line = reader.ReadLine(); while (line != null) { var bits = Tools.GetBitsFromLine(line); if (bits.Count > 1) { var first = bits[0]; // Is it a pillar? if (first.Contains("Pillar_")) { ParseBlock(bits, first, Pillars); } // Is it a platform? else if (first.Contains("Platform_")) { ParseBlock(bits, first, Platforms); } // Is it a ceiling? else if (first.Contains("Ceiling_")) { HasCeiling = true; var pq = ParseBlock(bits, first, Ceilings); pq.Data.BottomFlush = true; } // Is it a start piece? if (first.Contains("Start_")) { ParseBlock(bits, first, StartBlock); } // Is it an end piece? if (first.Contains("End_")) { ParseBlock(bits, first, EndBlock); } // Is it a moving block? else if (first.Contains("MovingBlock_")) { ParseBlock(bits, first, MyTileSetInfo.MovingBlocks.Group); } // Is it an elevator block? else if (first.Contains("Elevator_")) { ParseBlock(bits, first, MyTileSetInfo.Elevators.Group); } // Is it a pendulum block? else if (first.Contains("Pendulum_")) { ParseBlock(bits, first, MyTileSetInfo.Pendulums.Group); } // Is it a falling block? else if (first.Contains("FallingBlock_")) { ParseBlock(bits, first, MyTileSetInfo.FallingBlocks.Group); } // Is it a bouncy block? else if (first.Contains("BouncyBlock_")) { ParseBlock(bits, first, MyTileSetInfo.BouncyBlocks.Group); } else { switch (first) { case "sprite_anim": var dict = Tools.GetLocations(bits, "name", "file", "size", "frames", "frame_length", "reverse_at_end"); var name = bits[dict["name"] + 1]; var file = bits[dict["file"] + 1]; AnimationData_Texture sprite_anim = null; if (dict.ContainsKey("frames")) { int start_frame = int.Parse(bits[dict["frames"] + 1]); int end_frame; if (bits[dict["frames"] + 2][0] == 't') { end_frame = int.Parse(bits[dict["frames"] + 3]); } else { end_frame = int.Parse(bits[dict["frames"] + 2]); } sprite_anim = new AnimationData_Texture(file, start_frame, end_frame); } if (dict.ContainsKey("frame_length")) { var frame_length = int.Parse(bits[dict["frame_length"] + 1]); sprite_anim.Anims[0].Speed = 1f / frame_length; } Tools.TextureWad.Add(sprite_anim, name); break; case "BackgroundFile": BackgroundTemplate template; try { template = BackgroundType.NameLookup[bits[1]]; } catch { template = new BackgroundTemplate(); template.Name = bits[1]; } MyBackgroundType = template; break; case "Name": Name = bits[1]; break; default: Tools.ReadLineToObj(MyTileSetInfo, bits); break; } } } line = reader.ReadLine(); } reader.Close(); stream.Close(); _Finish(); }