blockbench-types 4.3.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blockbench-types",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "description": "Blockbench typescript types",
5
5
  "main": "",
6
6
  "types": "types/index.d.ts",
@@ -19,6 +19,7 @@
19
19
  "homepage": "https://github.com/JannisX11/blockbench-types#readme",
20
20
  "dependencies": {
21
21
  "@types/jquery": "^3.5.4",
22
+ "@types/tinycolor2": "^1.4.3",
22
23
  "three": "^0.129.0",
23
24
  "vue": "^2.6.14",
24
25
  "wintersky": "^1.1.0"
package/types/action.d.ts CHANGED
@@ -54,20 +54,128 @@ interface ActionOptions extends BarItemOptions {
54
54
  }
55
55
  declare class Action extends BarItem {
56
56
  constructor(id: string, options: ActionOptions);
57
+ /**
58
+ * Trigger to run or select the action. This is the equivalent of clicking or using a keybind to trigger it. Also checks if the condition is met.
59
+ */
57
60
  trigger(event: Event): boolean;
58
61
  updateKeybindingLabel(): this;
59
- setIcon(icon: string): void;
62
+ /** Change the icon of the action */
63
+ setIcon(icon: IconString): void;
60
64
  toggleLinkedSetting(change: any): void;
61
65
  nodes: HTMLElement[]
66
+ /**
67
+ * Provide a menu that belongs to the action, and gets displayed as a small arrow next to it in toolbars.
68
+ */
69
+ side_menu?: Menu
70
+ }
71
+
72
+ type RGBAColor = {r: number, g: number, b: number, a: number}
73
+ type ViewMode = 'textured' | 'solid' | 'wireframe' | 'uv' | 'normal'
74
+ type PaintContext = {
75
+ /**
76
+ * Brush color, set by the Blockbench color panel
77
+ */
78
+ color: string,
79
+ /**
80
+ * Opacity, as set by the Opacity slider
81
+ */
82
+ opacity: number,
83
+ /**
84
+ * 2D Canvas context of the texture that is being edited
85
+ */
86
+ ctx: CanvasRenderingContext2D,
87
+ /**X Coordinate of the position of the brush stroke */
88
+ x: number,
89
+ /**Y Coordinate of the position of the brush stroke */
90
+ y: number,
91
+ /**
92
+ * Brush size, as set by the Brush Size slider
93
+ */
94
+ size: number,
95
+ /**
96
+ * Brush softness, as set by the Brush Softness slider
97
+ */
98
+ softness: number,
99
+ /**
100
+ * Blockbench texture that is being edited
101
+ */
102
+ texture: Texture,
103
+ /**
104
+ * Javascript pointer event that the brush stroke originated from
105
+ */
106
+ event: PointerEvent
62
107
  }
108
+ interface BrushOptions {
109
+ /**
110
+ * Enable the input for blend modes when this tool is selected
111
+ */
112
+ blend_modes: boolean
113
+ /**
114
+ * Enable the input for shapes when this tool is selected
115
+ */
116
+ shapes: boolean
117
+ /**
118
+ * Enable the input for brush size when this tool is selected
119
+ */
120
+ size: boolean
121
+ /**
122
+ * Enable the input for softness when this tool is selected
123
+ */
124
+ softness: boolean
125
+ /**
126
+ * Enable the input for opacity when this tool is selected
127
+ */
128
+ opacity: boolean
129
+ /**
130
+ * When the brush size is an even number, offset the snapping by half a pixel so that even size brush strokes can be correctly centered
131
+ */
132
+ offset_even_radius: boolean
133
+ /**
134
+ * Set whether the brush coordinates get floored to snap to the nearest pixel.
135
+ */
136
+ floor_coordinates: boolean | (() => boolean)
137
+ /**
138
+ * Function that runs per pixel when the brush is used. Mutually exclusive with draw().
139
+ * @param pixel_x Local X coordinate relative to the brush center
140
+ * @param pixel_y Local Y coordinate relative to the brush center
141
+ * @param pixel_color Current color of the pixel on the texture
142
+ * @param local_opacity Local opacity of the current pixel on the brush, between 0 and 1. Opacity falls of to the sides of the brush if the brush is set to smooth. Opacity from the Opacity slider is not factored in yet.
143
+ * @param PaintContext Additional context to the paint stroke
144
+ */
145
+ changePixel(pixel_x: number, pixel_y, pixel_color: RGBAColor, local_opacity: number, PaintContext: PaintContext): RGBAColor
146
+ /**
147
+ * Function that runs when a new brush stroke starts. Return false to cancel the brush stroke
148
+ * @param context
149
+ */
150
+ onStrokeStart(context: {texture: Texture, x: number, y: number, uv?: object, event: PointerEvent, raycast_data: RaycastResult}): boolean
151
+ /**
152
+ * Function that runs when a new brush stroke starts. Return false to cancel the brush stroke
153
+ * @param context
154
+ */
155
+ onStrokeMove(context: {texture: Texture, x: number, y: number, uv?: object, event: PointerEvent, raycast_data: RaycastResult}): boolean
156
+ /**
157
+ * Function that runs when a new brush stroke starts.
158
+ * @param context
159
+ */
160
+ onStrokeEnd(context: {texture: Texture, x: number, y: number, uv?: object, raycast_data: RaycastResult})
161
+ /**
162
+ * Alternative way to create a custom brush, mutually exclusive with the changePixel() function. Draw runs once every time the brush starts or moves, and also along the bath on lines.
163
+ * @param context
164
+ */
165
+ draw(context: {ctx: CanvasRenderingContext2D, x: number, y: number, size: number, softness: number, texture: Texture, event: PointerEvent})
63
166
 
167
+ }
64
168
  interface ToolOptions extends ActionOptions {
65
169
  selectFace?: boolean
170
+ selectElements?: boolean
66
171
  transformerMode?: 'translate' | ''
67
172
  animation_channel?: string
68
173
  toolbar?: string
69
174
  alt_tool?: string
70
175
  modes?: string[]
176
+ allowed_view_modes?: ViewMode
177
+ paintTool?: boolean
178
+ brush?: BrushOptions
71
179
  }
72
180
  declare class Tool extends Action {
73
181
  constructor(id: string, options: ToolOptions);
package/types/codec.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  interface CodecOptions {
2
2
  name: string
3
3
  load?(model: any, file: object, add?: boolean): void
4
- compile?(): void
5
- parse?(): void
4
+ compile?(options?: object): void
5
+ parse?(data: any, path: string): void
6
6
  export?(): void
7
7
  /**
8
8
  * Generate a file name to suggest when exporting
@@ -10,6 +10,7 @@ interface CodecOptions {
10
10
  fileName?(): string
11
11
  startPath?(): string
12
12
  write?(content: any, path: string): void
13
+ overwrite?(content: any, path: string, callback: ((path) => void)): void
13
14
  afterDownload?(path): void
14
15
  afterSave?(path): void
15
16
 
@@ -30,8 +31,8 @@ declare class Codec extends Deletable {
30
31
  constructor(id: string, options: CodecOptions)
31
32
 
32
33
  load?(model: any, file: object, add?: boolean): void
33
- compile?(): any
34
- parse?(model): void
34
+ compile?(options?: object): any
35
+ parse?(data: any, path: string): void
35
36
  export?(): void
36
37
  /**
37
38
  * Generate a file name to suggest when exporting
@@ -39,6 +40,7 @@ declare class Codec extends Deletable {
39
40
  fileName?(): string
40
41
  startPath?(): string
41
42
  write?(content: any, path: string): void
43
+ overwrite?(content: any, path: string, callback: ((path) => void)): void
42
44
  afterDownload?(path): void
43
45
  afterSave?(path): void
44
46
  on(event_name: string, callback: (data: object) => void): void
package/types/dialog.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  interface DialogFormElement {
2
2
  label: string
3
3
  description?: string
4
- type: 'text' | 'number' | 'checkbox' | 'select' | 'radio' | 'textarea' | 'vector' | 'color' | 'file' | 'folder' | 'save' | 'info'
4
+ type: 'text' | 'number' | 'range' | 'checkbox' | 'select' | 'radio' | 'textarea' | 'vector' | 'color' | 'file' | 'folder' | 'save' | 'info'
5
5
  nocolon?: boolean
6
+ full_width?: boolean
6
7
  readonly?: boolean
7
8
  value?: any
8
9
  placeholder?: string
@@ -54,7 +55,7 @@ interface DialogOptions {
54
55
  /**
55
56
  * Array of HTML object strings for each line of content in the dialog.
56
57
  */
57
- lines?: (string|HTMLElement)[]
58
+ lines?: (HTMLElement | {label?: string, widget?: Widget|(() => Widget), nocolon?: boolean} | string)[]
58
59
  /**
59
60
  * Creates a form in the dialog
60
61
  */
@@ -86,6 +87,10 @@ interface DialogOptions {
86
87
  * List of buttons
87
88
  */
88
89
  buttons?: string[]
90
+ /**
91
+ * Unless set to false, clicking on the darkened area outside of the dialog will cancel the dialog.
92
+ */
93
+ cancel_on_click_outside?: boolean
89
94
  }
90
95
 
91
96
  interface DialogSidebarOptions {
@@ -25,6 +25,10 @@ declare namespace Blockbench {
25
25
  * Reads the content from the specified files. Desktop app only.
26
26
  */
27
27
  export function read(files: string[], options?: ReadOptions, callback?: (files: FileResult[]) => void): void
28
+ /**
29
+ * Reads the content from the specified files. Desktop app only.
30
+ */
31
+ export function readFile(files: string[], options?: ReadOptions, callback?: (files: FileResult[]) => void): void
28
32
 
29
33
 
30
34
 
package/types/format.d.ts CHANGED
@@ -9,6 +9,28 @@ interface FormatPage {
9
9
  } | string)[]
10
10
  button_text?: string
11
11
  }
12
+ interface CubeSizeLimiter {
13
+ /**
14
+ * Test whether the cube with the optionally provided values violates the size restrictions
15
+ */
16
+ test: (cube: Cube, values?: {from: ArrayVector3, to: ArrayVector3, inflate: number}) => boolean
17
+ /**
18
+ * Move the cube back into the restructions
19
+ */
20
+ move: (cube: Cube, values?: {from: ArrayVector3, to: ArrayVector3, inflate: number}) => void
21
+ /**
22
+ * Clamp the cube to fit into the restrictions. When an axis and direction is provided, clamp the element on that side to prevent wandering.
23
+ */
24
+ clamp: (cube: Cube, values?: {from: ArrayVector3, to: ArrayVector3, inflate: number}, axis?: number, direction?: boolean | null) => void
25
+ /**
26
+ * Set to true to tell Blockbench to check and adjust the cube limit after rotating a cube
27
+ */
28
+ rotation_affected?: boolean,
29
+ /**
30
+ * Optionally set the coordinate limits of cubes in local space
31
+ */
32
+ coordinate_limits?: [number, number]
33
+ }
12
34
 
13
35
  interface FormatOptions {
14
36
  id: string
@@ -27,6 +49,9 @@ interface FormatOptions {
27
49
  box_uv?: boolean
28
50
  optional_box_uv?: boolean
29
51
  single_texture?: boolean
52
+ model_identifier?: boolean
53
+ parent_model_id?: boolean
54
+ vertex_color_ambient_occlusion?: boolean
30
55
  animated_textures?: boolean
31
56
  bone_rig?: boolean
32
57
  centered_grid?: boolean
@@ -35,14 +60,21 @@ interface FormatOptions {
35
60
  meshes?: boolean
36
61
  texture_meshes?: boolean
37
62
  locators?: boolean
38
- canvas_limit?: boolean
39
63
  rotation_limit?: boolean
40
64
  uv_rotation?: boolean
65
+ java_face_properties?: boolean
66
+ select_texture_for_particles?: boolean
67
+ bone_binding_expression?: boolean
68
+ animation_files?: boolean
69
+ texture_folder?: boolean
70
+ image_editor?: boolean
71
+ edit_mode?: boolean
72
+ paint_mode?: boolean
41
73
  display_mode?: boolean
42
74
  animation_mode?: boolean
43
- animation_files?: boolean
44
75
  pose_mode?: boolean
45
- texture_folder?: boolean
76
+
77
+ cube_size_limiter?: CubeSizeLimiter
46
78
 
47
79
  codec?: Codec
48
80
  onActivation?(): void
@@ -80,18 +112,21 @@ declare class ModelFormat extends Deletable {
80
112
  meshes: boolean
81
113
  texture_meshes: boolean
82
114
  locators: boolean
83
- canvas_limit: boolean
84
115
  rotation_limit: boolean
85
116
  uv_rotation: boolean
86
117
  java_face_properties: boolean
87
118
  select_texture_for_particles: boolean
88
119
  bone_binding_expression: boolean
89
120
  animation_files: boolean
90
- pose_mode: boolean
121
+ texture_folder: boolean
122
+ image_editor: boolean
123
+ edit_mode: boolean
124
+ paint_mode: boolean
91
125
  display_mode: boolean
92
126
  animation_mode: boolean
93
- texture_folder: boolean
127
+ pose_mode: boolean
94
128
 
129
+ cube_size_limiter?: CubeSizeLimiter
95
130
  /**
96
131
  * Selects the format
97
132
  */
package/types/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  /// <reference types="vue" />
2
2
  /// <reference types="three" />
3
+ /// <reference types="@types/tinycolor2" />
3
4
  /// <reference types="@types/jquery" />
4
5
  /// <reference types="wintersky" />
5
6
 
7
+ /// <reference types="./textures" />
6
8
  /// <reference types="./action" />
7
9
  /// <reference types="./animation" />
8
10
  /// <reference types="./canvas" />
@@ -21,9 +23,9 @@
21
23
  /// <reference types="./preview" />
22
24
  /// <reference types="./project" />
23
25
  /// <reference types="./settings" />
24
- /// <reference types="./textures" />
25
26
  /// <reference types="./timeline" />
26
27
  /// <reference types="./undo" />
28
+ /// <reference types="./validator" />
27
29
  /// <reference types="./util" />
28
30
 
29
31
 
@@ -38,7 +40,7 @@ type UUID = string
38
40
  declare const isApp: boolean
39
41
 
40
42
  type EventName = 'remove_animation'
41
- | 'display_animation_fram'
43
+ | 'display_animation_frame'
42
44
  | 'before_closing'
43
45
  | 'create_session'
44
46
  | 'join_session'
@@ -79,16 +81,26 @@ type EventName = 'remove_animation'
79
81
  | 'change_active_panel'
80
82
  | 'resize_window'
81
83
  | 'press_key'
84
+ | 'select_format'
82
85
  | 'convert_format'
86
+ | 'construct_format'
87
+ | 'delete_format'
83
88
  | 'select_project'
84
89
  | 'unselect_project'
85
90
  | 'setup_project'
86
91
  | 'update_project_resolution'
87
- | 'update_project_settings'
88
92
  | 'merge_project'
89
93
  | 'update_view'
90
94
  | 'update_camera_position'
91
95
  | 'render_frame'
96
+ | 'construct_model_loader'
97
+ | 'delete_model_loader'
98
+ | 'update_recent_project_data'
99
+ | 'update_recent_project_thumbnail'
100
+ | 'load_from_recent_project_data'
101
+ | 'edit_animation_properties'
102
+ | 'select_preview_scene'
103
+ | 'unselect_preview_scene'
92
104
 
93
105
  type IconString = string;
94
106
 
@@ -107,6 +119,12 @@ interface MessageBoxOptions {
107
119
  message?: string
108
120
  icon?: string
109
121
  width: number
122
+ /**
123
+ * Display a list of actions to do in the dialog. When clicked, the message box closes with the string ID of the command as first argument.
124
+ */
125
+ commands?: {
126
+ [id: string]: string | {text: string}
127
+ }
110
128
  }
111
129
 
112
130
  declare namespace Blockbench {
@@ -167,7 +185,7 @@ declare namespace Blockbench {
167
185
  /**
168
186
  * Opens a message box
169
187
  */
170
- function showMessageBox(options: MessageBoxOptions, callback: (buttonID: number) => void): void
188
+ function showMessageBox(options: MessageBoxOptions, callback: (buttonID: number | string) => void): void
171
189
 
172
190
  function textPrompt(title: string, value: string, callback: (value: string) => void): void
173
191
  /**
@@ -197,7 +215,7 @@ declare namespace Blockbench {
197
215
  function addListener(event_names: EventName, callback: (data: object) => void): void
198
216
  function on(event_names: EventName, callback: (data: object) => void): void
199
217
 
200
- function removeEventListener(event_names: EventName): void
218
+ function removeListener(event_names: EventName): void
201
219
  }
202
220
 
203
221
 
package/types/menu.d.ts CHANGED
@@ -13,15 +13,21 @@ interface CustomMenuItem {
13
13
  */
14
14
  searchable?: boolean
15
15
  children?: MenuItem[] | (() => MenuItem[])
16
- click?: (context?: any, event: Event)
16
+ click?: (context?: any, event?: Event) => void
17
17
  }
18
18
  type MenuItem = CustomMenuItem | Action | BarSelect | string;
19
-
20
- /**
21
- * Creates a new context menu
22
- */
19
+ interface MenuOptions {
20
+ onOpen?: (position: MouseEvent | HTMLElement, context?: any) => void
21
+ onClose?: () => void
22
+ keep_open?: boolean
23
+ searchable?: boolean
24
+ }
23
25
  declare class Menu extends Deletable {
24
- constructor(template: MenuItem[])
26
+ /**
27
+ * Creates a new context menu
28
+ */
29
+ constructor(id: string, template: MenuItem[] | ((context?: any) => MenuItem[]), options?: MenuOptions)
30
+ constructor(template: MenuItem[] | ((context?: any) => MenuItem[]), options?: MenuOptions)
25
31
 
26
32
  /**
27
33
  * Opens the menu somewhere
@@ -13,7 +13,17 @@ interface PreviewOptions {
13
13
  antialias?: boolean
14
14
  }
15
15
 
16
- class Preview extends Deletable {
16
+ type RaycastResult = {
17
+ type: 'keyframe' | 'vertex' | 'cube'
18
+ event: Event
19
+ cube?: Cube
20
+ intersects?: object[]
21
+ face?: string
22
+ vertex: any
23
+ keyframe: Keyframe
24
+ }
25
+
26
+ declare class Preview extends Deletable {
17
27
  constructor(options: PreviewOptions)
18
28
 
19
29
  id: string
@@ -45,15 +55,7 @@ class Preview extends Deletable {
45
55
  }
46
56
  raycaster: THREE.Raycaster
47
57
 
48
- raycast(event: MouseEvent): false | {
49
- type: 'keyframe' | 'vertex' | 'cube'
50
- event: Event
51
- cube?: Cube
52
- intersects?: object[]
53
- face?: string
54
- vertex: any
55
- keyframe: Keyframe
56
- }
58
+ raycast(event: MouseEvent): false | RaycastResult
57
59
  render(): void
58
60
  setProjectionMode(orthographic: boolean): this
59
61
  setFOV(fov: number): void
package/types/undo.d.ts CHANGED
@@ -40,21 +40,70 @@ type UndoEntry = {
40
40
  action: string
41
41
  time: number
42
42
  }
43
+ interface AmendEditForm {
44
+ condition?: Condition
45
+ type?: 'number'
46
+ label: string
47
+ interval_type: 'position' | 'rotation'
48
+ getInterval?: (Event) => number
49
+ value?: number | string,
50
+ min?: number,
51
+ max?: number,
52
+ step?: number,
53
+ }
43
54
 
44
55
  declare class UndoSystem {
45
56
  constructor();
57
+ /**
58
+ * Starts an edit to the current project by saving the state of the provided aspects
59
+ * @param aspects Aspects to save
60
+ */
46
61
  initEdit(aspects: UndoAspects): any;
62
+ /**
63
+ * Finishes an edit by saving the state of the project after it was changed
64
+ * @param action Description of the edit
65
+ */
47
66
  finishEdit(action: string, aspects?: UndoAspects): {
48
67
  before: any;
49
68
  post: any;
50
69
  action: any;
51
70
  time: number;
52
71
  };
72
+ /**
73
+ * Cancels an event before it was finished and reset the project to the state before
74
+ */
53
75
  cancelEdit(): void;
76
+ /**
77
+ * Add keyframes to the current edit that were indirectly removed by moving other keyframes to their position
78
+ * @param keyframes
79
+ */
54
80
  addKeyframeCasualties(keyframes: Keyframe[]): void;
81
+ /**
82
+ * Undoes the latest edit
83
+ */
55
84
  undo(remote?: boolean): void;
85
+ /**
86
+ * Redoes the latest edit
87
+ */
88
+ redo(remote?: boolean): void;
89
+ /**
90
+ * Redoes the latest edit
91
+ */
56
92
  redo(remote?: boolean): void;
57
- remoteEdit(entry: UndoEntry): void;
58
- loadSave(save: UndoSave, reference: UndoSave, mode?: string): void;
93
+ /**
94
+ * Provides a menu to amend the latest edit with slightly changed values
95
+ */
96
+ amendEdit(form: AmendEditForm, callback: (values: {}, form: {}) => void)
97
+
98
+ /**
99
+ * Loads a specific undo save
100
+ * @param save The undo save to load
101
+ * @param reference The current undo save for reference
102
+ * @param mode The load save modes
103
+ */
104
+ loadSave(save: UndoSave, reference: UndoSave, mode?: 'session'): void;
59
105
  }
106
+ /**
107
+ * Blockbench's system to register edits to the project and switch between them
108
+ */
60
109
  declare let Undo: UndoSystem;
@@ -0,0 +1,60 @@
1
+ declare namespace Validator {
2
+ const checks: ValidatorCheck[]
3
+
4
+ const warnings: []
5
+ const errors: []
6
+ /**
7
+ * Run the validator
8
+ * @param trigger ID of the Blockbench event that triggered the call
9
+ */
10
+ function validate(trigger?: EventName): void
11
+ /**
12
+ * Opens the Validator dialog
13
+ */
14
+ function openDialog(): void
15
+
16
+ /**
17
+ * Cached trigger IDs
18
+ */
19
+ const triggers: EventName[]
20
+ /**
21
+ * Update the cached triggers list
22
+ */
23
+ function updateCashedTriggers(): void
24
+ }
25
+
26
+ interface ValidatorCheckOptions {
27
+ /**
28
+ * Function that runs when the validator check runs
29
+ */
30
+ run(): void
31
+ /**
32
+ * Names of events that automatically trigger this check
33
+ */
34
+ update_triggers?: EventName[]
35
+ condition?: Condition
36
+ }
37
+ interface WarningOrError {
38
+ message: string
39
+ buttons?: {
40
+ name: string
41
+ icon: IconString
42
+ click(): void
43
+ }[]
44
+ }
45
+ declare class ValidatorCheck extends Deletable {
46
+ constructor(id: string, options: ValidatorCheckOptions)
47
+
48
+ /**
49
+ * Manually run this check
50
+ */
51
+ update(): void
52
+ /**
53
+ * Throw a warning. This is intended to be used inside the run() method
54
+ */
55
+ warn(...warnings: WarningOrError[]): void
56
+ /**
57
+ * Throw an error. This is intended to be used inside the run() method
58
+ */
59
+ fail(...warnings: WarningOrError[]): void
60
+ }