using Cryville.EEW.Core.Map;
using System.Drawing;
using UnityEngine;
using Color = UnityEngine.Color;

namespace Cryville.EEW.Unity.Map.Element {
	class PointElement : MapElement {
		PointF _tilePos;
		public override RectangleF? AABB => new(_tilePos, SizeF.Empty);

		public void SetLocation(PointF location, ref int order) {
			_tilePos = MapTileUtils.WorldToTilePos(location);
			Vector3 pos = _tilePos.ToVector2();
			pos.z = OrderToZ(ref order);
			transform.localPosition = pos;
		}

		[SerializeField]
		Color m_color = Color.white;
		public Color Color {
			get => m_color;
			set {
				if (m_color == value) return;
				m_color = value;
				_spriteRenderer.color = value;
			}
		}

		float m_size;
		public float Size {
			get => m_size;
			set {
				if (m_size == value) return;
				m_size = value;
				OnSetScale();
			}
		}

		SpriteRenderer _spriteRenderer;
		void Awake() {
			_spriteRenderer = GetComponent<SpriteRenderer>();
		}

		protected override void OnSetScale() {
			transform.localScale = ComputedScale * m_size / 256 * Vector3.one;
		}
	}
}
