async def change_shape_floor(sid: str, data: ShapeFloorChange): pr: PlayerRoom = game_state.get(sid) if pr.role != Role.DM: logger.warning(f"{pr.player.name} attempted to move the floor of a shape") return floor: Floor = Floor.get(location=pr.active_location, name=data["floor"]) shapes: List[Shape] = [s for s in Shape.select().where(Shape.uuid << data["uuids"])] layer: Layer = Layer.get(floor=floor, name=shapes[0].layer.name) old_layer = shapes[0].layer for shape in shapes: old_index = shape.index shape.layer = layer shape.index = layer.shapes.count() shape.save() Shape.update(index=Shape.index - 1).where( (Shape.layer == old_layer) & (Shape.index >= old_index) ).execute() await sio.emit( "Shapes.Floor.Change", data, room=pr.active_location.get_path(), skip_sid=sid, namespace=GAME_NS, )
async def remove_shapes(sid: str, data: TemporaryShapesList): pr: PlayerRoom = game_state.get(sid) if data["temporary"]: # This stuff is not stored so we cannot do any server side validation /shrug for shape in data["uuids"]: game_state.remove_temp(sid, shape) else: # Use the server version of the shapes. try: shapes: List[Shape] = [ s for s in Shape.select().where(Shape.uuid << data["uuids"]) ] except Shape.DoesNotExist: logger.warning( f"Attempt to update unknown shape by {pr.player.name}") return layer = shapes[0].layer group_ids = set() for shape in shapes: if not has_ownership(shape, pr): logger.warning( f"User {pr.player.name} tried to update a shape it does not own." ) return if shape.group: group_ids.add(shape.group) old_index = shape.index shape.delete_instance(True) Shape.update(index=Shape.index - 1).where((Shape.layer == layer) & (Shape.index >= old_index)).execute() for group_id in group_ids: await remove_group_if_empty(group_id) await sio.emit( "Shapes.Remove", data["uuids"], room=pr.active_location.get_path(), skip_sid=sid, namespace=GAME_NS, )
async def change_shape_layer(sid: str, data: Dict[str, Any]): pr: PlayerRoom = game_state.get(sid) if pr.role != Role.DM: logger.warning(f"{pr.player.name} attempted to move the layer of a shape") return floor = Floor.get(location=pr.active_location, name=data["floor"]) shapes: List[Shape] = [s for s in Shape.select().where(Shape.uuid << data["uuids"])] layer = Layer.get(floor=floor, name=data["layer"]) old_layer = shapes[0].layer if old_layer.player_visible and not layer.player_visible: for room_player in pr.room.players: if room_player.role == Role.DM: continue for psid in game_state.get_sids( player=room_player.player, active_location=pr.active_location, skip_sid=sid, ): await sio.emit( "Shapes.Remove", data["uuids"], room=psid, namespace=GAME_NS, ) for shape in shapes: old_index = shape.index shape.layer = layer shape.index = layer.shapes.count() shape.save() Shape.update(index=Shape.index - 1).where( (Shape.layer == old_layer) & (Shape.index >= old_index) ).execute() if old_layer.player_visible and layer.player_visible: await sio.emit( "Shapes.Layer.Change", data, room=pr.active_location.get_path(), skip_sid=sid, namespace=GAME_NS, ) else: for room_player in pr.room.players: is_dm = room_player.role == Role.DM for psid in game_state.get_sids( player=room_player.player, active_location=pr.active_location, skip_sid=sid, ): if is_dm: await sio.emit( "Shapes.Layer.Change", data, room=psid, skip_sid=sid, namespace=GAME_NS, ) elif layer.player_visible: await sio.emit( "Shapes.Add", [shape.as_dict(room_player.player, False) for shape in shapes], room=psid, namespace=GAME_NS, )