<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using RimWorld;
using UnityEngine;
using Verse;

namespace CommunityCoreLibrary.MiniMap
{

    public class MiniMapController : MapComponent
    {

        #region Fields
        public static bool              visible = false;

        public static bool              dirty = true;
        public static bool              initialized = false;
        public static Vector2           windowSize = new Vector2( 250f, 250f );
        public static List<MiniMap>     visibleMiniMaps = new List<MiniMap>();

        #endregion Fields

        #region Properties

        private Window_MiniMap          GetWindow
        {
            get
            {
                return Find.WindowStack.WindowOfType<Window_MiniMap>();
            }
        }

        #endregion Properties

        #region Base Overrides

        public override void            MapComponentOnGUI()
        {
            // No minimap
            if( !visible )
            {
                // Close the window if needed
                if( GetWindow != null )
                {
                    CloseWindow();
                }
                return;
            }

            // Initialize the map component
            if( !initialized )
            {
                Initialize();
            }

            // Make sure the window is open
            if( GetWindow == null )
            {
                if( !OpenWindow() )
                {
                    return;
                }
            }

            // Update the window
            UpdateWindow();

            // (Re-)sort minimaps
            if( dirty )
            {
                SortMiniMaps();
            }

            // Update the minimaps
            UpdateMiniMaps();
        }

        #endregion

        #region Initialization

        private void Initialize()
        {
            // Sort minimaps in drawOrder
            SortMiniMaps();

            // ready to go
            initialized = true;

            // perform initial update for all overlays
            // do after initialization flag to avoid infinite loop.
            foreach( var minimap in visibleMiniMaps )
            {
                minimap.Update();
            }
        }<commit_msg>[adds] + Minimap controller scribes minimap and overlay states<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using RimWorld;
using UnityEngine;
using Verse;

namespace CommunityCoreLibrary.MiniMap
{

    public class MiniMapController : MapComponent
    {

        #region Fields
        public static bool              visible = false;

        public static bool              dirty = true;
        public static bool              initialized = false;
        public static Vector2           windowSize = new Vector2( 250f, 250f );
        public static List<MiniMap>     visibleMiniMaps = new List<MiniMap>();

        #endregion Fields

        #region Properties

        private Window_MiniMap          GetWindow
        {
            get
            {
                return Find.WindowStack.WindowOfType<Window_MiniMap>();
            }
        }

        #endregion Properties

        #region Base Overrides

        public override void            MapComponentOnGUI()
        {
            // No minimap
            if( !visible )
            {
                // Close the window if needed
                if( GetWindow != null )
                {
                    CloseWindow();
                }
                return;
            }

            // Initialize the map component
            if( !initialized )
            {
                Initialize();
            }

            // Make sure the window is open
            if( GetWindow == null )
            {
                if( !OpenWindow() )
                {
                    return;
                }
            }

            // Update the window
            UpdateWindow();

            // (Re-)sort minimaps
            if( dirty )
            {
                SortMiniMaps();
            }

            // Update the minimaps
            UpdateMiniMaps();
        }

        public override void ExposeData()
        {
            base.ExposeData();
            foreach( var minimap in Controller.Data.MiniMaps )
            {
                #region Minimap Header
                Scribe.EnterNode( minimap.miniMapDef.defName );
                #endregion

                var hidden = minimap.Hidden;
                Scribe_Values.LookValue( ref hidden, "hidden" );

                if( Scribe.mode == LoadSaveMode.LoadingVars )
                {
                    minimap.Hidden = hidden;
                }

                #region Handle all MiniMap Overlays
                foreach( var overlay in minimap.overlayWorkers )
                {
                    #region Overlay Header
                    Scribe.EnterNode( overlay.overlayDef.defName );
                    #endregion

                    hidden = overlay.Hidden;
                    Scribe_Values.LookValue( ref hidden, "hidden" );

                    if( Scribe.mode == LoadSaveMode.LoadingVars )
                    {
                        overlay.Hidden = hidden;
                    }

                    #region Finalize Overlay
                    Scribe.ExitNode();
                    #endregion
                }
                #endregion

                #region Finalize Minimap
                Scribe.ExitNode();
                #endregion
            }
        }

        #endregion

        #region Initialization

        private void Initialize()
        {
            // Sort minimaps in drawOrder
            SortMiniMaps();

            // ready to go
            initialized = true;

            // perform initial update for all overlays
            // do after initialization flag to avoid infinite loop.
            foreach( var minimap in visibleMiniMaps )
            {
                minimap.Update();
            }
        }
{'fraction_non_alphanumeric': 0.06585167074164629, 'fraction_numerical': 0.0026079869600651997, 'mean_word_length': 1.0666891209161333, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4323967', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1361, 'n_words': 381}