(Feat) Add Build

This commit is contained in:
2026-07-22 12:56:13 +02:00
parent 3657b870d8
commit 0052b0d98e
244 changed files with 35752 additions and 3112 deletions
@@ -4,12 +4,15 @@ using Ashwild.Inventory;
namespace Ashwild.Player
{
/// <summary>
/// Held-item logic for the build hammer, placed on its hand prefab. It turns the single
/// right-click into two gestures without any extra keybind: a quick <b>tap</b> opens/closes the
/// construction menu through the bus, while <b>holding</b> right-click past a short threshold puts
/// the hammer into demolition mode for as long as it is held (releasing leaves it). The hammer
/// stays a pure input source — it only raises bus requests; BuildManager owns the menu and the
/// world-facing targeting/destroy, so this never reaches for either.
/// Held-item logic for the build hammer, placed on its hand prefab. It is the single arbiter of the
/// right-click gesture in a build context, so the menu can never fight a placement over the same
/// click. One right-click is a <b>tap</b>, resolved on release as a clean build-mode toggle: while
/// placing a ghost it cancels the placement (back to idle, no menu), otherwise it opens/closes the
/// construction menu. <b>Holding</b> right-click past a short threshold instead enters demolition
/// mode for as long as it is held. The tap is gated only by hard UI locks (dead, inventory, chest,
/// pause) — not by the build menu being open (so a tap closes it) nor by a placement being active
/// (so a tap cancels it). The hammer stays a pure input source: it only raises bus requests;
/// BuildManager owns the menu and the world-facing targeting/destroy, so this never reaches for either.
/// </summary>
[DisallowMultipleComponent]
public class BuildHammerBehaviour : MonoBehaviour, IHeldItemBehaviour
@@ -109,16 +112,18 @@ namespace Ashwild.Player
#region Event Handlers
/// <summary>
/// The single right-click gesture, split by press and release: a press is tracked (unless
/// input is locked or a ghost is being placed, where right-click means "cancel" and is left to
/// BuildManager); its release either ends demolition mode (if the hold engaged it) or, for a
/// quick tap, toggles the construction menu under the cooldown.
/// The single right-click gesture, split by press and release. A press is tracked unless a hard
/// UI lock is up; the build menu being open or a placement being active do NOT block it, because
/// this gesture is what drives those states. The release resolves the gesture in priority order:
/// a hold that engaged demolition leaves demolition; a tap while placing a ghost cancels it
/// (the single arbiter — BuildManager no longer listens to the raw click, so the menu can't
/// reopen on the same click); otherwise a tap toggles the construction menu.
/// </summary>
private void HandleSecondaryUse(bool held)
{
if (held)
{
if (PlayerEvents.InputLocked || PlayerEvents.IsPlacingBuild) return;
if (HardLocked) return;
secondaryDown = true;
secondaryDownTime = Time.time;
return;
@@ -127,14 +132,24 @@ namespace Ashwild.Player
if (!secondaryDown) return;
secondaryDown = false;
if (demoActive) ExitDemolition();
else ToggleMenu();
if (demoActive) { ExitDemolition(); return; }
if (PlayerEvents.IsPlacingBuild) { PlayerEvents.RaiseBuildCancelRequested(); return; }
ToggleMenu();
}
#endregion
#region Internal Helpers
/// <summary>
/// A hard UI lock (dead, inventory, chest, pause) where right-click must do nothing. Unlike the
/// bus's InputLocked, it deliberately ignores the build menu being open and a placement being
/// active — both are build states this gesture is meant to drive (close the menu, cancel the
/// placement), not locks that should swallow the click.
/// </summary>
private static bool HardLocked =>
PlayerEvents.IsDead || PlayerEvents.IsInventoryOpen || PlayerEvents.IsChestOpen || PlayerEvents.IsPaused;
/// <summary>
/// Requests the construction menu to open/close, gated by the toggle cooldown.
/// </summary>