Skip to content

Commit

Permalink
input: Support rotate action with cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
tchx84 committed Feb 22, 2024
1 parent 170e40d commit b8f0f83
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/gameeky/client/input/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@


class Cursor:
__sequence__ = {
Direction.NORTH: Direction.EAST,
Direction.EAST: Direction.SOUTH,
Direction.SOUTH: Direction.WEST,
Direction.WEST: Direction.NORTH,
}

def __init__(self, widget: Gtk.Widget, model: Scene, service: Service) -> None:
super().__init__()
self._service = service
Expand Down Expand Up @@ -64,9 +71,12 @@ def __init__(self, widget: Gtk.Widget, model: Scene, service: Service) -> None:
self._action: Optional[Action] = None
self._direction: Optional[Direction] = None

def _find(self, position: Vector) -> Optional[Entity]:
def _find_player(self) -> Optional[Entity]:
if self._service.session is None:
return None

for entity in self._model.entities:
if entity.position == position:
if entity.id == self._service.session.entity_id:
return entity

return None
Expand All @@ -87,7 +97,7 @@ def __on_tick(self, *args) -> int:
if self._target is None:
return GLib.SOURCE_CONTINUE

if (player := self._find(self._model.anchor)) is None:
if (player := self._find_player()) is None:
return GLib.SOURCE_CONTINUE

x = (
Expand Down Expand Up @@ -167,7 +177,12 @@ def __on_left_pressed(
self._popover.display(x, y)

def __on_action_perfomed(self, popover: Gtk.Popover, action: Action) -> None:
self._service.message(action, 0)
value = 0

if action == Action.ROTATE and (player := self._find_player()):
value = self.__sequence__[player.direction]

self._service.message(action, value)
self._target = None

def shutdown(self) -> None:
Expand Down
11 changes: 11 additions & 0 deletions src/gameeky/player/widgets/actions_popover.ui
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@
<property name="name">interact</property>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="child">
<object class="GtkLabel">
<property name="label" translatable="yes">Rotate</property>
<property name="xalign">0.0</property>
</object>
</property>
<property name="name">rotate</property>
</object>
</child>
<child>
<object class="GtkListBoxRow">
<property name="child">
Expand Down

0 comments on commit b8f0f83

Please sign in to comment.