<commit_before>using UnityEngine;
using Assets.Scripts.Content;
using System.IO;
using System.Collections.Generic;

public class ReorderComponents
{
    EditorSelectionList sourceESL;
    string source = "";

    public ReorderComponents()
    {
        Game game = Game.Get();

        HashSet<string> sources = new HashSet<string>();
        foreach (QuestData.QuestComponent c in game.quest.qd.components.Values)
        {
            if (!(c is PerilData)) sources.Add(c.source);
        }

        List<EditorSelectionList.SelectionListEntry> list = new List<EditorSelectionList.SelectionListEntry>();
        foreach (string s in sources)
        {
            list.Add(new EditorSelectionList.SelectionListEntry(s));
        }

        sourceESL = new EditorSelectionList(new StringKey("val", "SELECT", new StringKey("val", "FILE")), list, delegate { ReorderSource(); });
        sourceESL.SelectItem();
    }

    public void ReorderSource()
    {
        source = sourceESL.selection;
        Update();
    }

    public void Update()
    {
        Game game = Game.Get();
        Destroyer.Dialog();

        // Border
        DialogBox db = new DialogBox(new Vector2(UIScaler.GetHCenter(-12.5f), 0), new Vector2(25, 30), StringKey.NULL);
        db.AddBorder();

        // Title
        db = new DialogBox(new Vector2(UIScaler.GetHCenter(-12), 0), new Vector2(24, 1), new StringKey(null, source, false));

        float offset = 2f;
        TextButton tb = null;

        // Scroll BG
        float scrollStart = offset;
        db = new DialogBox(new Vector2(UIScaler.GetHCenter(-11.5f), offset), new Vector2(23, 27 - offset), StringKey.NULL);
        db.AddBorder();
        db.background.AddComponent<UnityEngine.UI.Mask>();
        UnityEngine.UI.ScrollRect scrollRect = db.background.AddComponent<UnityEngine.UI.ScrollRect>();

        GameObject scrollArea = new GameObject("scroll");
        RectTransform scrollInnerRect = scrollArea.AddComponent<RectTransform>();
        scrollArea.transform.parent = db.background.transform;
        scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 22 * UIScaler.GetPixelsPerUnit());
        scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 1);

        GameObject scrollBarObj = new GameObject("scrollbar");
        scrollBarObj.transform.parent = db.background.transform;
        RectTransform scrollBarRect = scrollBarObj.AddComponent<RectTransform>();
        scrollBarRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, (28 - offset) * UIScaler.GetPixelsPerUnit());
        scrollBarRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 22 * UIScaler.GetPixelsPerUnit(), 1 * UIScaler.GetPixelsPerUnit());
        UnityEngine.UI.Scrollbar scrollBar = scrollBarObj.AddComponent<UnityEngine.UI.Scrollbar>();
        scrollBar.direction = UnityEngine.UI.Scrollbar.Direction.BottomToTop;
        scrollRect.verticalScrollbar = scrollBar;

        GameObject scrollBarHandle = new GameObject("scrollbarhandle");
        scrollBarHandle.transform.parent = scrollBarObj.transform;
        scrollBarHandle.AddComponent<UnityEngine.UI.Image>();
        scrollBarHandle.GetComponent<UnityEngine.UI.Image>().color = new Color(0.7f, 0.7f, 0.7f);
        scrollBar.handleRect = scrollBarHandle.GetComponent<RectTransform>();
        scrollBar.handleRect.offsetMin = Vector2.zero;
        scrollBar.handleRect.offsetMax = Vector2.zero;

        scrollRect.content = scrollInnerRect;
        scrollRect.horizontal = false;
        scrollRect.scrollSensitivity = 27f;

        bool first = true;
        foreach (QuestData.QuestComponent c in game.quest.qd.components.Values)
        {
            if (!c.source.Equals(source)) continue;

            string name = c.sectionName;

            if (!first)
            {
                tb = new TextButton(new Vector2(UIScaler.GetHCenter(9.5f), offset++), new Vector2(1, 1), 
                    new StringKey(null, "▽", false), delegate { DecComponent(name); }, Color.black);
                tb.button.GetComponent<UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont();
                tb.button.GetComponent<UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial");
                tb.background.GetComponent<UnityEngine.UI.Image>().color = Color.green;
                tb.background.transform.parent = scrollArea.transform;

                tb = new TextButton(new Vector2(UIScaler.GetHCenter(-11.5f), offset), new Vector2(1, 1), 
                    new StringKey(null, "△", false), delegate { DecComponent(name); }, Color.black);
                tb.button.GetComponent<UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont();
                tb.button.GetComponent<UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial");
                tb.background.GetComponent<UnityEngine.UI.Image>().color = Color.green;
                tb.background.transform.parent = scrollArea.transform;
            }
            db = new DialogBox(new Vector2(UIScaler.GetHCenter(-10.5f), offset), new Vector2(20, 1), new StringKey(null, c.sectionName, false), Color.black, Color.white);
            db.textObj.GetComponent<UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial");
            db.background.transform.parent = scrollArea.transform;
            first = false;
        }
        offset++;
        if (offset < 28) offset = 28;

        scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, (offset - scrollStart) * UIScaler.GetPixelsPerUnit());
        // Cancel button
        tb = new TextButton(new Vector2(UIScaler.GetHCenter(-4.5f), 28f), new Vector2(9, 1), CommonStringKeys.CANCEL, delegate { Destroyer.Dialog(); });
        tb.background.GetComponent<UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f);
        tb.button.GetComponent<UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont();
    }

    public void DecComponent(string name)
    {
        Game game = Game.Get();
        bool held = false;
        Dictionary<string, QuestData.QuestComponent> newDict = new Dictionary<string, QuestData.QuestComponent>();
        foreach (KeyValuePair<string, QuestData.QuestComponent> kv in game.quest.qd.components)
        {
            if (!kv.Key.Equals(name))
            {
                newDict.Add(kv.Key, kv.Value);
                if (held && kv.Value.source.Equals(source))
                {
                    held = false;
                    newDict.Add(name, game.quest.qd.components[name]);
                }
            }
            else
            {
                held = true;
            }
        }
        if (held)
        {
            newDict.Add(name, game.quest.qd.components[name]);
        }
        Update();
    }
}<commit_msg>Reorder working.<commit_after>using UnityEngine;
using Assets.Scripts.Content;
using System.IO;
using System.Collections.Generic;

public class ReorderComponents
{
    EditorSelectionList sourceESL;
    string source = "";

    public ReorderComponents()
    {
        Game game = Game.Get();

        HashSet<string> sources = new HashSet<string>();
        foreach (QuestData.QuestComponent c in game.quest.qd.components.Values)
        {
            if (!(c is PerilData)) sources.Add(c.source);
        }

        List<EditorSelectionList.SelectionListEntry> list = new List<EditorSelectionList.SelectionListEntry>();
        foreach (string s in sources)
        {
            list.Add(new EditorSelectionList.SelectionListEntry(s));
        }

        sourceESL = new EditorSelectionList(new StringKey("val", "SELECT", new StringKey("val", "FILE")), list, delegate { ReorderSource(); });
        sourceESL.SelectItem();
    }

    public void ReorderSource()
    {
        source = sourceESL.selection;
        Update();
    }

    public void Update()
    {
        Game game = Game.Get();
        Destroyer.Dialog();

        // Border
        DialogBox db = new DialogBox(new Vector2(UIScaler.GetHCenter(-12.5f), 0), new Vector2(25, 30), StringKey.NULL);
        db.AddBorder();

        // Title
        db = new DialogBox(new Vector2(UIScaler.GetHCenter(-12), 0), new Vector2(24, 1), new StringKey(null, source, false));

        float offset = 2f;
        TextButton tb = null;

        // Scroll BG
        float scrollStart = offset;
        db = new DialogBox(new Vector2(UIScaler.GetHCenter(-11.5f), offset), new Vector2(23, 27 - offset), StringKey.NULL);
        db.AddBorder();
        db.background.AddComponent<UnityEngine.UI.Mask>();
        UnityEngine.UI.ScrollRect scrollRect = db.background.AddComponent<UnityEngine.UI.ScrollRect>();

        GameObject scrollArea = new GameObject("scroll");
        RectTransform scrollInnerRect = scrollArea.AddComponent<RectTransform>();
        scrollArea.transform.parent = db.background.transform;
        scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 22 * UIScaler.GetPixelsPerUnit());
        scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 1);

        GameObject scrollBarObj = new GameObject("scrollbar");
        scrollBarObj.transform.parent = db.background.transform;
        RectTransform scrollBarRect = scrollBarObj.AddComponent<RectTransform>();
        scrollBarRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, (28 - offset) * UIScaler.GetPixelsPerUnit());
        scrollBarRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 22 * UIScaler.GetPixelsPerUnit(), 1 * UIScaler.GetPixelsPerUnit());
        UnityEngine.UI.Scrollbar scrollBar = scrollBarObj.AddComponent<UnityEngine.UI.Scrollbar>();
        scrollBar.direction = UnityEngine.UI.Scrollbar.Direction.BottomToTop;
        scrollRect.verticalScrollbar = scrollBar;

        GameObject scrollBarHandle = new GameObject("scrollbarhandle");
        scrollBarHandle.transform.parent = scrollBarObj.transform;
        scrollBarHandle.AddComponent<UnityEngine.UI.Image>();
        scrollBarHandle.GetComponent<UnityEngine.UI.Image>().color = new Color(0.7f, 0.7f, 0.7f);
        scrollBar.handleRect = scrollBarHandle.GetComponent<RectTransform>();
        scrollBar.handleRect.offsetMin = Vector2.zero;
        scrollBar.handleRect.offsetMax = Vector2.zero;

        scrollRect.content = scrollInnerRect;
        scrollRect.horizontal = false;
        scrollRect.scrollSensitivity = 27f;

        bool first = true;
        foreach (QuestData.QuestComponent c in game.quest.qd.components.Values)
        {
            if (!c.source.Equals(source)) continue;

            string name = c.sectionName;

            if (!first)
            {
                tb = new TextButton(new Vector2(UIScaler.GetHCenter(9.5f), offset++), new Vector2(1, 1), 
                    new StringKey(null, "▽", false), delegate { IncComponent(name); }, Color.black);
                tb.button.GetComponent<UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont();
                tb.button.GetComponent<UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial");
                tb.background.GetComponent<UnityEngine.UI.Image>().color = Color.green;
                tb.background.transform.parent = scrollArea.transform;

                tb = new TextButton(new Vector2(UIScaler.GetHCenter(-11.5f), offset), new Vector2(1, 1), 
                    new StringKey(null, "△", false), delegate { IncComponent(name); }, Color.black);
                tb.button.GetComponent<UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont();
                tb.button.GetComponent<UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial");
                tb.background.GetComponent<UnityEngine.UI.Image>().color = Color.green;
                tb.background.transform.parent = scrollArea.transform;
            }
            db = new DialogBox(new Vector2(UIScaler.GetHCenter(-10.5f), offset), new Vector2(20, 1), new StringKey(null, c.sectionName, false), Color.black, Color.white);
            db.textObj.GetComponent<UnityEngine.UI.Text>().material = (Material)Resources.Load("Fonts/FontMaterial");
            db.background.transform.parent = scrollArea.transform;
            first = false;
        }
        offset++;
        if (offset < 28) offset = 28;

        scrollInnerRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, (offset - scrollStart) * UIScaler.GetPixelsPerUnit());
        // Cancel button
        tb = new TextButton(new Vector2(UIScaler.GetHCenter(-4.5f), 28f), new Vector2(9, 1), CommonStringKeys.FINISHED, delegate { Destroyer.Dialog(); });
        tb.background.GetComponent<UnityEngine.UI.Image>().color = new Color(0.03f, 0.0f, 0f);
        tb.button.GetComponent<UnityEngine.UI.Text>().fontSize = UIScaler.GetSmallFont();
    }

    public void IncComponent(string name)
    {
        Game game = Game.Get();
        Dictionary<string, QuestData.QuestComponent> preDict = new Dictionary<string, QuestData.QuestComponent>();
        List<QuestData.QuestComponent> postList = new List<QuestData.QuestComponent>();
        foreach (QuestData.QuestComponent c in game.quest.qd.components.Values)
        {
            if (c.sectionName.Equals(name))
            {
                preDict.Add(c.sectionName, c);
            }
            else
            {
                if (c.source.Equals(game.quest.qd.components[name].source))
                {
                    foreach (QuestData.QuestComponent post in postList)
                    {
                        preDict.Add(post.sectionName, post);
                    }
                    postList = new List<QuestData.QuestComponent>();
                }
                postList.Add(c);
            }
        }

        foreach (QuestData.QuestComponent post in postList)
        {
            preDict.Add(post.sectionName, post);
        }

        game.quest.qd.components = preDict;
        Update();
    }
}
{'fraction_non_alphanumeric': 0.11908003152539944, 'fraction_numerical': 0.012753457046643261, 'mean_word_length': 2.6263964666147053, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7146178', 'n_tokens_mistral': 4040, 'n_tokens_neox': 3882, 'n_words': 692}