<commit_before>﻿var Component = (function () {

    /**
     * used in _callOnEnable to ensure onEnable and onDisable will be called alternately
     * 从逻辑上来说OnEnable和OnDisable的交替调用不需要由额外的变量进行保护，但那样会使设计变得复杂
     * 例如Entity.destroy调用后但还未真正销毁时，会调用所有Component的OnDisable。
     * 这时如果又有addComponent，Entity需要对这些新来的Component特殊处理。将来调度器做了之后可以尝试去掉这个标记。
     */
    var IsOnEnableCalled = Fire._ObjectFlags.IsOnEnableCalled;

    // IsOnEnableCalled 会收到 executeInEditMode 的影响，IsEditorOnEnabledCalled 不会
    var IsEditorOnEnabledCalled = Fire._ObjectFlags.IsEditorOnEnabledCalled;
    var IsOnLoadCalled = Fire._ObjectFlags.IsOnLoadCalled;
    var IsOnStartCalled = Fire._ObjectFlags.IsOnStartCalled;

    var compCtor;
// @ifdef EDITOR
    compCtor = function () {
        Fire._AssetsWatcher.initComponent(this);
    };
// @endif

    /**
     * Base class for everything attached to Entity.
     *
     * NOTE: Not allowed to use construction parameters for Component's subclasses,
     *         because Component is created by the engine.
     *
     * @class Component
     * @extends HashObject
     * @constructor
     */
    var Component = Fire.extend('Fire.Component', HashObject, compCtor);

    /**
     * The entity this component is attached to. A component is always attached to an entity.
     * @property entity
     * @type {Entity}
     */
    Component.prop('entity', null, Fire.HideInInspector);

    // @ifdef EDITOR

    // 如果不带有 uuid，则返回空字符串
    Component.getset('_scriptUuid',
        function () {
            return this._cacheUuid || '';
        },
        function (value) {
            if (this._cacheUuid !== value) {
                if (value && Fire.isUuid(value)) {
                    var classId = Fire.compressUuid(value);
                    var newComp = Fire.JS._getClassById(classId);
                    if (newComp) {
                        Fire.warn('Sorry, replacing component script is not yet implemented.');
                        //Fire.sendToWindows('reload:window-scripts', Fire._Sandbox.compiled);
                    }
                    else {
                        Fire.error('Can not find a component in the script which uuid is "%s".', value);
                    }
                }
                else {
                    Fire.error('invalid script');
                }
            }
        },
        Fire.DisplayName("Script"),
        Fire.ObjectType(Fire.ScriptAsset, true)
    );

    // @endif

    /**
     * @property _enabled
     * @type boolean
     * @private
     */
    Component.prop('_enabled', true, Fire.HideInInspector);

    // properties

    /**
     * indicates whether this component is enabled or not.
     * @property enabled
     * @type boolean
     * @default true
     */
    Object.defineProperty(Component.prototype, 'enabled', {<commit_msg>Attribute: 将 type: 'uuid' 特化成只有 script asset 才能用 (fireball-x/dev#317)<commit_after>﻿var Component = (function () {

    /**
     * used in _callOnEnable to ensure onEnable and onDisable will be called alternately
     * 从逻辑上来说OnEnable和OnDisable的交替调用不需要由额外的变量进行保护，但那样会使设计变得复杂
     * 例如Entity.destroy调用后但还未真正销毁时，会调用所有Component的OnDisable。
     * 这时如果又有addComponent，Entity需要对这些新来的Component特殊处理。将来调度器做了之后可以尝试去掉这个标记。
     */
    var IsOnEnableCalled = Fire._ObjectFlags.IsOnEnableCalled;

    // IsOnEnableCalled 会收到 executeInEditMode 的影响，IsEditorOnEnabledCalled 不会
    var IsEditorOnEnabledCalled = Fire._ObjectFlags.IsEditorOnEnabledCalled;
    var IsOnLoadCalled = Fire._ObjectFlags.IsOnLoadCalled;
    var IsOnStartCalled = Fire._ObjectFlags.IsOnStartCalled;

    var compCtor;
// @ifdef EDITOR
    compCtor = function () {
        Fire._AssetsWatcher.initComponent(this);
    };
// @endif

    /**
     * Base class for everything attached to Entity.
     *
     * NOTE: Not allowed to use construction parameters for Component's subclasses,
     *         because Component is created by the engine.
     *
     * @class Component
     * @extends HashObject
     * @constructor
     */
    var Component = Fire.extend('Fire.Component', HashObject, compCtor);

    /**
     * The entity this component is attached to. A component is always attached to an entity.
     * @property entity
     * @type {Entity}
     */
    Component.prop('entity', null, Fire.HideInInspector);

    // @ifdef EDITOR

    // 如果不带有 uuid，则返回空字符串
    Component.getset('_scriptUuid',
        function () {
            return this._cacheUuid || '';
        },
        function (value) {
            if (this._cacheUuid !== value) {
                if (value && Fire.isUuid(value)) {
                    var classId = Fire.compressUuid(value);
                    var newComp = Fire.JS._getClassById(classId);
                    if (newComp) {
                        Fire.warn('Sorry, replacing component script is not yet implemented.');
                        //Fire.sendToWindows('reload:window-scripts', Fire._Sandbox.compiled);
                    }
                    else {
                        Fire.error('Can not find a component in the script which uuid is "%s".', value);
                    }
                }
                else {
                    Fire.error('invalid script');
                }
            }
        },
        Fire.DisplayName("Script"),
        Fire._ScriptUuid
    );

    // @endif

    /**
     * @property _enabled
     * @type boolean
     * @private
     */
    Component.prop('_enabled', true, Fire.HideInInspector);

    // properties

    /**
     * indicates whether this component is enabled or not.
     * @property enabled
     * @type boolean
     * @default true
     */
    Object.defineProperty(Component.prototype, 'enabled', {
{'fraction_non_alphanumeric': 0.09783945195854558, 'fraction_numerical': 0.0005269629369401019, 'mean_word_length': 2.030335284725918, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3080429', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1729, 'n_words': 365}