Codec
Codec
Extends: Deletable
A codec represents a specific file format that can be imported into and exported from Blockbench. The codec handles the compilation and parsing, as well as the loading and exporting logic
new Codec( id, options )
Creates a new codec
Arguments:
id
: string - Codec IDoptions
: CodecOptions - Codec optionsname
: stringload
: Function (Optional)compile
: Function (Optional)parse
: Function (Optional)export
: Function (Optional)fileName
: Function (Optional)startPath
: Function (Optional)write
: Function (Optional)overwrite
: Function (Optional)afterDownload
: Function (Optional)afterSave
: Function (Optional)exportCollection
: Function (Optional)writeCollection
: Function (Optional)dispatchEvent
: Function (Optional)extension
: stringremember
: boolean - Whether to remember the models exported using this codecload_filter
: See types (Optional)export_options
: See types (Optional) - List of export option inputs, based on the Dialog form APIexport_action
: Action (Optional) - Default action that is used to export to the codec
Property | Type | Description |
---|---|---|
name | string | The display name of the codec |
extension | string | The default file extension that the codec uses |
remember | boolean | Whether to remember files that use this codec in the recent models list |
export_action | Action | If available, the action that is used to export files using this codec |
export_options | See types | List of export option inputs |
format | ModelFormat |
load( model, file[, add] )
Load a file into the program
Arguments:
model
: any -file
: any -add
: boolean (Optional) -
compile( [options] )
Compiles the file content
Arguments:
options
: any (Optional) -
Returns: any
parse( data, path[, add] )
Takes the content of a file, and loads the model into the current Blockbench project
Arguments:
data
: any - File contentpath
: string - File pathadd
: boolean (Optional)
export()
Opens the file browser to export a file of this type
fileName()
Generate a file name to suggest when exporting
Returns: string
startPath()
Generates the suggested file path. This is the path that the explorer opens in when exporting this type
Returns: string
write( content, path )
Write the content of this file to the selected location. The default method can be overwritten to achieve custom behavior
Arguments:
content
: any - File content, as generated by compile()path
: string - The file export path
overwrite( content, path, callback )
Arguments:
content
: anypath
: stringcallback
: See types
afterDownload( path )
Arguments:
path
: string
afterSave( path )
Arguments:
path
: string
exportCollection( collection )
Arguments:
collection
: Collection
writeCollection( collection )
Arguments:
collection
: Collection
getExportOptions()
Return the stored export option values of the current project
Returns: See types
promptExportOptions()
Prompt the user to enter their preferred export settings into the dialog
Returns: Promise
on( event_name, callback )
Adds an event listener to the codec
Arguments:
event_name
: string - The event type to listen forcallback
: See types -
once( event_name, callback )
Adds a single-use event listener to the codec
Arguments:
event_name
: string - The event type to listen forcallback
: See types -
removeListener( event_name, callback )
Removes an event listener from the codec
Arguments:
event_name
: string -callback
: See types -
dispatchEvent( event_name, data )
Arguments:
event_name
: stringdata
: any
Codec.getAllExtensions()
Get a list of all possible extensions of all codecs
Returns: Array of string
delete()
Codecs
Global Variable
Type: See types