コード例 #1
0
ファイル: Charger.cs プロジェクト: Niker323/VS-mods
    // We need the tool item textures also in the block atlas
    public override void OnCollectTextures(ICoreAPI api, ITextureLocationDictionary textureDict)
    {
        base.OnCollectTextures(api, textureDict);

        for (int i = 0; i < api.World.Items.Count; i++)
        {
            Item item = api.World.Items[i];
            if (item.Attributes?["rechargeable"].AsBool() != true)
            {
                continue;
            }

            ToolTextures tt = new ToolTextures();


            if (item.Shape != null)
            {
                IAsset asset = api.Assets.TryGet(item.Shape.Base.Clone().WithPathPrefixOnce("shapes/").WithPathAppendixOnce(".json"));
                if (asset != null)
                {
                    Shape shape = asset.ToObject <Shape>();
                    foreach (var val in shape.Textures)
                    {
                        CompositeTexture ctex = new CompositeTexture(val.Value.Clone());
                        ctex.Bake(api.Assets);

                        textureDict.AddTextureLocation(new AssetLocationAndSource(ctex.Baked.BakedName, "Shape code " + item.Shape.Base));
                        tt.TextureSubIdsByCode[val.Key] = textureDict[new AssetLocationAndSource(ctex.Baked.BakedName)];
                    }
                }
            }

            foreach (var val in item.Textures)
            {
                val.Value.Bake(api.Assets);
                textureDict.AddTextureLocation(new AssetLocationAndSource(val.Value.Baked.BakedName, "Item code " + item.Code));
                tt.TextureSubIdsByCode[val.Key] = textureDict[new AssetLocationAndSource(val.Value.Baked.BakedName)];
            }



            ToolTextureSubIds(api)[item] = tt;
        }
    }
コード例 #2
0
ファイル: Charger.cs プロジェクト: Niker323/VS-mods
    public TextureAtlasPosition this[string textureCode]
    {
        get
        {
            ToolTextures tt = null;

            if (BlockTFCharger.ToolTextureSubIds(Api).TryGetValue((Item)tmpItem, out tt))
            {
                int textureSubId = 0;
                if (tt.TextureSubIdsByCode.TryGetValue(textureCode, out textureSubId))
                {
                    return(((ICoreClientAPI)Api).BlockTextureAtlas.Positions[textureSubId]);
                }

                return(((ICoreClientAPI)Api).BlockTextureAtlas.Positions[tt.TextureSubIdsByCode.First().Value]);
            }

            return(null);
        }
    }