diff --git a/Helpers/FilesSearcher.cs b/Helpers/FilesSearcher.cs index efbacfd..f1b7acb 100644 --- a/Helpers/FilesSearcher.cs +++ b/Helpers/FilesSearcher.cs @@ -58,5 +58,16 @@ public static List GetDirectoriesWithoutOrigPath(string path, string sea #endregion Directory + + #region Path + public static string GetExportConfigPath(string configFileName, string fullpath) + { + string fullpathPart = fullpath.Replace(EnvironmentController.lastImportPath, ""); + string configName = configFileName.Replace(EnvironmentController.configFormat, ""); + string exportPath = $"{EnvironmentController.lastExportPath}\\{configName}\\{fullpathPart}"; + return exportPath; + } + + #endregion Path } } diff --git a/Processors/DMIStatesProcessor.cs b/Processors/DMIStatesProcessor.cs index cdfb46a..09ef30e 100644 --- a/Processors/DMIStatesProcessor.cs +++ b/Processors/DMIStatesProcessor.cs @@ -14,6 +14,7 @@ using System.Windows.Media.Imaging; using SixLabors.ImageSharp.Processing; using AdaptiveSpritesDMItool.Resources; +using AdaptiveSpritesDMItool.Helpers; namespace AdaptiveSpritesDMItool.Processors { @@ -105,7 +106,7 @@ public static void ProcessFileWithConfig(IProgress progress, ConfigItem con { iter++; progress?.Report(iter); - ProcessStateWithConfig(state, config, dataPixelStorage); + ProcessStateWithConfig(state, config, dataPixelStorage, path); //Thread.Sleep(200); } @@ -135,6 +136,12 @@ public static void ProcessFileWithConfig(IProgress progress, ConfigItem con } Debug.WriteLine($"[{iter}/{maxIter}] NOT SAVED {fileExportPath}"); + foreach (DMIState state in file.States) + { + iter++; + iter += state.TotalFrames; + //Thread.Sleep(200); + } } #endregion Processors @@ -143,12 +150,34 @@ public static void ProcessFileWithConfig(IProgress progress, ConfigItem con #region Draw - private static void ProcessStateWithConfig(DMIState state, ConfigItem config, DataPixelStorage dataPixelStorage) + private static void ProcessStateWithConfig(DMIState state, ConfigItem config, DataPixelStorage dataPixelStorage, string path) { - // TODO: Checking that this state is already in the processed file - //if (!StatesController.isOverrideToggle) - // if (state.Name == state.Name) - // return; + + if (!(state.Name == "vox1" || state.Name == "vox2" || state.Name == "vox3")) + { + return; + } + + if (!StatesController.isOverrideToggle) + { + string exportPath = FilesSearcher.GetExportConfigPath(config.FileName, path); + //Debug.WriteLine($"PROCESS {exportPath} \n\t--- {path}"); + if (File.Exists(exportPath) == false) + { + EditStateWithConfig(state, config, dataPixelStorage); + return; + } + + DMIFile exportedDMIFile = new DMIFile(exportPath); + foreach (DMIState exportedState in exportedDMIFile.States) + { + if (state.Name == exportedState.Name) + { + iter += state.TotalFrames; + return; + } + } + } EditStateWithConfig(state, config, dataPixelStorage); } diff --git a/Resources/DataPixelStorage.cs b/Resources/DataPixelStorage.cs index d82447f..a7fa562 100644 --- a/Resources/DataPixelStorage.cs +++ b/Resources/DataPixelStorage.cs @@ -67,11 +67,15 @@ private void FillDataSimilarPoints(int width, int height) public Point GetPointStorage(StateDirection direction, Point point) { var storagePoint = ConvertToStoragePoint(point); + storagePoint.x = Math.Max(storagePoint.x, 0); + storagePoint.y = Math.Max(storagePoint.y, 0); return ConvertFromStoragePoint(pixelStorages[direction][storagePoint]); } public (int x, int y) GetPointStorage(StateDirection direction, (int x, int y) point) { + point.x = Math.Max(point.x, 0); + point.y = Math.Max(point.y, 0); return pixelStorages[direction][point]; } diff --git a/Views/Pages/DataPage.xaml.cs b/Views/Pages/DataPage.xaml.cs index 6615282..11949b5 100644 --- a/Views/Pages/DataPage.xaml.cs +++ b/Views/Pages/DataPage.xaml.cs @@ -38,9 +38,11 @@ public partial class DataPage : INavigableView /// Paths to files to be processed. private List filesPaths = new List(); + private Brush correctBrush = Brushes.ForestGreen; private Brush incorrectBrush = Brushes.Orange; - private Brush correctBrush = Brushes.Green; private Brush badBrush = Brushes.Red; + private Brush skipBrush = Brushes.Gray; + private Brush doneBrush = Brushes.GreenYellow; public DataViewModel ViewModel { get; } public DataPage(DataViewModel viewModel) @@ -121,22 +123,55 @@ private TreeViewItem GetTreeViewItem(string directory, string file) { string headerFile = GetHeaderFile(file); var fileTreeItem = new TreeViewItem { Header = headerFile }; - if (!headerFile.Contains(EnvironmentController.defaultFileFormat)) - fileTreeItem.Foreground = incorrectBrush; - else + string fullPath = $"{directory}\\{headerFile}"; + fileTreeItem.Foreground = GetColorTreeItem(headerFile, fullPath); + if (headerFile.Contains(EnvironmentController.defaultFileFormat)) { - string fullPath = $"{directory}\\{headerFile}"; filesPaths.Add(fullPath); } return fileTreeItem; } + private Brush GetColorTreeItem(string headerFile, string fullPath) + { + // No DMI file? No process. + if (!headerFile.Contains(EnvironmentController.defaultFileFormat)) + return badBrush; + + if (fullPath == string.Empty) + return badBrush; + + // Work with configs & DMI file states + using DMIFile fileDmi = new DMIFile(fullPath); + if (fileDmi.States.Count == 0) + return badBrush; + + if (StatesController.isOverrideToggle) + return correctBrush; + + foreach (ConfigItem config in selectedConfigs) + { + string exportPath = FilesSearcher.GetExportConfigPath(config.FileName, fullPath); + if (File.Exists(exportPath) == false) + continue; + DMIFile exportedDMIFile = new DMIFile(exportPath); + foreach (DMIState state in fileDmi.States) + { + foreach (DMIState exportedState in exportedDMIFile.States) + { + if (state.Name == exportedState.Name) + return incorrectBrush; + } + } + } + return correctBrush; + } #endregion Tree View - #region Buttons + #region Changed Events public void TreeItemChanged(object sender, RoutedEventArgs e) { @@ -165,8 +200,14 @@ private void ConfigChanged(object sender, SelectionChangedEventArgs e) ConfigItem? config = item as ConfigItem; selectedConfigs.Add(config); } + GenerateTreeItems(); } + #endregion Changed Events + + + #region Buttons + private void SetImportFolderButton_Click(object sender, RoutedEventArgs e) { string path = ViewModel.FolderImportPath; @@ -183,12 +224,16 @@ private void OverrideButton_Click(object sender, RoutedEventArgs e) var pressed = StatesController.GetPressedButtonAppearance(); var unpressed = StatesController.GetUnPressedButtonAppearance(); OverrideButton.Appearance = StatesController.isOverrideToggle ? pressed : unpressed; + + string fullPath = EnvironmentController.lastImportPath; + GenerateTreeItems(); } private void ConfigRemoveButton_Click(object sender, RoutedEventArgs e) { - Button button = sender as Button; - ConfigItem config = button.DataContext as ConfigItem; + Button? button = sender as Button; + ConfigItem? config = button?.DataContext as ConfigItem; + if (config == null) return; ViewModel.RemoveConfig(config); } @@ -262,14 +307,30 @@ private void ViewItemsFromSelectedDMI(string fullPath) return; ViewModel.ClearStatesCollection(); - //var StateItems = new ObservableCollection(); using DMIFile fileDmi = new DMIFile(fullPath); var states = fileDmi.States; foreach (DMIState state in states) { WriteableBitmap writeableBitmap = ImageEncoder.GetBMPFromDMIState(state, StateDirection.South); - Brush color = Brushes.GreenYellow; + + Brush color = correctBrush; + if (!StatesController.isOverrideToggle) + { + foreach (ConfigItem config in selectedConfigs) + { + string exportPath = FilesSearcher.GetExportConfigPath(config.FileName, fullPath); + if (File.Exists(exportPath) == false) + continue; + DMIFile exportedDMIFile = new DMIFile(exportPath); + foreach (DMIState exportedState in exportedDMIFile.States) + { + if (state.Name == exportedState.Name) + color = incorrectBrush; + } + } + } + StateItem stateItem = new StateItem( "NoName", fullPath, diff --git a/Views/Pages/StatesEditorPage.xaml.cs b/Views/Pages/StatesEditorPage.xaml.cs index 2d3728a..7c16b2d 100644 --- a/Views/Pages/StatesEditorPage.xaml.cs +++ b/Views/Pages/StatesEditorPage.xaml.cs @@ -699,8 +699,9 @@ private void StateChanged(object sender, SelectionChangedEventArgs e) private void StateRemoveButton_Click(object sender, RoutedEventArgs e) { - Button button = sender as Button; - StateItem state = button.DataContext as StateItem; + Button? button = sender as Button; + StateItem? state = button?.DataContext as StateItem; + if (state == null) return; ViewModel.RemoveState(state); } @@ -730,8 +731,9 @@ private void ClearConfigButton_Click(object sender, RoutedEventArgs e) private void ConfigRemoveButton_Click(object sender, RoutedEventArgs e) { - Button button = sender as Button; - ConfigItem config = button.DataContext as ConfigItem; + Button? button = sender as Button; + ConfigItem? config = button?.DataContext as ConfigItem; + if (config == null) return; ViewModel.RemoveConfig(config); }