From 23b0ef330e7db7a89fde24a5a6fb27f134a6a280 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sun, 12 Mar 2023 11:57:06 +0100 Subject: [PATCH] Introduce enum property type --- js/animations/keyframe.js | 2 +- js/outliner/cube.js | 2 +- js/property.js | 8 ++++++++ js/texturing/textures.js | 6 +++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/js/animations/keyframe.js b/js/animations/keyframe.js index 2775321a..63f5e5a5 100644 --- a/js/animations/keyframe.js +++ b/js/animations/keyframe.js @@ -546,7 +546,7 @@ class Keyframe { new Property(Keyframe, 'number', 'time') new Property(Keyframe, 'number', 'color', {default: -1}) new Property(Keyframe, 'boolean', 'uniform', {condition: keyframe => keyframe.channel == 'scale', default: settings.uniform_keyframe.value}) - new Property(Keyframe, 'string', 'interpolation', {default: 'linear'}) + new Property(Keyframe, 'enum', 'interpolation', {default: 'linear'}) new Property(Keyframe, 'boolean', 'bezier_linked', {default: true}) new Property(Keyframe, 'vector', 'bezier_left_time', {default: [-0.1, -0.1, -0.1]}); new Property(Keyframe, 'vector', 'bezier_left_value'); diff --git a/js/outliner/cube.js b/js/outliner/cube.js index 3ba403c4..9f51d5ef 100644 --- a/js/outliner/cube.js +++ b/js/outliner/cube.js @@ -52,7 +52,7 @@ class CubeFace extends Face { } new Property(CubeFace, 'number', 'rotation', {default: 0}); new Property(CubeFace, 'number', 'tint', {default: -1}); -new Property(CubeFace, 'string', 'cullface', )//{merge_validation: (val) => (UVEditor.cube_faces.includes(val) || val == '')}); +new Property(CubeFace, 'enum', 'cullface', {values: ['', 'north', 'south', 'west', 'east', 'up', 'down']}); new Property(CubeFace, 'string', 'material_name'); new Property(CubeFace, 'boolean', 'enabled', {default: true}); diff --git a/js/property.js b/js/property.js index c301bc23..2ca7f47e 100644 --- a/js/property.js +++ b/js/property.js @@ -14,6 +14,7 @@ class Property { } else { switch (this.type) { case 'string': this.default = ''; break; + case 'enum': this.default = options.values?.[0] || ''; break; case 'molang': this.default = '0'; break; case 'number': this.default = 0; break; case 'boolean': this.default = false; break; @@ -25,6 +26,7 @@ class Property { } switch (this.type) { case 'string': this.isString = true; break; + case 'enum': this.isEnum = true; break; case 'molang': this.isMolang = true; break; case 'number': this.isNumber = true; break; case 'boolean': this.isBoolean = true; break; @@ -44,6 +46,9 @@ class Property { } }) } + if (this.isEnum) { + this.enum_values = options.values; + } if (typeof options.merge == 'function') this.merge = options.merge; if (typeof options.reset == 'function') this.reset = options.reset; @@ -72,6 +77,9 @@ class Property { if (this.isString) { Merge.string(instance, data, this.name, this.merge_validation) } + else if (this.isEnum) { + Merge.string(instance, data, this.name, val => (!this.enum_values || this.enum_values.includes(val))); + } else if (this.isNumber) { Merge.number(instance, data, this.name) } diff --git a/js/texturing/textures.js b/js/texturing/textures.js index e8a1f396..c688fac2 100644 --- a/js/texturing/textures.js +++ b/js/texturing/textures.js @@ -1614,11 +1614,11 @@ class Texture { new Property(Texture, 'string', 'namespace') new Property(Texture, 'string', 'id') new Property(Texture, 'boolean', 'particle') - new Property(Texture, 'string', 'render_mode', {default: 'default'}) - new Property(Texture, 'string', 'render_sides', {default: 'auto'}) + new Property(Texture, 'enum', 'render_mode', {default: 'default'}) + new Property(Texture, 'enum', 'render_sides', {default: 'auto'}) new Property(Texture, 'number', 'frame_time', {default: 1}) - new Property(Texture, 'string', 'frame_order_type', {default: 'loop'}) + new Property(Texture, 'enum', 'frame_order_type', {default: 'loop', values: ['custom', 'loop', 'backwards', 'back_and_forth']}) new Property(Texture, 'string', 'frame_order') new Property(Texture, 'boolean', 'frame_interpolate')