From 9faaf65601987a6e4fcbe0e28ab6b8e283a90059 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:51:49 +0200 Subject: [PATCH] Updated ChangeTile.cs --- .../Additional-Popups/Animation/ChangeTile.cs | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/PCK-Studio/Forms/Additional-Popups/Animation/ChangeTile.cs b/PCK-Studio/Forms/Additional-Popups/Animation/ChangeTile.cs index b6e740af..0c54fe5f 100644 --- a/PCK-Studio/Forms/Additional-Popups/Animation/ChangeTile.cs +++ b/PCK-Studio/Forms/Additional-Popups/Animation/ChangeTile.cs @@ -31,16 +31,16 @@ namespace PckStudio.Forms.Additional_Popups.Animation private void InitializeTreeviews() { Profiler.Start(); - GetTileDataToView("blocks", treeViewBlocks.Nodes, treeViewBlockCache.Add); - GetTileDataToView("items", treeViewItems.Nodes, treeViewItemCache.Add); + GetTileDataToView(Internal.Animation.AnimationCategory.Blocks, treeViewBlocks.Nodes, treeViewBlockCache.Add); + GetTileDataToView(Internal.Animation.AnimationCategory.Items, treeViewItems.Nodes, treeViewItemCache.Add); Profiler.Stop(); } private void treeViews_AfterSelect(object sender, TreeViewEventArgs e) { - if (e.Node.Name is string tileData) + if (e.Node.Tag is JsonTileInfo tileData) { - selectedTile = tileData; + selectedTile = tileData.InternalName; Debug.WriteLine(selectedTile); category = e.Node.TreeView == treeViewItems ? Internal.Animation.AnimationCategory.Items @@ -48,40 +48,29 @@ namespace PckStudio.Forms.Additional_Popups.Animation } } - private void GetTileDataToView(string key, TreeNodeCollection collection, Action additinalAction) + private void GetTileDataToView(Internal.Animation.AnimationCategory key, TreeNodeCollection collection, Action additinalAction) { List textureInfos = key switch { - "blocks" => Tiles.BlockTileInfos, - "items" => Tiles.ItemTileInfos, - _ => throw new InvalidOperationException(key) + Internal.Animation.AnimationCategory.Blocks => Tiles.BlockTileInfos, + Internal.Animation.AnimationCategory.Items => Tiles.ItemTileInfos, + _ => throw new InvalidOperationException(nameof(key)) }; Profiler.Start(); - try + if (textureInfos is not null) { - if (textureInfos is not null) - { - foreach ((int i, var content) in textureInfos.enumerate()) + foreach ((int i, var content) in textureInfos.enumerate()) + { + if (string.IsNullOrEmpty(content.InternalName) || collection.ContainsKey(content.InternalName)) + continue; + TreeNode tileNode = new TreeNode(content.DisplayName, i, i) { - if (!string.IsNullOrEmpty(content.InternalName) && !collection.ContainsKey(content.InternalName)) - { - TreeNode tileNode = new TreeNode(content.DisplayName) - { - Name = content.InternalName, - Tag = content.DisplayName, - ImageIndex = i, - SelectedImageIndex = i, - }; - collection.Add(tileNode); - additinalAction(tileNode); - } - } - } - } - catch (Newtonsoft.Json.JsonException j_ex) - { - MessageBox.Show(j_ex.Message, "Error"); - return; + Name = content.InternalName, + Tag = content + }; + collection.Add(tileNode); + additinalAction(tileNode); + } } Profiler.Stop(); }