using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class gameIdJsonData
{
    public string nowId = "";
    public short width = 0;
    public short height = 0;
    public List<gameAreaItem> roomDatas = new List<gameAreaItem>();
    public List<gameAreaGroupItem> roomGroupsData = new List<gameAreaGroupItem>();
    private short validSize = 0;
    public bool findGid(short gid)
    {
        for (int i = 0; i < roomGroupsData.Count; i++)
        {
            if (roomGroupsData[i].id.Equals(gid))return true;
        }
        return false;
    }
    public gameAreaItem getAid(short id)
    {
        for (int i = 0; i < roomDatas.Count; i++)
        {
            if (roomDatas[i].id.Equals(id))
            {
                return roomDatas[i];
            }
        }
        return null;
    }
    public int findAid(short id)
    {
        for (int i = 0; i < roomDatas.Count; i++)
        {
            if (roomDatas[i].id.Equals(id))
            {
                return i;
            }
        }
        return -1;
    }
    public short getNextGid(short nowGid)
    {
        for (int i = 0; i < roomDatas.Count; i++)
        {
            if (roomDatas[i].id.Equals(nowGid))
            {
                if (i == roomGroupsData.Count - 1) return -1;
                return roomGroupsData[i + 1].id;
            }
        }
        return -1;
    }
    public gameAreaGroupItem getRoomGroup(short id)
    {
        for (int i = 0; i < roomGroupsData.Count; i++)
        {
            if (roomGroupsData[i].id.Equals(id)) return roomGroupsData[i];
        }
        return null;
    }
    public short getAllAreaItemSize ()
    {
        return (short)roomDatas.Count;
    }
    public int getAllValidAreaItemSize()
    {
        if(validSize == 0)
        {
            foreach (var item in roomDatas)
            {
                if (item.IsValid())
                {
                    validSize++;
                }
            }
        }
        return validSize;
    }
}
