def reset_players(result): """Resets Players to Lobby""" Players().collection.update_one( {"player_id": int(result["player_yellow"])}, {'$set': {'status': 'IN_LOBBY'}}) Players().collection.update_one( {"player_id": int(result["player_red"])}, {'$set': {'status': 'IN_LOBBY'}})
def player_status_chk(player_id): """ Checks player Status to add to game """ player_result = Players().get_one_player_id(float(player_id)) if isinstance(player_result, dict): player_status = player_result['status'] if player_status == "LOBBY": return player_id return { "message": f"Player {player_id} is not eligible to join" }, 400 return { "message": f"Player {player_id} could not be found!" }, 400
def update_game_player(self, game_id, color, player_id): """ Assign Player Color with Player ID """ game_result = self.collection.find_one({'game_id': int(game_id)}, {'_id': 0}) gstat = self.game_status_chk(color, game_id, game_result) pstat = self.player_status_chk(player_id) if pstat == player_id and gstat == game_id: self.collection.update_one({'game_id': int(game_id)}, {'$set': {color: player_id}}) Players().collection.update_one({'player_id': float(player_id)}, {'$set': {"status": "IN_GAME"}} ) gstat_changer = self.game_status_changer(game_id) return { 'message': f'Player {color} added [id={player_id}] {gstat_changer}' }, 200 return { 'game': f"{pstat} {gstat}" }, 400
def put(self, username, password): ''' updates a player username and password ''' #do this separately? return Players().update_many(username, password, request.json)
def delete(self, username): ''' deletes a player by username ''' return Players().delete_one(username)
def put(self, username): ''' updates a player's username via old username''' return Players().update_one(username, request.json)
def get(self, username): ''' gets a player by username ''' return Players().get_one(username)
def post(self, display_name='displayName'): ''' adds a new player ''' print(f'request={request.get_json()}') return Players().create_one(display_name, request.get_json())
def get(self, username): """gets state for username""" return Players().get_user_state(username)
def delete(self, display_name): ''' deletes a player by display name ''' return Players().delete_one(display_name)
def post(self): """ Adds a new Player """ return Players().create_one(request.get_json())
def put(self, player_id): """ Updates Player by player_id """ return Players().update_one_by_id(player_id, request.json)
def get(self, player_id): """ Returns Player by Id number""" return Players().get_one_player_id(player_id)
def get(self): """ Returns List of Players """ args = GET_PARSER.parse_args() return Players().get_all(args["status"])
def put(self, display_name): ''' updates a player by display name ''' return Players().update_one(display_name, request.json)
def get(self, username): return Players().get_history(username)
def put(self, username): """ Updates a player with username """ return Players().update_one(username, request.json)
def get(self): """ Returns list of Players """ args = GET_PARSER.parse_args() print(f'args={args}') return Players().get_all(args['level'], args['state'])
def get(self, display_name): ''' get a player by display name''' return Players().get_one(display_name)
def get(self, username): """ Returns a player with username """ return Players().get_one(username)
def get(self): ''' returns a list of all players ''' args = GET_PARSER.parse_args() print(f'args={args}') return Players().get_all(args['state'])
def delete(self, username): """ Deletes a player with username """ return Players().delete_one(username)
def post(self): ''' adds a new player ''' print(f'request={request.get_json()}') return Players().create_one(request.get_json())
def put(self, username): """updates state of player""" return Players().update_one_state(username, request.json)
def get(self): ''' returns a list of all players ''' return Players().get_all()