+# Nit module targeting the Gamnit framework
+#
+# Gamnit's `Texture` already manage the lazy loading, no need to do it here.
+class GamnitImageSetSrc
+ super ImageSetSrc
+
+ private fun attributes: Array[String]
+ do
+ # Separate the images from the arrays of images
+ var single_images = new Array[Image]
+ var arrays_of_images = new HashMap[String, Array[Image]]
+
+ for image in images do
+ var nit_name = image.name
+ var last_char = nit_name.chars.last
+ if last_char.to_s.is_numeric then
+
+ # Is an array
+ nit_name = nit_name.substring(0, nit_name.length-1)
+ if not arrays_of_images.keys.has(nit_name) then
+ # Create a new array
+ var array = new Array[Image]
+ arrays_of_images[nit_name] = array
+ end
+
+ arrays_of_images[nit_name].add image
+ else
+ # Is a single image
+ single_images.add image
+ end
+ end
+
+ # Attributes of the class
+ var attributes = new Array[String]
+ attributes.add "\tprivate var main_image = 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"
+ end
+
+ # Add array of images too
+ for name, images in arrays_of_images do
+
+ var lines = new Array[String]
+ for image in images do
+ var coordinates = document.coordinates(image)
+ lines.add "\t\tmain_image.subtexture({coordinates})"
+ end
+
+ attributes.add """
+ var {{{name}}} = new Array[Texture].with_items(
+{{{lines.join(",\n")}}})
+"""
+ end
+
+ return attributes
+ end
+
+ redef fun rendering
+ do
+ add """
+# File generated by svg_to_png_and_nit, do not modify, redef instead
+
+import gamnit::display
+
+class {{{document.nit_class_name}}}
+
+"""
+ add_all attributes
+ add """
+end
+"""
+ end
+end
+