Scripting
Overview
A script file is a fully enclosed that does not require any other script or file to use. Dungeondraft will poll each script at load, but can also poll every tick or input input based on the way you configure it. From those methods, you can communicate to Dungeondraft through API calls. It is through this back-and-forth communication that Dungeondraft can be modded.
Mod Load Time
A mod is loaded and therefore, a script is loaded just after a new map or saved map finished loading and the canvas displays. By the time a script is initialized.
Minimum Viable Script
The following code is the smallest scripts for the 2 script types.
Tool Script
The variable script_class is a string that Dungeondraft inspects to see what type of script has been loaded.
The start() method is called after an instance of the script has been created and just after all of the assets needed for drawing has been loaded. It is not called in the welcome screen before a new map has been created.
Export Format Script
var script_class = "export_format"
var export_format_name = "Export Format Name"
var export_file_extension = "myexportextension"
var export_image_format = "webp"
var show_quality_slider = true
func start():
pass
func process(path : String, image : File, ppi : int):
pass
The variable export_format_name is a string that is displayed to users in the export window.
The variable export_file_extension is the file extension your custom format will save with.
The variable export_image_format is the type of image the export will use. Valid options are: "png", "jpg", and "webp".
The variable show_quality_slider displays the quality slider in the export window, useful for png and webp.
The process() method is only called within an Export Format script and is called just after the imaging step of the export process has been completed. It allows you to manipulate the end result of the image. This is an ideal script type to add specialized export to a custom VTT.