public void GetFrameIndexTest() { IconState target = new IconState(); // TODO: Initialize to an appropriate value target.NumDirections = 4; // Directionality. Assert.AreEqual<uint>(0, target.GetFrameIndex(0, Direction.SOUTH, NoLengthChecks: true), "SOUTH:0 does not produce frame 0."); Assert.AreEqual<uint>(1, target.GetFrameIndex(0, Direction.NORTH, NoLengthChecks: true), "NORTH:0 does not produce frame 1."); Assert.AreEqual<uint>(2, target.GetFrameIndex(0, Direction.EAST, NoLengthChecks: true), "EAST:0 does not produce frame 2."); Assert.AreEqual<uint>(3, target.GetFrameIndex(0, Direction.WEST, NoLengthChecks: true), "WEST:0 does not produce frame 3."); }
void loadFramesForState(ref int x, ref int y, ref int total, ref IconState currentState) { // Init array size. currentState.Initialize(); // Grab the icons we need, operating like a typewriter. // Loop X times, incrementing i from 0 to <X, where X = GetTotalNumIcons() for (int i = 0; i < currentState.GetTotalNumIcons(); i++) { // Make a new frame. IconFrame frame = new IconFrame(); // Icon # frame.frame = i; // Store our position and rectangle. frame.rect = new Rectangle(x * iconWidth, y * iconHeight, iconWidth, iconHeight); log.DebugFormat(" Frame {0}: {1}, {2}", i, x, y); // Store frame in the state. currentState.Frames[i] = frame; // Move over 1 icon X position. x++; // Bump total # of frames loaded. total++; // If we're over the number of columns, go to the next line. if (x >= columns) { x = 0; y++; log.DebugFormat("NEXT LINE: x={0}, y={1}", x, y); } } // Debug spam. log.DebugFormat("Loaded {0} icons for state {1}.", currentState.Frames.Length, currentState.Name); // Store state. states[currentState.GetCollKey()] = currentState; }
public IconState GetIconState(string icon_state, bool movement = false) { return(states[IconState.CollectionKey(icon_state, movement)]); }
public void Load(string icon) { FileName = Path.GetFullPath(icon); string ztxt = GetHeader(icon); //////////////////////////// // Current state of things. IconState currentState = null; // IconState being operated on // Current X/Y position (ICON, not pixel) int x = 0; int y = 0; // Total icons made int total = 0; // Any unknown keys we run into. List <string> UnknownKeys = new List <string>(); // Breaking up into lines. string[] lines = ztxt.Split('\n'); // Loop over each line foreach (string line in lines) { // Skip comments and empty lines. if (String.IsNullOrWhiteSpace(line)) { continue; } if (line.StartsWith("#")) { continue; } // Break each key = value into chunks of (key,value) String[] chunks = line.Split('='); // Trim. chunks = chunks.Select(chunk => { return(chunk.Trim()); }).ToArray(); // Separate into key and val. string key = chunks[0]; string val = chunks[1]; // Spam debug log. log.DebugFormat("{0} = {1}", key, val); switch (key) { case "width": iconWidth = int.Parse(val); columns = (int)Math.Ceiling((double)width / (double)iconWidth); log.DebugFormat("Columns: {0}/{1} = {2}", width, iconWidth, columns); break; case "height": iconHeight = int.Parse(val); rows = height / iconHeight; log.DebugFormat("Rows: {0}/{1} = {2}", height, iconHeight, rows); break; case "state": // Already have a state? Let's wrap it up and store it. if (currentState != null) { loadFramesForState(ref x, ref y, ref total, ref currentState); } // New state. currentState = new IconState(); currentState.Name = val.Substring(1, val.Length - 2); break; case "dirs": currentState.NumDirections = uint.Parse(val); break; case "movement": currentState.Movement = (int.Parse(val) == 1); break; case "frames": currentState.NumFrames = uint.Parse(val); break; default: if (!UnknownKeys.Contains(key)) { UnknownKeys.Add(key); } break; } } if (currentState != null) { loadFramesForState(ref x, ref y, ref total, ref currentState); } if (UnknownKeys.Count > 0) { log.WarnFormat("DMI ERROR: Unhandled keys: {0}", string.Join(", ", UnknownKeys)); } log.DebugFormat("Sprites per row: {0}, Rows of sprites: {1}, Total frames: {2}", columns, rows, total); }
internal string GetCollKey() { return(IconState.CollectionKey(Name, Movement)); }
public void Load(string icon) { FileName = Path.GetFullPath(icon); string ztxt = GetHeader(icon); //////////////////////////// // Current state of things. IconState currentState = null; // IconState being operated on // Current X/Y position (ICON, not pixel) int x = 0; int y = 0; // Total icons made int total = 0; // Any unknown keys we run into. List<string> UnknownKeys = new List<string>(); // Breaking up into lines. string[] lines = ztxt.Split('\n'); // Loop over each line foreach (string line in lines) { // Skip comments and empty lines. if (String.IsNullOrWhiteSpace(line)) continue; if (line.StartsWith("#")) continue; // Break each key = value into chunks of (key,value) String[] chunks = line.Split('='); // Trim. chunks = chunks.Select(chunk => { return chunk.Trim(); }).ToArray(); // Separate into key and val. string key = chunks[0]; string val = chunks[1]; // Spam debug log. log.DebugFormat("{0} = {1}", key, val); switch (key) { case "width": iconWidth = int.Parse(val); columns = (int)Math.Ceiling((double)width / (double)iconWidth); log.DebugFormat("Columns: {0}/{1} = {2}", width, iconWidth, columns); break; case "height": iconHeight = int.Parse(val); rows = height / iconHeight; log.DebugFormat("Rows: {0}/{1} = {2}", height, iconHeight, rows); break; case "state": // Already have a state? Let's wrap it up and store it. if (currentState != null) { loadFramesForState(ref x, ref y, ref total, ref currentState); } // New state. currentState = new IconState(); currentState.Name = val.Substring(1, val.Length - 2); break; case "dirs": currentState.NumDirections = uint.Parse(val); break; case "movement": currentState.Movement = (int.Parse(val) == 1); break; case "frames": currentState.NumFrames = uint.Parse(val); break; default: if (!UnknownKeys.Contains(key)) UnknownKeys.Add(key); break; } } if (currentState != null) { loadFramesForState(ref x, ref y, ref total, ref currentState); } if (UnknownKeys.Count > 0) { log.WarnFormat("DMI ERROR: Unhandled keys: {0}", string.Join(", ", UnknownKeys)); } log.DebugFormat("Sprites per row: {0}, Rows of sprites: {1}, Total frames: {2}", columns, rows, total); }