Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
            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;
                }