blockbench-types 4.3.0 → 4.4.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.4.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/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
@@ -24,25 +46,34 @@ interface FormatOptions {
24
46
  onFormatPage?(): void
25
47
  onStart?(): void
26
48
 
27
- box_uv?: boolean
28
- optional_box_uv?: boolean
29
- single_texture?: boolean
30
- animated_textures?: boolean
31
- bone_rig?: boolean
32
- centered_grid?: boolean
33
- rotate_cubes?: boolean
34
- integer_size?: boolean
35
- meshes?: boolean
36
- texture_meshes?: boolean
37
- locators?: boolean
38
- canvas_limit?: boolean
39
- rotation_limit?: boolean
40
- uv_rotation?: boolean
49
+ box_uv: boolean
50
+ optional_box_uv: boolean
51
+ single_texture: boolean
52
+ model_identifier: boolean
53
+ parent_model_id: boolean
54
+ vertex_color_ambient_occlusion: boolean
55
+ animated_textures: boolean
56
+ bone_rig: boolean
57
+ centered_grid: boolean
58
+ rotate_cubes: boolean
59
+ integer_size: boolean
60
+ meshes: boolean
61
+ texture_meshes: boolean
62
+ locators: boolean
63
+ rotation_limit: boolean
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
+ edit_mode?: boolean
71
+ paint_mode?: boolean
41
72
  display_mode?: boolean
42
73
  animation_mode?: boolean
43
- animation_files?: boolean
44
74
  pose_mode?: boolean
45
- texture_folder?: boolean
75
+
76
+ cube_size_limiter?: CubeSizeLimiter
46
77
 
47
78
  codec?: Codec
48
79
  onActivation?(): void
@@ -80,18 +111,20 @@ declare class ModelFormat extends Deletable {
80
111
  meshes: boolean
81
112
  texture_meshes: boolean
82
113
  locators: boolean
83
- canvas_limit: boolean
84
114
  rotation_limit: boolean
85
115
  uv_rotation: boolean
86
116
  java_face_properties: boolean
87
117
  select_texture_for_particles: boolean
88
118
  bone_binding_expression: boolean
89
119
  animation_files: boolean
90
- pose_mode: boolean
91
- display_mode: boolean
92
- animation_mode: boolean
93
120
  texture_folder: boolean
121
+ edit_mode?: boolean
122
+ paint_mode?: boolean
123
+ display_mode?: boolean
124
+ animation_mode?: boolean
125
+ pose_mode?: boolean
94
126
 
127
+ cube_size_limiter?: CubeSizeLimiter
95
128
  /**
96
129
  * Selects the format
97
130
  */
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
 
@@ -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
  /**
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
-
19
+ interface MenuOptions {
20
+ onOpen?: (position: MouseEvent | HTMLElement, context?: any) => void
21
+ onClose?: () => void
22
+ keep_open?: boolean
23
+ searchable?: boolean
24
+ }
20
25
  /**
21
26
  * Creates a new context menu
22
27
  */
23
28
  declare class Menu extends Deletable {
24
- constructor(template: MenuItem[])
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
@@ -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
+ }