using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpaceshipSkin : MonoBehaviour
{
    public SpriteRenderer playerImg;
    public SkinsData skinsData;
    private bool initialized=false;
    void Update()
    {
        if(!DBmanager.LoggedIn) {
            return;
        }

        if(!initialized){

            //Validate the ownership of skin here
            if(!DBmanager.SkinsPurchased.Contains(SkinShopManager.GetEquipedSkin())){
                return; //False skin purchase
            }

            Sprite newSprite = SkinManagerHelper.getSkinSprite(SkinShopManager.GetEquipedSkin(),skinsData);
            if(newSprite==null){return;}

            playerImg.sprite = newSprite;

            initialized = true;
        }
    }
}

public static class SkinManagerHelper{
    public static Sprite getSkinSprite(string name, SkinsData data){
        foreach(SkinShopItemData skin in data.skins){
            if(skin.name==name){
                return skin.image;
            }
        }

        return null;
    }
}
