UI/SpawnMenu/Dupes/DupesLocal.razor
@using Sandbox;
@using Sandbox.UI;
@using Sandbox.Mounting;
@inherits Panel
@namespace Sandbox
<SpawnMenuContent>
<Body>
<VirtualGrid Items=@( GetData() ) ItemSize=@ItemSize>
<Item Context="item">
@if (item is Storage.Entry content)
{
<LocalDupeIcon Content="@content" @onclick="@(() => SwitchToDupe(content))"></LocalDupeIcon>
}
</Item>
</VirtualGrid>
</Body>
</SpawnMenuContent>
@code
{
public static int ItemSize { get; set; } = 120;
protected override int BuildHash() => HashCode.Combine(ItemSize);
protected override async Task OnParametersSetAsync()
{
}
void SwitchToDupe( Storage.Entry content )
{
var localPlayer = Player.FindLocalPlayer();
if ( localPlayer == null ) return;
var inventory = localPlayer.GetComponent<PlayerInventory>();
if ( !inventory.IsValid() ) return;
inventory.SetToolMode( "Duplicator" );
var toolmode = localPlayer.GetComponentInChildren<DuplicatorTool>();
if ( toolmode is null )
{
// we are a client and didn't switch tools in time, we need to wait for the server to tell us we have the tool
// Some kind of async wait on an rpc would work, probably.
Log.Warning( "I thought this might happen. We are a client and didn't switch tools in time." );
return;
}
var json = content.Files.ReadAllText( "/dupe.json" );
toolmode.Load( json );
}
IEnumerable<object> GetData()
{
return Storage.GetAll( "dupe" ).OrderByDescending( x => x.Created );
}
}