forked from acm-ndsu/byte_le_engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* base of generic station more work required * basics of occupied_station * Station: minor fixes * Station: major fix occupied_station didn't have .py... yeah * fixed station classes * station / avatar fixes occupied_by changed to GameObject, isinstance added to setter methods
- Loading branch information
1 parent
9518a3f
commit 7236b50
Showing
6 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from game.common.avatar import Avatar | ||
from game.common.enums import ObjectType | ||
from game.common.items.item import Item | ||
from game.common.stations.station import Station | ||
from game.common.game_object import GameObject | ||
from typing import Self | ||
|
||
# create station object that contains occupied_by | ||
class Occupiable_Station(Station): | ||
def __init__(self, item: Item = None, occupied_by: GameObject = None): | ||
super().__init__(self, item) | ||
self.object_type = ObjectType.OCCUPIABLE_STATION | ||
self.occupied_by = occupied_by | ||
|
||
# occupied_by getter and setter methods | ||
@property | ||
def occupied_by(self) -> GameObject: | ||
return self.__occupied_by | ||
|
||
@occupied_by.setter | ||
def occupied_by(self, occupied_by: GameObject): | ||
if occupied_by and not isinstance(occupied_by, GameObject): | ||
raise ValueError(f"{self.__class__.__name__}.occupied_by must be a GameObject.") | ||
self.__occupied_by = occupied_by | ||
|
||
# take action method | ||
def take_action(self, avatar: Avatar = None): | ||
return | ||
|
||
# json methods | ||
def to_json(self) -> dict: | ||
dict_data = super().to_json() | ||
dict_data['occupied_by'] = self.occupied_by | ||
return dict_data | ||
|
||
def from_json(self, data: dict) -> Self: | ||
super().from_json(data) | ||
self.occupied_by = data['occupied_by'] | ||
|
||
# framework match case for from json, can add more cases if they can occupy station | ||
match self.occupied_by["object_type"]: | ||
case ObjectType.AVATAR: | ||
self.occupied_by = Avatar().from_json(data['occupied_by']) | ||
case _: | ||
raise Exception(f'Could not parse occupied_by: {self.occupied_by}') | ||
|
||
return self | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from game.common.avatar import Avatar | ||
from game.common.game_object import GameObject | ||
from game.common.enums import ObjectType | ||
from game.common.items.item import Item | ||
from typing import Self | ||
|
||
# create Station object from GameObject that allows item to be contained in it | ||
class Station(GameObject): | ||
def __init__(self, item: Item = None): | ||
super().__init__() | ||
self.object_type = ObjectType.station | ||
self.item: Item = item | ||
|
||
# item getter and setter methods | ||
@property | ||
def item(self) -> Item: | ||
return self.__item | ||
|
||
@item.setter | ||
def item(self, item: Item): | ||
if item and not isinstance(item, Item): | ||
raise ValueError(f"{self.__class__.__name__}.item must be an Item.") | ||
self.__item = item | ||
|
||
# take action method | ||
def take_action(self, avatar: Avatar = None): | ||
return | ||
|
||
# json methods | ||
def to_json(self) -> dict: | ||
dict_data = super().to_json() | ||
dict_data['item'] = self.item.to_json() if self.item else None | ||
|
||
return dict_data | ||
|
||
def from_json(self, data: dict) -> Self: | ||
super().from_json(data) | ||
if not data['item']: | ||
self.item = None | ||
|
||
# framework match case for from json, can add more object types that can be item | ||
match self.item["object_type"]: | ||
case ObjectType.ITEM: | ||
self.item = Item().from_json(data['item']) | ||
case _: | ||
raise Exception(f'Could not parse item: {self.item}') | ||
|
||
return self | ||
|