Ejemplo n.º 1
0
    public static void SetItem(Item item)
    {
        Image image = _instance._itemImages[(int)item.Slot];

        image.sprite = ItemImageLoader.GetSprite(item);
        image.color  = new Color(1, 1, 1, 1);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates item object from Jobject, adds it to Item.All, starts coroutine to load image, and returns reference to Item
    /// </summary>
    /// <param name="jobj"></param>
    /// <returns></returns>
    public static Item FromJObjectOrExisting(JObject jobj)
    {
        string uniqueID = (string)jobj["UniqueID"];

        if (ContainsID(uniqueID))
        {
            return(Get(uniqueID));
        }
        Item item = new Item();

        item.UniqueID    = uniqueID;
        item.Name        = (string)jobj["Name"];
        item.Source      = (string)jobj["Source"];
        item.Description = (string)jobj["Description"];
        item.Slot        = (string)jobj["Slot"];
        List <string> attributeNames = ((JObject)jobj["Attributes"]).Properties().Select(p => p.Name).ToList();

        foreach (string attName in attributeNames)
        {
            item._attributes[attName] = (int)jobj["Attributes"][attName];
        }
        item.ImageURL = (string)jobj["ImageUrl"];
        ItemImageLoader.StartLoadingImage(item);
        _all.Add(item);
        return(item);
    }
Ejemplo n.º 3
0
    private IEnumerator LoadCharacter(bool test)
    {
        JObject jcharacter;

        if (!test)
        {
            string response = null;
            APIHandler.GetCharacter(r => response = r);

            while (response == null)
            {
                yield return(null);
            }
            Debug.Log("Got character response");

            JArray jresp = JArray.Parse(response);
            jcharacter = (JObject)jresp[0];
        }
        else
        {
            Debug.Log("Using mock character json for testing.");
            string mockCharacter = System.IO.File.ReadAllText(Application.streamingAssetsPath + "/mockCharacter.json");
            jcharacter = JObject.Parse(mockCharacter);
        }

        //Create all owned items
        JArray jitems = (JArray)jcharacter["ownedItems"];

        foreach (JObject jitem in jitems)
        {
            Item.FromJObject(jitem);
        }

        //Item image loading now started (called from each Item's constructor)
        Debug.Log("Loading all item images...");
        while (!ItemImageLoader.AllLoaded())
        {
            yield return(null);
        }
        Debug.Log("All item images loaded.");
        Inventory.Update();

        //Based on response jresp, equip correct items
        try
        {
            JArray jequippedItems = (JArray)jcharacter["equippedItems"];
            foreach (var jitemID in jequippedItems)
            {
                Equipment.Equip(Item.Get((string)jitemID), updateBackend: false);
            }
        }
        catch (System.InvalidCastException)
        {
            Debug.Log("equippedItems was null and not an empty list, which means no items were equipped.");
        }
    }
Ejemplo n.º 4
0
    public void SetItem(Item item)
    {
        Item = item;
        //Texture will not be null, because ItemBox.SetItem() is called only after
        //ItemImageLoader.AllLoaded() == true
        _itemImage.sprite = ItemImageLoader.GetSprite(item);
        Color averageColor = AverageColor(ItemImageLoader.GetTexture(item));

        _backgroundImage.color = Color.Lerp(_origBackgroundColor, averageColor, 0.8f);
    }
Ejemplo n.º 5
0
 public void Show(Item item)
 {
     _showing = true;
     _window.SetActive(true);
     Audio.PlaySound(_showHideSound);
     Item              = item;
     _itemName.text    = item.Name;
     _source.text      = item.Source;
     _description.text = item.Description;
     _itemImage.sprite = ItemImageLoader.GetSprite(item);
     _attributesDisplay.UpdateView(item.Attributes);
 }
Ejemplo n.º 6
0
 private void Update()
 {
     _spinner.Rotate(Vector3.forward, 100 * Time.deltaTime);
     if (_close)
     {
         if (ItemImageLoader.FirstRequestSent && ItemImageLoader.AllLoaded())
         {
             _appearingWindow.Close();
             _close = false;
         }
     }
 }
Ejemplo n.º 7
0
    /// <summary>
    /// Creates item object from Jobject, adds it to Item.All, starts coroutine to load image, and returns reference to Item
    /// </summary>
    /// <param name="jobj"></param>
    /// <returns></returns>
    public static Item FromJObject(JObject jobj)
    {
        Item item = new Item();

        item.UniqueID    = (string)jobj["UniqueID"];
        item.Name        = (string)jobj["Name"];
        item.Source      = (string)jobj["Source"];
        item.Description = (string)jobj["Description"];
        item.Slot        = (Slot)Enum.Parse(typeof(Slot), (string)jobj["Slot"]);
        List <string> attributeNames = ((JObject)jobj["Attributes"]).Properties().Select(p => p.Name).ToList();

        foreach (string attName in attributeNames)
        {
            item._attributes[attName] = (int)jobj["Attributes"][attName];
        }
        item.ImageURL = (string)jobj["ImageUrl"];
        ItemImageLoader.StartLoadingImage(item);
        _all.Add(item);
        return(item);
    }
Ejemplo n.º 8
0
 public void Show(Item item)
 {
     _showing = true;
     _window.SetActive(true);
     AudioManager.Play(_showHideSound);
     Item              = item;
     _itemName.text    = item.Name;
     _source.text      = item.Source;
     _description.text = item.Description;
     _itemImage.sprite = ItemImageLoader.GetSprite(item);
     _attributesDisplay.UpdateView(item.Attributes);
     if (!Equipment.IsEquipped(item))
     {
         _equipText.text         = "Equip";
         _equipButtonImage.color = _equipColor;
     }
     else
     {
         _equipText.text         = "Unequip";
         _equipButtonImage.color = _unequipColor;
     }
 }
Ejemplo n.º 9
0
 private void Awake()
 {
     _instance = this;
 }