<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using Tilemaps.Scripts.Behaviours.Objects;
using Tilemaps.Scripts.Tiles;
using Tilemaps.Scripts.Utils;
using UnityEngine;

namespace Tilemaps.Scripts.Behaviours.Layers
{
    [ExecuteInEditMode]
    public class ObjectLayer : Layer
    {
        private TileList _objects;

        public TileList Objects => _objects ?? (_objects = new TileList());

        public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix)
        {
            var objectTile = tile as ObjectTile;

            if (objectTile)
            {
                if (!objectTile.IsItem)
                    tilemap.SetTile(position, null);
                objectTile.SpawnObject(position, tilemap, transformMatrix);
            }
            else
            {
                base.SetTile(position, tile, transformMatrix);
            }
        }

        public override bool HasTile(Vector3Int position)
        {
            return (Objects.Get(position).Count > 0) || base.HasTile(position);
        }

        public override void RemoveTile(Vector3Int position)
        {
            foreach (var obj in Objects.Get(position).ToArray())
            {
                DestroyImmediate(obj.gameObject);
            }

            base.RemoveTile(position);
        }

        public override bool IsPassableAt(Vector3Int origin, Vector3Int to)
        {
            var objTo = Objects.GetFirst<RegisterObject>(to);

            if (objTo && (!objTo.IsPassable() || !objTo.IsPassable(origin)))
            {
                return false;
            }

            var objOrigin = Objects.GetFirst<RegisterObject>(origin);
            if (objOrigin && !objOrigin.IsPassable(to))
            {
                return false;
            }

            return base.IsPassableAt(origin, to);
        }

        public override bool IsPassableAt(Vector3Int position)
        {
            var obj = Objects.GetFirst<RegisterObject>(position);

            if (obj)
            {
                return obj.IsPassable();
            }

            var player = Objects.GetFirst<RegisterPlayer>(position);
            return player ? player.IsPassable() : base.IsPassableAt(position);
        }

        public override bool IsAtmosPassableAt(Vector3Int position)
        {
            var obj = Objects.GetFirst<RegisterObject>(position);

            return obj ? obj.IsAtmosPassable() : base.IsAtmosPassableAt(position);
        }
<commit_msg>fixed doors closing with player inside<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using Tilemaps.Scripts.Behaviours.Objects;
using Tilemaps.Scripts.Tiles;
using Tilemaps.Scripts.Utils;
using UnityEngine;

namespace Tilemaps.Scripts.Behaviours.Layers
{
    [ExecuteInEditMode]
    public class ObjectLayer : Layer
    {
        private TileList _objects;

        public TileList Objects => _objects ?? (_objects = new TileList());

        public override void SetTile(Vector3Int position, GenericTile tile, Matrix4x4 transformMatrix)
        {
            var objectTile = tile as ObjectTile;

            if (objectTile)
            {
                if (!objectTile.IsItem)
                    tilemap.SetTile(position, null);
                objectTile.SpawnObject(position, tilemap, transformMatrix);
            }
            else
            {
                base.SetTile(position, tile, transformMatrix);
            }
        }

        public override bool HasTile(Vector3Int position)
        {
            return (Objects.Get(position).Count > 0) || base.HasTile(position);
        }

        public override void RemoveTile(Vector3Int position)
        {
            foreach (var obj in Objects.Get(position).ToArray())
            {
                DestroyImmediate(obj.gameObject);
            }

            base.RemoveTile(position);
        }

        public override bool IsPassableAt(Vector3Int origin, Vector3Int to)
        {
            var objTo = Objects.GetFirst<RegisterObject>(to);

            if (objTo && (!objTo.IsPassable() || !objTo.IsPassable(origin)))
            {
                return false;
            }

            var objOrigin = Objects.GetFirst<RegisterObject>(origin);
            if (objOrigin && !objOrigin.IsPassable(to))
            {
                return false;
            }

            return base.IsPassableAt(origin, to);
        }

        public override bool IsPassableAt(Vector3Int position)
        {
            var objects = Objects.Get<RegisterTile>(position);
            
            return objects.All(x => x.IsPassable()) && base.IsPassableAt(position);
        }

        public override bool IsAtmosPassableAt(Vector3Int position)
        {
            var obj = Objects.GetFirst<RegisterObject>(position);

            return obj ? obj.IsAtmosPassable() : base.IsAtmosPassableAt(position);
        }

{'fraction_non_alphanumeric': 0.08819345661450925, 'fraction_numerical': 0.00406421459053038, 'mean_word_length': 1.8716452742123688, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 17, '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': '6079568', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1266, 'n_words': 268}