JannisX11 / blockbench

Blockbench - A low poly 3D model editor
https://www.blockbench.net
GNU General Public License v3.0
3.13k stars 277 forks source link

Update GIF Recorder to allow plugins to add their own formats #2134

Closed ewanhowell5195 closed 4 months ago

ewanhowell5195 commented 7 months ago

This PR updates the screenshot.js file to move the gif recorder formats into an object, so that plugins can add entries into this object, therefore adding their own gif recorder formats.

Example of how you can now add a new format:

// onload
ScreencamGIFFormats.mp4 = {
  name: "MP4 Video",
  process(vars, options) {
    // do stuff with vars.frame_canvases and either save the file, or show it in a dialog
  } 
}
Screencam.gif_options_dialog.form.format.options.mp4 = "MP4 Video"

// onunload
delete ScreencamGIFFormats.mp4
delete Screencam.gif_options_dialog.form.format.options.mp4

ScreencamGIFFormats Formatting:

const ScreencamGIFFormats = {
  id: {                                  // The ID of the format.
    name: "Name",                        // The name of the format.
    interval: vars => vars.interval / 2, // An optional function to modify the user selected interval.
    frameRendered(vars, options) {},     // An optional function to process a frame and add it to the frame array. If not provided, frame gets automatically added to the frame array.
    process(vars, options) {}            // A function to process the frames after they have been rendered, display the output to the user, and save the output.
  }
}

I also updated the language files because I changed the status bar to say: Recording FORMATNAME rather than always saying Recording GIF. There may be some translation issues now.