示例#1
0
        public TimingCopierVm()
        {
            _importPath   = "";
            _exportPath   = "";
            _resnapMode   = "Number of beats between objects stays the same";
            _beatDivisors = RationalBeatDivisor.GetDefaultBeatDivisors();

            ImportLoadCommand = new CommandImplementation(
                _ => {
                try {
                    string path = IOHelper.GetCurrentBeatmap();
                    if (path != "")
                    {
                        ImportPath = path;
                    }
                } catch (Exception ex) {
                    ex.Show();
                }
            });

            ImportBrowseCommand = new CommandImplementation(
                _ => {
                string[] paths = IOHelper.BeatmapFileDialog(restore: !SettingsManager.Settings.CurrentBeatmapDefaultFolder);
                if (paths.Length != 0)
                {
                    ImportPath = paths[0];
                }
            });

            ExportLoadCommand = new CommandImplementation(
                _ => {
                try {
                    string path = IOHelper.GetCurrentBeatmap();
                    if (path != "")
                    {
                        ExportPath = path;
                    }
                } catch (Exception ex) {
                    ex.Show();
                }
            });

            ExportBrowseCommand = new CommandImplementation(
                _ => {
                string[] paths = IOHelper.BeatmapFileDialog(true, !SettingsManager.Settings.CurrentBeatmapDefaultFolder);
                if (paths.Length != 0)
                {
                    ExportPath = string.Join("|", paths);
                }
            });
        }
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is string str))
            {
                return(new IBeatDivisor[0]);
            }

            var vals         = str.Split(',');
            var beatDivisors = new IBeatDivisor[vals.Length];

            for (int i = 0; i < vals.Length; i++)
            {
                var val = vals[i];

                // Check if it is a positive rational and non-zero and not dividing by zero
                if (Regex.IsMatch(val, "^[\\s]*[1-9][0-9]*[\\s]*/[\\s]*[1-9][0-9]*[\\s]*$"))
                {
                    var ndSplit = val.Split('/');
                    beatDivisors[i] = new RationalBeatDivisor(int.Parse(ndSplit[0], CultureInfo.InvariantCulture),
                                                              int.Parse(ndSplit[1], CultureInfo.InvariantCulture));
                }
                else
                {
                    var valid = TypeConverters.TryParseDouble(val, out double doubleValue);
                    if (valid)
                    {
                        if (doubleValue <= 0)
                        {
                            return(new ValidationResult(false, "Beat divisor must be greater than zero."));
                        }

                        beatDivisors[i] = new IrrationalBeatDivisor(doubleValue);
                    }
                    else
                    {
                        return(new ValidationResult(false, "Double format error."));
                    }
                }
            }

            return(beatDivisors);
        }