# Attributes of the class
var attributes = new Array[String]
- attributes.add "\tprivate var main_image = new Texture(\"images/{document.drawing_name}.png\")\n"
+ attributes.add "\tprivate var root_texture = new Texture(\"images/{document.drawing_name}.png\")\n"
# Add single images to Nit source file
for image in single_images do
# Adapt coordinates to new top left and scale
var coordinates = document.coordinates(image)
- attributes.add "\tvar {image.name}: Texture = main_image.subtexture({coordinates})\n"
+ attributes.add "\tvar {image.name}: Texture = root_texture.subtexture({coordinates})\n"
end
# Add array of images too
add """
# File generated by svg_to_png_and_nit, do not modify, redef instead
-import gamnit::display
+import gamnit::textures
class {{{document.nit_class_name}}}
var opt_assets = new OptionString("Path to assert dir where to put PNG files", "--assets", "-a")
var opt_scale = new OptionFloat("Apply scaling to exported images (default at 1.0 of 90dpi)", 1.0, "--scale", "-x")
var opt_gamnit = new OptionBool("Target the Gamnit framework (by default it targets Mnit)", "--gamnit", "-g")
+var opt_pow2 = new OptionBool("Round the image size to the next power of 2", "--pow2")
var opt_help = new OptionBool("Print this help message", "--help", "-h")
var opt_context = new OptionContext
-opt_context.add_option(opt_out_src, opt_assets, opt_scale, opt_gamnit, opt_help)
+opt_context.add_option(opt_out_src, opt_assets, opt_scale, opt_gamnit, opt_pow2, opt_help)
opt_context.parse(args)
var rest = opt_context.rest
end
svg_file.close
- assert page_width != -1
- assert page_height != -1
+ if page_width == -1 or page_height == -1 then
+ stderr.write "Source drawing file '{drawing}' doesn't look like an SVG file\n"
+ exit 1
+ end
# Query Inkscape
var prog = "inkscape"
nit_src.write_to(src_file)
src_file.close
- # Find closest power of 2
- var dx = max_x - min_x
- max_x = dx.next_pow2 + min_x
+ # Find next power of 2
+ if opt_pow2.value then
+ var dx = max_x - min_x
+ max_x = dx.next_pow2 + min_x
- var dy = max_y - min_y
- max_y = dy.next_pow2 + min_y
+ var dy = max_y - min_y
+ max_y = dy.next_pow2 + min_y
+ end
# Inkscape's --export-area inverts the Y axis. It uses the lower left corner of
# the drawing area where as queries return coordinates from the top left.