<commit_before>/*
 * Copyright (c) 2011-2013 by Animatron.
 * All rights are reserved.
 *
 * Animatron Player is licensed under the MIT License, see LICENSE.
 *
 * @VERSION
 */

// see ./animatron-project-@VERSION.orderly for a readable scheme of accepted project

// This importer imports only the compact format of scenes (where all elements are arrays
// of arrays)

var AnimatronImporter = (function() {

var IMPORTER_ID = 'ANM';

var C = anm.C,
    Scene = anm.Scene,
    Element = anm.Element,
    Path = anm.Path,
    Text = anm.Text,
    Bands = anm.Bands,
    is = anm._typecheck;
    //test = anm._valcheck

function _reportError(e) {
    __anm.console.error(e);
    // throw e; // skip errors if they do not affect playing ability
}

var Import = {};

anm.I[IMPORTER_ID] = Import;

var cur_import_id;

// -> Array[?]
Import._find = function(idx, src) {
    var res = src[idx];
    if (!res) _reportError('Element with index ' + idx + ' was not found'
                           + (src ? ' among ' + src.length + ' elements.' : '.') );
    return src[idx];
}
// -> Integer
Import._type = function(src) {
    return src[0];
}

/** project **/
/*
 * object {
 *     object *meta*;     // meta info about the project (the same as for full format)
 *     object *anim*;     // animation info
 * } *project*;
 */
// -> Scene
Import.project = function(prj) {
    //if (window && console && window.__anm_conf && window.__anm_conf.logImport) console.log(prj);
    if (__anm_conf.logImport) __anm.console.log(prj);
    cur_import_id = __anm.guid();
    __anm.lastImportedProject = prj;
    __anm.lastImportId = cur_import_id;
    var scenes_ids = prj.anim.scenes;
    if (!scenes_ids.length) _reportError('No scenes found in given project');
    var root = new Scene(),
        elems = prj.anim.elements,
        last_scene_band = [ 0, 0 ];
    root.__import_id = cur_import_id;
    for (var i = 0, il = scenes_ids.length; i < il; i++) {
        var node_src = Import._find(scenes_ids[i], elems);
        if (Import._type(node_src) != TYPE_SCENE) _reportError('Given Scene ID ' + scenes_ids[i] + ' points to something else');
        var node_res = Import.node(node_src, elems);
        if (i > 0) { // start from second scene, if there is one
            // FIXME: smells like a hack
            // correct the band of the next scene to follow the previous scene
            // gband[1] contains the duration of the scene there, while gband[0] contains 0
            // (see SCENE type handling in Import.node)
            // TODO: fix it with proper native scenes when they will be supported in player
            var gband_before = node_res.xdata.gband;
            node_res.xdata.gband = [ last_scene_band[1] + gband_before[0],
                                     last_scene_band[1] + gband_before[1] ];
            // local band is equal to global band on top level
            node_res.xdata.lband = node_res.xdata.lband;
            node_res.travelChildren(function(elm) {
                var e_gband_before = elm.xdata.gband;
                elm.xdata.gband = [ last_scene_band[1] + e_gband_before[0],
                                    last_scene_band[1] + e_gband_before[1] ];
                if (elm.parent === node_res) {
                    var e_lband_before = elm.xdata.lband;
                    elm.xdata.lband = [ last_scene_band[1] + e_lband_before[0],
                                        last_scene_band[1] + e_lband_before[1] ]
                }
            });
        }
        last_scene_band = node_res.xdata.gband;
        root.add(node_res);
    }

    if (scenes_ids.length > 0) {
        node_res.xdata.gband = [last_scene_band[0], Infinity];
        node_res.xdata.lband = node_res.xdata.gband;
    }

    if (prj.meta.duration != undefined) root.setDuration(prj.meta.duration);
    if (prj.anim.background) root.bgfill = Import.fill(prj.anim.background);
    return root;
}
/** meta **/
// -> Object
Import.meta = function(prj) {
    var _m = prj.meta;
    return {
        'title': _m.name,
        'author': _m.author,
        'copyright': _m.copyright,
        'version': _m.version,
        'description': _m.description,
        'duration': _m.duration,
        'created': _m.created,
        'modified': _m.modified<commit_msg>fix import: do not touch lband for scene children<commit_after>/*
 * Copyright (c) 2011-2013 by Animatron.
 * All rights are reserved.
 *
 * Animatron Player is licensed under the MIT License, see LICENSE.
 *
 * @VERSION
 */

// see ./animatron-project-@VERSION.orderly for a readable scheme of accepted project

// This importer imports only the compact format of scenes (where all elements are arrays
// of arrays)

var AnimatronImporter = (function() {

var IMPORTER_ID = 'ANM';

var C = anm.C,
    Scene = anm.Scene,
    Element = anm.Element,
    Path = anm.Path,
    Text = anm.Text,
    Bands = anm.Bands,
    is = anm._typecheck;
    //test = anm._valcheck

function _reportError(e) {
    __anm.console.error(e);
    // throw e; // skip errors if they do not affect playing ability
}

var Import = {};

anm.I[IMPORTER_ID] = Import;

var cur_import_id;

// -> Array[?]
Import._find = function(idx, src) {
    var res = src[idx];
    if (!res) _reportError('Element with index ' + idx + ' was not found'
                           + (src ? ' among ' + src.length + ' elements.' : '.') );
    return src[idx];
}
// -> Integer
Import._type = function(src) {
    return src[0];
}

/** project **/
/*
 * object {
 *     object *meta*;     // meta info about the project (the same as for full format)
 *     object *anim*;     // animation info
 * } *project*;
 */
// -> Scene
Import.project = function(prj) {
    //if (window && console && window.__anm_conf && window.__anm_conf.logImport) console.log(prj);
    if (__anm_conf.logImport) __anm.console.log(prj);
    cur_import_id = __anm.guid();
    __anm.lastImportedProject = prj;
    __anm.lastImportId = cur_import_id;
    var scenes_ids = prj.anim.scenes;
    if (!scenes_ids.length) _reportError('No scenes found in given project');
    var root = new Scene(),
        elems = prj.anim.elements,
        last_scene_band = [ 0, 0 ];
    root.__import_id = cur_import_id;
    for (var i = 0, il = scenes_ids.length; i < il; i++) {
        var node_src = Import._find(scenes_ids[i], elems);
        if (Import._type(node_src) != TYPE_SCENE) _reportError('Given Scene ID ' + scenes_ids[i] + ' points to something else');
        var node_res = Import.node(node_src, elems);
        if (i > 0) { // start from second scene, if there is one
            // FIXME: smells like a hack
            // correct the band of the next scene to follow the previous scene
            // gband[1] contains the duration of the scene there, while gband[0] contains 0
            // (see SCENE type handling in Import.node)
            // TODO: fix it with proper native scenes when they will be supported in player
            var gband_before = node_res.xdata.gband;
            node_res.xdata.gband = [ last_scene_band[1] + gband_before[0],
                                     last_scene_band[1] + gband_before[1] ];
            // local band is equal to global band on top level
            node_res.xdata.lband = node_res.xdata.gband;
            node_res.travelChildren(function(elm) {
                var e_gband_before = elm.xdata.gband;
                elm.xdata.gband = [ last_scene_band[1] + e_gband_before[0],
                                    last_scene_band[1] + e_gband_before[1] ];
            });
        }
        last_scene_band = node_res.xdata.gband;
        root.add(node_res);
    }

    if (scenes_ids.length > 0) {
        node_res.xdata.gband = [last_scene_band[0], Infinity];
        node_res.xdata.lband = node_res.xdata.gband;
    }

    if (prj.meta.duration != undefined) root.setDuration(prj.meta.duration);
    if (prj.anim.background) root.bgfill = Import.fill(prj.anim.background);
    return root;
}
/** meta **/
// -> Object
Import.meta = function(prj) {
    var _m = prj.meta;
    return {
        'title': _m.name,
        'author': _m.author,
        'copyright': _m.copyright,
        'version': _m.version,
        'description': _m.description,
        'duration': _m.duration,
        'created': _m.created,
        'modified': _m.modified
{'fraction_non_alphanumeric': 0.1250301422715216, 'fraction_numerical': 0.006751868820834338, 'mean_word_length': 2.265748031496063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2114948', 'n_tokens_mistral': 2748, 'n_tokens_neox': 2700, 'n_words': 694}