sasalka/Editor/UpdateCloths.cs
2025-06-26 21:12:11 +03:00

59 lines
1.6 KiB
C#

using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Sandbox;
using System.Text.Json;
public static class UpdateCloths
{
private static string outputFolder = @"c:/users/hamit_ba31xcg/documents/s&box projects/sasalka/assets/items/cloth/";
[Menu( "Editor", "MyClothing/Generate .clitem Files" )]
public static async void GenerateClitemFiles()
{
var packageResult = await Package.FindAsync( "type:clothing", 500 );
Directory.CreateDirectory( outputFolder );
foreach ( var package in packageResult.Packages )
{
var clothUrl = package.Url.Replace( "https://sbox.game/", "" ); //package.Url;
var imageUrl = package.Thumb;
var fileName = $"{SanitizeFileName( package.Ident )}.clitem";
var filePath = Path.Combine( outputFolder, fileName );
if ( File.Exists( filePath ) )
continue;
var itemObject = new
{
ClothUrl = clothUrl,
Slot = "Body",
Name = package.Title,
Description = package.Ident.Replace( "_", "" ).Replace( " ", "" ),
Prefab = new { _type = "gameobject", prefab = "prefabs/item_parcel.prefab" },
ImageTexture = (string)null,
ImageUrl = imageUrl,
MaxCount = 1,
__references = new object[] { },
__version = 0
};
var json = JsonSerializer.Serialize( itemObject, new JsonSerializerOptions { WriteIndented = true } );
await File.WriteAllTextAsync( filePath, json );
}
}
private static string SanitizeFileName( string name )
{
var invalidChars = Path.GetInvalidFileNameChars();
foreach ( var c in invalidChars )
{
name = name.Replace( c, '_' );
}
return name;
}
}