<commit_before>pc.extend(pc.fw, function() {

    var ParticleSystemComponentSystem = function ParticleSystemComponentSystem(context) {
        this.id = 'particlesystem';
        this.description = "Updates and renders particle system in the scene.";
        context.systems.add(this.id, this);

        this.ComponentType = pc.fw.ParticleSystemComponent;
        this.DataType = pc.fw.ParticleSystemComponentData;

        this.schema = [{
                name: "enabled",
                displayName: "Enabled",
                description: "Enables or disables the component",
                type: "boolean",
                defaultValue: true
            }, {
                name: "numParticles",
                displayName: "Particle count",
                description: "Total number of particles allocated",
                type: "number",
                defaultValue: 30,
                options: {
                    min: 1,
                    max: 4096,
                    step: 1
                }
            }, {
                name: "lifetime",
                displayName: "Lifetime",
                description: "The lifetime of each particle in seconds",
                type: "number",
                defaultValue: 5,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "lifetime2",
                displayName: "Lifetime 2",
                description: "",
                type: "number",
                exposed: false,
                defaultValue: 5,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "rate",
                displayName: "Emission Rate",
                description: "Delay between emission of each particle in seconds",
                type: "number",
                defaultValue: 0.05,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "rate2",
                displayName: "Emission Rate 2",
                description: "",
                type: "number",
                defaultValue: 0.05,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "startAngle",
                displayName: "Start Angle",
                description: "",
                type: "number",
                defaultValue: 0.0,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "startAngle2",
                displayName: "Start Angle 2",
                description: "",
                type: "number",
                defaultValue: 0.0,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "oneShot",
                displayName: "One Shot",
                description: "Disables looping",
                type: "boolean",
                defaultValue: false,
            }, {
                name: "maxEmissionTime",
                displayName: "Max emission time",
                description: "Limits time for one-shot emission. Should be only used in case of high Speed Divergence",
                type: "number",
                defaultValue: 15.0,
                options: {
                    min: 0,
                    max: 600,
                    step: 0.5
                },
                filter: {
                    oneShot: true
                }
            }, {
                name: "preWarm",
                displayName: "Pre Warm",
                description: "Starts particles in the middle of simulation",
                type: "boolean",
                defaultValue: false,
                filter: {
                    oneShot: false
                }
            }, {
                name: "lighting",
                displayName: "Lighting",
                description: "Enables particle lighting; Only ambient and directional lights are used",
                type: "boolean",
                defaultValue: false,
            }, {
                name: "halfLambert",
                displayName: "Half-Lambert",
                description: "Uses Half-Lambert shading instead of Lambert, for softer lighting.",
                type: "boolean",
                defaultValue: false,
                filter: {
                    lighting: true
                }
            }, {
                name: "intensity",
                displayName: "Color intensity",
                description: "Controls the intensity of the colors for each particle",
                type: "number",
                defaultValue: 1,
                options: {
                    min: 0,
                    max: 10,
                    step: 0.1
                }
            }, {
                name: "depthTest",
                displayName: "Depth Test",
                description: "Enables hardware depth testing; don't use it for semi-transparent particles",
                type: "boolean",
                defaultValue: false,
            }, {
                name: "depthSoftening",
                displayName: "Depth Softening",
                description: "Softens particle intersections with scene geometry",
                type: "number",
                defaultValue: 0,
                options: {
                    min: 0,
                    max: 1,
                    step: 0.01
                }
            }, {
                name: "sort",
                displayName: "Sorting Mode",
                description: "How to sort particles; Only works in CPU mode",
                type: "enumeration",
                options: {
                    enumerations: [{
                        name: 'None',
                        value: pc.scene.PARTICLES_SORT_NONE
                    }, {
                        name: 'Camera Distance',
                        value: pc.scene.PARTICLES_SORT_DISTANCE
                    }, {
                        name: 'Newer First',
                        value: pc.scene.PARTICLES_SORT_NEWER_FIRST
                    }, {
                        name: 'Older First',
                        value: pc.scene.PARTICLES_SORT_OLDER_FIRST
                    }]
                },
                defaultValue: 0,
            }, {
                name: "blendType",
                displayName: "Blending Mode",
                description: "How to blend particles",
                type: "enumeration",
                options: {
                    enumerations: [{
                        name: 'Premultiplied Alpha',
                        value: pc.scene.BLEND_PREMULTIPLIED
                    }, {
                        name: 'Alpha',
                        value: pc.scene.BLEND_NORMAL
                    }, {
                        name: 'Add',
                        value: pc.scene.BLEND_ADDITIVE
                    }, {
                        name: 'Multiply',
                        value: pc.scene.BLEND_MULTIPLICATIVE
                    }]
                },
                defaultValue: pc.scene.BLEND_PREMULTIPLIED,
            }, {
                name: "stretch",
                displayName: "Stretch",
                description: "Stretch particles in the direction of motion",
                type: "number",
                defaultValue: 0,
                options: {
                    min: 0,
                    max: 32,
                    step: 0.25
                }
            }, {
                name: "spawnBounds",
                displayName: "Spawn Bounds",
                description: "Defines an AABB in which particles are allowed to spawn",
                type: "vector",
                defaultValue: [0, 0, 0]
            }, {
                name: "wrap",
                displayName: "Wrap",
                description: "Set to true to wrap particles around the camera. Used for infinite atmospheric effect like rain or mist.",
                type: 'boolean',
                defaultValue: false
            }, {
                name: "wrapBounds",
                displayName: "Wrap Bounds",
                description: "AABB around to camera to wrap particles. Used for infinite atmospheric effect like rain or mist.",
                type: "vector",
                filter: {
                    wrap: true
                },
                defaultValue: [0, 0, 0]
            }, {
                name: "colorMapAsset",
                displayName: "Color Map",
                description: "Color map used for each particle, with alpha channel",
                type: "asset",
                options: {
                    max: 1,
                    type: "texture"
                },
                defaultValue: null
            }, {
                name: "normalMapAsset",
                displayName: "Normal map",
                description: "Normal map used for each particle",
                type: "asset",
                options: {
                    max: 1,
                    type: "texture"
                },
                defaultValue: null
            }, {
                name: "mesh",
                displayName: "Particle mesh",
                description: "Mesh to use as particle; Will be quad, if not set",
                type: "asset",
                options: {
                    max: 1,
                    type: "model"
                },
                defaultValue: null
            }, {
                name: 'localVelocityGraph',
                displayName: "Local Velocity",
                description: "A graph that defines the local velocity of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 0], [0, 0], [0, 0]]
                },
                options: {
                    curveNames: ['X', 'Y', 'Z']
                }
            }, {
                name: 'localVelocityGraph2',
                displayName: "Local Velocity 2",
                description: "A graph that defines the local velocity of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 0], [0, 0], [0, 0]]
                },
                options: {
                    curveNames: ['X', 'Y', 'Z']
                }
            }, {
                name: 'velocityGraph',
                displayName: "Velocity",
                description: "A graph that defines the world velocity of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 0], [0, 1], [0, 0]]
                },
                options: {
                    curveNames: ['X', 'Y', 'Z']
                }
            }, {
                name: 'velocityGraph2',
                displayName: "Velocity 2",
                description: "A graph that defines the world velocity of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 0], [0, 1], [0, 0]]
                },
                options: {
                    curveNames: ['X', 'Y', 'Z']
                }
            }, {
                name: 'rotationSpeedGraph',
                displayName: "Rotation Speed",
                description: "A graph that defines how fast particle rotates over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 0]
                },
                options: {
                    curveNames: ['Angle']
                }
            }, {
                name: 'rotationSpeedGraph2',
                displayName: "Rotation Speed 2",
                description: "A graph that defines how fast particle rotates over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 0]
                },
                options: {
                    curveNames: ['Angle']
                }
            }, {
                name: 'scaleGraph',
                displayName: "Scale",
                description: "A graph that defines the scale of particles over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 1]
                },
                options: {
                    curveNames: ['Scale'],
                    verticalAxisValue: 1
                }
            }, {
                name: 'scaleGraph2',
                displayName: "Scale 2",
                description: "A graph that defines the scale of particles over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 1]
                },
                options: {
                    curveNames: ['Scale'],
                    verticalAxisValue: 1
                }
            }, {
                name: 'colorGraph',
                displayName: "Color",
                description: "A graph that defines the color of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 1, 1, 1], [0, 1, 1, 1], [0, 1, 1, 1]],
                },
                options: {
                    curveNames: ['R', 'G', 'B'],
                    max: 1,
                    min: 0
                }
            }, {
                name: 'colorGraph2',
                displayName: "Color 2",
                description: "A graph that defines the color of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 1, 1, 1], [0, 1, 1, 1], [0, 1, 1, 1]],
                },
                options: {
                    curveNames: ['R', 'G', 'B'],
                    max: 1,
                    min: 0
                }
            }, {
                name: 'alphaGraph',
                displayName: "Opacity",
                description: "A graph that defines the opacity of particles over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 1],
                },
                options: {
                    curveNames: ['Opacity'],
                    max: 1,
                    min: 0
                }
            }, {
                name: 'alphaGraph2',
                displayName: "Opacity 2",
                description: "A graph that defines the opacity of particles over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 1],
                },
                options: {
                    curveNames: ['Opacity'],
                    max: 1,
                    min: 0
                }
            }, {
                name: "smoothness",
                displayName: "Smoothness",
                description: "Graph interpolation smoothness",
                type: "number",
                defaultValue: 4,
                options: {
                    min: 0,
                    max: 32,
                    step: 1
                }
            }, {
                name: 'camera',
                exposed: false
            }, {
                name: 'colorMap',
                exposed: false
            }, {
                name: 'normalMap',
                exposed: false
            }
        ];

        this.exposeProperties();

        this.propertyTypes = {};
        for (var i=0; i<this.schema.length; i++) {
            var s = this.schema[i];
            this.propertyTypes[s.name] = s.type;
        }

        this.on('remove', this.onRemove, this);
        pc.fw.ComponentSystem.on('update', this.onUpdate, this);
    };
    ParticleSystemComponentSystem = pc.inherits(ParticleSystemComponentSystem, pc.fw.ComponentSystem);

    pc.extend(ParticleSystemComponentSystem.prototype, {

        initializeComponentData: function(component, data, properties) {

            properties = [];
            var types = this.propertyTypes;
            var type;

            for (var prop in data) {
                if (data.hasOwnProperty(prop)) {
                    properties.push(prop);
                }

                if (types[prop] === 'vector') {
                    if (pc.type(data[prop]) === 'array') {
                        data[prop] = new pc.Vec3(data[prop]);
                    }
                } else if (types[prop] === 'curve') {
                    if (!(data[prop] instanceof pc.Curve)) {
                        type = data[prop].type;
                        data[prop] = new pc.Curve(data[prop].keys);
                        data[prop].type = type;
                    }
                } else if (types[prop] === 'curveset') {
                    if (!(data[prop] instanceof pc.CurveSet)) {
                        type = data[prop].type;
                        data[prop] = new pc.CurveSet(data[prop].keys);
                        data[prop].type = type;
                    }
                }
            }

            ParticleSystemComponentSystem._super.initializeComponentData.call(this, component, data, properties);
        },

        cloneComponent: function (entity, clone) {
            var source = entity.particlesystem.data;
            var schema = this.schema;

            var data = {};

            for (var i = 0, len = schema.length; i < len; i++) {
                var prop = schema[i];
                var sourceProp = source[prop.name];
                if (sourceProp instanceof pc.Vec3 ||
                    sourceProp instanceof pc.Curve ||
                    sourceProp instanceof pc.CurveSet) {

                    sourceProp = sourceProp.clone();
                    data[prop.name] = sourceProp;
                }
            }
            return this.addComponent(clone, data);
        },

        onUpdate: function(dt) {
            var components = this.store;
            var currentCamera;

            for (var id in components) {
                if (components.hasOwnProperty(id)) {
                    var c = components[id];
                    var data = c.data;

                    if (data.enabled && c.entity.enabled) {
                        var emitter = data.model.emitter;
                        // check if the emitter has no camera set or if the
                        // camera is disabled
                        var cameraEntity = data.camera;
                        var camera = cameraEntity ? cameraEntity.camera : null;
                        if (!cameraEntity || !camera || !camera.enabled) {

                            // if there is no valid camera then get the first enabled camera
                            if (!currentCamera) {
                                currentCamera = this.context.systems.camera.cameras[0];
                                if (currentCamera) {
                                    currentCamera = currentCamera.entity;
                                }
                            }

                            c.entity.particlesystem.camera = currentCamera;
                        }

                        emitter.addTime(dt);
                    }
                }
            }
        },

        onRemove: function(entity, data) {
            if (data.model) {
                this.context.scene.removeModel(data.model);
                entity.removeChild(data.model.getGraph());
                data.model = null;
            }
        }
    });

    return {
        ParticleSystemComponentSystem: ParticleSystemComponentSystem
    };
}());
<commit_msg>Added metadata to particle system curves to support between two curves editing in Designer<commit_after>pc.extend(pc.fw, function() {

    var ParticleSystemComponentSystem = function ParticleSystemComponentSystem(context) {
        this.id = 'particlesystem';
        this.description = "Updates and renders particle system in the scene.";
        context.systems.add(this.id, this);

        this.ComponentType = pc.fw.ParticleSystemComponent;
        this.DataType = pc.fw.ParticleSystemComponentData;

        this.schema = [{
                name: "enabled",
                displayName: "Enabled",
                description: "Enables or disables the component",
                type: "boolean",
                defaultValue: true
            }, {
                name: "numParticles",
                displayName: "Particle count",
                description: "Total number of particles allocated",
                type: "number",
                defaultValue: 30,
                options: {
                    min: 1,
                    max: 4096,
                    step: 1
                }
            }, {
                name: "lifetime",
                displayName: "Lifetime",
                description: "The lifetime of each particle in seconds",
                type: "number",
                defaultValue: 5,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "lifetime2",
                displayName: "Lifetime 2",
                description: "",
                type: "number",
                exposed: false,
                defaultValue: 5,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "rate",
                displayName: "Emission Rate",
                description: "Delay between emission of each particle in seconds",
                type: "number",
                defaultValue: 0.05,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "rate2",
                displayName: "Emission Rate 2",
                description: "",
                type: "number",
                defaultValue: 0.05,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "startAngle",
                displayName: "Start Angle",
                description: "",
                type: "number",
                defaultValue: 0.0,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "startAngle2",
                displayName: "Start Angle 2",
                description: "",
                type: "number",
                defaultValue: 0.0,
                options: {
                    min: 0,
                    step: 0.01
                }
            }, {
                name: "oneShot",
                displayName: "One Shot",
                description: "Disables looping",
                type: "boolean",
                defaultValue: false,
            }, {
                name: "maxEmissionTime",
                displayName: "Max emission time",
                description: "Limits time for one-shot emission. Should be only used in case of high Speed Divergence",
                type: "number",
                defaultValue: 15.0,
                options: {
                    min: 0,
                    max: 600,
                    step: 0.5
                },
                filter: {
                    oneShot: true
                }
            }, {
                name: "preWarm",
                displayName: "Pre Warm",
                description: "Starts particles in the middle of simulation",
                type: "boolean",
                defaultValue: false,
                filter: {
                    oneShot: false
                }
            }, {
                name: "lighting",
                displayName: "Lighting",
                description: "Enables particle lighting; Only ambient and directional lights are used",
                type: "boolean",
                defaultValue: false,
            }, {
                name: "halfLambert",
                displayName: "Half-Lambert",
                description: "Uses Half-Lambert shading instead of Lambert, for softer lighting.",
                type: "boolean",
                defaultValue: false,
                filter: {
                    lighting: true
                }
            }, {
                name: "intensity",
                displayName: "Color intensity",
                description: "Controls the intensity of the colors for each particle",
                type: "number",
                defaultValue: 1,
                options: {
                    min: 0,
                    max: 10,
                    step: 0.1
                }
            }, {
                name: "depthTest",
                displayName: "Depth Test",
                description: "Enables hardware depth testing; don't use it for semi-transparent particles",
                type: "boolean",
                defaultValue: false,
            }, {
                name: "depthSoftening",
                displayName: "Depth Softening",
                description: "Softens particle intersections with scene geometry",
                type: "number",
                defaultValue: 0,
                options: {
                    min: 0,
                    max: 1,
                    step: 0.01
                }
            }, {
                name: "sort",
                displayName: "Sorting Mode",
                description: "How to sort particles; Only works in CPU mode",
                type: "enumeration",
                options: {
                    enumerations: [{
                        name: 'None',
                        value: pc.scene.PARTICLES_SORT_NONE
                    }, {
                        name: 'Camera Distance',
                        value: pc.scene.PARTICLES_SORT_DISTANCE
                    }, {
                        name: 'Newer First',
                        value: pc.scene.PARTICLES_SORT_NEWER_FIRST
                    }, {
                        name: 'Older First',
                        value: pc.scene.PARTICLES_SORT_OLDER_FIRST
                    }]
                },
                defaultValue: 0,
            }, {
                name: "blendType",
                displayName: "Blending Mode",
                description: "How to blend particles",
                type: "enumeration",
                options: {
                    enumerations: [{
                        name: 'Premultiplied Alpha',
                        value: pc.scene.BLEND_PREMULTIPLIED
                    }, {
                        name: 'Alpha',
                        value: pc.scene.BLEND_NORMAL
                    }, {
                        name: 'Add',
                        value: pc.scene.BLEND_ADDITIVE
                    }, {
                        name: 'Multiply',
                        value: pc.scene.BLEND_MULTIPLICATIVE
                    }]
                },
                defaultValue: pc.scene.BLEND_PREMULTIPLIED,
            }, {
                name: "stretch",
                displayName: "Stretch",
                description: "Stretch particles in the direction of motion",
                type: "number",
                defaultValue: 0,
                options: {
                    min: 0,
                    max: 32,
                    step: 0.25
                }
            }, {
                name: "spawnBounds",
                displayName: "Spawn Bounds",
                description: "Defines an AABB in which particles are allowed to spawn",
                type: "vector",
                defaultValue: [0, 0, 0]
            }, {
                name: "wrap",
                displayName: "Wrap",
                description: "Set to true to wrap particles around the camera. Used for infinite atmospheric effect like rain or mist.",
                type: 'boolean',
                defaultValue: false
            }, {
                name: "wrapBounds",
                displayName: "Wrap Bounds",
                description: "AABB around to camera to wrap particles. Used for infinite atmospheric effect like rain or mist.",
                type: "vector",
                filter: {
                    wrap: true
                },
                defaultValue: [0, 0, 0]
            }, {
                name: "colorMapAsset",
                displayName: "Color Map",
                description: "Color map used for each particle, with alpha channel",
                type: "asset",
                options: {
                    max: 1,
                    type: "texture"
                },
                defaultValue: null
            }, {
                name: "normalMapAsset",
                displayName: "Normal map",
                description: "Normal map used for each particle",
                type: "asset",
                options: {
                    max: 1,
                    type: "texture"
                },
                defaultValue: null
            }, {
                name: "mesh",
                displayName: "Particle mesh",
                description: "Mesh to use as particle; Will be quad, if not set",
                type: "asset",
                options: {
                    max: 1,
                    type: "model"
                },
                defaultValue: null
            }, {
                name: 'localVelocityGraph',
                displayName: "Local Velocity",
                description: "A graph that defines the local velocity of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 0], [0, 0], [0, 0]],
                    betweenCurves: false
                },
                options: {
                    curveNames: ['X', 'Y', 'Z'],
                    secondCurve: 'localVelocityGraph2'
                }
            }, {
                name: 'localVelocityGraph2',
                displayName: "Local Velocity 2",
                description: "The second curve that defines the range of the localVelocityGraph",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 0], [0, 0], [0, 0]]
                },
                filter: {
                    always: false // hide from Designer but do expose it
                }
            }, {
                name: 'velocityGraph',
                displayName: "Velocity",
                description: "A graph that defines the world velocity of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 0], [0, 1], [0, 0]],
                    betweenCurves: false
                },
                options: {
                    curveNames: ['X', 'Y', 'Z'],
                    secondCurve: 'velocityGraph2'
                }
            }, {
                name: 'velocityGraph2',
                displayName: "Velocity 2",
                description: "The second curve that defines the range of the velocityGraph",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 0], [0, 1], [0, 0]]
                },
                options: {
                    curveNames: ['X', 'Y', 'Z']
                },
                filter: {
                    always: false // hide from Designer but do expose it
                }
            }, {
                name: 'rotationSpeedGraph',
                displayName: "Rotation Speed",
                description: "A graph that defines how fast particle rotates over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 0],
                    betweenCurves: false
                },
                options: {
                    curveNames: ['Angle'],
                    secondCurve: 'rotationSpeedGraph2'
                }
            }, {
                name: 'rotationSpeedGraph2',
                displayName: "Rotation Speed 2",
                description: "The second curve that defines the range of the rotationSpeedGraph",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 0]
                },
                options: {
                    curveNames: ['Angle']
                },
                filter: {
                    always: false
                }
            }, {
                name: 'scaleGraph',
                displayName: "Scale",
                description: "A graph that defines the scale of particles over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 1],
                    betweenCurves: false
                },
                options: {
                    curveNames: ['Scale'],
                    verticalAxisValue: 1,
                    secondCurve: 'scaleGraph2'
                }
            }, {
                name: 'scaleGraph2',
                displayName: "Scale 2",
                description: "The second curve that defines the range of scaleGraph",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 1]
                },
                options: {
                    curveNames: ['Scale'],
                    verticalAxisValue: 1
                },
                filter: {
                    always: false
                }
            }, {
                name: 'colorGraph',
                displayName: "Color",
                description: "A graph that defines the color of particles over time.",
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 1], [0, 1], [0, 1]],
                    betweenCurves: false
                },
                options: {
                    curveNames: ['R', 'G', 'B'],
                    max: 1,
                    min: 0
                }
            }, {
                name: 'colorGraph2',
                displayName: "Color 2",
                description: "A graph that defines the color of particles over time.",
                exposed: false, // not used at the moment
                type: "curveset",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [[0, 1, 1, 1], [0, 1, 1, 1], [0, 1, 1, 1]],
                },
                options: {
                    curveNames: ['R', 'G', 'B'],
                    max: 1,
                    min: 0
                }
            }, {
                name: 'alphaGraph',
                displayName: "Opacity",
                description: "A graph that defines the opacity of particles over time.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 1],
                    betweenCurves: false
                },
                options: {
                    curveNames: ['Opacity'],
                    max: 1,
                    min: 0,
                    secondCurve: 'alphaGraph2'
                }
            }, {
                name: 'alphaGraph2',
                displayName: "Opacity 2",
                description: "The second graph that defines the range of alphaGraph.",
                type: "curve",
                defaultValue: {
                    type: pc.CURVE_SMOOTHSTEP,
                    keys: [0, 1],
                },
                options: {
                    curveNames: ['Opacity'],
                    max: 1,
                    min: 0
                },
                filter: {
                    always: false
                }
            }, {
                name: "smoothness",
                displayName: "Smoothness",
                description: "Graph interpolation smoothness",
                type: "number",
                defaultValue: 4,
                options: {
                    min: 0,
                    max: 32,
                    step: 1
                }
            }, {
                name: 'camera',
                exposed: false
            }, {
                name: 'colorMap',
                exposed: false
            }, {
                name: 'normalMap',
                exposed: false
            }
        ];

        this.exposeProperties();

        this.propertyTypes = {};
        for (var i=0; i<this.schema.length; i++) {
            var s = this.schema[i];
            this.propertyTypes[s.name] = s.type;
        }

        this.on('remove', this.onRemove, this);
        pc.fw.ComponentSystem.on('update', this.onUpdate, this);
    };
    ParticleSystemComponentSystem = pc.inherits(ParticleSystemComponentSystem, pc.fw.ComponentSystem);

    pc.extend(ParticleSystemComponentSystem.prototype, {

        initializeComponentData: function(component, data, properties) {

            properties = [];
            var types = this.propertyTypes;
            var type;

            for (var prop in data) {
                if (data.hasOwnProperty(prop)) {
                    properties.push(prop);
                }

                if (types[prop] === 'vector') {
                    if (pc.type(data[prop]) === 'array') {
                        data[prop] = new pc.Vec3(data[prop]);
                    }
                } else if (types[prop] === 'curve') {
                    if (!(data[prop] instanceof pc.Curve)) {
                        type = data[prop].type;
                        data[prop] = new pc.Curve(data[prop].keys);
                        data[prop].type = type;
                    }
                } else if (types[prop] === 'curveset') {
                    if (!(data[prop] instanceof pc.CurveSet)) {
                        type = data[prop].type;
                        data[prop] = new pc.CurveSet(data[prop].keys);
                        data[prop].type = type;
                    }
                }
            }

            ParticleSystemComponentSystem._super.initializeComponentData.call(this, component, data, properties);
        },

        cloneComponent: function (entity, clone) {
            var source = entity.particlesystem.data;
            var schema = this.schema;

            var data = {};

            for (var i = 0, len = schema.length; i < len; i++) {
                var prop = schema[i];
                var sourceProp = source[prop.name];
                if (sourceProp instanceof pc.Vec3 ||
                    sourceProp instanceof pc.Curve ||
                    sourceProp instanceof pc.CurveSet) {

                    sourceProp = sourceProp.clone();
                    data[prop.name] = sourceProp;
                }
            }
            return this.addComponent(clone, data);
        },

        onUpdate: function(dt) {
            var components = this.store;
            var currentCamera;

            for (var id in components) {
                if (components.hasOwnProperty(id)) {
                    var c = components[id];
                    var data = c.data;

                    if (data.enabled && c.entity.enabled) {
                        var emitter = data.model.emitter;
                        // check if the emitter has no camera set or if the
                        // camera is disabled
                        var cameraEntity = data.camera;
                        var camera = cameraEntity ? cameraEntity.camera : null;
                        if (!cameraEntity || !camera || !camera.enabled) {

                            // if there is no valid camera then get the first enabled camera
                            if (!currentCamera) {
                                currentCamera = this.context.systems.camera.cameras[0];
                                if (currentCamera) {
                                    currentCamera = currentCamera.entity;
                                }
                            }

                            c.entity.particlesystem.camera = currentCamera;
                        }

                        emitter.addTime(dt);
                    }
                }
            }
        },

        onRemove: function(entity, data) {
            if (data.model) {
                this.context.scene.removeModel(data.model);
                entity.removeChild(data.model.getGraph());
                data.model = null;
            }
        }
    });

    return {
        ParticleSystemComponentSystem: ParticleSystemComponentSystem
    };
}());
<|endoftext|>


<commit_before>import reducer, { initialState } from '../reducer';
import * as actions from '../actions';

describe('reducer', () => {
  it('should return state for unknown action', () => {
    const mockState = { test: 'testItem' };
    const mockAction = { type: 'mystery-meat' };
    const result = reducer(mockState, mockAction);
    expect(result).toEqual(mockState);
  });

  it('should use initial state if state not provided', () => {
    const mockAction = { type: 'mystery-meat' };
    const result = reducer(undefined, mockAction);
    expect(result).toEqual(initialState);
  });

  it('should add new items on ADD_ITEM', () => {
    const state = {
      items: [
        { id: 1, content: 'first' },
        { id: 2, content: 'second' },
      ]
    }
    const mockAction = actions.addItem('third');
    const result = reducer(state, mockAction);
    expect(result.items).toHaveLength(3);
    expect(result.items[2].id).toEqual(3);
    expect(result.items[2].content).toEqual('third');
  });

  it('should remove items from the list REMOVE_ITEM', () => {
    const state = {
      items: [
        { id: 1, content: 'first' },
        { id: 2, content: 'second' },
      ]
    }
    const mockAction = actions.removeItem(1);
    const result = reducer(state, mockAction);
    expect(result.items).toHaveLength(1);
    expect(result.items[0].id).toEqual(2);
  });
});
<commit_msg>-Task 2. Add reducer test<commit_after>import reducer, { initialState } from '../reducer';
import * as actions from '../actions';

describe('reducer', () => {
  it('should return state for unknown action', () => {
    const mockState = { test: 'testItem' };
    const mockAction = { type: 'mystery-meat' };
    const result = reducer(mockState, mockAction);
    expect(result).toEqual(mockState);
  });

  it('should use initial state if state not provided', () => {
    const mockAction = { type: 'mystery-meat' };
    const result = reducer(undefined, mockAction);
    expect(result).toEqual(initialState);
  });

  it('should add new items on ADD_ITEM', () => {
    const state = {
      items: [
        { id: 1, content: 'first' },
        { id: 2, content: 'second' },
      ]
    }
    const mockAction = actions.addItem('third');
    const result = reducer(state, mockAction);
    expect(result.items).toHaveLength(3);
    expect(result.items[2].id).toEqual(3);
    expect(result.items[2].content).toEqual('third');
  });

  it('should remove items from the list REMOVE_ITEM', () => {
    const state = {
      items: [
        { id: 1, content: 'first' },
        { id: 2, content: 'second' },
      ]
    }
    const mockAction = actions.removeItem(1);
    const result = reducer(state, mockAction);
    expect(result.items).toHaveLength(1);
    expect(result.items[0].id).toEqual(2);
  });

  it('should toggle the value done by on the matching id item TOGGLE_DONE', () => {
    const state = {
      items: [
        { id: 1, content: 'first', done: false },
        { id: 2, content: 'second', done: false },
      ]
    }
    const mockAction = actions.toggleDone(1);
    let result = reducer(state, mockAction);
    expect(result.items[0].id).toEqual(1);
    expect(result.items[0].done).toBe(true);
  });
});
<|endoftext|>


<commit_before>module.exports = `
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <air:AirPriceReq
            AuthorizedBy="user" TraceId="{{requestId}}" TargetBranch="{{TargetBranch}}"
            CheckOBFees="false"
            FareRuleType="{{#if long}}long{{else}}short{{/if}}"
            xmlns:air="http://www.travelport.com/schema/air_v36_0"
            xmlns:com="http://www.travelport.com/schema/common_v36_0">
            <com:BillingPointOfSaleInfo OriginApplication="uAPI"/>
            <air:AirItinerary>
                {{#segments}}
                <air:AirSegment Key="{{@index}}" Group="0" ProviderCode="1G"
                                Carrier="{{airline}}"
                                CabinClass="{{serviceClass}}"
                                FlightNumber="{{flightNumber}}"
                                Origin="{{from}}"
                                Destination="{{to}}"
                                DepartureTime="{{departure}}"
                                ArrivalTime="{{arrival}}"
                                {{#if duration}}TravelTime="{{duration}}"{{/if}}
                                ClassOfService="{{bookingClass}}"
                                TravelOrder="{{@index}}" />
                    {{#if transfer}}
                    <air:Connection/>
                    {{/if}}
                {{/segments}}
            </air:AirItinerary>
            <com:SearchPassenger Key="P_0" Code="ADT" />
            {{#if hasFareBasis}}
            <air:AirPricingCommand>
                {{#segments}}
                <air:AirSegmentPricingModifiers AirSegmentRef="{{@index}}" FareBasisCode="{{fareBasisCode}}"/>
                {{/segments}}
            </air:AirPricingCommand>
            {{/if}}
            {{#if emulatePcc}}
            <com:OverridePCC ProviderCode="1G" PseudoCityCode="{{emulatePcc}}"/>
            {{/if}}
        </air:AirPriceReq>
    </soapenv:Body>
</soapenv:Envelope>
`;
<commit_msg>#266 revert AIR_FARE_RULES_REQUEST<commit_after>module.exports = `
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <air:AirFareRulesReq
            TraceId="test" AuthorizedBy="{{requestId}}" TargetBranch="{{TargetBranch}}"
            RetrieveProviderReservationDetails="false" FareRuleType="long"
            xmlns:air="http://www.travelport.com/schema/air_v36_0"
            xmlns:com="http://www.travelport.com/schema/common_v36_0"
            >
            <com:BillingPointOfSaleInfo OriginApplication="uAPI" xmlns:com="http://www.travelport.com/schema/common_v36_0"/>
            <air:FareRuleKey FareInfoRef="0" ProviderCode="1G">{{uapi_fare_rule_key}}</air:FareRuleKey>
            {{#each provider_cmds}}
            <air:AirFareDisplayRuleKey ProviderCode="1G">{{this}}</air:AirFareDisplayRuleKey>
            {{/each}}
            {{#if emulatePcc}}
            <com:OverridePCC ProviderCode="1G" PseudoCityCode="{{emulatePcc}}"/>
            {{/if}}
        </air:AirFareRulesReq>
    </soapenv:Body>
</soapenv:Envelope>
`;
<|endoftext|>


<commit_before>/*
 * L.Map.Keyboard is handling keyboard interaction with the map, enabled by default.
 */

L.Map.mergeOptions({
	keyboard: true,
	keyboardPanOffset: 80,
	keyboardZoomOffset: 1
});

L.Map.Keyboard = L.Handler.extend({

	keyCodes: {
		left:    [37],
		right:   [39],
		down:    [40],
		up:      [38],
		zoomIn:  [187, 107, 61, 171],
		zoomOut: [189, 109, 173]
	},

	initialize: function (map) {
		this._map = map;

		this._setPanOffset(map.options.keyboardPanOffset);
		this._setZoomOffset(map.options.keyboardZoomOffset);
	},

	addHooks: function () {
		var container = this._map._container;

		// make the container focusable by tabbing
		if (container.tabIndex === -1) {
			container.tabIndex = '0';
		}

		L.DomEvent.on(container, {
		    focus: this._onFocus,
		    blur: this._onBlur,
		    mousedown: this._onMouseDown
		}, this);

		this._map.on({
			focus: this._addHooks,
		    blur: this._removeHooks
		}, this);
	},

	removeHooks: function () {
		this._removeHooks();

		L.DomEvent.off(this._map._container, {
		    focus: this._onFocus,
		    blur: this._onBlur,
		    mousedown: this._onMouseDown
		}, this);

		this._map.off({
			focus: this._addHooks,
		    blur: this._removeHooks
		}, this);
	},

	_onMouseDown: function () {
		if (this._focused) { return; }

		var body = document.body,
		    docEl = document.documentElement,
		    top = body.scrollTop || docEl.scrollTop,
		    left = body.scrollLeft || docEl.scrollLeft;

		this._map._container.focus();

		window.scrollTo(left, top);
	},

	_onFocus: function () {
		this._focused = true;
		this._map.fire('focus');
	},

	_onBlur: function () {
		this._focused = false;
		this._map.fire('blur');
	},

	_setPanOffset: function (pan) {
		var keys = this._panKeys = {},
		    codes = this.keyCodes,
		    i, len;

		for (i = 0, len = codes.left.length; i < len; i++) {
			keys[codes.left[i]] = [-1 * pan, 0];
		}
		for (i = 0, len = codes.right.length; i < len; i++) {
			keys[codes.right[i]] = [pan, 0];
		}
		for (i = 0, len = codes.down.length; i < len; i++) {
			keys[codes.down[i]] = [0, pan];
		}
		for (i = 0, len = codes.up.length; i < len; i++) {
			keys[codes.up[i]] = [0, -1 * pan];
		}
	},

	_setZoomOffset: function (zoom) {
		var keys = this._zoomKeys = {},
		    codes = this.keyCodes,
		    i, len;

		for (i = 0, len = codes.zoomIn.length; i < len; i++) {
			keys[codes.zoomIn[i]] = zoom;
		}
		for (i = 0, len = codes.zoomOut.length; i < len; i++) {
			keys[codes.zoomOut[i]] = -zoom;
		}
	},

	_addHooks: function () {
		L.DomEvent.on(document, 'keydown', this._onKeyDown, this);
	},

	_removeHooks: function () {
		L.DomEvent.off(document, 'keydown', this._onKeyDown, this);
	},

	_onKeyDown: function (e) {
		if (e.altKey || e.ctrlKey || e.shiftKey || e.metaKey) { return; }

		var key = e.keyCode,
		    map = this._map;

		if (key in this._panKeys) {

			if (map._panAnim && map._panAnim._inProgress) { return; }

			map.panBy(this._panKeys[key]);

			if (map.options.maxBounds) {
				map.panInsideBounds(map.options.maxBounds);
			}

		} else if (key in this._zoomKeys) {
			map.setZoom(map.getZoom() + this._zoomKeys[key]);

		} else {
			return;
		}

		L.DomEvent.stop(e);
	}
});

L.Map.addInitHook('addHandler', 'keyboard', L.Map.Keyboard);
<commit_msg>allow shift key to be active<commit_after>/*
 * L.Map.Keyboard is handling keyboard interaction with the map, enabled by default.
 */

L.Map.mergeOptions({
	keyboard: true,
	keyboardPanOffset: 80,
	keyboardZoomOffset: 1
});

L.Map.Keyboard = L.Handler.extend({

	keyCodes: {
		left:    [37],
		right:   [39],
		down:    [40],
		up:      [38],
		zoomIn:  [187, 107, 61, 171],
		zoomOut: [189, 109, 173]
	},

	initialize: function (map) {
		this._map = map;

		this._setPanOffset(map.options.keyboardPanOffset);
		this._setZoomOffset(map.options.keyboardZoomOffset);
	},

	addHooks: function () {
		var container = this._map._container;

		// make the container focusable by tabbing
		if (container.tabIndex === -1) {
			container.tabIndex = '0';
		}

		L.DomEvent.on(container, {
		    focus: this._onFocus,
		    blur: this._onBlur,
		    mousedown: this._onMouseDown
		}, this);

		this._map.on({
			focus: this._addHooks,
		    blur: this._removeHooks
		}, this);
	},

	removeHooks: function () {
		this._removeHooks();

		L.DomEvent.off(this._map._container, {
		    focus: this._onFocus,
		    blur: this._onBlur,
		    mousedown: this._onMouseDown
		}, this);

		this._map.off({
			focus: this._addHooks,
		    blur: this._removeHooks
		}, this);
	},

	_onMouseDown: function () {
		if (this._focused) { return; }

		var body = document.body,
		    docEl = document.documentElement,
		    top = body.scrollTop || docEl.scrollTop,
		    left = body.scrollLeft || docEl.scrollLeft;

		this._map._container.focus();

		window.scrollTo(left, top);
	},

	_onFocus: function () {
		this._focused = true;
		this._map.fire('focus');
	},

	_onBlur: function () {
		this._focused = false;
		this._map.fire('blur');
	},

	_setPanOffset: function (pan) {
		var keys = this._panKeys = {},
		    codes = this.keyCodes,
		    i, len;

		for (i = 0, len = codes.left.length; i < len; i++) {
			keys[codes.left[i]] = [-1 * pan, 0];
		}
		for (i = 0, len = codes.right.length; i < len; i++) {
			keys[codes.right[i]] = [pan, 0];
		}
		for (i = 0, len = codes.down.length; i < len; i++) {
			keys[codes.down[i]] = [0, pan];
		}
		for (i = 0, len = codes.up.length; i < len; i++) {
			keys[codes.up[i]] = [0, -1 * pan];
		}
	},

	_setZoomOffset: function (zoom) {
		var keys = this._zoomKeys = {},
		    codes = this.keyCodes,
		    i, len;

		for (i = 0, len = codes.zoomIn.length; i < len; i++) {
			keys[codes.zoomIn[i]] = zoom;
		}
		for (i = 0, len = codes.zoomOut.length; i < len; i++) {
			keys[codes.zoomOut[i]] = -zoom;
		}
	},

	_addHooks: function () {
		L.DomEvent.on(document, 'keydown', this._onKeyDown, this);
	},

	_removeHooks: function () {
		L.DomEvent.off(document, 'keydown', this._onKeyDown, this);
	},

	_onKeyDown: function (e) {
		if (e.altKey || e.ctrlKey || e.metaKey) { return; }

		var key = e.keyCode,
		    map = this._map;

		if (key in this._panKeys) {

			if (map._panAnim && map._panAnim._inProgress) { return; }

			map.panBy(this._panKeys[key]);

			if (map.options.maxBounds) {
				map.panInsideBounds(map.options.maxBounds);
			}

		} else if (key in this._zoomKeys) {
			map.setZoom(map.getZoom() + this._zoomKeys[key]);

		} else {
			return;
		}

		L.DomEvent.stop(e);
	}
});

L.Map.addInitHook('addHandler', 'keyboard', L.Map.Keyboard);
<|endoftext|>


<commit_before>var e = module.exports = {};

const fs = require('fs');
const path = require('path');

e.init = () => {
    e.category = bu.CommandType.CAT;
};

e.requireCtx = require;

e.isCommand = true;
e.hidden = false;
e.usage = '';
e.info = '';

e.execute = async function(msg, words) {
    if (msg.author.id == bu.CAT_ID) {
        await bot.sendChannelTyping(msg.channel.id);
        if (words[1]) {
            switch (words[1].toLowerCase()) {
                case 'add':
                    if (msg.mentions.length > 0 && words[2]) {
                        let ids = msg.mentions.map(u => u.id);
                        await r.db('blargdb').table('markovs').insert({
                            userid: ids.length == 1 ? ids[0] || ids,
                            id: words[2].toLowerCase()
                        });
                        bu.send(msg, 'Added.');
                    } else {
                        bu.send(msg, 'Nope.');
                    }
                    break;
                case 'remove':
                    if (words[2]) {
                        await r.db('blargdb').table('markovs').get(words[2].toLowerCase()).delete();
                        bu.send(msg, 'Removed.');
                    } else {
                        bu.send(msg, 'Nope.');
                    }
                    break;
                case 'list':
                    let things = await r.db('blargdb').table('markovs').withFields('id');
                    bu.send(msg, things.map(t => t.id).join('\n'));
                    break;
                default:
                    let markov = await r.db('blargdb').table('markovs').get(words[1]);
                    if (markov) {
                        genlogs(msg, markov.userid, markov.id);
                    }
                    break;
            }

        } else {
            let catMsgs = await r.table('catchat').orderBy('msgid');
            let content = [];
            for (let message of catMsgs) {
                if (message.guildid != '197529405659021322' && message.nsfw == 0)
                    content.push(message.content);
            }
            fs.writeFile(path.join(__dirname, '..', '..', 'catbot', 'cat.json'),
                JSON.stringify(content, null, 2), (err) => {
                    if (err) bu.send(msg, err);
                    bu.send(msg, 'Done!');
                });
        }
    }
};

async function genlogs(msg, id, name) {
    let msg2 = await bu.send(msg, 'Performing query...');
    let msgs;
    if (Array.isArray(id)) {
        id.push({
            index: 'userid'
        });
        msgs = await r.db('blargdb').table('chatlogs').getAll(id[0], id[1], id[2]);
    } else
        msgs = await r.db('blargdb').table('chatlogs').getAll(id, {
            index: 'userid'
        });
    await msg2.edit('Generating array...');
    let content = [];
    for (let message of msgs) {
        content.push(message.content);
    }
    let userId;
    if (Array.isArray(id)) userId = id[0];
    else userId = id;
    msg2.edit('Writing file...');
    fs.writeFile(path.join(__dirname, '..', '..', 'catbot', 'jsons', userId + '.json'),
        JSON.stringify({
            name: name,
            lines: content
        }, null, 2), (err) => {
            if (err) bu.send(msg, err);
            msg2.edit('Done.');
        });
}<commit_msg>aaaaaa why am I so bad at this<commit_after>var e = module.exports = {};

const fs = require('fs');
const path = require('path');

e.init = () => {
    e.category = bu.CommandType.CAT;
};

e.requireCtx = require;

e.isCommand = true;
e.hidden = false;
e.usage = '';
e.info = '';

e.execute = async function(msg, words) {
    if (msg.author.id == bu.CAT_ID) {
        await bot.sendChannelTyping(msg.channel.id);
        if (words[1]) {
            switch (words[1].toLowerCase()) {
                case 'add':
                    if (msg.mentions.length > 0 && words[2]) {
                        let ids = msg.mentions.map(u => u.id);
                        if (ids.length == 1) {
                            ids = ids[0];
                        }
                        await r.db('blargdb').table('markovs').insert({
                            userid: ids,
                            id: words[2].toLowerCase()
                        });
                        bu.send(msg, 'Added.');
                    } else {
                        bu.send(msg, 'Nope.');
                    }
                    break;
                case 'remove':
                    if (words[2]) {
                        await r.db('blargdb').table('markovs').get(words[2].toLowerCase()).delete();
                        bu.send(msg, 'Removed.');
                    } else {
                        bu.send(msg, 'Nope.');
                    }
                    break;
                case 'list':
                    let things = await r.db('blargdb').table('markovs').withFields('id');
                    bu.send(msg, things.map(t => t.id).join('\n'));
                    break;
                default:
                    let markov = await r.db('blargdb').table('markovs').get(words[1]);
                    if (markov) {
                        genlogs(msg, markov.userid, markov.id);
                    }
                    break;
            }

        } else {
            let catMsgs = await r.table('catchat').orderBy('msgid');
            let content = [];
            for (let message of catMsgs) {
                if (message.guildid != '197529405659021322' && message.nsfw == 0)
                    content.push(message.content);
            }
            fs.writeFile(path.join(__dirname, '..', '..', 'catbot', 'cat.json'),
                JSON.stringify(content, null, 2), (err) => {
                    if (err) bu.send(msg, err);
                    bu.send(msg, 'Done!');
                });
        }
    }
};

async function genlogs(msg, id, name) {
    let msg2 = await bu.send(msg, 'Performing query...');
    let msgs;
    if (Array.isArray(id)) {
        id.push({
            index: 'userid'
        });
        msgs = await r.db('blargdb').table('chatlogs').getAll(id[0], id[1], id[2]);
    } else
        msgs = await r.db('blargdb').table('chatlogs').getAll(id, {
            index: 'userid'
        });
    await msg2.edit('Generating array...');
    let content = [];
    for (let message of msgs) {
        content.push(message.content);
    }
    let userId;
    if (Array.isArray(id)) userId = id[0];
    else userId = id;
    msg2.edit('Writing file...');
    fs.writeFile(path.join(__dirname, '..', '..', 'catbot', 'jsons', userId + '.json'),
        JSON.stringify({
            name: name,
            lines: content
        }, null, 2), (err) => {
            if (err) bu.send(msg, err);
            msg2.edit('Done.');
        });
}<|endoftext|>


<commit_before>define(function () {
  var axis = {};

  return function (_, options) {
    axis.show = typeof _.show !== "undefined" ? _.show : options.show;
    axis.gClass = typeof _.gClass !== "undefined" ? _.gClass : options.gClass;
    axis.transform = typeof _.transform !== "undefined" ? _.transform : options.transform;

    axis.tick = typeof _.tick !== "undefined" ? _.tick : {};
    axis.tick.number = _.tick && typeof _.tick.number !== "undefined" ? _.tick.number : options.tick.number;
    axis.tick.values = _.tick && typeof _.tick.values !== "undefined" ? _.tick.values : options.tick.values;
    axis.tick.size = _.tick && typeof _.tick.size !== "undefined" ? _.tick.size : options.tick.size;
    axis.tick.padding = _.tick && typeof _.tick.padding !== "undefined" ? _.tick.padding : options.tick.padding;
    axis.tick.format = _.tick && typeof _.tick.format !== "undefined" ? _.tick.format : options.tick.format;
    axis.tick.rotate = _.tick && typeof _.tick.rotate !== "undefined" ? _.tick.rotate : options.tick.rotate;
    axis.tick.innerTickSize = _.tick && typeof _.tick.innerTickSize !== "undefined" ?
      _.tick.innerTickSize : options.tick.innerTickSize;
    axis.tick.outerTickSize = _.tick && typeof _.tick.outerTickSize !== "undefined" ?
      _.tick.outerTickSize : options.tick.outerTickSize;

    axis.tick.text = _.tick && typeof _.tick.text !== "undefined" ? _.tick.text : {};
    axis.tick.text.anchor = _.tick && _.tick.text && typeof _.tick.text.anchor !== "undefined" ?
      _.tick.text.anchor : options.tick.text.anchor;
    axis.tick.text.x = _.tick && _.tick.text && typeof _.tick.text.x !== "undefined" ?
      _.tick.text.x : options.tick.text.x;
    axis.tick.text.y = _.tick && _.tick.text && typeof _.tick.text.y !== "undefined" ?
      _.tick.text.y : options.tick.text.y;
    axis.tick.text.dx = _.tick && _.tick.text && typeof _.tick.text.dx !== "undefined" ?
      _.tick.text.dx : options.tick.text.dx;
    axis.tick.text.dy = _.tick && _.tick.text && typeof _.tick.text.dy !== "undefined" ?
      _.tick.text.dy : options.tick.text.dy;

    axis.title = typeof _.title !== "undefined" ? _.title : {};
    axis.title.titleClass = _.title && typeof _.title.titleClass !== "undefined" ?
      _.title.titleClass : options.title.titleClass;
    axis.title.x = _.title && typeof _.title.x !== "undefined" ? _.title.x : options.title.x;
    axis.title.y = _.title && typeof _.title.y !== "undefined" ? _.title.y : options.title.y;
    axis.title.dx = _.title && typeof _.title.dx !== "undefined" ? _.title.dx : options.title.dx;
    axis.title.dy = _.title && typeof _.title.dy !== "undefined" ? _.title.dy : options.title.dy;
    axis.title.anchor = _.title && typeof _.title.anchor !== "undefined" ? _.title.anchor : options.title.anchor;
    axis.title.transform = _.title && typeof _.title.transform !== "undefined" ?
      _.title.transform : options.title.transform;
    axis.title.text = _.title && typeof _.title.text !== "undefined" ? _.title.text : options.title.text;

    return axis;
  };
});
<commit_msg>fixing bug with axis options<commit_after>define(function () {
  return function (_, options) {
    var axis = {};

    axis.show = typeof _.show !== "undefined" ? _.show : options.show;
    axis.gClass = typeof _.gClass !== "undefined" ? _.gClass : options.gClass;
    axis.transform = typeof _.transform !== "undefined" ? _.transform : options.transform;

    axis.tick = typeof _.tick !== "undefined" ? _.tick : {};
    axis.tick.number = _.tick && typeof _.tick.number !== "undefined" ? _.tick.number : options.tick.number;
    axis.tick.values = _.tick && typeof _.tick.values !== "undefined" ? _.tick.values : options.tick.values;
    axis.tick.size = _.tick && typeof _.tick.size !== "undefined" ? _.tick.size : options.tick.size;
    axis.tick.padding = _.tick && typeof _.tick.padding !== "undefined" ? _.tick.padding : options.tick.padding;
    axis.tick.format = _.tick && typeof _.tick.format !== "undefined" ? _.tick.format : options.tick.format;
    axis.tick.rotate = _.tick && typeof _.tick.rotate !== "undefined" ? _.tick.rotate : options.tick.rotate;
    axis.tick.innerTickSize = _.tick && typeof _.tick.innerTickSize !== "undefined" ?
      _.tick.innerTickSize : options.tick.innerTickSize;
    axis.tick.outerTickSize = _.tick && typeof _.tick.outerTickSize !== "undefined" ?
      _.tick.outerTickSize : options.tick.outerTickSize;

    axis.tick.text = _.tick && typeof _.tick.text !== "undefined" ? _.tick.text : {};
    axis.tick.text.anchor = _.tick && _.tick.text && typeof _.tick.text.anchor !== "undefined" ?
      _.tick.text.anchor : options.tick.text.anchor;
    axis.tick.text.x = _.tick && _.tick.text && typeof _.tick.text.x !== "undefined" ?
      _.tick.text.x : options.tick.text.x;
    axis.tick.text.y = _.tick && _.tick.text && typeof _.tick.text.y !== "undefined" ?
      _.tick.text.y : options.tick.text.y;
    axis.tick.text.dx = _.tick && _.tick.text && typeof _.tick.text.dx !== "undefined" ?
      _.tick.text.dx : options.tick.text.dx;
    axis.tick.text.dy = _.tick && _.tick.text && typeof _.tick.text.dy !== "undefined" ?
      _.tick.text.dy : options.tick.text.dy;

    axis.title = typeof _.title !== "undefined" ? _.title : {};
    axis.title.titleClass = _.title && typeof _.title.titleClass !== "undefined" ?
      _.title.titleClass : options.title.titleClass;
    axis.title.x = _.title && typeof _.title.x !== "undefined" ? _.title.x : options.title.x;
    axis.title.y = _.title && typeof _.title.y !== "undefined" ? _.title.y : options.title.y;
    axis.title.dx = _.title && typeof _.title.dx !== "undefined" ? _.title.dx : options.title.dx;
    axis.title.dy = _.title && typeof _.title.dy !== "undefined" ? _.title.dy : options.title.dy;
    axis.title.anchor = _.title && typeof _.title.anchor !== "undefined" ? _.title.anchor : options.title.anchor;
    axis.title.transform = _.title && typeof _.title.transform !== "undefined" ?
      _.title.transform : options.title.transform;
    axis.title.text = _.title && typeof _.title.text !== "undefined" ? _.title.text : options.title.text;

    return axis;
  };
});
<|endoftext|>


<commit_before>/*!
GPII Process Reporter processes bridge -- gpii.processes.

Copyright 2016-2017 Inclusive Design Research Centre, OCAD University

Licensed under the New BSD license. You may not use this file except in
compliance with this License.

You may obtain a copy of the License at
https://github.com/gpii/universal/LICENSE.txt
*/

/*global require */

"use strict";

var path = require("path"),
    edge = require("edge"),
    fluid = require("universal");

var gpii = fluid.registerNamespace("gpii");
var dotNetProcesses = edge.func(path.join(__dirname, "dotNetProcesses.csx"));

fluid.defaults("gpii.processes.windows", {
    gradeNames: ["gpii.processes"],
    invokers: {
        getPlatformProcessList: {
            funcName: "gpii.processes.windows.getProcessList",
            args: ["{arguments}.0"]
                   // process name or id, optional.
        }
    }
});

/**
 * Return a list of processes -- a snapshot of the current processes.  If the
 * process name or process id is passed, then the return value will be limited
 * to only processes with that name or the process with that pid.
 *
 * @param {String} or {Number} Optional.  Specify a process to find via a name
 *                                        (string), or a process id (number).
 */
gpii.processes.windows.getProcessList = function (processIdentifier) {
    return dotNetProcesses(processIdentifier, true);
};
<commit_msg>GPII-442:  Removed getPlatformProcessList() invoker from the processes bridge<commit_after>/*!
GPII Process Reporter processes bridge -- gpii.processes.

Copyright 2016-2017 Inclusive Design Research Centre, OCAD University

Licensed under the New BSD license. You may not use this file except in
compliance with this License.

You may obtain a copy of the License at
https://github.com/gpii/universal/LICENSE.txt
*/

/*global require */

"use strict";

var path = require("path"),
    edge = require("edge"),
    fluid = require("universal");

var gpii = fluid.registerNamespace("gpii");
var dotNetProcesses = edge.func(path.join(__dirname, "dotNetProcesses.csx"));

fluid.defaults("gpii.processes.windows", {
    gradeNames: ["gpii.processes"],
    invokers: {
        getProcessList: {
            funcName: "gpii.processes.windows.getProcessList",
            args: ["{arguments}.0"]
                   // process name or id, optional.
        }
    }
});

/**
 * Return a list of processes -- a snapshot of the current processes.  If the
 * process name or process id is passed, then the return value will be limited
 * to only processes with that name or the process with that pid.
 *
 * @param {String} or {Number} Optional.  Specify a process to find via a name
 *                                        (string), or a process id (number).
 */
gpii.processes.windows.getProcessList = function (processIdentifier) {
    return dotNetProcesses(processIdentifier, true);
};
<|endoftext|>


<commit_before>import Emitter from '../emitter';
import define from '../define';
import * as is from '../is';
import Selector from '../selector';

let emitterOptions = {
  qualifierCompare: function( selector1, selector2 ){
    if( selector1 == null || selector2 == null ){
      return selector1 == null && selector2 == null;
    } else {
      return selector1.sameText( selector2 );
    }
  },
  eventMatches: function( ele, listener, eventObj ){
    let selector = listener.qualifier;

    if( selector != null ){
      return ele !== eventObj.target && is.element( eventObj.target ) && selector.matches( eventObj.target );
    }

    return true;
  },
  addEventFields: function( ele, evt ){
    evt.cy = ele.cy();
    evt.target = ele;
  },
  callbackContext: function( ele, listener, eventObj ){
    return listener.qualifier != null ? eventObj.target : ele;
  },
  beforeEmit: function( context, listener/*, eventObj*/ ){
    if( listener.conf && listener.conf.once ){
      listener.conf.onceCollection.removeListener( listener.event, listener.qualifier, listener.callback );
    }
  },
  bubble: function(){
    return true;
  },
  parent: function( ele ){
    return ele.isChild() ? ele.parent() : ele.cy();
  }
};

let argSelector = function( arg ){
  if( is.string(arg) ){
    return new Selector( arg );
  } else {
    return arg;
  }
};

let elesfn = ({
  createEmitter: function(){
    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];
      let _p = ele._private;

      if( !_p.emitter ){
        _p.emitter = new Emitter( emitterOptions, ele );
      }
    }

    return this;
  },

  emitter: function(){
    return this._private.emitter;
  },

  on: function( events, selector, callback ){
    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().on( events, argSelector(selector), callback );
    }

    return this;
  },

  removeListener: function( events, selector, callback ){
    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().removeListener( events, argSelector(selector), callback );
    }

    return this;
  },

  one: function( events, selector, callback ){
    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().one( events, argSelector(selector), callback );
    }

    return this;
  },

  once: function( events, selector, callback ){
    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().on( events, argSelector(selector), callback, {
        once: true,
        onceCollection: this
      } );
    }
  },

  emit: function( events, extraParams ){
    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().emit( events, extraParams );
    }

    return this;
  },

  emitAndNotify: function( event, extraParams ){ // for internal use only
    if( this.length === 0 ){ return; } // empty collections don't need to notify anything

    // notify renderer
    this.cy().notify( event, this );

    this.emit( event, extraParams );

    return this;
  }
});

define.eventAliasesOn( elesfn );

export default elesfn;
<commit_msg>Create selector object only once for `eles` event functions #2271<commit_after>import Emitter from '../emitter';
import define from '../define';
import * as is from '../is';
import Selector from '../selector';

let emitterOptions = {
  qualifierCompare: function( selector1, selector2 ){
    if( selector1 == null || selector2 == null ){
      return selector1 == null && selector2 == null;
    } else {
      return selector1.sameText( selector2 );
    }
  },
  eventMatches: function( ele, listener, eventObj ){
    let selector = listener.qualifier;

    if( selector != null ){
      return ele !== eventObj.target && is.element( eventObj.target ) && selector.matches( eventObj.target );
    }

    return true;
  },
  addEventFields: function( ele, evt ){
    evt.cy = ele.cy();
    evt.target = ele;
  },
  callbackContext: function( ele, listener, eventObj ){
    return listener.qualifier != null ? eventObj.target : ele;
  },
  beforeEmit: function( context, listener/*, eventObj*/ ){
    if( listener.conf && listener.conf.once ){
      listener.conf.onceCollection.removeListener( listener.event, listener.qualifier, listener.callback );
    }
  },
  bubble: function(){
    return true;
  },
  parent: function( ele ){
    return ele.isChild() ? ele.parent() : ele.cy();
  }
};

let argSelector = function( arg ){
  if( is.string(arg) ){
    return new Selector( arg );
  } else {
    return arg;
  }
};

let elesfn = ({
  createEmitter: function(){
    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];
      let _p = ele._private;

      if( !_p.emitter ){
        _p.emitter = new Emitter( emitterOptions, ele );
      }
    }

    return this;
  },

  emitter: function(){
    return this._private.emitter;
  },

  on: function( events, selector, callback ){
    let argSel = argSelector(selector);

    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().on( events, argSel, callback );
    }

    return this;
  },

  removeListener: function( events, selector, callback ){
    let argSel = argSelector(selector);

    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().removeListener( events, argSel, callback );
    }

    return this;
  },

  one: function( events, selector, callback ){
    let argSel = argSelector(selector);

    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().one( events, argSel, callback );
    }

    return this;
  },

  once: function( events, selector, callback ){
    let argSel = argSelector(selector);

    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().on( events, argSel, callback, {
        once: true,
        onceCollection: this
      } );
    }
  },

  emit: function( events, extraParams ){
    for( let i = 0; i < this.length; i++ ){
      let ele = this[i];

      ele.emitter().emit( events, extraParams );
    }

    return this;
  },

  emitAndNotify: function( event, extraParams ){ // for internal use only
    if( this.length === 0 ){ return; } // empty collections don't need to notify anything

    // notify renderer
    this.cy().notify( event, this );

    this.emit( event, extraParams );

    return this;
  }
});

define.eventAliasesOn( elesfn );

export default elesfn;
<|endoftext|>


<commit_before>import { expect } from 'chai';
import Draft from 'draft-js';
import omitBlocksKeyFromContentState from '../../modifiers/__test__/helpers/omitBlocksKeyFromContentState';
import createEditorState from '../../__test__/helpers/createEditorState';

import processText from '../processText';

describe('processText', () => {
  const beforeRawContentState = {
    entityMap: {},
    blocks: [{
      key: 'item1',
      text: '',
      type: 'unstyled',
      depth: 0,
      inlineStyleRanges: [],
      entityRanges: [],
      data: {}
    }]
  };
  const rawSelectionState = {
    anchorKey: 'item1',
    anchorOffset: 0,
    focusKey: 'item1',
    focusOffset: 0,
    isBackward: false,
    hasFocus: true
  };
  let afterRawContentState;
  it('insert text with new block', () => {
    const editorState = createEditorState(beforeRawContentState, rawSelectionState);
    const newEditorState = processText(editorState, 'text1', 'unstyled');
    afterRawContentState = {
      entityMap: {},
      blocks: [{
        key: 'item1',
        text: 'text1',
        type: 'unstyled',
        depth: 0,
        inlineStyleRanges: [],
        entityRanges: [],
        data: {}
      }]
    };
    expect(newEditorState).not.to.equal(editorState);
    const expected = Draft.convertToRaw(newEditorState.getCurrentContent());
    expect(
      expected
    ).to.deep.equal(
      afterRawContentState
    );
  });
  it('insert multiline text with new blocks', () => {
    const editorState = createEditorState(beforeRawContentState, rawSelectionState);
    const newEditorState = processText(editorState, 'text1\ntext2\ntext3', 'unstyled');
    afterRawContentState = {
      entityMap: {},
      blocks: [
        {
          key: 'item1',
          text: 'text1',
          type: 'unstyled',
          depth: 0,
          inlineStyleRanges: [],
          entityRanges: [],
          data: {}
        },
        {
          key: 'item2',
          text: 'text2',
          type: 'unstyled',
          depth: 0,
          inlineStyleRanges: [],
          entityRanges: [],
          data: {}
        },
        {
          key: 'item3',
          text: 'text3',
          type: 'unstyled',
          depth: 0,
          inlineStyleRanges: [],
          entityRanges: [],
          data: {}
        },
      ]
    };
    expect(newEditorState).not.to.equal(editorState);
    const expected = Draft.convertToRaw(newEditorState.getCurrentContent());
    console.log('ex expected ---------------------------------------------', expected);
    expect(
      omitBlocksKeyFromContentState(
        expected
      )
    ).to.deep.equal(
      omitBlocksKeyFromContentState(
        afterRawContentState
      )
    );
  });
});
<commit_msg>Pass ESLint<commit_after>import { expect } from 'chai';
import Draft from 'draft-js';
import omitBlocksKeyFromContentState from '../../modifiers/__test__/helpers/omitBlocksKeyFromContentState';
import createEditorState from '../../__test__/helpers/createEditorState';

import processText from '../processText';

describe('processText', () => {
  const beforeRawContentState = {
    entityMap: {},
    blocks: [{
      key: 'item1',
      text: '',
      type: 'unstyled',
      depth: 0,
      inlineStyleRanges: [],
      entityRanges: [],
      data: {}
    }]
  };
  const rawSelectionState = {
    anchorKey: 'item1',
    anchorOffset: 0,
    focusKey: 'item1',
    focusOffset: 0,
    isBackward: false,
    hasFocus: true
  };
  let afterRawContentState;
  it('insert text with new block', () => {
    const editorState = createEditorState(beforeRawContentState, rawSelectionState);
    const newEditorState = processText(editorState, 'text1', 'unstyled');
    afterRawContentState = {
      entityMap: {},
      blocks: [{
        key: 'item1',
        text: 'text1',
        type: 'unstyled',
        depth: 0,
        inlineStyleRanges: [],
        entityRanges: [],
        data: {}
      }]
    };
    expect(newEditorState).not.to.equal(editorState);
    const expected = Draft.convertToRaw(newEditorState.getCurrentContent());
    expect(
      expected
    ).to.deep.equal(
      afterRawContentState
    );
  });
  it('insert multiline text with new blocks', () => {
    const editorState = createEditorState(beforeRawContentState, rawSelectionState);
    const newEditorState = processText(editorState, 'text1\ntext2\ntext3', 'unstyled');
    afterRawContentState = {
      entityMap: {},
      blocks: [
        {
          key: 'item1',
          text: 'text1',
          type: 'unstyled',
          depth: 0,
          inlineStyleRanges: [],
          entityRanges: [],
          data: {}
        },
        {
          key: 'item2',
          text: 'text2',
          type: 'unstyled',
          depth: 0,
          inlineStyleRanges: [],
          entityRanges: [],
          data: {}
        },
        {
          key: 'item3',
          text: 'text3',
          type: 'unstyled',
          depth: 0,
          inlineStyleRanges: [],
          entityRanges: [],
          data: {}
        },
      ]
    };
    expect(newEditorState).not.to.equal(editorState);
    const expected = Draft.convertToRaw(newEditorState.getCurrentContent());
    expect(
      omitBlocksKeyFromContentState(
        expected
      )
    ).to.deep.equal(
      omitBlocksKeyFromContentState(
        afterRawContentState
      )
    );
  });
});
<|endoftext|>