xabbo-scripts/Scripts/pixelart_v2.csx
Administrator 7a548130a3 Move all scripts into Scripts/ subfolder
Keeps the repo root clean - only README.md visible on landing page.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 09:49:37 +01:00

72 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
var catalog = GetBcCatalog();
var nodes = catalog.Where(x => x.Id > 0).ToArray();
var pages = new List<(ICatalogPageNode Node, ICatalogPage Page)>();
for (int i = 0; i < nodes.Length; i++)
{
var node = nodes[i];
Status($"Loading pages {i + 1}/{nodes.Length}...");
pages.Add((node, GetCatalogPage(node)));
}
string[] regexPatterns = new string[]
{
@"^bc_block_",
};
string[] blacklistStrings = new string[]
{
"Small Block",
};
var furniData = await FetchFurniDataAsync();
string json = JsonSerializer.Serialize(
pages.SelectMany(x => x.Page.Offers
.SelectMany(offer => offer.Products.Select(product => new { Product = product, OfferId = offer.Id, PageId = x.Page.Id, FurniName = product.GetName() })))
.Where(item => IsFurni(item.Product)
&& regexPatterns.Any(pattern => Regex.IsMatch(item.Product.GetIdentifier(), pattern))
&& !blacklistStrings.Any(blacklistString => item.FurniName.Contains(blacklistString))) // Check against FurniName
.Select(item => new
{
Identifier = item.Product.GetIdentifier(),
OfferId = item.OfferId,
PageId = item.PageId,
FurniName = item.FurniName,
Color = furniData.GetValueOrDefault(item.Product.GetIdentifier())
}),
new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
}
);
Directory.CreateDirectory("Bc_Block_Data");
File.WriteAllText($"Bc_Block_Data/Bc_Block_Data.json", json);
static async Task<Dictionary<string, string>> FetchFurniDataAsync()
{
using var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36");
var response = await httpClient.GetStringAsync("https://www.habbo.com/gamedata/furnidata_json/0");
using var jsonDoc = JsonDocument.Parse(response);
return jsonDoc.RootElement.GetProperty("roomitemtypes").GetProperty("furnitype").EnumerateArray()
.Where(furni => furni.TryGetProperty("partcolors", out var partColors) && partColors.TryGetProperty("color", out var colors) && colors.GetArrayLength() > 1)
.ToDictionary(
furni => furni.GetProperty("classname").GetString(),
furni => furni.GetProperty("partcolors").GetProperty("color")[1].GetString()
);
}
static bool IsFurni(IItem it) => it.Type == ItemType.Floor || it.Type == ItemType.Wall;