Loading...
Searching...
No Matches
CityBuilderCore.StorageComponent Class Reference

Detailed Description

building component that stores items

https://citybuilder.softleitner.com/manual/resources

Inheritance diagram for CityBuilderCore.StorageComponent:
CityBuilderCore.BuildingComponent CityBuilderCore.IStorageComponent CityBuilderCore.IBuildingComponent CityBuilderCore.IBuildingTrait< IStorageComponent > CityBuilderCore.IItemReceiver CityBuilderCore.IItemGiver CityBuilderCore.IItemOwner CityBuilderCore.ISaveData CityBuilderCore.IBuildingTrait< IItemReceiver > CityBuilderCore.IItemOwner CityBuilderCore.IBuildingTrait< IItemGiver > CityBuilderCore.IItemOwner CityBuilderCore.StorageWalkerComponent

Classes

class  StorageData
 

Public Member Functions

override void InitializeComponent ()
 initialization is performed when the building is placed or loaded
use to create references, register traits, ...
 
override void OnReplacing (IBuilding replacement)
 called when a component gets replaced
use to transfer resources, replace references
 
override void TerminateComponent ()
 termination is performed when the building is destroyed
use to deregister traits, remove references from other systems
 
override string GetDebugText ()
 returns text that gets displayed for debugging in the scene editor
 
IEnumerable< ItemGetReceiveItems ()
 returns the kinds of items the receiver needs
 
int GetReceiveCapacity (Item item)
 how much of the item the receiver can still fit
 
void ReserveCapacity (Item item, int quantity)
 reserves a capacity in the receiver so it is not filled up by someone else
 
void UnreserveCapacity (Item item, int quantity)
 releases capacity that was earlier reserved by ReserveCapacity(Item, int)
call before actually moving items into the receiver or if the delivery was somehow interrupted
 
int Receive (ItemStorage storage, Item item, int quantity)
 requests that a quantity of items is moved from the storage to the receiver
if the full amount does not fit the remaining quantity is returned
 
int GetGiveQuantity (Item item)
 checks how much of an item is available to be given
 
void ReserveQuantity (Item item, int quantity)
 reserves a quantity of items that may later be given
dont reverse more than is available(GetGiveQuantity(Item))
 
void UnreserveQuantity (Item item, int quantity)
 releases a quantity that was reserved by ReserveQuantity(Item, int) before
should be called before acutally moving items with Give(ItemStorage, Item, int) or if the process was interrupted
 
int Give (ItemStorage storage, Item item, int quantity)
 requests that a quantity of items is put into the specified storage
if the full amount is not available the remaining quantity is returned
 
override string SaveData ()
 serializes the objects state(usually to json) and returns it
 
override void LoadData (string json)
 deserializes the serialized json data and loads the data as its new state
 
- Public Member Functions inherited from CityBuilderCore.BuildingComponent
virtual void SetupComponent ()
 only called when the building is originally placed, before Initialize
 
virtual void OnMoving ()
 called when the building is about to be moved
can be used to remove/deregister stuff from the old position
 
virtual void OnMoved (Vector2Int oldPoint, BuildingRotation oldRotation)
 called after a building has been moved
can be used to register things at the new position
 
virtual void SuspendComponent ()
 temporarily stops the component from working
 
virtual void ResumeComponent ()
 resumes work in the component after SuspendComponent has been called
 
virtual string GetDescription ()
 gets displayed in dialogs to show the component status to players
 

Public Attributes

ItemStorage Storage
 
StorageOrder[] Orders
 

Properties

override string Key [get]
 unique key used to identify the component in save/load
 
int Priority [get]
 can be used so certain receivers are preferred over others
for example construction sites or production may be more important that putting items into storage
 
BuildingComponentReference< IStorageComponentReference [get, set]
 
BuildingComponentReference< IItemReceiverReceiverReference [get, set]
 
BuildingComponentReference< IItemGiverGiverReference [get, set]
 
IItemContainer ItemContainer [get]
 holds and manages the items for the owner
 
- Properties inherited from CityBuilderCore.BuildingComponent
string Key [get]
 unique key used to identify the component in save/load
 
IBuilding Building [get, set]
 the building the component is attached to
is set by the building in awake
 
- Properties inherited from CityBuilderCore.IBuildingComponent
- Properties inherited from CityBuilderCore.IStorageComponent
- Properties inherited from CityBuilderCore.IBuildingTrait< IStorageComponent >
BuildingComponentReference< T > Reference [get, set]
 reference to the building trait, use when the building might be replaced and when the reference has to be saved
 
- Properties inherited from CityBuilderCore.IItemReceiver
- Properties inherited from CityBuilderCore.IBuildingTrait< IItemReceiver >
BuildingComponentReference< T > Reference [get, set]
 reference to the building trait, use when the building might be replaced and when the reference has to be saved
 
- Properties inherited from CityBuilderCore.IItemOwner
- Properties inherited from CityBuilderCore.IBuildingTrait< IItemGiver >
BuildingComponentReference< T > Reference [get, set]
 reference to the building trait, use when the building might be replaced and when the reference has to be saved
 

Additional Inherited Members

- Protected Member Functions inherited from CityBuilderCore.BuildingComponent
getOther< T > ()
 gets the first building component of the specified type on the same building
 
IEnumerable< T > getOthers< T > ()
 gets all building components of the specified type on the same building
 
BuildingComponentReference< T > registerTrait< T > (T trait)
 registers the building component as a trait so it is globally accessible
usually done in InitializeComponent
 
void replaceTrait< T > (T trait, T replacement)
 replaces the reference a trait points to in the global manager
done when a building is replaced(OnReplacing(IBuilding)) so the trait now points to the new component instead of the one that has been removed
 
void deregisterTrait< T > (T trait)
 removes a previously registered trait
usually when a building is removed which calls TerminateComponent
 

Member Function Documentation

◆ GetDebugText()

override string CityBuilderCore.StorageComponent.GetDebugText ( )
virtual

returns text that gets displayed for debugging in the scene editor

Returns
a debugging string or null

Reimplemented from CityBuilderCore.BuildingComponent.

◆ GetGiveQuantity()

int CityBuilderCore.StorageComponent.GetGiveQuantity ( Item item)
inline

checks how much of an item is available to be given

Parameters
itemthe wanted item
Returns
unreserved quantity available

Implements CityBuilderCore.IItemGiver.

◆ GetReceiveCapacity()

int CityBuilderCore.StorageComponent.GetReceiveCapacity ( Item item)
inline

how much of the item the receiver can still fit

Parameters
item
Returns
unreserved capacity available

Implements CityBuilderCore.IItemReceiver.

◆ GetReceiveItems()

IEnumerable< Item > CityBuilderCore.StorageComponent.GetReceiveItems ( )

returns the kinds of items the receiver needs

Returns
the pertinent items

Implements CityBuilderCore.IItemReceiver.

◆ Give()

int CityBuilderCore.StorageComponent.Give ( ItemStorage storage,
Item item,
int quantity )
inline

requests that a quantity of items is put into the specified storage
if the full amount is not available the remaining quantity is returned

Parameters
storagethe storage the items will be added to
itemthe item to give
quantitythe desired quantity
Returns
the remaining quantity that was not available

Implements CityBuilderCore.IItemGiver.

◆ InitializeComponent()

override void CityBuilderCore.StorageComponent.InitializeComponent ( )
inlinevirtual

initialization is performed when the building is placed or loaded
use to create references, register traits, ...

Reimplemented from CityBuilderCore.BuildingComponent.

◆ LoadData()

override void CityBuilderCore.StorageComponent.LoadData ( string json)
inlinevirtual

deserializes the serialized json data and loads the data as its new state

Parameters
json

Reimplemented from CityBuilderCore.BuildingComponent.

Reimplemented in CityBuilderCore.StorageWalkerComponent.

◆ OnReplacing()

override void CityBuilderCore.StorageComponent.OnReplacing ( IBuilding replacement)
inlinevirtual

called when a component gets replaced
use to transfer resources, replace references

Parameters
replacement

Reimplemented from CityBuilderCore.BuildingComponent.

◆ Receive()

int CityBuilderCore.StorageComponent.Receive ( ItemStorage storage,
Item item,
int quantity )
inline

requests that a quantity of items is moved from the storage to the receiver
if the full amount does not fit the remaining quantity is returned

Parameters
storagethe storage that items will be taken from
itemthe item to receive
quantitythe maximum quantity of items to receive
Returns
remaining quantity that did not fit

Implements CityBuilderCore.IItemReceiver.

◆ ReserveCapacity()

void CityBuilderCore.StorageComponent.ReserveCapacity ( Item item,
int quantity )
inline

reserves a capacity in the receiver so it is not filled up by someone else

Parameters
itemthe item to be reserved
quantitythe quantity to reserve

Implements CityBuilderCore.IItemReceiver.

◆ ReserveQuantity()

void CityBuilderCore.StorageComponent.ReserveQuantity ( Item item,
int quantity )
inline

reserves a quantity of items that may later be given
dont reverse more than is available(GetGiveQuantity(Item))

Parameters
itemwanted item
quantityquantity of the item

Implements CityBuilderCore.IItemGiver.

◆ SaveData()

override string CityBuilderCore.StorageComponent.SaveData ( )
inlinevirtual

serializes the objects state(usually to json) and returns it

Returns
serialized save data

Reimplemented from CityBuilderCore.BuildingComponent.

Reimplemented in CityBuilderCore.StorageWalkerComponent.

◆ TerminateComponent()

override void CityBuilderCore.StorageComponent.TerminateComponent ( )
inlinevirtual

termination is performed when the building is destroyed
use to deregister traits, remove references from other systems

Reimplemented from CityBuilderCore.BuildingComponent.

◆ UnreserveCapacity()

void CityBuilderCore.StorageComponent.UnreserveCapacity ( Item item,
int quantity )
inline

releases capacity that was earlier reserved by ReserveCapacity(Item, int)
call before actually moving items into the receiver or if the delivery was somehow interrupted

Parameters
itemitem to unreserve
quantityquantity to unreserve

Implements CityBuilderCore.IItemReceiver.

◆ UnreserveQuantity()

void CityBuilderCore.StorageComponent.UnreserveQuantity ( Item item,
int quantity )
inline

releases a quantity that was reserved by ReserveQuantity(Item, int) before
should be called before acutally moving items with Give(ItemStorage, Item, int) or if the process was interrupted

Parameters
item
quantity

Implements CityBuilderCore.IItemGiver.

Property Documentation

◆ ItemContainer

IItemContainer CityBuilderCore.StorageComponent.ItemContainer
get

holds and manages the items for the owner

Implements CityBuilderCore.IItemOwner.

◆ Key

override string CityBuilderCore.StorageComponent.Key
get

unique key used to identify the component in save/load

Implements CityBuilderCore.IBuildingComponent.

◆ Priority

int CityBuilderCore.StorageComponent.Priority
get

can be used so certain receivers are preferred over others
for example construction sites or production may be more important that putting items into storage

Implements CityBuilderCore.IItemReceiver.