Exemplo n.º 1
0
 public static void SetFrame(DMIState state, Image <Rgba32> image, DirectionDepth depth, StateDirection direction, int frame)
 {
     if (depth == DirectionDepth.One)
     {
         state.SetFrame(image, frame);
     }
     else
     {
         state.SetFrame(image, direction, frame);
     }
 }
Exemplo n.º 2
0
        public static DmiEXState FromDmiState(DmiEX parent, DMIState dmiState)
        {
            RawDmiState raw = dmiState.ToRaw();

            DmiEXImage[,] images = new DmiEXImage[(int)raw.Dirs.Value, raw.Frames.Value];
            for (int dir = 0; dir < (int)raw.Dirs.Value; dir++)
            {
                for (int frame = 0; frame < raw.Frames.Value; frame++)
                {
                    images[dir, frame] = new DmiEXImage(dmiState.GetBitmap(dir, frame));
                }
            }

            return(new DmiEXState(parent, images, raw));
        }
Exemplo n.º 3
0
        public void CanCreateDMIFromImages()
        {
            using var newDMI = new DMIFile(32, 32);
            var sourceData = new List <string>()
            {
                "sord", "sordvert", "steve32"
            };

            foreach (var source in sourceData)
            {
                var img      = Image.Load <Rgba32>($@"Data/Input/SourceImages/{source}.png");
                var newState = new DMIState(source, DirectionDepth.One, 1, 32, 32);
                newState.SetFrame(img, 0);
                newDMI.AddState(newState);
            }

            newDMI.Save(@"Data/Output/minecraft.dmi");
        }
Exemplo n.º 4
0
        public void CanChangeDMIDepths()
        {
            using var newDMI = new DMIFile(32, 32);

            // Create state
            var img      = Image.Load <Rgba32>($@"Data/Input/SourceImages/steve32.png");
            var newState = new DMIState("steve32", DirectionDepth.One, 1, 32, 32);

            newState.SetFrame(img, 0);
            newDMI.AddState(newState);

            // Modifying state
            newDMI.States.First().SetDirectionDepth(DirectionDepth.Four);
            newDMI.States.First().SetFrameCount(10);

            // Check new states
            Assert.Equal(DirectionDepth.Four, newDMI.States.First().DirectionDepth);
            Assert.Equal(10, newDMI.States.First().Frames);

            // Cannot save
            Assert.False(newDMI.CanSave());
        }
Exemplo n.º 5
0
 public StateEditor GetStateEditor(DMIState state)
 {
     return((from StateEditorTabItem tabItem in stateTabControl.Items where tabItem.StateEditor.State == state select tabItem.StateEditor).FirstOrDefault());
 }
Exemplo n.º 6
0
        private static string ExtractDMI(string input, string outPath, string file)
        {
            var ser =
                new Serializer(new List <Type> {
                typeof(DmiImage), typeof(DMIState), typeof(DMIFrame), typeof(DMIImageData)
            });
            DmiImage dmi = null;

            dmi = new DmiImage(file);

/*            try
 *          {
 *              dmi = new DmiImage(file);
 *          }
 *          catch (Exception e)
 *          {
 *              _log.Error("Error during extraction", e);
 *              return null;
 *          }
 */
            var oPath = Path.Combine(outPath, Path.GetDirectoryName(file.Replace(input + "\\", "")), dmi.DmiName);

            if (!Directory.Exists(oPath))
            {
                Directory.CreateDirectory(oPath);
            }


            using (var stream = File.Create(Path.Combine(oPath, Datafile)))
            {
                ser.Serialize(stream, dmi);
            }


            var stateIndex = 0;

            for (int i = 0; i < dmi.States.Count(); i++)
            {
                DMIState dmiState  = dmi.States[i];
                var      statePath = Path.Combine(oPath, stateIndex.ToString());
                if (!Directory.Exists(statePath))
                {
                    Directory.CreateDirectory(statePath);
                }
                int frameIndex = 0;
                foreach (var frame in dmiState.GetFrames())
                {
                    var framePath = Path.Combine(statePath, frameIndex.ToString());
                    if (!Directory.Exists(framePath))
                    {
                        Directory.CreateDirectory(framePath);
                    }
                    foreach (var image in frame.GetImages())
                    {
                        var imgPath = Path.Combine(framePath, image.Dir + ".png");
                        //                  MakeImageTransform(image);
                        image.Bitmap.Save(imgPath);
                    }
                    frameIndex++;
                }
                stateIndex++;
            }
            _log.InfoFormat("Extracted {0}", file);

            return(Path.Combine(oPath, Datafile));
        }