Пример #1
0
        private static int ParseResourceName(string line, UndertaleData data)
        {
            if (data != null)
            {
                UndertaleNamedResource byName = data.ByName(line);
                if (byName == null)
                {
                    throw new FormatException("Could not locate resource named '" + line + "'.");
                }

                int id = data.IndexOf(byName);
                if (id >= 0)
                {
                    return(id);
                }
            }
            throw new FormatException("Unable to parse " + line + " as number or resource name");
        }
Пример #2
0
    public static int GetAssetTagID(UndertaleData data, UndertaleNamedResource resource)
    {
        ResourceType type = resource switch
        {
            UndertaleGameObject => ResourceType.Object,
            UndertaleSprite => ResourceType.Sprite,
            UndertaleSound => ResourceType.Sound,
            UndertaleRoom => ResourceType.Room,
            UndertalePath => ResourceType.Path,
            UndertaleScript => ResourceType.Script,
            UndertaleFont => ResourceType.Font,
            UndertaleTimeline => ResourceType.Timeline,
            UndertaleBackground => ResourceType.Background,
            UndertaleShader => ResourceType.Shader,
            UndertaleSequence => ResourceType.Sequence,
            UndertaleAnimationCurve => ResourceType.AnimCurve,
            _ => throw new ArgumentException("Invalid resource type!")
        };
        IList list = data[resource.GetType()] as IList;

        int offset = resource is UndertaleScript ? 100000 : 0;

        return(((int)type << 24) | ((list.IndexOf(resource) + offset) & 0xFFFFFF));
    }
Пример #3
0
            /// Constructs an element at the specified offset.
            /// May return null if no element should be constructed.
            public override VisualLineElement ConstructElement(int offset)
            {
                Match m = FindMatch(offset, regex);

                if (m.Success && m.Index == 0)
                {
                    UndertaleData data = (Application.Current.MainWindow as MainWindow).Data;
                    bool          func = (offset + m.Length + 1 < CurrentContext.VisualLine.LastDocumentLine.EndOffset) &&
                                         (CurrentContext.Document.GetCharAt(offset + m.Length) == '(');
                    UndertaleNamedResource val = null;

                    var doc      = CurrentContext.Document;
                    var textArea = CurrentContext.TextView.GetService(typeof(TextArea)) as TextArea;
                    var editor   = textArea.GetService(typeof(TextEditor)) as TextEditor;
                    var parent   = VisualTreeHelper.GetParent(editor);
                    do
                    {
                        if ((parent as FrameworkElement) is UserControl)
                        {
                            break;
                        }
                        parent = VisualTreeHelper.GetParent(parent);
                    } while (parent != null);

                    // Process the content of this identifier/function
                    if (func)
                    {
                        val = data.Scripts.ByName(m.Value);
                        if (val == null)
                        {
                            val = data.Functions.ByName(m.Value);
                        }
                    }
                    else
                    {
                        val = data.ByName(m.Value);
                    }
                    if (val == null)
                    {
                        if (offset >= 7)
                        {
                            if (CurrentContext.Document.GetText(offset - 7, 7) == "global.")
                            {
                                return(new ColorVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                               new SolidColorBrush(Color.FromRgb(0xF9, 0x7B, 0xF9))));
                            }
                        }
                        if (data.BuiltinList.Constants.ContainsKey(m.Value))
                        {
                            return(new ColorVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                           new SolidColorBrush(Color.FromRgb(0xFF, 0x80, 0x80))));
                        }
                        if (data.BuiltinList.GlobalNotArray.ContainsKey(m.Value) ||
                            data.BuiltinList.Instance.ContainsKey(m.Value) ||
                            data.BuiltinList.GlobalArray.ContainsKey(m.Value))
                        {
                            return(new ColorVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                           new SolidColorBrush(Color.FromRgb(0x58, 0xE3, 0x5A))));
                        }
                        if ((parent as UndertaleCodeEditor).CurrentDecompiledLocals.Contains(m.Value))
                        {
                            return(new ColorVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                           new SolidColorBrush(Color.FromRgb(0xFF, 0xF8, 0x99))));
                        }
                        return(null);
                    }

                    var line = new ClickVisualLineText(m.Value, CurrentContext.VisualLine, m.Length,
                                                       func ? null : new SolidColorBrush(Color.FromRgb(0xFF, 0x80, 0x80)));
                    line.Clicked += (text) =>
                    {
                        (Application.Current.MainWindow as MainWindow).ChangeSelection(val);
                    };

                    return(line);
                }

                return(null);
            }