initial code snippets
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
from __builtins__ import OutpostComponent, OutpostRef, LargeWarehouse, Warehouse, StorageBin
|
||||
|
||||
class Item:
|
||||
@staticmethod
|
||||
def get_storages(
|
||||
item: str, outpost: OutpostComponent | OutpostRef | str = None,
|
||||
sbin: bool = True, whouse: bool = True,
|
||||
nearest: tuple[int, int] | None = None
|
||||
) -> list[StorageBin | Warehouse | LargeWarehouse]:
|
||||
"""get all storages (without inventory) for with a given item
|
||||
|
||||
Args:
|
||||
item (str): item id
|
||||
outpost (OutpostComponent | OutpostRef | str): outpost to search for storages
|
||||
sbin (bool): control StorageBin search. default True
|
||||
whouse (bool): control Warehouese & LargeWarehouse search. default True
|
||||
TODO: nearest (tuple[int, int] | None): on True get only the nearest storage for position (x, y). None = get all. default None (planed!)
|
||||
Return:
|
||||
list[StorageBin | Warehouse | LargeWarehouse]
|
||||
"""
|
||||
# check type of item
|
||||
if not isinstance(item, str):
|
||||
return list()
|
||||
|
||||
# check type of outpost
|
||||
if outpost is None:
|
||||
# get all outposts
|
||||
for op in get_component("outpost_network").outposts():
|
||||
outposts = get_component("outpost_network").outposts()
|
||||
else:
|
||||
# ensure outpost is a OutpostComponent
|
||||
if isinstance(outpost, str): outpost = get_component(outpost)
|
||||
if isinstance(outpost, OutpostRef): outpost = get_component(outpost.id)
|
||||
if not isinstance(outpost, OutpostComponent):
|
||||
return list()
|
||||
outposts = [outpost]
|
||||
|
||||
storages = list()
|
||||
for outpost in outposts:
|
||||
# search for StorgageBins
|
||||
if sbin:
|
||||
for b in outpost.buildings("storage_bin"):
|
||||
storage = get_component(b.id)
|
||||
if item == storage.get_material(): storages.append(storage)
|
||||
|
||||
# search for Warehouse and LargeWarehouse
|
||||
if whouse:
|
||||
for w in outpost.buildings("warehouse"):
|
||||
storage = get_component(w.id)
|
||||
if item in storage.materials(): storages.append(storage)
|
||||
|
||||
# check if nearest is a tuple and has 2 int insert
|
||||
if isinstance(nearest, tuple) and len(nearest) == 2 and all(isinstance(v, int) for v in nearest):
|
||||
pass # TODO
|
||||
return storages
|
||||
|
||||
def count(item, outpost: str = None):
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user