<commit_before>﻿using System.Linq;
using System.Collections.Generic;
using SanAndreasUnity.Importing.Conversion;
using UnityEngine;

namespace SanAndreasUnity.Behaviours
{
    public class FrameContainer : MonoBehaviour, IEnumerable<Frame>
    {
        private Frame[] _frames;
        private Dictionary<int, Frame> _boneIdDict;

        public Frame Root { get { return _frames.FirstOrDefault(x => x.Parent == null); } }

        internal void Initialize(Geometry.GeometryFrame[] frames,
            Dictionary<Geometry.GeometryFrame, Transform> transforms)
        {
            _frames = frames.Select(x => {
                var frame = transforms[x].gameObject.AddComponent<Frame>();
                frame.Initialize(x);
                return frame;
            }).ToArray();

            for (var i = 0; i < frames.Length; ++i) {
                var frame = frames[i];
                if (frame.ParentIndex == -1) continue;
                _frames[i].Parent = _frames[frame.ParentIndex];
            }

            _boneIdDict = _frames.ToDictionary(x => x.BoneId, x => x);
        }

        public Frame GetByName(string name)
        {
            return _frames.FirstOrDefault(x => x.Name == name);
        }

        public Frame GetByIndex(int index)
        {
            return _frames.FirstOrDefault(x => x.Name == name);
        }

        public Frame GetByBoneId(int boneId)
        {
            return _boneIdDict[boneId];
        }

        public IEnumerator<Frame> GetEnumerator()
        {
            return _frames.AsEnumerable().GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _frames.GetEnumerator();
        }<commit_msg>Fix for possible exception when loading a model with bones.<commit_after>﻿using System.Linq;
using System.Collections.Generic;
using SanAndreasUnity.Importing.Conversion;
using UnityEngine;

namespace SanAndreasUnity.Behaviours
{
    public class FrameContainer : MonoBehaviour, IEnumerable<Frame>
    {
        private Frame[] _frames;
        private Dictionary<int, Frame> _boneIdDict;

        public Frame Root { get { return _frames.FirstOrDefault(x => x.Parent == null); } }

        internal void Initialize(Geometry.GeometryFrame[] frames,
            Dictionary<Geometry.GeometryFrame, Transform> transforms)
        {
            _frames = frames.Select(x => {
                var frame = transforms[x].gameObject.AddComponent<Frame>();
                frame.Initialize(x);
                return frame;
            }).ToArray();

            for (var i = 0; i < frames.Length; ++i) {
                var frame = frames[i];
                if (frame.ParentIndex == -1) continue;
                _frames[i].Parent = _frames[frame.ParentIndex];
            }

            _boneIdDict = _frames.Where(x => x.BoneId > -1).ToDictionary(x => x.BoneId, x => x);
        }

        public Frame GetByName(string name)
        {
            return _frames.FirstOrDefault(x => x.Name == name);
        }

        public Frame GetByIndex(int index)
        {
            return _frames.FirstOrDefault(x => x.Name == name);
        }

        public Frame GetByBoneId(int boneId)
        {
            return _boneIdDict[boneId];
        }

        public IEnumerator<Frame> GetEnumerator()
        {
            return _frames.AsEnumerable().GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _frames.GetEnumerator();
        }
{'fraction_non_alphanumeric': 0.10291643297812675, 'fraction_numerical': 0.0014021312394840158, 'mean_word_length': 2.0075885328836427, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 27, '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': '3302275', 'n_tokens_mistral': 981, 'n_tokens_neox': 955, 'n_words': 207}