예제 #1
0
        private void LoadStage()
        {
            string texoDataFolder = PathExtensions.GetAndCreateDataDirectoryPath(FileManagerConstants.STORAGE_DIRECTORY_NAME);
            string filePath       = texoDataFolder.CombinePathWith(FileManagerConstants.STORAGE_STAGE_FILE_NAME);

            if (!File.Exists(filePath))
            {
                return;
            }

            using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                IStashEntry stage = serialisation.DeserializeFromStream <StashEntry>(file);

                if (stage == null)
                {
                    return;
                }

                lobby = stage.GetLobby() ?? string.Empty;
                var pathsBuilder = ImmutableSortedSet.CreateBuilder(new InsensitiveFullPathComparer());
                pathsBuilder.UnionWith(stage.GetPaths());
                paths = pathsBuilder.ToImmutable();
            }
        }
예제 #2
0
        public void Add(IStashEntry stash)
        {
            if (stash == null)
            {
                return;
            }

            Add(stash.GetPaths());
        }
예제 #3
0
        private static Item BuildStashOverviewItem(IStashEntry stash, int index)
        {
            MarkdownBuilder builder = new MarkdownBuilder();

            builder.Header(GetStashHeader(stash, index));
            builder.Bullet();
            builder.Italic(GetStashLobbyTitle(stash));
            builder.WritePathOverview(stash.GetPaths(), stash.GetLobby());
            return(Item.AsMarkdown(builder.ToString()));
        }
예제 #4
0
        private void ApplyStashToStage(IStashEntry stash, bool replace)
        {
            if (replace)
            {
                stage.Clear();
            }

            stage.SetLobby(stash.GetLobby());
            stage.Add(stash);
        }
예제 #5
0
        private static Item BuildStashDetailItem(IStashEntry stash, int index)
        {
            MarkdownBuilder builder = new MarkdownBuilder();

            builder.Header(GetStashHeader(stash, index));
            builder.Italic(GetStashLobbyTitle(stash));
            builder.WriteLine();
            builder.WritePathLists(stash.GetPaths(), stash.GetLobby());
            return(Item.AsMarkdown(builder.ToString()));
        }
예제 #6
0
        private ICommandResult Peek(CommandContext context)
        {
            IStashEntry stash = stashes.GetStash(0);

            if (stash == null)
            {
                return(new TextResult("The stash stack is empty."));
            }

            ApplyStashToStage(stash, !context.HasOption(StashOptions.ADD));
            return(new ItemsResult($"{GetStashHeader(stash, 0)} has been applied to stage."));
        }
예제 #7
0
        private ICommandResult Pop(CommandContext context)
        {
            IStashEntry stash = stashes.GetStash(0);

            if (stash == null)
            {
                return(new TextResult("The stash stack is empty."));
            }

            ApplyStashToStage(stash, !context.HasOption(StashOptions.ADD));
            stashes.RemoveStash(stash);
            return(new TextResult($"{GetStashHeader(stash, 0)} has been applied to stage and removed from top of the stack."));
        }
예제 #8
0
        private ICommandResult Push(CommandContext context)
        {
            IImmutableList <string> paths = stage.GetPaths();

            if (paths == null || paths.Count < 1)
            {
                return(new ErrorTextResult("The stage is empty."));
            }

            string      name  = context.GetParameterValue(ParameterKeys.NAME);
            IStashEntry stash = stashes.CreateStash(stage.GetLobby(), paths, name);

            return(new ItemsResult(BuildStashDetailItem(stash, 0)));
        }
예제 #9
0
        private ICommandResult Show(CommandContext context)
        {
            string      id    = context.GetParameterValue(StashParameters.IDENTIFIER);
            IStashEntry stash = int.TryParse(id, out int index)
                ? stashes.GetStash(index)
                : stashes.GetStash(id);

            if (stash == null)
            {
                return(new ErrorTextResult($"No stash @{id} found."));
            }

            return(new ItemsResult(BuildStashDetailItem(stash, index)));
        }
예제 #10
0
        private ICommandResult Drop(CommandContext context)
        {
            string      id    = context.GetParameterValue(StashParameters.IDENTIFIER);
            IStashEntry stash = int.TryParse(id, out int index)
                ? stashes.GetStash(index)
                : stashes.GetStash(id);

            if (stash == null)
            {
                return(new ErrorTextResult($"No stash @{id} found."));
            }

            stashes.RemoveStash(stash);
            return(new TextResult($"{GetStashHeader(stash, index)} has been dropped."));
        }
예제 #11
0
        private ICommandResult List(CommandContext context)
        {
            var allStashes = stashes.GetStashes();

            if (allStashes.Count < 1)
            {
                return(new TextResult("The stash stack is empty."));
            }

            var result = ImmutableList <Item> .Empty.ToBuilder();

            for (int i = 0; i < allStashes.Count; i++)
            {
                IStashEntry stash = allStashes[i];
                result.Add(BuildStashOverviewItem(stash, i));
            }

            return(new ItemsResult(result.ToImmutable()));
        }
예제 #12
0
        private ICommandResult Apply(CommandContext context)
        {
            if (!context.HasParameter(StashParameters.IDENTIFIER))
            {
                return(Peek(context));
            }

            string      id    = context.GetParameterValue(StashParameters.IDENTIFIER);
            IStashEntry stash = int.TryParse(id, out int index)
                ? stashes.GetStash(index)
                : stashes.GetStash(id);

            if (stash == null)
            {
                return(new ErrorTextResult($"No stash @{id} found."));
            }

            ApplyStashToStage(stash, !context.HasOption(StashOptions.ADD));
            return(new TextResult($"{GetStashHeader(stash, index)} has been applied to stage."));
        }
예제 #13
0
        public void RemoveStash(int index)
        {
            if (stashes.Count == 0 && index == 0)
            {
                return;
            }

            if (index < 0 || index >= stashes.Count)
            {
                throw new IndexOutOfRangeException();
            }

            IStashEntry stash = stashes[index];

            if (!string.IsNullOrWhiteSpace(stash.Name))
            {
                nameMap.Remove(stash.Name);
            }

            stashes.RemoveAt(index);
        }
예제 #14
0
        public void RemoveStash(IStashEntry stash)
        {
            int index = -1;

            if (string.IsNullOrWhiteSpace(stash.Name))
            {
                if (nameMap.TryGetValue(stash.Name, out int nameIndex))
                {
                    index = nameIndex;
                    nameMap.Remove(stash.Name);
                }
            }
            else
            {
                index = stashes.IndexOf(stash);
            }

            if (index < 0)
            {
                return;
            }

            stashes.RemoveAt(index);
        }
예제 #15
0
 private static string GetStashHeader(IStashEntry stash, int index)
 {
     return(string.IsNullOrWhiteSpace(stash.Name)
         ? $"Stash @{index}"
         : $"Stash @{stash.Name}");
 }
예제 #16
0
 private static string GetStashLobbyTitle(IStashEntry stash)
 {
     return(string.IsNullOrEmpty(stash.GetLobby())
         ? "No lobby directory."
         : stash.GetLobby());
 }