Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorio Magnet Refactor #899

Merged
merged 8 commits into from
Jan 29, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ public sealed partial class MaterialReclaimerMagnetPickupComponent : Component

[ViewVariables(VVAccess.ReadWrite), DataField("range")]
public float Range = 1f;

/// <summary>
/// Frontier - Is the magnet currently enabled?
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("magnetEnabled")]
public bool MagnetEnabled = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ public sealed partial class MaterialStorageMagnetPickupComponent : Component

[ViewVariables(VVAccess.ReadWrite), DataField("range")]
public float Range = 1f;

/// <summary>
/// Frontier - Is the magnet currently enabled?
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("magnetEnabled")]
public bool MagnetEnabled = false;
}
1 change: 0 additions & 1 deletion Content.Shared/Storage/EntitySystems/MagnetPickupSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public bool ToggleMagnet(EntityUid uid, MagnetPickupComponent comp)
return comp.MagnetEnabled;
}


public override void Update(float frameTime)
{
base.Update(frameTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using Content.Shared.Materials;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
using Content.Shared.Examine; // Frontier
using Content.Shared.Hands.Components; // Frontier
using Content.Shared.Verbs; // Frontier
using Robust.Shared.Utility; // Frontier

namespace Content.Shared.Storage.EntitySystems;

Expand All @@ -24,6 +28,8 @@ public override void Initialize()
_physicsQuery = GetEntityQuery<PhysicsComponent>();
SubscribeLocalEvent<MaterialReclaimerMagnetPickupComponent, MapInitEvent>(OnMagnetMapInit);
SubscribeLocalEvent<MaterialReclaimerMagnetPickupComponent, EntityUnpausedEvent>(OnMagnetUnpaused);
SubscribeLocalEvent<MaterialReclaimerMagnetPickupComponent, ExaminedEvent>(OnExamined); // Frontier
SubscribeLocalEvent<MaterialReclaimerMagnetPickupComponent, GetVerbsEvent<AlternativeVerb>>(AddToggleMagnetVerb); // Frontier
}

private void OnMagnetUnpaused(EntityUid uid, MaterialReclaimerMagnetPickupComponent component, ref EntityUnpausedEvent args)
Expand All @@ -33,7 +39,48 @@ private void OnMagnetUnpaused(EntityUid uid, MaterialReclaimerMagnetPickupCompon

private void OnMagnetMapInit(EntityUid uid, MaterialReclaimerMagnetPickupComponent component, MapInitEvent args)
{
component.NextScan = _timing.CurTime + TimeSpan.FromSeconds(1f);
component.NextScan = _timing.CurTime + TimeSpan.FromSeconds(1); // Need to add 1 sec to fix a weird time bug with it that make it never start the magnet
}

// Frontier, used to add the magnet toggle to the context menu
private void AddToggleMagnetVerb(EntityUid uid, MaterialReclaimerMagnetPickupComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;

if (!HasComp<HandsComponent>(args.User))
return;

AlternativeVerb verb = new()
{
Act = () =>
{
ToggleMagnet(uid, component);
},
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/Spare/poweronoff.svg.192dpi.png")),
Text = Loc.GetString("magnet-pickup-component-toggle-verb"),
Priority = 3
};

args.Verbs.Add(verb);
}

// Frontier, used to show the magnet state on examination
private void OnExamined(EntityUid uid, MaterialReclaimerMagnetPickupComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString("magnet-pickup-component-on-examine-main",
("stateText", Loc.GetString(component.MagnetEnabled
? "magnet-pickup-component-magnet-on"
: "magnet-pickup-component-magnet-off"))));
}

// Frontier, used to toggle the magnet on the ore bag/box
public bool ToggleMagnet(EntityUid uid, MaterialReclaimerMagnetPickupComponent comp)
{
var query = EntityQueryEnumerator<MaterialReclaimerMagnetPickupComponent>();
comp.MagnetEnabled = !comp.MagnetEnabled;

return comp.MagnetEnabled;
}

public override void Update(float frameTime)
Expand All @@ -49,6 +96,10 @@ public override void Update(float frameTime)

comp.NextScan += ScanDelay;

// Frontier - magnet disabled
if (!comp.MagnetEnabled)
continue;

var parentUid = xform.ParentUid;

foreach (var near in _lookup.GetEntitiesInRange(uid, comp.Range, LookupFlags.Dynamic | LookupFlags.Sundries))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
using Content.Shared.Materials;
using Robust.Shared.Physics.Components;
using Robust.Shared.Timing;
using Content.Shared.Examine; // Frontier
using Content.Shared.Hands.Components; // Frontier
using Content.Shared.Verbs; // Frontier
using Robust.Shared.Utility; // Frontier

namespace Content.Shared.Storage.EntitySystems;

Expand All @@ -24,6 +28,8 @@ public override void Initialize()
_physicsQuery = GetEntityQuery<PhysicsComponent>();
SubscribeLocalEvent<MaterialStorageMagnetPickupComponent, MapInitEvent>(OnMagnetMapInit);
SubscribeLocalEvent<MaterialStorageMagnetPickupComponent, EntityUnpausedEvent>(OnMagnetUnpaused);
SubscribeLocalEvent<MaterialStorageMagnetPickupComponent, ExaminedEvent>(OnExamined); // Frontier
SubscribeLocalEvent<MaterialStorageMagnetPickupComponent, GetVerbsEvent<AlternativeVerb>>(AddToggleMagnetVerb); // Frontier
}

private void OnMagnetUnpaused(EntityUid uid, MaterialStorageMagnetPickupComponent component, ref EntityUnpausedEvent args)
Expand All @@ -33,7 +39,48 @@ private void OnMagnetUnpaused(EntityUid uid, MaterialStorageMagnetPickupComponen

private void OnMagnetMapInit(EntityUid uid, MaterialStorageMagnetPickupComponent component, MapInitEvent args)
{
component.NextScan = _timing.CurTime + TimeSpan.FromSeconds(1f);
component.NextScan = _timing.CurTime + TimeSpan.FromSeconds(1); // Need to add 1 sec to fix a weird time bug with it that make it never start the magnet
}

// Frontier, used to add the magnet toggle to the context menu
private void AddToggleMagnetVerb(EntityUid uid, MaterialStorageMagnetPickupComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;

if (!HasComp<HandsComponent>(args.User))
return;

AlternativeVerb verb = new()
{
Act = () =>
{
ToggleMagnet(uid, component);
},
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/Spare/poweronoff.svg.192dpi.png")),
Text = Loc.GetString("magnet-pickup-component-toggle-verb"),
Priority = 3
};

args.Verbs.Add(verb);
}

// Frontier, used to show the magnet state on examination
private void OnExamined(EntityUid uid, MaterialStorageMagnetPickupComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString("magnet-pickup-component-on-examine-main",
("stateText", Loc.GetString(component.MagnetEnabled
? "magnet-pickup-component-magnet-on"
: "magnet-pickup-component-magnet-off"))));
}

// Frontier, used to toggle the magnet on the ore bag/box
public bool ToggleMagnet(EntityUid uid, MaterialStorageMagnetPickupComponent comp)
{
var query = EntityQueryEnumerator<MaterialStorageMagnetPickupComponent>();
comp.MagnetEnabled = !comp.MagnetEnabled;

return comp.MagnetEnabled;
}

public override void Update(float frameTime)
Expand All @@ -49,6 +96,10 @@ public override void Update(float frameTime)

comp.NextScan += ScanDelay;

// Frontier - magnet disabled
if (!comp.MagnetEnabled)
continue;

var parentUid = xform.ParentUid;

foreach (var near in _lookup.GetEntitiesInRange(uid, comp.Range, LookupFlags.Dynamic | LookupFlags.Sundries))
Expand Down
4 changes: 2 additions & 2 deletions Resources/Prototypes/Entities/Structures/Machines/lathe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
price: 800
- type: ResearchClient
- type: TechnologyDatabase
- type: MaterialStorageMagnetPickup # Frontier
range: 0.30

- type: entity
id: Autolathe
Expand Down Expand Up @@ -880,8 +882,6 @@
- IngotGold30
- IngotSilver30
- MaterialBananium10
- type: MaterialStorageMagnetPickup # Frontier
range: 0.30

- type: entity
parent: BaseLathe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@
powerLoad: 500 # Allows us to not use the 1000 baseline
- type: MaterialReclaimerMagnetPickup # Frontier
range: 0.30
magnetEnabled: true
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
gasType: CarbonDioxide
# 0.5 moles of gas for every sheet of plasma.
moleRatio: 0.5
- type: MaterialStorageMagnetPickup # Frontier
range: 0.30

- type: entity
name: S.U.P.E.R.P.A.C.M.A.N.-type portable generator
Expand Down Expand Up @@ -219,6 +221,8 @@
- type: UpgradePowerSupplier
powerSupplyMultiplier: 1.25
scaling: Exponential
- type: MaterialStorageMagnetPickup # Frontier
range: 0.30

- type: entity
name: J.R.P.A.C.M.A.N.-type portable generator
Expand Down
Loading