<commit_before>var Ipc = require('ipc');
var Async = require('async');

Ipc.on('scene:ipc-messages', function ( ipcList ) {
    for ( var i = 0; i < ipcList.length; ++i ) {
        Ipc.emit.apply( Ipc, ipcList[i] );
    }
});

Ipc.on('scene:new-scene', function () {
    window.sceneView.newScene();
});

Ipc.on('scene:save-scene-from-page', function ( url ) {
    var sceneAsset = new Fire.Scene();
    sceneAsset.scene = Fire.engine.getCurrentScene();

    Editor.sendToCore( 'scene:save-scene', url, Editor.serialize(sceneAsset) );
});

Ipc.on('scene:open-scene-by-uuid', function ( uuid ) {
    window.sceneView.loadScene(uuid);
});

Ipc.on('scene:play', function () {
    window.sceneView.play();
});

Ipc.on('scene:drop', function ( uuids, type, x, y ) {
    Editor.Selection.clear('node');

    Async.each( uuids, function ( uuid, done ) {
        Async.waterfall([
            function ( next ) {
                Fire.AssetLibrary.loadAsset(uuid, next);
            },

            function ( asset, next ) {
                if ( asset && asset.createNode ) {
                    asset.createNode( next );
                    return;
                }

                next ( null, null );
            },

            function ( node, next ) {
                var nodeID;
                if ( node ) {
                    var wrapper = Fire.node(node);
                    nodeID = wrapper.id;

                    wrapper.position = window.sceneView.pixelToScene( Fire.v2(x,y) );
                    wrapper.parent = Fire.engine.getCurrentScene();
                }

                next ( null, nodeID );
            },

        ], function ( err, nodeID ) {
            if ( err ) {
                Editor.failed( 'Failed to drop asset %s, message: %s', uuid, err.stack );
                return;
            }

            if ( nodeID ) {
                Editor.Selection.select('node', nodeID, false, true );
            }
            Fire.engine.repaintInEditMode();
            done();
        });
    });
});

Ipc.on('scene:create-assets', function ( uuids, nodeID ) {
    var parentNode;
    if ( nodeID ) {
        parentNode = Fire.node(Fire.engine.getRuntimeInstanceById(nodeID));
    }
    if ( !parentNode ) {
        parentNode = Fire.engine.getCurrentScene();
    }

    Editor.Selection.clear('node');

    //
    Async.each( uuids, function ( uuid, done ) {
        Async.waterfall([
            function ( next ) {
                Fire.AssetLibrary.loadAsset(uuid, next);
            },

            function ( asset, next ) {
                if ( asset && asset.createNode ) {
                    asset.createNode( next );
                    return;
                }

                next ( null, null );
            },

            function ( node, next ) {
                var nodeID;
                if ( node ) {
                    var wrapper = Fire.node(node);
                    nodeID = wrapper.id;

                    if ( parentNode ) {
                        wrapper.parent = parentNode;
                    }
                    var center_x = Fire.engine.canvasSize.x/2;
                    var center_y = Fire.engine.canvasSize.y/2;
                    wrapper.scenePosition = window.sceneView.pixelToScene( Fire.v2(center_x, center_y) );
                }

                next ( null, nodeID );
            },

        ], function ( err, nodeID ) {
            if ( err ) {
                Editor.failed( 'Failed to drop asset %s, message: %s', uuid, err.stack );
                return;
            }

            if ( nodeID ) {
                Editor.Selection.select('node', nodeID, false, true );
            }
            Fire.engine.repaintInEditMode();
            done();
        });
    });
});

Ipc.on('scene:create-new-node', function ( menuItem, parentID ) {
    var parentNode;
    if ( parentID ) {
        parentNode = Fire.engine.getRuntimeInstanceById(parentID);
    }
    if ( !parentNode ) {
        parentNode = Fire.engine.getCurrentRuntimeScene();
    }
    var wrapperID = menuItem.id;
    var Wrapper = Fire.JS._getClassById(wrapperID);
    if (Wrapper) {
        var wrapper = new Wrapper();
        wrapper.onAfterDeserialize();
        wrapper.runtimeParent = parentNode;

        var menuPath = menuItem.menuPath;
        wrapper.name = 'New ' + menuPath.split('/').slice(-1)[0];

        var center_x = Fire.engine.canvasSize.x/2;
        var center_y = Fire.engine.canvasSize.y/2;
        wrapper.scenePosition = window.sceneView.pixelToScene( Fire.v2(center_x, center_y) );

        Fire.engine.repaintInEditMode();
        Editor.Selection.select('node', wrapper.id, true, true );
    }
    else {
        Editor.error('Unknown node to create:', wrapperID);
    }
});

Ipc.on('scene:query-hierarchy', function ( queryID ) {
    var nodes = Fire.takeHierarchySnapshot();
    Editor.sendToWindows( 'scene:reply-query-hierarchy', queryID, nodes );
});


Ipc.on('scene:query-node', function ( queryID, nodeID ) {
    var node = Fire.engine.getRuntimeInstanceById(nodeID);
    var dump = Editor.getNodeDump(node);
    Editor.sendToWindows( 'scene:reply-query-node', queryID, dump );
});

Ipc.on('scene:node-set-property', function ( id, path, value, isMixin ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        var objToSet = isMixin ? node : Fire.node(node);
        try {
            Editor.setDeepPropertyByPath(objToSet, path, value);
        }
        catch (e) {
            Editor.warn('Failed to set property %s of %s to %s, ' + e.message,
                path, Fire.node(node).name, value);
        }
    }
});

Ipc.on('scene:node-mixin', function ( id, uuid ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        var className = Editor.compressUuid(uuid);
        var classToMix = Fire.JS._getClassById(className);
        if (classToMix) {
            Fire.mixin(node, classToMix);
        }
        else {
            Editor.error('Can not find %s to mixin', uuid);
        }
    }
});

Ipc.on('scene:move-nodes', function ( ids, parentID, nextSiblingId ) {
    var parent;
<commit_msg>repaint when node set property<commit_after>var Ipc = require('ipc');
var Async = require('async');

Ipc.on('scene:ipc-messages', function ( ipcList ) {
    for ( var i = 0; i < ipcList.length; ++i ) {
        Ipc.emit.apply( Ipc, ipcList[i] );
    }
});

Ipc.on('scene:new-scene', function () {
    window.sceneView.newScene();
});

Ipc.on('scene:save-scene-from-page', function ( url ) {
    var sceneAsset = new Fire.Scene();
    sceneAsset.scene = Fire.engine.getCurrentScene();

    Editor.sendToCore( 'scene:save-scene', url, Editor.serialize(sceneAsset) );
});

Ipc.on('scene:open-scene-by-uuid', function ( uuid ) {
    window.sceneView.loadScene(uuid);
});

Ipc.on('scene:play', function () {
    window.sceneView.play();
});

Ipc.on('scene:drop', function ( uuids, type, x, y ) {
    Editor.Selection.clear('node');

    Async.each( uuids, function ( uuid, done ) {
        Async.waterfall([
            function ( next ) {
                Fire.AssetLibrary.loadAsset(uuid, next);
            },

            function ( asset, next ) {
                if ( asset && asset.createNode ) {
                    asset.createNode( next );
                    return;
                }

                next ( null, null );
            },

            function ( node, next ) {
                var nodeID;
                if ( node ) {
                    var wrapper = Fire.node(node);
                    nodeID = wrapper.id;

                    wrapper.position = window.sceneView.pixelToScene( Fire.v2(x,y) );
                    wrapper.parent = Fire.engine.getCurrentScene();
                }

                next ( null, nodeID );
            },

        ], function ( err, nodeID ) {
            if ( err ) {
                Editor.failed( 'Failed to drop asset %s, message: %s', uuid, err.stack );
                return;
            }

            if ( nodeID ) {
                Editor.Selection.select('node', nodeID, false, true );
            }
            Fire.engine.repaintInEditMode();
            done();
        });
    });
});

Ipc.on('scene:create-assets', function ( uuids, nodeID ) {
    var parentNode;
    if ( nodeID ) {
        parentNode = Fire.node(Fire.engine.getRuntimeInstanceById(nodeID));
    }
    if ( !parentNode ) {
        parentNode = Fire.engine.getCurrentScene();
    }

    Editor.Selection.clear('node');

    //
    Async.each( uuids, function ( uuid, done ) {
        Async.waterfall([
            function ( next ) {
                Fire.AssetLibrary.loadAsset(uuid, next);
            },

            function ( asset, next ) {
                if ( asset && asset.createNode ) {
                    asset.createNode( next );
                    return;
                }

                next ( null, null );
            },

            function ( node, next ) {
                var nodeID;
                if ( node ) {
                    var wrapper = Fire.node(node);
                    nodeID = wrapper.id;

                    if ( parentNode ) {
                        wrapper.parent = parentNode;
                    }
                    var center_x = Fire.engine.canvasSize.x/2;
                    var center_y = Fire.engine.canvasSize.y/2;
                    wrapper.scenePosition = window.sceneView.pixelToScene( Fire.v2(center_x, center_y) );
                }

                next ( null, nodeID );
            },

        ], function ( err, nodeID ) {
            if ( err ) {
                Editor.failed( 'Failed to drop asset %s, message: %s', uuid, err.stack );
                return;
            }

            if ( nodeID ) {
                Editor.Selection.select('node', nodeID, false, true );
            }
            Fire.engine.repaintInEditMode();
            done();
        });
    });
});

Ipc.on('scene:create-new-node', function ( menuItem, parentID ) {
    var parentNode;
    if ( parentID ) {
        parentNode = Fire.engine.getRuntimeInstanceById(parentID);
    }
    if ( !parentNode ) {
        parentNode = Fire.engine.getCurrentRuntimeScene();
    }
    var wrapperID = menuItem.id;
    var Wrapper = Fire.JS._getClassById(wrapperID);
    if (Wrapper) {
        var wrapper = new Wrapper();
        wrapper.onAfterDeserialize();
        wrapper.runtimeParent = parentNode;

        var menuPath = menuItem.menuPath;
        wrapper.name = 'New ' + menuPath.split('/').slice(-1)[0];

        var center_x = Fire.engine.canvasSize.x/2;
        var center_y = Fire.engine.canvasSize.y/2;
        wrapper.scenePosition = window.sceneView.pixelToScene( Fire.v2(center_x, center_y) );

        Fire.engine.repaintInEditMode();
        Editor.Selection.select('node', wrapper.id, true, true );
    }
    else {
        Editor.error('Unknown node to create:', wrapperID);
    }
});

Ipc.on('scene:query-hierarchy', function ( queryID ) {
    var nodes = Fire.takeHierarchySnapshot();
    Editor.sendToWindows( 'scene:reply-query-hierarchy', queryID, nodes );
});


Ipc.on('scene:query-node', function ( queryID, nodeID ) {
    var node = Fire.engine.getRuntimeInstanceById(nodeID);
    var dump = Editor.getNodeDump(node);
    Editor.sendToWindows( 'scene:reply-query-node', queryID, dump );
});

Ipc.on('scene:node-set-property', function ( id, path, value, isMixin ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        var objToSet = isMixin ? node : Fire.node(node);
        try {
            Editor.setDeepPropertyByPath(objToSet, path, value);
            Fire.engine.repaintInEditMode();
        }
        catch (e) {
            Editor.warn('Failed to set property %s of %s to %s, ' + e.message,
                path, Fire.node(node).name, value);
        }
    }
});

Ipc.on('scene:node-mixin', function ( id, uuid ) {
    var node = Fire.engine.getRuntimeInstanceById(id);
    if (node) {
        var className = Editor.compressUuid(uuid);
        var classToMix = Fire.JS._getClassById(className);
        if (classToMix) {
            Fire.mixin(node, classToMix);
        }
        else {
            Editor.error('Can not find %s to mixin', uuid);
        }
    }
});

Ipc.on('scene:move-nodes', function ( ids, parentID, nextSiblingId ) {
    var parent;

{'fraction_non_alphanumeric': 0.1340632603406326, 'fraction_numerical': 0.0016220600162206002, 'mean_word_length': 1.731723526805494, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1417301', 'n_tokens_mistral': 3670, 'n_tokens_neox': 3579, 'n_words': 713}