78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
|
from sqlalchemy import Column, Integer, String, ForeignKey, Enum
|
||
|
import enum
|
||
|
from sqlalchemy.ext.declarative import declarative_base
|
||
|
from BotErrors import LocationInitError
|
||
|
|
||
|
SQL_Base = declarative_base()
|
||
|
|
||
|
|
||
|
class TunnelDirection(enum.Enum):
|
||
|
North = 'green'
|
||
|
East = 'blue'
|
||
|
South = 'red'
|
||
|
West = 'yellow'
|
||
|
|
||
|
def str_to_tunnel_dir(arg):
|
||
|
arg = arg.lower()
|
||
|
if arg == TunnelDirection.North.value:
|
||
|
return TunnelDirection.North
|
||
|
elif arg == TunnelDirection.East.value:
|
||
|
return TunnelDirection.East
|
||
|
elif arg == TunnelDirection.South.value:
|
||
|
return TunnelDirection.South
|
||
|
elif arg == TunnelDirection.West.value:
|
||
|
return TunnelDirection.West
|
||
|
else:
|
||
|
raise ValueError
|
||
|
|
||
|
|
||
|
class Player(SQL_Base):
|
||
|
__tablename__ = 'Players'
|
||
|
|
||
|
id = Column(Integer, primary_key=True)
|
||
|
in_game_name = Column(String)
|
||
|
|
||
|
def __init__(self, name):
|
||
|
self.in_game_name = name
|
||
|
|
||
|
|
||
|
class Location(SQL_Base):
|
||
|
__tablename__ = 'Locations'
|
||
|
|
||
|
id = Column(Integer, primary_key=True)
|
||
|
name = Column(String)
|
||
|
x = Column(Integer)
|
||
|
y = Column(Integer)
|
||
|
z = Column(Integer)
|
||
|
tunnelNumber = Column(Integer)
|
||
|
direction = Column(Enum(TunnelDirection))
|
||
|
owner = Column(String, ForeignKey('Players.in_game_name'))
|
||
|
|
||
|
def __init__(self, name, x, y, z, owner, args):
|
||
|
try:
|
||
|
self.name = name
|
||
|
self.x = x
|
||
|
self.y = y
|
||
|
self.z = z
|
||
|
self.owner = owner
|
||
|
|
||
|
if len(args) > 0:
|
||
|
self.direction = TunnelDirection.str_to_tunnel_dir(args[0])
|
||
|
self.tunnelNumber = int(args[1])
|
||
|
|
||
|
except (ValueError, IndexError):
|
||
|
raise LocationInitError
|
||
|
|
||
|
def pos_to_str(self):
|
||
|
return '(x= {}, y= {}, z= {})'.format(self.x, self.y, self.z)
|
||
|
|
||
|
def nether_tunnel_addr_to_str(self):
|
||
|
return '{} {}'.format(self.direction.value.title(), self.tunnelNumber)
|
||
|
|
||
|
def __str__(self):
|
||
|
if self.direction is not None:
|
||
|
return "Name: {}, Position: {}, Tunnel: {}".format(self.name, self.pos_to_str(),
|
||
|
self.nether_tunnel_addr_to_str())
|
||
|
else:
|
||
|
return "Name: {}, Position: {}".format(self.name, self.pos_to_str())
|