Пример #1
0
async def set_name_visible(sid: str, data: ShapeSetBooleanValue):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "NameVisible.Set")
    if shape is None:
        return

    shape.name_visible = data["value"]
    shape.save()

    owners = [*get_owner_sids(pr, shape, skip_sid=sid)]

    await sio.emit(
        "Shape.Options.NameVisible.Set",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )

    for psid in game_state.get_sids(active_location=pr.active_location,
                                    skip_sid=sid):
        if psid in owners:
            continue
        await sio.emit(
            "Shape.Options.Name.Set",
            {
                "shape": shape.uuid,
                "value": shape.name if data["value"] else "?"
            },
            room=psid,
            namespace=GAME_NS,
        )
Пример #2
0
async def create_aura(sid: str, data: AuraDelta):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "Aura.Create")
    if shape is None:
        return

    model = reduce_data_to_model(Aura, data)
    aura = Aura.create(**model)
    aura.save()

    owners = [*get_owner_sids(pr, shape, skip_sid=sid)]
    for psid in owners:
        await sio.emit(
            "Shape.Options.Aura.Create", data, room=psid, namespace=GAME_NS,
        )
    if aura.visible:
        for psid in game_state.get_sids(
            active_location=pr.active_location, skip_sid=sid
        ):
            if psid in owners:
                continue
            await sio.emit(
                "Shape.Options.Aura.Create", data, room=psid, namespace=GAME_NS,
            )
Пример #3
0
async def set_name(sid: str, data: ShapeSetStringValue):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "Name.Set")
    if shape is None:
        return

    shape.name = data["value"]
    shape.save()

    if shape.name_visible:
        await sio.emit(
            "Shape.Options.Name.Set",
            data,
            skip_sid=sid,
            room=pr.active_location.get_path(),
            namespace=GAME_NS,
        )
    else:
        for sid in get_owner_sids(pr, shape, skip_sid=sid):
            await sio.emit(
                "Shape.Options.Name.Set",
                data,
                room=sid,
                namespace=GAME_NS,
            )
Пример #4
0
async def add_toggle_composite_variant(sid: str, data: NewVariantMessage):
    pr: PlayerRoom = game_state.get(sid)

    parent = get_shape_or_none(pr, data["shape"],
                               "ToggleComposite.Variants.Add")
    variant = get_shape_or_none(pr, data["variant"],
                                "ToggleComposite.Variants.Add")
    if parent is None or variant is None:
        return

    CompositeShapeAssociation.create(parent=parent,
                                     variant=variant,
                                     name=data["name"])

    await sio.emit(
        "ToggleComposite.Variants.Add",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )
async def update_aura(sid: str, data: AuraDelta):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "Aura.Update")
    if shape is None:
        return

    aura = Aura.get_by_id(data["uuid"])
    changed_visible = aura.visible != data.get("visible", aura.visible)
    update_model_from_dict(aura, data)
    aura.save()

    owners = [*get_owner_sids(pr, shape, skip_sid=sid)]
    for psid in owners:
        await sio.emit(
            "Shape.Options.Aura.Update",
            data,
            room=psid,
            namespace=GAME_NS,
        )
    for psid in game_state.get_sids(active_location=pr.active_location,
                                    skip_sid=sid):
        if psid in owners:
            continue
        if changed_visible:
            if aura.visible:
                await sio.emit(
                    "Shape.Options.Aura.Create",
                    {
                        "shape": shape.uuid,
                        **aura.as_dict()
                    },
                    room=psid,
                    namespace=GAME_NS,
                )
            else:
                await sio.emit(
                    "Shape.Options.Aura.Remove",
                    {
                        "shape": shape.uuid,
                        "value": aura.uuid
                    },
                    room=psid,
                    namespace=GAME_NS,
                )
        else:
            await sio.emit(
                "Shape.Options.Aura.Update",
                data,
                room=psid,
                namespace=GAME_NS,
            )
async def update_tracker(sid: str, data: TrackerDelta):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "Tracker.Update")
    if shape is None:
        return

    tracker = Tracker.get_by_id(data["uuid"])
    changed_visible = tracker.visible != data.get("visible", tracker.visible)
    update_model_from_dict(tracker, data)
    tracker.save()

    owners = [*get_owner_sids(pr, shape, skip_sid=sid)]
    for psid in owners:
        await sio.emit(
            "Shape.Options.Tracker.Update",
            data,
            room=psid,
            namespace=GAME_NS,
        )
    for psid in game_state.get_sids(active_location=pr.active_location,
                                    skip_sid=sid):
        if psid in owners:
            continue
        if changed_visible:
            if tracker.visible:
                await sio.emit(
                    "Shape.Options.Tracker.Create",
                    {
                        "shape": shape.uuid,
                        **tracker.as_dict()
                    },
                    room=psid,
                    namespace=GAME_NS,
                )
            else:
                await sio.emit(
                    "Shape.Options.Tracker.Remove",
                    {
                        "shape": shape.uuid,
                        "value": tracker.uuid
                    },
                    room=psid,
                    namespace=GAME_NS,
                )
        else:
            await sio.emit(
                "Shape.Options.Tracker.Update",
                data,
                room=psid,
                namespace=GAME_NS,
            )
Пример #7
0
async def set_annotation(sid: str, data: ShapeSetStringValue):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "Annotation.Set")
    if shape is None:
        return

    shape.annotation = data["value"]
    shape.save()

    for sid in get_owner_sids(pr, shape, skip_sid=sid):
        await sio.emit(
            "Shape.Options.Annotation.Set", data, room=sid, namespace=GAME_NS,
        )
Пример #8
0
async def add_label(sid: str, data: ShapeSetStringValue):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "Label.Add")
    if shape is None:
        return

    ShapeLabel.create(shape=shape, label=data["value"])

    await sio.emit(
        "Shape.Options.Label.Add",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )
Пример #9
0
async def set_locked(sid: str, data: ShapeSetBooleanValue):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "Locked.Set")
    if shape is None:
        return

    shape.is_locked = data["value"]
    shape.save()

    await sio.emit(
        "Shape.Options.Locked.Set",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )
Пример #10
0
async def set_fill_colour(sid: str, data: ShapeSetStringValue):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "FillColour.Set")
    if shape is None:
        return

    shape.fill_colour = data["value"]
    shape.save()

    await sio.emit(
        "Shape.Options.FillColour.Set",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )
Пример #11
0
async def remove_label(sid: str, data: ShapeSetStringValue):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"], "Label.Remove")
    if shape is None:
        return

    label = ShapeLabel.get_by_id(data["value"])
    label.delete_instance(True)

    await sio.emit(
        "Shape.Options.Label.Remove",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )
Пример #12
0
async def move_aura(sid: str, data: AuraMove):
    pr: PlayerRoom = game_state.get(sid)

    new_shape = get_shape_or_none(pr, data["new_shape"],
                                  "Aura.Options.Tracker.Move")
    if new_shape is None:
        return

    aura = Aura.get_by_id(data["aura"])
    aura.shape = new_shape
    aura.save()

    await sio.emit(
        "Shape.Options.Aura.Move",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )
Пример #13
0
async def move_tracker(sid: str, data: TrackerMove):
    pr: PlayerRoom = game_state.get(sid)

    new_shape = get_shape_or_none(pr, data["new_shape"],
                                  "Tracker.Options.Tracker.Move")
    if new_shape is None:
        return

    tracker = Tracker.get_by_id(data["tracker"])
    tracker.shape = new_shape
    tracker.save()

    await sio.emit(
        "Shape.Options.Tracker.Move",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )
Пример #14
0
async def set_toggle_composite_active_variant(sid: str, data: VariantMessage):
    pr: PlayerRoom = game_state.get(sid)

    shape = get_shape_or_none(pr, data["shape"],
                              "ToggleComposite.Variants.Active.Set")
    if shape is None:
        return

    composite: ToggleComposite = shape.subtype

    composite.active_variant = data["variant"]
    composite.save()

    await sio.emit(
        "ToggleComposite.Variants.Active.Set",
        data,
        skip_sid=sid,
        room=pr.active_location.get_path(),
        namespace=GAME_NS,
    )