<commit_before>﻿using UnityEngine;
using System.Collections;


namespace ProcRoom.UI
{

    public class AbilitySelector : MonoBehaviour {

        AbilityStat[] selectors;
        AbilityStat selected;

        void OnEnable()
        {
            CharacterCreation.OnNewPoints += OnNewPointsAvailable;
        }

        void OnDisable()
        {
            CharacterCreation.OnNewPoints -= OnNewPointsAvailable;
        }

        private void OnNewPointsAvailable(int points)
        {
            for (int i=0; i<selectors.Length; i++)
            {
                if (!selectors[i].selected)
                {
                    if (selectors[i].cost <= points)
                    {
                        selectors[i].allowed = true;
                        points -= selectors[i].cost;
                    } else
                    {
                        selectors[i].allowed = false;
                        points = -1;
                    }
                }
            }
        }

        void Start() {

            var selectors = new AbilityStat[transform.childCount];
            int nextIndex = 0;
            for (int i = 0; i < selectors.Length; i++)
            {
                var sel = transform.GetChild(i).GetComponent<AbilityStat>();
                if (sel)
                {
                    selectors[nextIndex] = sel;
                    nextIndex++;
                }
            }
            this.selectors = new AbilityStat[nextIndex];
            System.Array.Copy(selectors, this.selectors, nextIndex);
            OnNewPointsAvailable(CharacterCreation.Points);
            for (int i=0; i<this.selectors.Length; i++)
            {
                if (this.selectors[i].selected)
                    selected = this.selectors[i];
            }
        }
                
        public void EmulateSelect(AbilityStat selector)
        {
            bool shouldBeSelected = selector != null;
            int culmulativeCost = 0;
            for (int i=0; i<selectors.Length;i++)
            {
                if (!selectors[i].allowed)
                    shouldBeSelected = false;

                if (shouldBeSelected && !selectors[i].selected)
                {
                    selectors[i].selected = true;
                    culmulativeCost += selectors[i].cost;
                } else if (!shouldBeSelected && selectors[i].selected)
                {
                    selectors[i].selected = false;
                    culmulativeCost -= selectors[i].cost;
                }

                //All coming should be not selected
                if (selector == selectors[i])
                    shouldBeSelected = false;
            }

            CharacterCreation.NewTransaction(culmulativeCost);
        }
<commit_msg>Coopted character creation UI parts for passive use<commit_after>﻿using UnityEngine;
using System.Collections;


namespace ProcRoom.UI
{

    public class AbilitySelector : MonoBehaviour {

        AbilityStat[] selectors;
        AbilityStat selected;

        CharacterCreation characterCreation;

        protected virtual void OnEnable()
        {
            if (characterCreation)
                CharacterCreation.OnNewPoints += OnNewPointsAvailable;
        }

        protected virtual void OnDisable()
        {
            if (characterCreation)
                CharacterCreation.OnNewPoints -= OnNewPointsAvailable;
        }

        protected virtual void OnNewPointsAvailable(int points)
        {
            for (int i=0; i<selectors.Length; i++)
            {
                if (!selectors[i].selected)
                {
                    if (selectors[i].cost <= points)
                    {
                        selectors[i].allowed = true;
                        points -= selectors[i].cost;
                    } else
                    {
                        selectors[i].allowed = false;
                        points = -1;
                    }
                }
            }
        }

        void Start() {
            characterCreation = GetComponentInParent<CharacterCreation>();
            var selectors = new AbilityStat[transform.childCount];
            int nextIndex = 0;
            for (int i = 0; i < selectors.Length; i++)
            {
                var sel = transform.GetChild(i).GetComponent<AbilityStat>();
                if (sel)
                {
                    selectors[nextIndex] = sel;
                    nextIndex++;
                }
            }
            this.selectors = new AbilityStat[nextIndex];
            System.Array.Copy(selectors, this.selectors, nextIndex);
            if (characterCreation)
                OnNewPointsAvailable(CharacterCreation.Points);
            for (int i=0; i<this.selectors.Length; i++)
            {
                if (this.selectors[i].selected)
                    selected = this.selectors[i];
            }
        }
                
        public void EmulateSelect(AbilityStat selector)
        {
            bool shouldBeSelected = selector != null;
            int culmulativeCost = 0;
            for (int i=0; i<selectors.Length;i++)
            {
                if (!selectors[i].allowed)
                    shouldBeSelected = false;

                if (shouldBeSelected && !selectors[i].selected)
                {
                    selectors[i].selected = true;
                    culmulativeCost += selectors[i].cost;
                } else if (!shouldBeSelected && selectors[i].selected)
                {
                    selectors[i].selected = false;
                    culmulativeCost -= selectors[i].cost;
                }

                //All coming should be not selected
                if (selector == selectors[i])
                    shouldBeSelected = false;
            }
            if (characterCreation)
                CharacterCreation.NewTransaction(culmulativeCost);
        }

{'fraction_non_alphanumeric': 0.08747682454070453, 'fraction_numerical': 0.002359683128265633, 'mean_word_length': 1.2117033171822587, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 6, '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': '2347041', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1366, 'n_words': 286}