Flatpacks and the Flatpacker 1001 (#23338)
* Flatpacker and flatpacks * ok that's good enough * convert solars/AME to flatpacks * mats, mats, we are the mats * basic mechanics are DONE * thing * final UI * sloth * rped jumpscare * rename
This commit is contained in:
@@ -81,7 +81,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return 0; //you have nothing
|
||||
return !component.Storage.TryGetValue(material, out var amount) ? 0 : amount;
|
||||
return component.Storage.GetValueOrDefault(material, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -123,9 +123,35 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return false;
|
||||
return CanTakeVolume(uid, volume, component) &&
|
||||
(component.MaterialWhiteList == null || component.MaterialWhiteList.Contains(materialId)) &&
|
||||
(!component.Storage.TryGetValue(materialId, out var amount) || amount + volume >= 0);
|
||||
|
||||
if (!CanTakeVolume(uid, volume, component))
|
||||
return false;
|
||||
|
||||
if (component.MaterialWhiteList != null && !component.MaterialWhiteList.Contains(materialId))
|
||||
return false;
|
||||
|
||||
var amount = component.Storage.GetValueOrDefault(materialId);
|
||||
return amount + volume >= 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the specified materials can be changed by the specified volumes.
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="materials"></param>
|
||||
/// <returns>If the amount can be changed</returns>
|
||||
public bool CanChangeMaterialAmount(Entity<MaterialStorageComponent?> entity, Dictionary<string,int> materials)
|
||||
{
|
||||
if (!Resolve(entity, ref entity.Comp))
|
||||
return false;
|
||||
|
||||
foreach (var (material, amount) in materials)
|
||||
{
|
||||
if (!CanChangeMaterialAmount(entity, material, amount, entity.Comp))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -136,20 +162,47 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
||||
/// <param name="materialId"></param>
|
||||
/// <param name="volume"></param>
|
||||
/// <param name="component"></param>
|
||||
/// <param name="dirty"></param>
|
||||
/// <returns>If it was successful</returns>
|
||||
public bool TryChangeMaterialAmount(EntityUid uid, string materialId, int volume, MaterialStorageComponent? component = null)
|
||||
public bool TryChangeMaterialAmount(EntityUid uid, string materialId, int volume, MaterialStorageComponent? component = null, bool dirty = true)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
return false;
|
||||
if (!CanChangeMaterialAmount(uid, materialId, volume, component))
|
||||
return false;
|
||||
if (!component.Storage.ContainsKey(materialId))
|
||||
component.Storage.Add(materialId, 0);
|
||||
component.Storage.TryAdd(materialId, 0);
|
||||
component.Storage[materialId] += volume;
|
||||
|
||||
var ev = new MaterialAmountChangedEvent();
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
Dirty(component);
|
||||
|
||||
if (dirty)
|
||||
Dirty(uid, component);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Changes the amount of a specific material in the storage.
|
||||
/// Still respects the filters in place.
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="materials"></param>
|
||||
/// <returns>If the amount can be changed</returns>
|
||||
public bool TryChangeMaterialAmount(Entity<MaterialStorageComponent?> entity, Dictionary<string,int> materials)
|
||||
{
|
||||
if (!Resolve(entity, ref entity.Comp))
|
||||
return false;
|
||||
|
||||
if (!CanChangeMaterialAmount(entity, materials))
|
||||
return false;
|
||||
|
||||
foreach (var (material, amount) in materials)
|
||||
{
|
||||
if (!TryChangeMaterialAmount(entity, material, amount, entity.Comp, false))
|
||||
return false;
|
||||
}
|
||||
|
||||
Dirty(entity, entity.Comp);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -225,7 +278,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
||||
insertingComp.MaterialColor = lastMat?.Color;
|
||||
}
|
||||
_appearance.SetData(receiver, MaterialStorageVisuals.Inserting, true);
|
||||
Dirty(insertingComp);
|
||||
Dirty(receiver, insertingComp);
|
||||
|
||||
var ev = new MaterialEntityInsertedEvent(material);
|
||||
RaiseLocalEvent(receiver, ref ev);
|
||||
@@ -245,7 +298,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
|
||||
var ev = new GetMaterialWhitelistEvent(uid);
|
||||
RaiseLocalEvent(uid, ref ev);
|
||||
component.MaterialWhiteList = ev.Whitelist;
|
||||
Dirty(component);
|
||||
Dirty(uid, component);
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, MaterialStorageComponent component, InteractUsingEvent args)
|
||||
|
||||
Reference in New Issue
Block a user