import { Color } from "./color" ; import { Gradient } from "./gradient" ; import { Image } from "./image" ; export enum PropertyType { Float = "float" , Int = "int" , Bool = "bool" , Color = "color" , Enum = "enum" , String = "string" , Gradient = "gradient" , Image = "image" } export class PropertyGroup { name : string = "" ; properties : Property [ ] = [ ] ; collapsed : boolean = true ; add ( prop ) { this . properties . push ( prop ) ; prop . group = this ; } } export class Property { public name : string ; public displayName : string ; public type : string ; public group : PropertyGroup ; public getValue ( ) { return null ; } public setValue ( val , completeCallback = null ) { } public clone ( ) { return null ; } } export interface IPropertyHolder { properties : Property [ ] ; propertyGroups : PropertyGroup [ ] ; setProperty ( name , value ) ; } export class FloatProperty extends Property { value : number ; minValue = 0 ; maxValue = 1 ; step = 1 ; public constructor ( name , displayName , value , step = 1 ) { super ( ) ; this . name = name ; this . displayName = displayName ; this . value = value ; this . step = step ; this . type = PropertyType . Float ; } public getValue ( ) { return this . value ; } public setValue ( val ) { this . value = val ; } public clone ( ) { const prop = new FloatProperty ( this . name , this . displayName , this . value , this . step ) ; prop . minValue = this . minValue ; prop . maxValue = this . maxValue ; return prop ; } public copyValuesFrom ( prop ) { this . minValue = prop . minValue ; this . maxValue = prop . maxValue ; this . value = prop . value ; this . step = prop . step ; } } export class IntProperty extends Property { value : number ; minValue = 0 ; maxValue = 100 ; step = 1 ; public constructor ( name , displayName , value , step = 1 ) { super ( ) ; this . name = name ; this . displayName = displayName ; this . value = value ; this . step = step ; this . type = PropertyType . Int ; } public getValue ( ) { return this . value ; } public setValue ( val ) { this . value = val ; } public clone ( ) { const prop = new IntProperty ( this . name , this . displayName , this . value , this . step ) ; prop . minValue = this . minValue ; prop . maxValue = this . maxValue ; return prop ; } public copyValuesFrom ( prop ) { this . minValue = prop . minValue ; this . maxValue = prop . maxValue ; this . value = prop . value ; this . step = prop . step ; } } export class BoolProperty extends Property { value : boolean ; public constructor ( name , displayName , value ) { super ( ) ; this . name = name ; this . displayName = displayName ; this . value = value ; this . type = PropertyType . Bool ; } public getValue ( ) { return this . value ; } public setValue ( val ) { this . value = val ; } public clone ( ) { const prop = new BoolProperty ( this . name , this . displayName , this . value ) ; return prop ; } public copyValuesFrom ( prop ) { this . value = prop . value ; } } export class EnumProperty extends Property { values : string [ ] ; index = 0 ; public constructor ( name , displayName , values ) { super ( ) ; this . name = name ; this . displayName = displayName ; this . values = values ; this . type = PropertyType . Enum ; } public getValues ( ) { return this . values ; } public getValue ( ) { return this . index ; } public setValue ( val ) { this . index = val ; } public clone ( ) { const prop = new EnumProperty ( this . name , this . displayName , this . values . slice ( 0 ) ) ; prop . index = this . index ; return prop ; } public copyValuesFrom ( prop ) { this . values = prop . values ; this . index = prop . index ; } } export class ColorProperty extends Property { value : Color ; public constructor ( name , displayName , value ) { super ( ) ; this . name = name ; this . displayName = displayName ; this . value = value ; this . type = PropertyType . Color ; } public getValue ( ) { return this . value ; } public setValue ( val ) { if ( val instanceof Color ) this . value = val ; else if ( typeof val == "string" ) this . value = Color . parse ( val ) ; else if ( typeof val == "object" ) { const value = new Color ( ) ; value . r = val . r || 0 ; value . g = val . g || 0 ; value . b = val . b || 0 ; value . a = val . a || 1.0 ; this . value = value ; } } public clone ( ) { const prop = new ColorProperty ( this . name , this . displayName , this . value ) ; return prop ; } public copyValuesFrom ( prop ) { this . setValue ( prop . value ) ; } } export class StringProperty extends Property { value : string ; isMultiline : boolean ; public constructor ( name , displayName , value = "" , isMultiline = false ) { super ( ) ; this . name = name ; this . displayName = displayName ; this . value = value ; this . type = PropertyType . String ; this . isMultiline = isMultiline ; } public getValue ( ) { return this . value ; } public setValue ( val ) { this . value = val ; } public clone ( ) { const prop = new StringProperty ( this . name , this . displayName , this . value ) ; return prop ; } public copyValuesFrom ( prop ) { this . value = prop . value ; } } export class GradientProperty extends Property { value : Gradient ; public constructor ( name , displayName , value ) { super ( ) ; this . name = name ; this . displayName = displayName ; this . value = value ; this . type = PropertyType . Gradient ; } public getValue ( ) { return this . value ; } public setValue ( val ) { this . value = Gradient . parse ( val ) ; } public clone ( ) { const prop = new GradientProperty ( this . name , this . displayName , this . value . clone ( ) ) ; return prop ; } public copyValuesFrom ( prop ) { this . setValue ( prop . value . clone ( ) ) ; } } export class ImageProperty extends Property { value : Image ; public constructor ( name , displayName , value = null ) { super ( ) ; this . name = name ; this . displayName = displayName ; this . value = value ; this . type = PropertyType . Image ; } public getValue ( ) { return this . value ; } public setValue ( val , completeCallback = null ) { if ( val instanceof Image ) { this . value = val ; completeCallback ( ) ; } else { let image = Image . empty ( ) ; image . deserialize ( val , completeCallback ) ; this . value = image ; } } public clone ( ) { const prop = new ImageProperty ( this . name , this . displayName , this . value . clone ( ) ) ; return prop ; } public copyValuesFrom ( prop ) { this . value = prop . value . clone ( ) ; } }