public static Texture2D ItemToTexture2D(Item tr, out Color c)
    {
        if (tr.IsNone)
        {
            c = Color.white;
            return(null);
        }

        Item t = new Item();

        t.CopyFrom(tr);
        if (t.ItemId >= 60_000)
        {
            if (FieldItemList.Items.TryGetValue(t.ItemId, out var def))
            {
                if (def.Dig != Item.NONE)
                {
                    t.ItemId = def.Dig;
                }
                else if (def.Pick != Item.NONE)
                {
                    t.ItemId = def.Pick;
                }
            }
        }

        Texture2D toAssignImage = ResourceLoader.GetLeafImage();

        System.Drawing.Color itemColor = FieldItemColor.GetItemColor(t);
        c = new Color(itemColor.R / 255f, itemColor.G / 255f, itemColor.B / 255f, itemColor.A / 255f);

        if (SpritesExist())
        {
            InitParser();
            byte[] bytes = SpriteParser.CurrentInstance.GetPng(t.ItemId, t.Count);
            if (bytes != null)
            {
                toAssignImage = new Texture2D(2, 2);
                toAssignImage.LoadImage(bytes);
                c = Color.white;
            }
        }

        return(toAssignImage);
    }
Пример #2
0
    public static Texture2D ItemToTexture2D(Item tr, out Color c)
    {
        if (tr.IsNone)
        {
            c = Color.white;
            return(null);
        }

        Item t = new Item();

        t.CopyFrom(tr);
        if (t.ItemId >= 60_000)
        {
            if (FieldItemList.Items.TryGetValue(t.ItemId, out var def))
            {
                if (def.Dig != Item.NONE)
                {
                    t.ItemId = def.Dig;
                }
                else if (def.Pick != Item.NONE)
                {
                    t.ItemId = def.Pick;
                }
            }
        }

        Texture2D toAssignImage = ResourceLoader.GetLeafImage();

        Beri.Drawing.Color itemColor = FieldItemColor.GetItemColor(t);
        c = new Color(itemColor.R / 255f, itemColor.G / 255f, itemColor.B / 255f, itemColor.A / 255f);

        if (SpritesExist())
        {
            InitParser();
            ItemKind itemKind = ItemInfo.GetItemKind(Convert.ToUInt16(t.ItemId));
            var      tx       = SpriteParser.CurrentInstance.GetTexture(t.ItemId, itemKind == ItemKind.Kind_Fence ? t.UseCount : t.Count);
            if (tx != null)
            {
                toAssignImage = tx;
                c             = Color.white;
            }
        }

        return(toAssignImage);
    }
Пример #3
0
    private Texture2D CreateItemLayerTexture(Item[] items, int width, int height)
    {
        Texture2D toRet = new Texture2D(width, height);

        for (int x = 0; x < width; x++)
        {
            var ix = x * height;
            for (int y = 0; y < height; y++)
            {
                var index = ix + y;
                var tile  = items[index];
                var pxl   = FieldItemColor.GetItemColor(tile);
                toRet.SetPixel(x, y, new Color32(pxl.R, pxl.G, pxl.B, pxl.A));
            }
        }

        toRet.filterMode = FilterMode.Point;
        toRet.Apply();
        toRet = Resize(toRet, width / 2, height / 2);
        return(toRet);
    }