Skip to content

Commit

Permalink
Merge pull request #114 from Lemirda/player-suggestions
Browse files Browse the repository at this point in the history
Работы от стажёров
  • Loading branch information
13lackHawk authored May 3, 2024
2 parents a98f2a1 + c337dc7 commit a86c650
Show file tree
Hide file tree
Showing 245 changed files with 4,533 additions and 36 deletions.
36 changes: 36 additions & 0 deletions Content.Shared/Andromeda/Playablecards/FoldableCardComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;

namespace Content.Shared.Andromeda.PlayableCards;

/// <summary>
/// Used to create "foldable structures" that you can pickup like an item when folded. Used for rollerbeds and wheelchairs.
/// </summary>
/// <remarks>
/// Wiill prevent any insertions into containers while this item is unfolded.
/// </remarks>
[RegisterComponent]
[NetworkedComponent]
[Access(typeof(FoldableCardSystem))]
public sealed partial class FoldableCardComponent : Component
{
[DataField("folded")]
public bool IsFolded = true;

[DataField("Description")]
public string Description = string.Empty;

public string CurrentDescription = string.Empty;
}

// ahhh, the ol' "state thats just a copy of the component".
[Serializable, NetSerializable]
public sealed class FoldableCardComponentState : ComponentState
{
public readonly bool IsFolded;

public FoldableCardComponentState(bool isFolded)
{
IsFolded = isFolded;
}
}
141 changes: 141 additions & 0 deletions Content.Shared/Andromeda/Playablecards/FoldableCardSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using Content.Shared.Examine;
using Content.Shared.Interaction.Events;
using Content.Shared.Verbs;
using Robust.Shared.Containers;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

namespace Content.Shared.Andromeda.PlayableCards;

public sealed class FoldableCardSystem : EntitySystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<FoldableCardComponent, GetVerbsEvent<AlternativeVerb>>(AddFoldVerb);
SubscribeLocalEvent<FoldableCardComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<FoldableCardComponent, ComponentHandleState>(OnHandleState);

SubscribeLocalEvent<FoldableCardComponent, ComponentInit>(OnFoldableInit);
SubscribeLocalEvent<FoldableCardComponent, UseInHandEvent>(UseInHand);
SubscribeLocalEvent<FoldableCardComponent, ExaminedEvent>(OnExamine);
}

private void OnExamine(EntityUid uid, FoldableCardComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString(component.CurrentDescription));
}

private void UseInHand(EntityUid uid, FoldableCardComponent component, UseInHandEvent args)
{
component.IsFolded = !component.IsFolded;
SetFolded(uid, component, component.IsFolded);
}

private void OnGetState(EntityUid uid, FoldableCardComponent component, ref ComponentGetState args)
{
args.State = new FoldableCardComponentState(component.IsFolded);
}

private void OnHandleState(EntityUid uid, FoldableCardComponent component, ref ComponentHandleState args)
{
if (args.Current is not FoldableCardComponentState state)
return;

if (state.IsFolded != component.IsFolded)
SetFolded(uid, component, state.IsFolded);
}

private void OnFoldableInit(EntityUid uid, FoldableCardComponent component, ComponentInit args)
{
SetFolded(uid, component, component.IsFolded);
}

public bool IsFolded(EntityUid uid, FoldableCardComponent? component = null)
{
if (!Resolve(uid, ref component))
return false;

return component.IsFolded;
}

public void SetFolded(EntityUid uid, FoldableCardComponent component, bool folded)
{
if (folded)
{
component.CurrentDescription = "card-folded";
}
else
{
component.CurrentDescription = component.Description;
}
component.IsFolded = folded;
Dirty(uid, component);
_appearance.SetData(uid, FoldedCardVisuals.State, folded);
}

public bool TryToggleFold(EntityUid uid, FoldableCardComponent comp)
{
return TrySetFolded(uid, comp, !comp.IsFolded);
}

public bool CanToggleFold(EntityUid uid, FoldableCardComponent? fold = null)
{
if (!Resolve(uid, ref fold))
return false;

var ev = new FoldAttemptEvent();
RaiseLocalEvent(uid, ref ev);
return !ev.Cancelled;
}

public bool TrySetFolded(EntityUid uid, FoldableCardComponent comp, bool state)
{
if (state == comp.IsFolded)
return false;

if (!CanToggleFold(uid, comp))
return false;

SetFolded(uid, comp, state);
return true;
}

#region Verb

private void AddFoldVerb(EntityUid uid, FoldableCardComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!CanToggleFold(uid, component))
return;
if (!args.CanInteract || !args.CanAccess)
return;

AlternativeVerb verb = new()
{
Act = () => TryToggleFold(uid, component),
Text = component.IsFolded ? Loc.GetString("unfold-verb") : Loc.GetString("fold-verb"),
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/fold.svg.192dpi.png")),

// If the object is unfolded and they click it, they want to fold it, if it's folded, they want to pick it up
Priority = component.IsFolded ? 0 : 2,
};

args.Verbs.Add(verb);
}

#endregion

[Serializable, NetSerializable]
public enum FoldedCardVisuals : byte
{
State
}
}

[ByRefEvent]
public record struct FoldAttemptEvent(bool Cancelled = false);
Binary file not shown.
Binary file modified Resources/Audio/Andromeda/Lemird/Misc/plushiescientist.ogg
Binary file not shown.
Loading

0 comments on commit a86c650

Please sign in to comment.