xabbo-scripts/Scripts/Color Matching Simple.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

101 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
const int SOURCE_MIN_X = 18;
const int SOURCE_MAX_X = 29;
const int SOURCE_MIN_Y = 25;
const int SOURCE_MAX_Y = 36;
const int FIELD_MIN_X = 18;
const int FIELD_MAX_X = 29;
const int FIELD_MIN_Y = 9;
const int FIELD_MAX_Y = 20;
int GetColorNumber(string name)
{
var match = Regex.Match(name, @"\d+$");
return match.Success ? int.Parse(match.Value) : -1;
}
Log("=== AUTO DETECTING COLORS ===");
var selectors = new Dictionary<int, int>();
foreach (var item in FloorItems)
{
string name = item.GetName();
if (name.Contains("Cylinder Block") || name.Contains("Hemisphere Block"))
{
int colorNum = GetColorNumber(name);
if (colorNum > 0 && !selectors.ContainsKey(colorNum))
{
selectors[colorNum] = (int)item.Id;
Log($"Selector: {name} -> Color {colorNum}");
}
}
}
Log($"Total selectors: {selectors.Count}");
var sourcePixels = new Dictionary<(int x, int y), int>();
foreach (var item in FloorItems)
{
int x = item.Location.X;
int y = item.Location.Y;
double z = item.Location.Z;
if (x < SOURCE_MIN_X || x > SOURCE_MAX_X || y < SOURCE_MIN_Y || y > SOURCE_MAX_Y) continue;
if (z < 0.7 || z > 1.0) continue;
int colorNum = GetColorNumber(item.GetName());
if (colorNum > 0)
sourcePixels[(x, y)] = colorNum;
}
Log($"Source pixels: {sourcePixels.Count}");
var fieldTiles = new Dictionary<(int x, int y), int>();
foreach (var item in FloorItems)
{
int x = item.Location.X;
int y = item.Location.Y;
double z = item.Location.Z;
if (x < FIELD_MIN_X || x > FIELD_MAX_X || y < FIELD_MIN_Y || y > FIELD_MAX_Y) continue;
if (z > 0.5) continue;
fieldTiles[(x, y)] = (int)item.Id;
}
Log($"Field tiles: {fieldTiles.Count}");
int offsetY = SOURCE_MIN_Y - FIELD_MIN_Y;
var toChange = new List<(int fieldId, int srcColor)>();
foreach (var src in sourcePixels)
{
int fieldX = src.Key.x;
int fieldY = src.Key.y - offsetY;
int srcColor = src.Value;
if (!fieldTiles.TryGetValue((fieldX, fieldY), out int fieldId)) continue;
if (!selectors.ContainsKey(srcColor)) continue;
toChange.Add((fieldId, srcColor));
}
var sorted = toChange.OrderBy(x => x.srcColor).ToList();
Log($"To change: {sorted.Count}");
int lastColor = -1;
int changed = 0;
foreach (var item in sorted)
{
if (item.srcColor != lastColor)
{
await SendAsync(Out["ClickFurni"], selectors[item.srcColor], 0);
await Task.Delay(50);
lastColor = item.srcColor;
}
await SendAsync(Out["ClickFurni"], item.fieldId, 0);
await Task.Delay(50);
changed++;
}
Log($"Done! Changed: {changed}");