[Feat] Внешний вид и название канистр можно изменить прямо в игре (#317)
* feat: Теперь можно менять внешний вид канистр газов * fix: русский язык (я его не знаю)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared._White.PolymorphableCanister;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
public sealed partial class PolymorphableCanisterComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public ResPath ResPath = new("Structures/Storage/canister.rsi");
|
||||
|
||||
[DataField, AutoNetworkedField]
|
||||
public ProtoId<EntityPrototype>? CurrentPrototype;
|
||||
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public int DoAfterTime = 3;
|
||||
|
||||
[DataField]
|
||||
public List<ProtoId<EntityPrototype>> Prototypes = new()
|
||||
{
|
||||
"GasCanister",
|
||||
"StorageCanister",
|
||||
"AirCanister",
|
||||
"OxygenCanister",
|
||||
"NitrogenCanister",
|
||||
"CarbonDioxideCanister",
|
||||
"PlasmaCanister",
|
||||
"TritiumCanister",
|
||||
"WaterVaporCanister",
|
||||
"AmmoniaCanister",
|
||||
"NitrousOxideCanister",
|
||||
"FrezonCanister",
|
||||
"BZCanister",
|
||||
"PluoxiumCanister",
|
||||
"HydrogenCanister",
|
||||
"NitriumCanister",
|
||||
"HealiumCanister",
|
||||
"HyperNobliumCanister",
|
||||
"ProtoNitrateCanister",
|
||||
"ZaukerCanister",
|
||||
"HalonCanister",
|
||||
"HeliumCanister",
|
||||
"AntiNobliumCanister",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Content.Shared.DoAfter;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared._White.PolymorphableCanister;
|
||||
|
||||
public abstract class SharedPolymorphableCanisterSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<PolymorphableCanisterComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<PolymorphableCanisterComponent, PolymorphableCanisterMessage>(OnMessage);
|
||||
SubscribeLocalEvent<PolymorphableCanisterComponent, PolymorphableCanisterDoAfterEvent>(OnDoAfter);
|
||||
}
|
||||
|
||||
private void OnInit(Entity<PolymorphableCanisterComponent> ent, ref ComponentInit args)
|
||||
{
|
||||
var proto = MetaData(ent.Owner).EntityPrototype;
|
||||
if (proto is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ent.Comp.CurrentPrototype = proto.ID;
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
private void OnMessage(Entity<PolymorphableCanisterComponent> ent, ref PolymorphableCanisterMessage args)
|
||||
{
|
||||
if (!args.Session.AttachedEntity.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var doAfterArgs = new DoAfterArgs(EntityManager,
|
||||
args.Session.AttachedEntity.Value,
|
||||
ent.Comp.DoAfterTime,
|
||||
new PolymorphableCanisterDoAfterEvent(args.ProtoId),
|
||||
ent.Owner
|
||||
)
|
||||
{
|
||||
BreakOnMove = true,
|
||||
NeedHand = true
|
||||
};
|
||||
|
||||
_doAfter.TryStartDoAfter(doAfterArgs);
|
||||
}
|
||||
|
||||
private void OnDoAfter(Entity<PolymorphableCanisterComponent> ent, ref PolymorphableCanisterDoAfterEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ent.Comp.CurrentPrototype = args.ProtoId;
|
||||
UpdateAppearance(ent, args.ProtoId);
|
||||
Dirty(ent);
|
||||
}
|
||||
|
||||
public void UpdateAppearance(EntityUid uid, ProtoId<EntityPrototype>? protoId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(protoId) || !_proto.TryIndex(protoId, out var proto))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var metadata = MetaData(uid);
|
||||
_metaData.SetEntityName(uid, proto.Name, metadata);
|
||||
_metaData.SetEntityDescription(uid, proto.Description, metadata);
|
||||
|
||||
UpdateSprite(uid, proto);
|
||||
}
|
||||
|
||||
protected virtual void UpdateSprite(EntityUid uid, EntityPrototype proto)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public enum PolymorphableCanisterUiKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PolymorphableCanisterMessage(string protoId) : BoundUserInterfaceMessage
|
||||
{
|
||||
public readonly ProtoId<EntityPrototype> ProtoId = protoId;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed partial class PolymorphableCanisterDoAfterEvent : SimpleDoAfterEvent
|
||||
{
|
||||
public readonly ProtoId<EntityPrototype> ProtoId;
|
||||
|
||||
public PolymorphableCanisterDoAfterEvent(string protoId)
|
||||
{
|
||||
ProtoId = protoId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user