private void OnWorldEntrySelected(WorldFileTreeViewModel worldFileModel)
        {
            var engineVersion = App.Settings.Get<EngineVersion>("Core.EngineVersion", EngineVersion.DarkAlliance);
            var lmpFile = worldFileModel.LmpFileProperty;
            var entry = lmpFile.Directory[worldFileModel.Text];
            WorldFileDecoder decoder = new WorldFileDecoder();
            var log = new StringLogger();
            _world.worldData = decoder.Decode(engineVersion, _worldTreeViewModel.World().WorldTex, log, lmpFile.FileData, entry.StartOffset, entry.Length);
            worldFileModel.ReloadChildren();
            _levelViewModel.WorldNode = worldFileModel;
            _levelViewModel.WorldData = _world.worldData;
            LogText = log.ToString();
            LogText += _world.worldData.ToString();

            _window.tabControl.SelectedIndex = 3; // Level View
            _window.ResetCamera();
            _window.SetViewportText(3, worldFileModel.Text, ""); // Set Level View Text
        }
        private void OnYakChildElementSelected(YakChildTreeViewItem childEntry)
        {
            SelectedNodeImage = TexDecoder.Decode(childEntry.YakFile.FileData, childEntry.Value.TextureOffset + childEntry.Value.VifOffset,
                childEntry.Value.VifLength - childEntry.Value.TextureOffset);
            var log = new StringLogger();
            _modelViewModel.Texture = SelectedNodeImage;
            _modelViewModel.AnimData = null;
            Model model = new Model();
            model.meshList = VifDecoder.Decode(
                log,
                childEntry.YakFile.FileData,
                childEntry.Value.VifOffset,
                childEntry.Value.TextureOffset,
                SelectedNodeImage.PixelWidth,
                SelectedNodeImage.PixelHeight);
            _modelViewModel.VifModel = model;

            LogText += log.ToString();

            _window.tabControl.SelectedIndex = 1; // Model View
            _window.ResetCamera();
            _window.SetViewportText(1, childEntry.Text + " of " + ((YakTreeViewItem)childEntry.Parent).Text, "");
        }
        private void OnLmpEntrySelected(LmpEntryTreeViewModel lmpEntry)
        {
            var lmpFile = lmpEntry.LmpFileProperty;
            var entry = lmpFile.Directory[lmpEntry.Text];

            var ext = (Path.GetExtension(lmpEntry.Text) ?? "").ToLower();

            switch (ext)
            {
                case ".tex":
                    {
                        SelectedNodeImage = TexDecoder.Decode(lmpFile.FileData, entry.StartOffset, entry.Length);

                        _window.tabControl.SelectedIndex = 0; // Texture View
                    }
                    break;
                case ".vif":
                    {
                        string texFilename = Path.GetFileNameWithoutExtension(lmpEntry.Text) + ".tex";
                        var texEntry = lmpFile.Directory[texFilename];
                        SelectedNodeImage = TexDecoder.Decode(lmpFile.FileData, texEntry.StartOffset, texEntry.Length);
                        var log = new StringLogger();
                        _modelViewModel.Texture = SelectedNodeImage;
                        _modelViewModel.AnimData = null;
                        Model model = new Model();
                        model.meshList = VifDecoder.Decode(log, lmpFile.FileData, entry.StartOffset, entry.Length,
                                                           SelectedNodeImage.PixelWidth, SelectedNodeImage.PixelHeight);
                        _modelViewModel.VifModel = model;

                        /*// Load animation data
                        var animData = LoadFirstAnim(lmpFile);
                        // Make sure the animation will work with the model
                        if (animData.Count > 0 && animData[0].NumBones == model.CountBones())
                            _modelViewModel.AnimData = animData.Count == 0 ? null : animData.First();*/

                        LogText += log.ToString();

                        _window.tabControl.SelectedIndex = 1; // Model View
                        _window.ResetCamera();
                        _window.SetViewportText(1, lmpEntry.Text, "");
                    }
                    break;
                case ".anm":
                    {
                        var engineVersion = App.Settings.Get("Core.EngineVersion", EngineVersion.DarkAlliance);
                        var animData = AnmDecoder.Decode(engineVersion, lmpFile.FileData, entry.StartOffset, entry.Length);
                        _skeletonViewModel.AnimData = animData;
                        LogText = animData.ToString();

                        if (_modelViewModel.VifModel != null)
                        {
                            int boneCount = _modelViewModel.VifModel.CountBones();
                            if (boneCount != 0 && boneCount == animData.NumBones)
                            {
                                _modelViewModel.AnimData = animData;

                                // Switch tab to animation tab only if the current tab isnt the model view tab
                                if (_window.tabControl.SelectedIndex != 1) // Model View
                                {
                                    _window.tabControl.SelectedIndex = 2; // Skeleton View
                                    _window.ResetCamera();
                                }
                            }
                            else
                            {
                                // Bone count doesn't match, switch to skeleton view
                                _window.tabControl.SelectedIndex = 2; // Skeleton View
                                _window.ResetCamera();
                            }
                        }
                        else
                        {
                            _window.tabControl.SelectedIndex = 2; // Skeleton View
                            _window.ResetCamera();
                        }
                    }

                    _window.SetViewportText(2, lmpEntry.Text, ""); // Set Skeleton View Text

                    break;
                case ".ob":
                    var objects = ObDecoder.Decode(lmpFile.FileData, entry.StartOffset, entry.Length);

                    var sb = new StringBuilder();

                    foreach (var obj in objects)
                    {
                        sb.AppendFormat("Name: {0}\n", obj.Name);
                        sb.AppendFormat("I6: {0}\n", obj.I6.ToString("X4"));
                        sb.AppendFormat("Floats: {0},{1},{2}\n", obj.Floats[0], obj.Floats[1], obj.Floats[2]);
                        if (obj.Properties != null)
                        {
                            foreach (var prop in obj.Properties)
                            {
                                sb.AppendFormat("Property: {0}\n", prop);
                            }
                        }
                        sb.Append("\n");
                    }

                    LogText = sb.ToString();
                    _window.tabControl.SelectedIndex = 4; // Log View

                    break;
            }
        }