public void TestOutput() { int w = 2, h = 1; string path = CreateTempBitmap(w * 32, h * 8); try { DrawablesGenerator dg = new DrawablesGenerator(path); dg.OffsetX = 5; dg.OffsetY = 3; DrawablesOutput dOutput = dg.Generate(); // Checking output Assert.AreEqual(64, dOutput.ImageWidth); Assert.AreEqual(8, dOutput.ImageHeight); // Checking drawables in output Assert.AreEqual(w, dOutput.Drawables.GetLength(0)); Assert.AreEqual(h, dOutput.Drawables.GetLength(1)); Drawable d = dOutput.Drawables[0, 0]; Drawable d2 = dOutput.Drawables[1, 0]; // Texture and ResultImage Assert.AreEqual(d.Texture, dg.DrawableTexture); Assert.AreEqual(d.Texture, d2.Texture); Assert.AreEqual(d.ResultImage, d.Texture + d.Directives); Assert.AreNotEqual(d.ResultImage, d2.ResultImage); // Offset matching Assert.AreEqual(dg.OffsetX, dOutput.OffsetX); Assert.AreEqual(dg.OffsetY, dOutput.OffsetY); // Drawable positioning Assert.AreEqual(0, d.X); Assert.AreEqual(0, d.Y); Assert.AreEqual(32, d2.X); Assert.AreEqual(0, d2.Y); Assert.AreEqual(0d, d.BlockX); Assert.AreEqual(4d, d2.BlockX); Assert.AreEqual(0d, d.BlockY); Assert.AreEqual(d.BlockY, d2.BlockY); } catch (DrawableException exc) { Assert.Fail(exc.Message); } finally { if (File.Exists(path)) { File.Delete(path); } } }
/// <summary> /// Sets up the properties of an instantiated generator, using the given parameters. /// </summary> /// <param name="generator">Generator to set up.</param> /// <param name="handX">String value for the horizontal hand offset in pixels, presumably from a text field. /// Value should be convertable to an integer.</param> /// <param name="handY">String value for the vertical hand offset in pixels, presumably from a text field. /// Value should be convertable to an integer.</param> /// <param name="ignoreColor">String value of the color to ignore, presumably from a text field. /// If given, value should be formatted RRGGBB or RRGGBBAA (hexadecimal string).</param> /// <returns>Reference to the given object.</returns> public static DrawablesGenerator SetUpGenerator(DrawablesGenerator generator, int handX, int handY) { generator.OffsetX = Convert.ToInt32(handX) + 1; generator.OffsetY = Convert.ToInt32(handY); generator.RotateFlipStyle = System.Drawing.RotateFlipType.RotateNoneFlipY; generator.ReplaceBlank = true; generator.ReplaceWhite = true; return(generator); }
public void TestNullGenerator() { try { DrawablesGenerator dg = new DrawablesGenerator((string)null); } catch (ArgumentException) { } catch (FileNotFoundException) { } catch (Exception) { Assert.Fail(); } }
private void ItemDescriptor_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) { if (image == null) { MessageBox.ShowDialog("Please select an image first!", "Error"); return; } try { DrawablesGenerator generator = new DrawablesGenerator(image); generator.OffsetX = Convert.ToInt32(tbxHandX.Text) + 1; generator.OffsetY = Convert.ToInt32(tbxHandY.Text); generator.FlipY = true; generator.ReplaceBlank = true; generator.ReplaceWhite = true; if (Data.IgnoreWhite) { generator.IgnoreColor = new Rgba32(255, 255, 255, 255); } DrawablesOutput output = generator.Generate(); Template t = GetTemplate(); Exporter.Exporter exporter = new Exporter.Exporter(output, t.Config); if (Data.WeaponGroup) { exporter.Groups.Add("weapon"); } JObject descriptor = exporter.GetDescriptor(Data.InventoryIcon); TextWindow tw = new TextWindow(descriptor.ToString(Formatting.Indented), "Item Descriptor"); tw.ShowDialog(); } catch (ArgumentException exc) { MessageBox.ShowDialog("Illegal argument:\n" + exc.Message, "Error"); } catch (FormatException) { MessageBox.ShowDialog("Could not convert hand offsets to numbers.", "Error"); } catch (Exception exc) { MessageBox.ShowDialog("Uncaught exception:\n" + exc.Message, "Error"); } }
/// <summary> /// Generate the starbound single texture directive by the given frame /// </summary> /// <param name="bsource">A frame to create directives from</param> /// <returns>The directive string</returns> protected static string GenerateDirective(BitmapSource bsource) { Bitmap bmp = BitmapConverter.BitmapSourceToBitmap(bsource); DrawablesGenerator generator = new DrawablesGenerator(BitmapConverter.BitmapSourceToBitmap(bsource)); bmp.Dispose(); generator = DrawableUtilities.SetUpGenerator(generator, 0, 0); generator.ReplaceBlank = true; generator.ReplaceWhite = true; DrawablesOutput output = generator.Generate(); return(DrawableUtilities.GenerateSingleTextureDirectives(output, 64)); }
public void TestValidGenerator() { string path = CreateTempBitmap(); try { DrawablesGenerator dg = new DrawablesGenerator(path); } finally { if (File.Exists(path)) { File.Delete(path); } } }
public void TestSmall() { // Well spotted, this isn't a proper unit test! It's a sample for Degranon, cleverly disguised as a unit test. string path = @"F:\Users\Silver\Pictures\grid.png"; DrawablesGenerator generator = new DrawablesGenerator(path) { RotateFlipStyle = RotateFlipType.RotateNoneFlipY // you may need to set this to RotateNoneFlipY, depending on where you apply the results. }; var result = generator.GenerateScale(); foreach (var item in result.Drawables) { TestContext.WriteLine(item.Directives); } }
private void SingleTexture_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e) { if (image == null) { MessageBox.ShowDialog("Please select an image first!", "Error"); return; } try { DrawablesGenerator generator = new DrawablesGenerator(image); generator.OffsetX = Convert.ToInt32(tbxHandX.Text); generator.OffsetY = Convert.ToInt32(tbxHandY.Text); generator.FlipY = true; generator.ReplaceBlank = true; generator.ReplaceWhite = true; if (Data.IgnoreWhite) { generator.IgnoreColor = new Rgba32(255, 255, 255, 255); } DrawablesOutput output = generator.Generate(); int j = int.Parse(tbxSourceImageSize.Text); TextWindow tw = new TextWindow(DrawablesGenerator.GenerateSingleTextureDirectives(output, j), "Single Texture Directives"); tw.ShowDialog(); } catch (ArgumentNullException) { MessageBox.ShowDialog("Could not parse the hand position or the source image size (text field next to the button). Please hover over it for more information.", "Error"); } catch (FormatException) { MessageBox.ShowDialog("Could not parse the hand position or source image size (text field next to the button). Please hover over it for more information.", "Error"); } catch (DrawableException exc) { MessageBox.ShowDialog(exc.Message, "Error"); } }
public virtual JObject GetDescriptor(bool addInventoryIcon) { JObject descriptor = (JObject)Template.DeepClone(); if (descriptor["name"] == null) { descriptor["name"] = "perfectlygenericitem"; } if (descriptor["count"] == null) { descriptor["count"] = 1; } if (descriptor["parameters"] == null) { descriptor["parameters"] = new JObject(); } JObject parameters = (JObject)descriptor["parameters"]; if (parameters == null) { parameters = new JObject(); } if (parameters["animationCustom"] == null) { parameters["animationCustom"] = new JObject(); } if (parameters["animationCustom"]["animatedParts"] == null) { parameters["animationCustom"]["animatedParts"] = new JObject(); } if (parameters["animationCustom"]["animatedParts"]["parts"] == null) { parameters["animationCustom"]["animatedParts"]["parts"] = new JObject(); } JToken parts = parameters["animationCustom"]["animatedParts"]["parts"]; string prefix = "D_"; int i = 1; JArray groups = new JArray(); foreach (var item in Groups) { groups.Add(item); } foreach (Drawable item in Output.Drawables) { if (item == null) { continue; } JObject part = JObject.Parse("{'properties':{'centered':false,'offset':[0,0]}}"); part["properties"]["image"] = item.ResultImage; part["properties"]["offset"][0] = item.BlockX + Math.Round(Output.OffsetX / 8d, 3); part["properties"]["offset"][1] = item.BlockY + Math.Round(Output.OffsetY / 8d, 3); part["properties"]["transformationGroups"] = groups; parts[prefix + i++] = part; } if (addInventoryIcon) { parameters["inventoryIcon"] = DrawablesGenerator.GenerateInventoryIcon(Output); } return(descriptor); }
public void TestGenerate() { int w = 4, h = 4; string path = CreateTempBitmap(w * 32, h * 8); try { DrawablesGenerator dg = new DrawablesGenerator(path); DrawablesOutput dOutput = dg.Generate(); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { Drawable drawable = dOutput.Drawables[i, j]; StringBuilder debuilder = new StringBuilder(drawable.Directives); debuilder.Remove(0, 8); while (debuilder.Length >= 18) { string from = debuilder.ToString(1, 6), to = debuilder.ToString(10, 6); int rFrom = Convert.ToInt32(from.Substring(0, 2)), bFrom = Convert.ToInt32(from.Substring(4, 2)); int rTo = ColorConversions.HexToInt(to.Substring(0, 2)), bTo = ColorConversions.HexToInt(to.Substring(4, 2)); if (rTo > 32) { rTo = --rTo % 32; rTo++; } if (bTo > 8) { bTo = --bTo % 8; bTo++; } Assert.AreEqual(rFrom, rTo); Assert.AreEqual(bFrom, bTo); debuilder.Remove(0, 18); } } } } } dg.IgnoreColor = Color.Blue; dg.OffsetX = 5; dg.OffsetY = 3; dg.Generate(); dg.ReplaceBlank = true; dg.ReplaceWhite = true; dg.Generate(); dg.RotateFlipStyle = RotateFlipType.Rotate180FlipY; dg.Generate(); } catch (DrawableException exc) { Assert.Fail(exc.Message); } finally { if (File.Exists(path)) { File.Delete(path); } } }