<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using MapMatrix;
using System.IO;
using System;
using UnityEditorInternal;
using System.Reflection;
using UnityEngine.SceneManagement;

public class MapToPNG: Editor {

    private static List<string> sortingLayerNames = GetSortingLayerNames();

    [MenuItem("Tools/Make Map PNG")]
    static void Map2PNG() {
        var nodesMapped = GetMappedNodes();

        var mapTexture = new Texture2D(nodesMapped.GetLength(1) * 32, nodesMapped.GetLength(0) * 32);


        Color[] colors = new Color[nodesMapped.GetLength(1) * 32 * nodesMapped.GetLength(0) * 32];

        for(int y = 0; y < nodesMapped.GetLength(0); y++) {
            for(int x = 0; x < nodesMapped.GetLength(1); x++) {
                var n = nodesMapped[y, x];

                if(n == null)
                    continue;

                var spriteRenderers = new List<SpriteRenderer>();

                foreach(var t in n.GetTiles()) {

                    foreach(var sr in t.GetComponentsInChildren<SpriteRenderer>()) {
                        if(!sr || !sr.sprite || sr.sortingLayerID == 0)
                            continue;

                        spriteRenderers.Add(sr);
                    }
                }

                spriteRenderers.Sort(CompareSpriteRenderer);

                foreach(var sr in spriteRenderers) {
                    var sprite = sr.sprite;

                    var pixels = sprite.texture.GetPixels((int) sprite.rect.x,
                                            (int) sprite.rect.y,
                                            (int) sprite.rect.width,
                                            (int) sprite.rect.height);

                    var texWidth = sprite.rect.width;
                    var texHeight = sprite.rect.height;
                    var localX = sr.transform.localPosition.x;
                    var localY = sr.transform.localPosition.y;

                    var texX = (int) ((x + (1 - (texWidth / 32)) / 2 + localX) * 32);
                    var texY = (int) ((y + (1 - (texHeight / 32)) / 2 + localY) * 32);

                    for(int x1 = 0; x1 < texWidth; x1++) {
                        for(int y1 = 0; y1 < texHeight; y1++) {
                            var px = pixels[y1 * (int) sprite.rect.width + x1];

                            var i = (texY + y1) * nodesMapped.GetLength(1) * 32 + texX + x1;

                            if(px.a > 0) {
                                if(colors[i] == null) {
                                    colors[i] = px;
                                } else {
                                    colors[i] = colors[i] * (1 - px.a) + px * px.a;
                                }
                            }
                        }
                    }
                }
            }
        }

        mapTexture.SetPixels(0, 0, nodesMapped.GetLength(1) * 32, nodesMapped.GetLength(0) * 32, colors);
        mapTexture.Apply();

        byte[] bytes = mapTexture.EncodeToPNG();

        File.WriteAllBytes(Application.dataPath + "/../" + SceneManager.GetActiveScene().name + ".png", bytes);

        Debug.Log("Making Map Image Done");
    }

    private static MatrixNode[,] GetMappedNodes() {

        var keys = Matrix.Nodes.keys;
        var values = Matrix.Nodes.values;

        var x = new List<int>();
        var y = new List<int>();

        var nodes = new List<MatrixNode>();

        for(int i = 0; i < keys.Count; i++) {
            var k = keys[i];
            var v = values[i];

            if(v.GetTiles().Count > 0) {
                nodes.Add(v);
                x.Add((int) (k >> 32));<commit_msg>reverted a changed that would have be broken on upstream<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Matrix;
using System.IO;
using System;
using UnityEditorInternal;
using System.Reflection;
using UnityEngine.SceneManagement;

public class MapToPNG: Editor {

    private static List<string> sortingLayerNames = GetSortingLayerNames();

    [MenuItem("Tools/Make Map PNG")]
    static void Map2PNG() {
        var nodesMapped = GetMappedNodes();

        var mapTexture = new Texture2D(nodesMapped.GetLength(1) * 32, nodesMapped.GetLength(0) * 32);

        Color[] colors = new Color[nodesMapped.GetLength(1) * 32 * nodesMapped.GetLength(0) * 32];

        for(int y = 0; y < nodesMapped.GetLength(0); y++) {
            for(int x = 0; x < nodesMapped.GetLength(1); x++) {
                var n = nodesMapped[y, x];

                if(n == null)
                    continue;

                var spriteRenderers = new List<SpriteRenderer>();

                foreach(var t in n.GetTiles()) {

                    foreach(var sr in t.GetComponentsInChildren<SpriteRenderer>()) {
                        if(!sr || !sr.sprite || sr.sortingLayerID == 0)
                            continue;

                        spriteRenderers.Add(sr);
                    }
                }

                spriteRenderers.Sort(CompareSpriteRenderer);

                foreach(var sr in spriteRenderers) {
                    var sprite = sr.sprite;

                    var pixels = sprite.texture.GetPixels((int) sprite.rect.x,
                                            (int) sprite.rect.y,
                                            (int) sprite.rect.width,
                                            (int) sprite.rect.height);

                    var texWidth = sprite.rect.width;
                    var texHeight = sprite.rect.height;
                    var localX = sr.transform.localPosition.x;
                    var localY = sr.transform.localPosition.y;

                    var texX = (int) ((x + (1 - (texWidth / 32)) / 2 + localX) * 32);
                    var texY = (int) ((y + (1 - (texHeight / 32)) / 2 + localY) * 32);

                    for(int x1 = 0; x1 < texWidth; x1++) {
                        for(int y1 = 0; y1 < texHeight; y1++) {
                            var px = pixels[y1 * (int) sprite.rect.width + x1];

                            var i = (texY + y1) * nodesMapped.GetLength(1) * 32 + texX + x1;

                            if(px.a > 0) {
                                if(colors[i] == null) {
                                    colors[i] = px;
                                } else {
                                    colors[i] = colors[i] * (1 - px.a) + px * px.a;
                                }
                            }
                        }
                    }
                }
            }
        }

        mapTexture.SetPixels(0, 0, nodesMapped.GetLength(1) * 32, nodesMapped.GetLength(0) * 32, colors);
        mapTexture.Apply();

        byte[] bytes = mapTexture.EncodeToPNG();

        File.WriteAllBytes(Application.dataPath + "/../" + SceneManager.GetActiveScene().name + ".png", bytes);

        Debug.Log("Making Map Image Done");
    }

    private static MatrixNode[,] GetMappedNodes() {

        var keys = Matrix.Matrix.Nodes.keys;
        var values = Matrix.Matrix.Nodes.values;

        var x = new List<int>();
        var y = new List<int>();

        var nodes = new List<MatrixNode>();

        for(int i = 0; i < keys.Count; i++) {
            var k = keys[i];
            var v = values[i];

            if(v.GetTiles().Count > 0) {
                nodes.Add(v);
                x.Add((int) (k >> 32));
{'fraction_non_alphanumeric': 0.11759989309100628, 'fraction_numerical': 0.016036349057864493, 'mean_word_length': 1.3148778224559232, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2634824', 'n_tokens_mistral': 2228, 'n_tokens_neox': 2013, 'n_words': 482}