feat: add spawn item console command

This commit was merged in pull request #1.
This commit is contained in:
2026-08-24 17:26:31 +02:00
parent bed12ad335
commit 00627a7e91
3 changed files with 46 additions and 0 deletions
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Game.Features.Console.Contracts;
using Game.Features.Items.Contracts;
namespace Game.Features.Console.Application.Commands;
public sealed class SpawnItemCommand : ICommand
{
private readonly IItemSpawner _spawner;
private readonly IItemSpawnPoint _spawnPoint;
public string Name => "spawn_item";
public string Description => "Spawns an item in front of the player.";
public IReadOnlyList<CommandArgSpec> Args { get; }
public SpawnItemCommand(IItemSpawner spawner, IItemSpawnPoint spawnPoint)
{
_spawner = spawner;
_spawnPoint = spawnPoint;
string[] definitions = spawner.DefinitionIds
.Select(id => id.Value)
.OrderBy(id => id, StringComparer.Ordinal)
.ToArray();
Args = new CommandArgsBuilder().AddChoiceArg("item", definitions).Build();
}
public CommandResult Execute(CommandArgValues args)
{
ItemDefinitionId definitionId = new(args.GetString(0));
ItemActionResult result = _spawner.TrySpawn(
definitionId,
_spawnPoint.GetItemSpawnPosition(),
out ItemInstanceId itemId
);
return result.Success
? CommandResult.Ok($"Spawned {definitionId} ({itemId}).")
: CommandResult.Fail(result.Message);
}
}
@@ -0,0 +1 @@
uid://e8m3q6v1r9k4w
+1
View File
@@ -48,6 +48,7 @@ public partial class GameBootstrap : Node
registry.Register(new EchoCommand());
registry.Register(new ClearCommand());
registry.Register(new NoclipCommand(Player));
registry.Register(new SpawnItemCommand(ItemSpawner, PlayerInteraction));
registry.Register(new HostCommand(MultiplayerController));
registry.Register(new JoinCommand(MultiplayerController));