public DMIResource(string resourcePath, byte[] data) : base(resourcePath, data) { if (!IsValidPNG()) { throw new Exception("Attempted to create a DMI using an invalid PNG"); } Stream dmiStream = new MemoryStream(data); DMIParser.ParsedDMIDescription description = DMIParser.ParseDMI(dmiStream); dmiStream.Seek(0, SeekOrigin.Begin); Image <Rgba32> image = Image.Load <Rgba32>(dmiStream); Texture = IoCManager.Resolve <IClyde>().LoadTextureFromImage(image); IconSize = new Vector2i(description.Width, description.Height); Description = description; IClickMapManager clickMapManager = IoCManager.Resolve <IClickMapManager>(); _states = new Dictionary <string, State>(); foreach (DMIParser.ParsedDMIState parsedState in description.States.Values) { State state = new State(Texture, parsedState, description.Width, description.Height); _states.Add(parsedState.Name, state); clickMapManager.CreateClickMap(state, image); } }
private DMIParser.ParsedDMIDescription ParseDMI() { string dmiDescription = ReadDMIDescription(); try { return(DMIParser.ParseDMIDescription(dmiDescription, ImageBitmap.Width)); } catch (Exception e) { Console.WriteLine("Error while parsing dmi '" + ResourcePath + "': " + e.Message); } return(null); }
public DreamIconObject(DreamResource rsc, DreamValue state, DreamValue dir, DreamValue frame, DreamValue moving) { if (Path.GetExtension(rsc.ResourcePath) != ".dmi") { throw new Exception("Invalid icon file"); } Description = DMIParser.ParseDMI(new MemoryStream(rsc.ResourceData)); Icon = rsc.ResourcePath; // TODO confirm BYOND behavior of invalid args for icon, dir, and frame state.TryGetValueAsString(out State); if (dir.TryGetValueAsInteger(out var dirVal) && (AtomDirection)dirVal != AtomDirection.None) { Direction = (AtomDirection)dirVal; }