- Add an extension method to get all inventories.
- Update README and TODO
This commit is contained in:
parent
16040e5f5a
commit
169719ba4b
5 changed files with 135 additions and 28 deletions
|
|
@ -1,8 +1,10 @@
|
|||
|
||||
using Sandbox.ModAPI.Ingame;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using VRage.Game.ModAPI.Ingame;
|
||||
|
|
@ -33,12 +35,12 @@ namespace IngameScript
|
|||
/// <param name="name"></param>
|
||||
/// <param name="grid"></param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<T> GetBlocks<T>(this IMyGridTerminalSystem gridTerminal, string name = null, IMyCubeGrid grid = null)
|
||||
public static IEnumerable<T> GetBlocks<T>(this IMyGridTerminalSystem gridTerminal, string name = null, IMyCubeGrid grid = null, Func<T, bool> filter = null)
|
||||
where T : class, IMyTerminalBlock
|
||||
{
|
||||
var l = new List<T>();
|
||||
gridTerminal.GetBlocksOfType(l, (T block) =>
|
||||
(name == null || block.CustomName == name) && (grid == null || block.CubeGrid == grid)
|
||||
(name == null || block.CustomName == name) && (grid == null || block.CubeGrid == grid) && (filter == null || filter(block))
|
||||
);
|
||||
return l;
|
||||
}
|
||||
|
|
@ -90,5 +92,46 @@ namespace IngameScript
|
|||
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
public static IEnumerable<IMyInventory> GetAllInventories(this IMyGridTerminalSystem gridTerminal, IMyCubeGrid grid = null)
|
||||
{
|
||||
var inventories = new List<IMyInventory>();
|
||||
|
||||
// Containers.
|
||||
foreach (var container in gridTerminal.GetBlocks<IMyCargoContainer>(grid: grid))
|
||||
inventories.Add(container.GetInventory());
|
||||
|
||||
// Assemblers.
|
||||
foreach (var assembler in gridTerminal.GetBlocks<IMyAssembler>(grid: grid))
|
||||
{
|
||||
inventories.Add(assembler.InputInventory);
|
||||
inventories.Add(assembler.OutputInventory);
|
||||
}
|
||||
|
||||
// Refineries
|
||||
foreach (var refinery in gridTerminal.GetBlocks<IMyRefinery>(grid: grid))
|
||||
{
|
||||
inventories.Add(refinery.InputInventory);
|
||||
inventories.Add(refinery.OutputInventory);
|
||||
}
|
||||
|
||||
// Connectors.
|
||||
foreach (var connector in gridTerminal.GetBlocks<IMyShipConnector>(grid: grid))
|
||||
inventories.Add(connector.GetInventory());
|
||||
|
||||
// Welders.
|
||||
foreach (var welder in gridTerminal.GetBlocks<IMyShipWelder>(grid: grid))
|
||||
inventories.Add(welder.GetInventory());
|
||||
|
||||
// Turrets.
|
||||
foreach (var turret in gridTerminal.GetBlocks<IMyLargeTurretBase>(grid: grid))
|
||||
inventories.Add(turret.GetInventory());
|
||||
|
||||
// Artillery and missile launcher.
|
||||
foreach (var missileLauncher in gridTerminal.GetBlocks<IMySmallMissileLauncher>(grid: grid))
|
||||
inventories.Add(missileLauncher.GetInventory());
|
||||
|
||||
return inventories;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue