Skip to content

Commit

Permalink
chore: marking attributes as optional (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrett-griffin authored May 23, 2024
1 parent 404170e commit e92178c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions examples/fix_labour.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async def main():
client = Client(os.environ["API_USER"], os.environ["API_TOKEN"])
player = await client.player()

manager = player.storehouse.inventory.managers.get(Item.Labour)
flow = player.storehouse.total_flow.get(Item.Labour)
manager = player.storehouse.data.inventory.managers.get(Item.Labour)
flow = player.storehouse.data.total_flow.get(Item.Labour)

consumed = flow.consumption - flow.production

Expand All @@ -39,7 +39,7 @@ async def main():
print(f"Adjusting labour purchase amount to {math.ceil(consumed)}")
manager.buy_volume = math.ceil(consumed)

result = await player.storehouse.set_manager(Item.Labour, manager)
result = await player.storehouse.data.set_manager(Item.Labour, manager)
if result:
print("Labour purchase amount adjusted successfully")
else:
Expand Down
2 changes: 1 addition & 1 deletion pymerc/api/models/businesses.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Business(BaseModel):
id: int
name: str
owner_id: int
transport_ids: list[int]
transport_ids: Optional[list[int]] = None


class BusinessAccount(BaseModel):
Expand Down
13 changes: 7 additions & 6 deletions pymerc/api/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,17 +689,18 @@ def selling(self) -> bool:
class InventoryFlow(BaseModel):
"""Represents an inventory flow."""

consumption: Optional[float] = None
expiration: Optional[float] = None
consumption: Optional[float] = 0.0
expiration: Optional[float] = 0.0
export: Optional[int] = None
imported: Optional[int] = Field(None, alias="import")
production: Optional[float] = None
production_cost: Optional[float] = None
production: Optional[float] = 0.0
production_cost: Optional[float] = 0.0
purchase: Optional[int] = None
purchase_cost: Optional[float] = None
purchase_cost: Optional[float] = 0.0
resident: Optional[float] = None
sale: Optional[int] = None
sale_value: Optional[float] = None
sale_value: Optional[float] = 0.0
shortfall: Optional[float] = 0.0


class DeliveryCost(BaseModel):
Expand Down
6 changes: 3 additions & 3 deletions pymerc/api/models/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Player(BaseModel):
username: str
household: Household
discord_id: str
discord_id: Optional[str] = None
settings: Settings
active: bool

Expand All @@ -24,7 +24,7 @@ class Household(BaseModel):
account_id: str
business_ids: list[str]
prestige: float
prestige_impacts: list[PrestigeImpact]
prestige_impacts: Optional[list[PrestigeImpact]] = None
workers: list[Worker]
operations: list[str]
caps: dict[str, int]
Expand All @@ -46,7 +46,7 @@ class Worker(BaseModel):
class Sustenance(BaseModel):
reference: str
inventory: common.Inventory
provider_id: str
provider_id: Optional[str] = None


class Settings(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions pymerc/api/models/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Transport(BaseModel):
inventory: common.Inventory
cargo: TransportCargo = None
previous_operations: Optional[common.Operation] = None
provider_id: int
provider_id: Optional[int] = None
producer: Optional[common.Producer] = None
route: Optional[TransportRoute] = None
journey: TransportJourney
Expand All @@ -34,7 +34,7 @@ class TransportCargo(BaseModel):
"""Represents the cargo of a transport."""

reference: str
inventory: common.Inventory
inventory: Optional[common.Inventory] = None


class TransportJourney(BaseModel):
Expand Down
9 changes: 5 additions & 4 deletions pymerc/game/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import TYPE_CHECKING

from pymerc.api.models import common
from pymerc.api.models import common, businesses
from pymerc.api.models.player import Household, Sustenance
from pymerc.api.models.player import Player as PlayerModel
from pymerc.game.building import BuildingsList
Expand All @@ -18,7 +18,7 @@ class Player:
"""A higher level representation of a player in the game."""

buildings: BuildingsList
business: common.Business
business: businesses.Business
data: PlayerModel
exports: ExportsSummed
imports: ImportsSummed
Expand All @@ -41,8 +41,9 @@ async def load(self):
self.buildings.append(await self._client.building(id))

self.transports = []
for id in self.business.transport_ids:
self.transports.append(await self._client.transport(id))
if self.business.transport_ids:
for id in self.business.transport_ids:
self.transports.append(await self._client.transport(id))

for transport in self.transports:
for item, exp in transport.exports.items():
Expand Down

0 comments on commit e92178c

Please sign in to comment.