forked from space-syndicate/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from Lemirda/player-suggestions
Работы от стажёров
- Loading branch information
Showing
245 changed files
with
4,533 additions
and
36 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
Content.Shared/Andromeda/Playablecards/FoldableCardComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
141
Content.Shared/Andromeda/Playablecards/FoldableCardSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+13 KB
Resources/Audio/Andromeda/Evil/SoundCollection/PlushiePaintor/karandash.ogg
Binary file not shown.
Binary file not shown.
Oops, something went wrong.