public IItemFilterScriptViewModel NewScript() { var newScript = _itemFilterScriptFactory.Create(); var newViewModel = _itemFilterScriptViewModelFactory.Create(); newViewModel.Initialise(newScript, true); return(newViewModel); }
public IItemFilterScript TranslateStringToItemFilterScript(string inputString) { var script = _itemFilterScriptFactory.Create(); _blockGroupHierarchyBuilder.Initialise(script.ItemFilterBlockGroups.First()); if (Regex.Matches(inputString, @"#Disabled\sBlock\s(Start|End).*?\n").Count > 0) { if (MessageBox.Show( "Loaded script contains special '#Disabled Block Start' lines." + " These may be coming from old versions of Filtration or Greengroove's filter." + "It is suggested to remove them however this may cause problems with original source" + Environment.NewLine + "(There is no in game effect of those lines)" + Environment.NewLine + Environment.NewLine + "Would you like to remove them?", "Special Comment Lines Found", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes) { //Remove old disabled tags inputString = Regex.Replace(inputString, @"#Disabled\sBlock\s(Start|End).*?\n", ""); inputString = (inputString.EndsWith("\n#Disabled Block End")) ? inputString.Substring(0, inputString.Length - 19) : inputString; } } var originalLines = Regex.Split(inputString, "\r\n|\r|\n"); inputString = inputString.Replace("\t", ""); List <bool> inBlock; inputString = PreprocessDisabledBlocks(inputString, out inBlock); var conditionBoundaries = IdentifyBlockBoundaries(inputString, inBlock); var lines = Regex.Split(inputString, "\r\n|\r|\n"); // Process the script header for (var i = 0; i < conditionBoundaries.Skip(1).First().StartLine; i++) { if (lines[i].StartsWith("# EnableBlockGroups")) { script.ItemFilterScriptSettings.BlockGroupsEnabled = true; } else if (lines[i].StartsWith("#")) { script.Description += lines[i].Substring(1).Trim(' ') + Environment.NewLine; } } if (!string.IsNullOrEmpty(script.Description)) { script.Description = script.Description.TrimEnd('\n').TrimEnd('\r'); } // Extract each block from between boundaries and translate it into a ItemFilterBlock object // and add that object to the ItemFilterBlocks list for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next) { if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ScriptDescription) { continue; } var begin = boundary.Value.StartLine; var end = boundary.Next?.Value.StartLine ?? lines.Length; var block = new string[end - begin]; Array.Copy(lines, begin, block, 0, end - begin); var blockString = string.Join("\r\n", block); Array.Copy(originalLines, begin, block, 0, end - begin); var originalString = ""; for (var i = block.Length - 1; i >= 0; i--) { if (block[i].Replace(" ", "").Replace("\t", "").Length > 0) { originalString = string.Join("\r\n", block, 0, i + 1); break; } } if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) { script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script, originalString)); } else { script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterCommentBlock(blockString, script, originalString)); } } _blockGroupHierarchyBuilder.Cleanup(); return(script); }
public IItemFilterScript TranslateStringToItemFilterScript(string inputString) { var script = _itemFilterScriptFactory.Create(); _blockGroupHierarchyBuilder.Initialise(script.ItemFilterBlockGroups.First()); inputString = inputString.Replace("\t", ""); if (inputString.Contains("#Disabled Block Start")) { inputString = PreprocessDisabledBlocks(inputString); } var conditionBoundaries = IdentifyBlockBoundaries(inputString); var lines = Regex.Split(inputString, "\r\n|\r|\n"); // Process the script header for (var i = 0; i < conditionBoundaries.Skip(1).First().StartLine; i++) { if (lines[i].StartsWith("# EnableBlockGroups")) { script.ItemFilterScriptSettings.BlockGroupsEnabled = true; } else if (lines[i].StartsWith("#")) { script.Description += lines[i].Substring(1).Trim(' ') + Environment.NewLine; } } if (!string.IsNullOrEmpty(script.Description)) { script.Description = script.Description.TrimEnd('\n').TrimEnd('\r'); } // Extract each block from between boundaries and translate it into a ItemFilterBlock object // and add that object to the ItemFilterBlocks list for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next) { if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ScriptDescription) { continue; } var begin = boundary.Value.StartLine; var end = boundary.Next?.Value.StartLine ?? lines.Length; var block = new string[end - begin]; Array.Copy(lines, begin, block, 0, end - begin); var blockString = string.Join("\r\n", block); if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) { script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script)); } else { script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterCommentBlock(blockString, script)); } } _blockGroupHierarchyBuilder.Cleanup(); return(script); }