Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions Content.Shared/Item/ItemToggle/ComponentTogglerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Content.Shared.Item.ItemToggle.Components;
using Robust.Shared.Timing;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using Robust.Shared.Timing;
using Robust.Shared.Timing; // LuaM


namespace Content.Shared.Item.ItemToggle;

/// <summary>
/// Handles <see cref="ComponentTogglerComponent"/> component manipulation.
/// </summary>
public sealed class ComponentTogglerSystem : EntitySystem
public sealed partial class ComponentTogglerSystem : EntitySystem

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public sealed partial class ComponentTogglerSystem : EntitySystem
public sealed partial class ComponentTogglerSystem : EntitySystem // LuaM: public sealed class > public sealed partial class

{
[Dependency] private IGameTiming _timing = default!; // LuaM: predict err fix

public override void Initialize()
{
base.Initialize();
Expand All @@ -22,14 +25,32 @@ private void OnToggled(Entity<ComponentTogglerComponent> ent, ref ItemToggledEve
// Goobstation - Make this system more flexible
public void ToggleComponent(EntityUid uid, bool activate)
{
if (!TryComp<ComponentTogglerComponent>(uid, out var component))
if (!_timing.IsFirstTimePredicted) // LuaM: predict err fix

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!_timing.IsFirstTimePredicted) // LuaM: predict err fix
if (!_timing.IsFirstTimePredicted) // LuaM: !TryComp<ComponentTogglerComponent>(uid, out var component) > _timing.IsFirstTimePredicted

return;

var target = component.Parent ? Transform(uid).ParentUid : uid;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Закомментить, а не удалить.

if (!TryComp<ComponentTogglerComponent>(uid, out var component))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!TryComp<ComponentTogglerComponent>(uid, out var component))
if (!TryComp<ComponentTogglerComponent>(uid, out var component)) // LuaM

return;

// LuaM-start: add target for the correct remove component, in o.w. - wizden logic
if (activate)
{
var target = component.Parent ? Transform(uid).ParentUid : uid;
if (TerminatingOrDeleted(target))
return;

component.Target = target;
EntityManager.AddComponents(target, component.Components);
}
else
EntityManager.RemoveComponents(target, component.RemoveComponents ?? component.Components);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Закомментить, а не удалить.

{
if (component.Target == null)
return;

if (TerminatingOrDeleted(component.Target.Value))
return;

EntityManager.RemoveComponents(component.Target.Value, component.RemoveComponents ?? component.Components);
}
// LuaM-end
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,10 @@ public sealed partial class ComponentTogglerComponent : Component
/// </summary>
[DataField]
public bool Parent;

// <summary>
// It holds the entity that the component gave the component to, so it can remove from it even if it changes parent.
// </summary>
[DataField]
public EntityUid? Target;
Comment on lines +32 to +37

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// <summary>
// It holds the entity that the component gave the component to, so it can remove from it even if it changes parent.
// </summary>
[DataField]
public EntityUid? Target;
// LuaM-start:
// <summary>
// It holds the entity that the component gave the component to, so it can remove from it even if it changes parent.
// </summary>
[DataField]
public EntityUid? Target;
// LuaM-end.

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
using Content.Shared.Inventory.Events;
using Content.Shared.Tag;
using Robust.Shared.Serialization.Manager;
using Robust.Shared.Timing; // LuaM
using YamlDotNet.Core.Tokens;

namespace Content.Shared._Goobstation.Clothing.Systems;

public sealed partial class ClothingGrantingSystem : EntitySystem
{
[Dependency] private ISerializationManager _serializationManager = default!;
[Dependency] private TagSystem _tagSystem = default!;
[Dependency] private IGameTiming _timing = default!; // LuaM: predict err fix

public override void Initialize()
{
Expand All @@ -25,6 +28,9 @@ public override void Initialize()
// Monolith Cleanup - Below
private void OnCompEquip(EntityUid uid, ClothingGrantComponentComponent component, GotEquippedEvent args)
{
if (!_timing.IsFirstTimePredicted) // LuaM: predict err fix
return;

if (!TryComp<ClothingComponent>(uid, out var clothing))
return;

Expand All @@ -33,7 +39,7 @@ private void OnCompEquip(EntityUid uid, ClothingGrantComponentComponent componen

foreach (var (name, data) in component.Components)
{
var newComp = (Component) Factory.GetComponent(name);
var newComp = (Component)Factory.GetComponent(name);

if (HasComp(args.Equipee, newComp.GetType()))
continue;
Expand All @@ -48,12 +54,15 @@ private void OnCompEquip(EntityUid uid, ClothingGrantComponentComponent componen

private void OnCompUnequip(EntityUid uid, ClothingGrantComponentComponent component, GotUnequippedEvent args)
{
if (!_timing.IsFirstTimePredicted) // LuaM: predict err fix
return;

foreach (var (name, _) in component.Components)
{
if (!component.Active.TryGetValue(name, out _))
continue;

var newComp = (Component) Factory.GetComponent(name);
var newComp = (Component)Factory.GetComponent(name);

RemComp(args.Equipee, newComp.GetType());
component.Active[name] = false;
Expand All @@ -63,6 +72,9 @@ private void OnCompUnequip(EntityUid uid, ClothingGrantComponentComponent compon

private void OnTagEquip(EntityUid uid, ClothingGrantTagComponent component, GotEquippedEvent args)
{
if (!_timing.IsFirstTimePredicted) // LuaM: predict err fix
return;

if (!TryComp<ClothingComponent>(uid, out var clothing))
return;

Expand All @@ -77,6 +89,9 @@ private void OnTagEquip(EntityUid uid, ClothingGrantTagComponent component, GotE

private void OnTagUnequip(EntityUid uid, ClothingGrantTagComponent component, GotUnequippedEvent args)
{
if (!_timing.IsFirstTimePredicted) // LuaM: predict err fix
return;

if (!component.IsActive)
return;

Expand Down
19 changes: 19 additions & 0 deletions Content.Shared/_LuaM/Containers/OutOfContainerGrantComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Robust.Shared.Prototypes;

namespace Content.Shared._LuaM.Container.Components
{
/// <summary>
/// Grants the listed components to entity if it NOT inside any container
/// for example: brain has Blip if he not in the containers (other words, brain in space)
/// <summary>
[RegisterComponent]
public sealed partial class OutOfContainerGrantComponent : Component
{
[DataField(required: true)]
[AlwaysPushInheritance]
public ComponentRegistry Components { get; private set; } = new();

[ViewVariables(VVAccess.ReadWrite)]
public Dictionary<string, bool> Active = new();
}
}
78 changes: 78 additions & 0 deletions Content.Shared/_LuaM/Containers/OutOfContainerGrantSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Content.Shared._LuaM.Container.Components;
using Robust.Shared.Containers;
using Robust.Shared.Serialization.Manager;

namespace Content.Shared._LuaM.Container.Systems; // idk how name that.

// A simple system that add components to entity if he not inside a container
// Following the example of goob <see cref="Content.Shared._Goobstation.Clothing.Systems.ClothingGrantingSystem"/>
public sealed partial class OutOfContainerGrantSystem : EntitySystem // this name is suck, i know
{
[Dependency] private readonly ISerializationManager _serializationManager = default!;
[Dependency] private readonly SharedContainerSystem _container = default!;

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

SubscribeLocalEvent<OutOfContainerGrantComponent, ComponentStartup>(OnStartup);

SubscribeLocalEvent<OutOfContainerGrantComponent, EntGotInsertedIntoContainerMessage>(OnContainerChanged);
SubscribeLocalEvent<OutOfContainerGrantComponent, EntGotRemovedFromContainerMessage>(OnContainerChanged);
}

private void OnStartup(EntityUid uid, OutOfContainerGrantComponent component, ComponentStartup args)
{
UpdateComp(uid, component);
}

private void OnContainerChanged(EntityUid uid, OutOfContainerGrantComponent component, EntityEventArgs args)
{
UpdateComp(uid, component);
}

private void UpdateComp(EntityUid uid, OutOfContainerGrantComponent component)
{
if (_container.IsEntityInContainer(uid))
RemoveComp(uid, component);
else
AddComp(uid, component);
}

private void AddComp(EntityUid uid, OutOfContainerGrantComponent component)
{
foreach (var (name, data) in component.Components)
{
if (component.Active.TryGetValue(name, out var active) && active)
continue;

var newComp = (Component)Factory.GetComponent(name);

if (HasComp(uid, newComp.GetType()))
{
component.Active[name] = true;
continue;
}

object? temp = newComp;
_serializationManager.CopyTo(data.Component, ref temp);
EntityManager.AddComponent(uid, (Component)temp!);

component.Active[name] = true;
}
}

private void RemoveComp(EntityUid uid, OutOfContainerGrantComponent component)
{
foreach (var (name, _) in component.Components)
{
if (!component.Active.TryGetValue(name, out var active) || !active)
continue;

var newComp = (Component)Factory.GetComponent(name);
RemComp(uid, newComp.GetType());

component.Active[name] = false;
}
}
}
15 changes: 15 additions & 0 deletions Resources/Prototypes/Body/Organs/diona.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@
reagents:
- ReagentId: GreyMatter
Quantity: 5
- type: OutOfContainerGrant # LuaM
components:
- type: RadarBlip
radarColor: "#E0FFFF"
scale: 3
shape: Star
maxDistance: 512
requireNoGrid: true
visibleFromOtherGrids: true
gridConfig:
color: "#E0FFFF"
shape: Star
respectZoom: true
rotate: true
bounds: "-0.5,-0.5,0.5,0.5"

- type: entity
id: OrganDionaEyes
Expand Down
26 changes: 15 additions & 11 deletions Resources/Prototypes/Body/Organs/human.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,21 @@
- type: Item
size: Small
heldPrefix: brain
# - type: RadarBlip # LuaM
# radarColor: "#E0FFFF"
# scale: 6
# shape: Star
# visibleFromOtherGrids: true
# gridConfig:
# color: "#E0FFFF"
# shape: Star
# respectZoom: true
# rotate: true
# bounds: "-0.5,-0.5,0.5,0.5"
- type: OutOfContainerGrant # LuaM
components:
- type: RadarBlip
radarColor: "#E0FFFF"
scale: 3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
scale: 3
scale: 3 // LuaM: 6 > 3

shape: Star
maxDistance: 512
requireNoGrid: true
Comment on lines +106 to +107

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
maxDistance: 512
requireNoGrid: true
# LuaM-start:
maxDistance: 512
requireNoGrid: true
# LuaM-end.

visibleFromOtherGrids: true
gridConfig:
color: "#E0FFFF"
shape: Star
respectZoom: true
rotate: true
bounds: "-0.5,-0.5,0.5,0.5"

- type: entity
id: OrganHumanEyes
Expand Down
Loading