예제 #1
0
        private bool ParseTarget(ReadOnlySpan <char> text)
        {
            try {
                text = text.SliceContent("{", "}");

                var line  = Functions.SplitHead(ref text);
                var title = line.SliceContent("\"label\": \"", "\",").ToString();
                if (title != _view.Title)
                {
                    return(false);
                }

                text = text.SliceContent("\"entries\": [", "]");
                while (text.Length > 5)
                {
                    _ = Functions.SplitHead(ref text);
                    var item = new SpellItem {
                        Id          = Functions.SplitHead(ref text).SliceContent("\"id\": \"", "\",").ToString(),
                        Name        = Functions.SplitHead(ref text).SliceContent("\"name\": \"", "\",").ToString(),
                        Description = Functions.SplitHead(ref text).SliceContent("\"description\": \"", "\"").ToString(),
                    };
                    _ = Functions.SplitHead(ref text);
                    _targetItems[item.Id] = item;
                }
            } catch (Functions.ParseFaildException) {
                return(false);
            }

            return(CheckMap());
        }
예제 #2
0
        private bool ParseSource(ReadOnlySpan <char> text)
        {
            var i = 0;

            try {
                text = text.SliceContent("{", "}");

                var line  = Functions.SplitHead(ref text);
                var title = line.SliceContent("\"label\": \"", "\",").ToString();
                _ = ModifyUI(() => _view.Title = title);

                text = text.SliceContent("\"entries\": [", "]");
                while (text.Length > 5)
                {
                    _ = Functions.SplitHead(ref text);
                    var item = new SpellItem {
                        Id          = Functions.SplitHead(ref text).SliceContent("\"id\": \"", "\",").ToString(),
                        Name        = Functions.SplitHead(ref text).SliceContent("\"name\": \"", "\",").ToString(),
                        Description = Functions.SplitHead(ref text).SliceContent("\"description\": \"", "\"").ToString(),
                    };
                    _ = Functions.SplitHead(ref text);
                    _ = ModifyUI(() => _sourceItems.Add(item));
                    ++i;
                }
            } catch (Functions.ParseFaildException) {
                return(false);
            }
            Debug.WriteLine($"Parsed {i} items from the source file.");

            return(true);
        }