This commit is contained in:
Oscar
2025-06-26 21:12:11 +03:00
parent 8b61aa1d7b
commit 793165bb03
66 changed files with 89 additions and 95 deletions

View File

@@ -123,7 +123,7 @@ public sealed partial class Dedugan : Component
}
else if ( item.Definition is ClothingItemDefinition clothingDef )
{
StripByName( clothingDef.Name );
StripByName( clothingDef.Description );
}
}

View File

@@ -140,7 +140,12 @@ partial class Dedugan
[Rpc.Broadcast]
public void StripByName( string name )
{
CurrentClothing.Clothing.RemoveAll( entry => entry.Clothing.Title == name );
CurrentClothing.Clothing.RemoveAll( entry =>
{
Log.Info( entry.Clothing.ResourceName.Replace( "_", "" ) );
return entry.Clothing.ResourceName.Replace( "_", "" ).Replace( " ", "" ) == name;
} );
CurrentClothing.Normalize();
CurrentClothing.Apply( Renderer );

View File

@@ -3,13 +3,13 @@ using Sasalka;
public sealed class WorlModelClothSpawner : Component
{
[Property] public GameObject Prefab { get; set; }
[Property] public Vector3 CenterPosition { get; set; } = Vector3.Zero;
[Property] public float Spacing { get; set; } = 50.0f;
[Property] public float Height { get; set; } = 0.0f;
protected override void OnStart()
{
if ( !Networking.IsHost ) return;
var definitions = ResourceLibrary.GetAll<ClothingItemDefinition>();
var clothingItemDefinitions = definitions.ToList();
int total = clothingItemDefinitions.Count();
@@ -20,40 +20,29 @@ public sealed class WorlModelClothSpawner : Component
return;
}
// Автоматически вычисляем минимальный радиус круга, чтобы вместить все предметы
// Площадь круга: πr², а площадь одного предмета: Spacing²
// Нам нужно чтобы πr² >= total * Spacing² → r >= sqrt(total * Spacing² / π)
float estimatedRadius = MathF.Sqrt( (total * Spacing * Spacing) / MathF.PI );
float radius = estimatedRadius;
// Вычисляем размер стороны квадрата
int itemsPerSide = 10; //Math.CeilToInt( Mathf.Sqrt( total ) );
float halfSize = (itemsPerSide - 1) * Spacing * 0.5f;
Log.Info( $"Auto-calculated radius: {radius}" );
Log.Info( $"Spawning {total} items in {itemsPerSide}x{itemsPerSide} square grid" );
int defIndex = 0;
for ( float x = -radius; x <= radius; x += Spacing )
for ( int i = 0; i < total; i++ )
{
for ( float y = -radius; y <= radius; y += Spacing )
{
if ( defIndex >= total )
break;
// Вычисляем позицию в сетке
int row = i / itemsPerSide;
int col = i % itemsPerSide;
if ( x * x + y * y <= radius * radius )
{
Vector3 pos = CenterPosition + new Vector3( x, y, Height );
float x = col * Spacing - halfSize;
float y = row * Spacing - halfSize;
var gO = Prefab.Clone( pos );
gO.NetworkSpawn( null );
Vector3 pos = WorldPosition + new Vector3( x, y, Height );
var item = gO.Components.Get<InventoryItem>();
if ( item is not null )
item.Definition = clothingItemDefinitions[defIndex];
var gO = Prefab.Clone( pos );
gO.NetworkSpawn( null );
defIndex++;
}
}
if ( defIndex >= total )
break;
var item = gO.Components.Get<InventoryItem>();
if ( item is not null )
item.Definition = clothingItemDefinitions[i];
}
}
}