async def put_pointer_action( data: PointerActionPut, manager: MapSetManager = Depends(get_map_set_manager) ) -> None: battle_map = get_battle_map(manager, data.map_set_uuid, data.battle_map_uuid) battle_map.process_pointer_action(data)
async def delete_battle_map( data: BattleMapDeleteRequest, manager: MapSetManager = Depends(get_map_set_manager), ): map_set = get_map_set(manager, data.map_set_uuid) battle_map = get_battle_map(manager, data.map_set_uuid, data.uuid) manager.delete_battle_map(map_set, battle_map) manager.save(map_set)
def battle_map_info( map_set_uuid: UUID, uuid: UUID, response: Response, manager: MapSetManager = Depends(get_map_set_manager), ) -> BattleMapInfo: response.headers['Cache-Control'] = 'no-cache' battle_map = get_battle_map(manager, map_set_uuid, uuid) return BattleMapInfo(map_set_uuid=map_set_uuid, **battle_map.__dict__)
def get_all_token_states( map_set_uuid: UUID, battle_map_uuid: UUID, manager: MapSetManager = Depends(get_map_set_manager), ) -> AllTokenStatesResponse: battle_map = get_battle_map(manager, map_set_uuid, battle_map_uuid) return AllTokenStatesResponse( next_action_index=battle_map.action_count, tokens=battle_map.tokens, )
async def put_token_action( data: TokenActionPut, manager: MapSetManager = Depends(get_map_set_manager) ) -> None: battle_map = get_battle_map(manager, data.map_set_uuid, data.battle_map_uuid) try: battle_map.process_token_action(data) manager.save_battle_map(battle_map) except IllegalMove as e: raise HTTPException(status.HTTP_409_CONFLICT, str(e))
async def update_battle_map( data: BattleMapUpdateRequest, manager: MapSetManager = Depends(get_map_set_manager), ) -> BattleMapInfo: map_set = get_map_set(manager, data.map_set_uuid) battle_map = get_battle_map(manager, data.map_set_uuid, data.uuid) battle_map.name = data.name battle_map.background_pixels_per_meter = data.background_pixels_per_meter battle_map.signal_update() manager.save(map_set) return BattleMapInfo(map_set_uuid=map_set.uuid, **battle_map.__dict__)
async def upload_image_data( image_data: UploadFile = File(...), uuid: UUID = Form(...), map_set_uuid: UUID = Form(...), manager: MapSetManager = Depends(get_map_set_manager), ): image_media_type_validator(image_data.content_type) map_set = get_map_set(manager, map_set_uuid) battle_map = get_battle_map(manager, map_set_uuid, uuid) data = await image_data.read() battle_map.set_background_image(data, image_data.content_type) manager.save_background(battle_map) manager.sanitize_token_positions(battle_map) battle_map.signal_update() manager.save(map_set)
def get_image_data( map_set_uuid: UUID, uuid: UUID, response: Response, manager: MapSetManager = Depends(get_map_set_manager), ) -> Response: response.headers['Cache-Control'] = 'no-cache' battle_map = get_battle_map(manager, map_set_uuid, uuid) image_data = battle_map.get_background_image() if image_data is None: content = get_default_map() media_type = 'image/svg+xml' else: content = image_data media_type = battle_map.background_media_type return Response(content=content, media_type=media_type)
async def get_history( map_set_uuid: UUID, battle_map_uuid: UUID, since: int, response: Response, manager: MapSetManager = Depends(get_map_set_manager), ): battle_map = get_battle_map(manager, map_set_uuid, battle_map_uuid) try: actions = await battle_map.wait_for_history_update(since) token_actions, pointer_actions = _split_actions(actions) except LogsExpired as e: raise HTTPException(status.HTTP_410_GONE, str(e)) response.headers['Cache-Control'] = 'no-cache' return HistoryResponse( map_set_uuid=battle_map.map_set.uuid, uuid=battle_map.uuid, last_action_index=battle_map.action_count - 1, battle_map_revision=battle_map.revision, token_actions=token_actions, pointer_actions=pointer_actions, )