{"size": 3742, "ext": "js", "max_stars_repo_path": "Engine/scripts/engine/worker/resources.js", "max_stars_repo_name": "vadkasevas/BAS", "max_stars_repo_stars_event_min_datetime": "2016-05-20T12:55:23.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T02:26:14.000Z", "max_issues_repo_path": "Engine/scripts/engine/worker/resources.js", "max_issues_repo_name": "chulakshana/BAS", "max_issues_repo_issues_event_min_datetime": "2016-07-21T09:04:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-16T07:34:42.000Z", "max_forks_repo_path": "Engine/scripts/engine/worker/resources.js", "max_forks_repo_name": "chulakshana/BAS", "max_forks_repo_forks_event_min_datetime": "2016-05-18T07:48:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-26T12:59:39.000Z"}
{"max_stars_count": 302, "max_issues_count": 9, "max_forks_count": 113, "avg_line_length": 20.905027933, "max_line_length": 195, "alphanum_fraction": 0.5954035275}
_R = {}
_RKEY = null

function _get_last_record_id(record)
{
    if(RInfo(_RKEY,'Type') === 'Database')
    {
        var res = csv_parse(_result().get())
        if(res.length > 0)
        {
            LAST_DATABASE_RECORD = res[res.length - 1];
        }
    }
}

function RS(key, notreuse, onlyfail, callback)
{
    IS_REFUSED=false


    if(!notreuse && !onlyfail)
    {
        // Reuse and die on non exists

        if(key in _R && _R[key])
        {
            _set_result(_R[key]);
            callback();
            return;
        }

        _RKEY = key
        ScriptWorker.GetHandler(key,true,"_get_last_record_id();_R[_RKEY]=_result();" + _get_function_body(callback));
    }else if(notreuse && !onlyfail)
    {
        if(key in _R && _R[key])
        {
            _R[key].success()
            _R[key] = null
        }

        _RKEY = key
        ScriptWorker.GetHandler(key,true,"_get_last_record_id();_R[_RKEY]=_result();" + _get_function_body(callback));
    }else if(!notreuse && onlyfail)
    {
        if(key in _R && _R[key])
        {
            _set_result(_R[key]);
            callback();
            return;
        }

        _RKEY = key
        ScriptWorker.GetHandler(key,false,"_get_last_record_id();if(_result() == null){fail('Resource get error for ' + _RKEY);return;}else{_R[_RKEY]=_result();}" + _get_function_body(callback));

    }else if(notreuse && onlyfail)
    {
        if(key in _R && _R[key])
        {
            _R[key].success()
            _R[key] = null
        }

        _RKEY = key
        ScriptWorker.GetHandler(key,false,"_get_last_record_id();if(_result() == null){fail('Resource get error for ' + _RKEY);return;}else{_R[_RKEY]=_result();}" + _get_function_body(callback));
    }
}

function R(key, callback)
{
    IS_REFUSED=false
    ScriptWorker.GetHandler(key,true,_get_function_body(callback));
}

function RSafe(key, callback)
{
    IS_REFUSED=false
    ScriptWorker.GetHandler(key,false,_get_function_body(callback));
}

function Refuse(key, value)
{
    ScriptWorker.Refuse(key,value);
}

function RIsRefused()
{
    return IS_REFUSED;
}

function Reload(key)
{
    ScriptWorker.ReloadResource(key);
}

function RInsert(name, value, onlywrite)
{
    EngineRes.Insert(name, value, onlywrite)
}

function RSync(name)
{
    EngineRes.Sync(name)
}

function RCreate(name, successes, fails, simultaneous, interval, greedy, dont_give_up)
{
    EngineRes.Create(name, successes, fails, simultaneous, interval, greedy, dont_give_up)
}


function RTake(name, callback)
{
    ARG_RES_NAME = name;
    RTakeAll_RESULT = [];
    _do(function(){
        RSafe(ARG_RES_NAME, function(){
            if(_result() === null)
            {
                _set_result(RTakeAll_RESULT);
                _break();
            }
            RTakeAll_RESULT.push(_result().get());
            _result().die()
        });

    }, callback)

}

function RSuccessAll()
{
    return ResourceHandlers.Success()
}
function RFailAll()
{
    return ResourceHandlers.Fail()
}
function RDieAll()
{
    return ResourceHandlers.Die()
}

function RInfo(name, key)
{
    return EngineRes.GetInfo(name, key);
}

function RPick(name)
{
    return ScriptWorker.GetAllData(name)
}

function RPickRandom(name, size)
{
    return ScriptWorker.GetRandomSubarrayData(name,size)
}

function RMap(name)
{
    function Map(_name){
      var __name = _name;
      this.length = function()
      {
          return ScriptWorker.GetTotalLength(__name);
      }
      this.at = function(index)
      {
           return ScriptWorker.GetAtIndex(__name,index);
      }
      this.set = function(index,value)
      {
           return ScriptWorker.SetAtIndex(__name,index,value);
      }

    };
    return new Map(name);
}
