Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/interface/panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ export class Panel extends EventSystem {
let panels: Panel[] = [];
for (let id in Panels) {
let panel = Panels[id] as Panel;
if (panel.attached_to == this.id && Condition(panel) && panel != this) {
if (panel.attached_to == this.id && Condition(!!panel) && panel != this) {
panels.push(panel);
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/io/formats/fbx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1447,7 +1447,7 @@ BARS.defineActions(function() {
codec.export_action = new Action('export_fbx', {
icon: 'icon-fbx',
category: 'file',
condition: () => Project,
condition: () => !!Project,
click: function () {
codec.export()
}
Expand Down
8 changes: 4 additions & 4 deletions js/io/formats/skin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export const skin_dialog = new Dialog({
bedrock_edition: 'Bedrock Edition',
},
condition(form: Record<string, FormResultValue>) {
return skin_presets[form.model as string].model_bedrock;
return !!skin_presets[form.model as string].model_bedrock;
}
},
variant: {
Expand All @@ -429,7 +429,7 @@ export const skin_dialog = new Dialog({
return (selected_model && skin_presets[selected_model].variants) || {}
},
condition(form) {
return skin_presets[form.model].variants;
return !!skin_presets[form.model].variants;
}
},
resolution: {label: 'dialog.create_texture.resolution', type: 'select', value: 1, options: {
Expand Down Expand Up @@ -588,7 +588,7 @@ BARS.defineActions(function() {
new Action('convert_minecraft_skin_variant', {
icon: 'compare_arrows',
category: 'edit',
condition: {formats: ['skin'], method: () => Group.all.find(g => g.name == 'Right Arm')},
condition: {formats: ['skin'], method: () => !!Group.all.find(g => g.name == 'Right Arm')},
click() {
let is_slim = Cube.all.find(c => c.name.match(/arm/i)).size(0) == 3;
new Dialog('convert_minecraft_skin_variant', {
Expand Down Expand Up @@ -689,7 +689,7 @@ BARS.defineActions(function() {
new Action('export_minecraft_skin', {
icon: 'icon-player',
category: 'file',
condition: () => Format == format && Texture.all[0],
condition: () => Format == format && !!Texture.all[0],
click: function () {
Texture.all[0].save(true);
}
Expand Down
6 changes: 3 additions & 3 deletions js/io/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BARS.defineActions(function() {
dialog.setFormValues({tags});
}
}},
animations: {label: 'dialog.sketchfab_uploader.animations', value: true, type: 'checkbox', condition: (Format.animation_mode && Animator.animations.length)},
animations: {label: 'dialog.sketchfab_uploader.animations', value: true, type: 'checkbox', condition: (Format.animation_mode && !!Animator.animations.length)},
draft: {label: 'dialog.sketchfab_uploader.draft', type: 'checkbox', value: true},
divider: '_',
private: {label: 'dialog.sketchfab_uploader.private', type: 'checkbox'},
Expand Down Expand Up @@ -151,15 +151,15 @@ BARS.defineActions(function() {
new Action('upload_sketchfab', {
icon: 'icon-sketchfab',
category: 'file',
condition: () => Project && Outliner.elements.length,
condition: () => Project && !!Outliner.elements.length,
click() {
uploadSketchfabModel()
}
})

new Action('share_model', {
icon: 'share',
condition: () => Project && Outliner.elements.length,
condition: () => Project && !!Outliner.elements.length,
async click() {
let thumbnail = await new Promise(resolve => {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion js/modeling/mesh/set_vertex_weights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ArmatureBone } from "../../outliner/types/armature_bone";

new Action('set_vertex_weights', {
icon: 'weight',
condition: {modes: ['edit'], method: () => (Mesh.selected[0]?.getArmature() && Mesh.selected[0].getSelectedVertices().length)},
condition: {modes: ['edit'], method: () => !!(Mesh.selected[0]?.getArmature() && Mesh.selected[0].getSelectedVertices().length)},
click() {
let mesh = Mesh.selected[0];
let selected_vertices = mesh.getSelectedVertices();
Expand Down
2 changes: 1 addition & 1 deletion js/modeling/weight_paint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ new Tool('weight_brush', {
transformerMode: 'hidden',
selectElements: false,
modes: ['edit'],
condition: {modes: ['edit'], method: () => Armature.all.length},
condition: {modes: ['edit'], method: () => !!Armature.all.length},

onCanvasClick(data: CanvasClickData) {
let element = 'element' in data && data.element;
Expand Down
2 changes: 1 addition & 1 deletion js/outliner/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ new Property(Collection, 'string', 'model_identifier', {
});
new Property(Collection, 'string', 'export_codec');
new Property(Collection, 'string', 'export_path', {
condition: (collection: Collection) => (isApp && collection.export_codec),
condition: (collection: Collection) => (isApp && !!collection.export_codec),
inputs: {
dialog: {
input: {
Expand Down
4 changes: 2 additions & 2 deletions js/outliner/element_panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Interface.definePanels(function() {
modes: ['edit', 'pose'],
method: () => !(Blockbench.isMobile && Settings.get('status_bar_transform_sliders'))
},
display_condition: () => Outliner.selected.length || Group.first_selected,
display_condition: () => !!(Outliner.selected.length || Group.first_selected),
min_height: 90,
default_position: {
slot: 'right_bar',
Expand All @@ -31,7 +31,7 @@ Interface.definePanels(function() {
let element_properties_panel = new Panel('element', {
icon: 'fas.fa-cube',
condition: {modes: ['edit']},
display_condition: () => Outliner.selected.length || Group.first_selected,
display_condition: () => !!(Outliner.selected.length || Group.first_selected),
default_position: {
slot: 'right_bar',
float_position: [0, 0],
Expand Down
12 changes: 6 additions & 6 deletions types/custom/util.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// <reference types="./blockbench"/>
type ConditionResolvable =
type ConditionResolvable<Context extends any = any> =
| undefined
| boolean
| any
| ((context: any) => any)
| ((context: Context) => boolean)
| Partial<{
modes: string[]
formats: string[]
Expand All @@ -23,16 +22,17 @@ type ConditionResolvable =
null_any?: boolean
texture_mesh?: boolean
outliner?: boolean
spline?: boolean
}
project: boolean
method(context: any): boolean
method(context: Context): boolean
}>

/**
* Tests if a condition is truthy of falsy. Returns true if the condition is unspecified
* Tests if a condition is truthy or falsy. Returns true if the condition is unspecified
* @param condition Boolean, function, any or anything else
*/
declare function Condition(condition: ConditionResolvable): boolean
declare function Condition<Context extends any = any>(condition: ConditionResolvable<Context>, context?: Context): boolean

/**
* Wrapper for anys that tells the custom JSON exporter to write in one line
Expand Down