Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editor: Add menu option to try the edited scene #85

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/gameeky/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ def callback() -> int:


def launch(command: str, arguments: str) -> None:
GLib.spawn_command_line_async(f"{GLib.find_program_in_path(command)} {arguments}")
GLib.spawn_command_line_async(
f"{GLib.find_program_in_path(command)} {arguments.strip()}"
)


def launch_path(path: str) -> None:
Expand All @@ -192,6 +194,27 @@ def launch_path(path: str) -> None:
Gio.AppInfo.launch_default_for_uri(uri, None)


def launch_player(project_path: str, scene_path: str) -> None:
launch(
"dev.tchx84.Gameeky.Player",
f"--project_path={quote(project_path)} {quote(scene_path)}",
)


def launch_scene(project_path: str, scene_path: str) -> None:
launch(
"dev.tchx84.Gameeky.Scene",
f"--project_path={quote(project_path)} {quote(scene_path)}",
)


def launch_entity(project_path: str, entity_path: str) -> None:
launch(
"dev.tchx84.Gameeky.Entity",
f"--project_path={quote(project_path)} {quote(entity_path)}",
)


def quote(string: str) -> str:
if not string:
return string
Expand Down
20 changes: 20 additions & 0 deletions src/gameeky/editor/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
find_project_path,
bytearray_to_string,
launch_path,
launch_player,
)


Expand Down Expand Up @@ -199,6 +200,21 @@ def _do_save(self, path) -> None:
self._scene_path = path
self._pending_changes = False

def __on_try(self, action: Gio.SimpleAction, data: Optional[Any] = None) -> None:
if self._scene_path is None:
self.__on_save_as()
else:
self._do_save(self._scene_path)
self._try_scene()

def _try_scene(self) -> None:
if self._project_path is None:
return
if self._scene_path is None:
return

launch_player(self._project_path, self._scene_path)

def __on_about(self, action: Gio.SimpleAction, data: Optional[Any] = None) -> None:
present_about(self._window)

Expand Down Expand Up @@ -287,6 +303,10 @@ def do_startup(self) -> None:
save_as_action.connect("activate", self.__on_save_as)
self.add_action(save_as_action)

try_action = Gio.SimpleAction.new("try", None)
try_action.connect("activate", self.__on_try)
self.add_action(try_action)

browse_action = Gio.SimpleAction.new("browse", None)
browse_action.connect("activate", self.__on_browse)
self.add_action(browse_action)
Expand Down
20 changes: 4 additions & 16 deletions src/gameeky/editor/widgets/scene_entity_popover.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from .entity_row import EntityRow

from ...common.utils import launch, quote, get_project_path
from ...common.utils import launch_entity, get_project_path


class Operation(StrEnum):
Expand Down Expand Up @@ -55,18 +55,6 @@ def _update_buttons(self, entity: Optional[EntityRow]) -> None:
self.edit.props.sensitive = sensitive
self.delete.props.sensitive = sensitive

def _launch_editor(self, path="") -> None:
command = "dev.tchx84.Gameeky.Entity"
argument = f"--project_path={quote(get_project_path())} {quote(path)}".strip()

launch(command, argument)

def _launch_editor_with_path(self) -> None:
if self._entity is None:
return

self._launch_editor(self._entity.model.path)

def _emit_deleted(self) -> None:
if self._entity is None:
return
Expand All @@ -78,9 +66,9 @@ def __on_activated(self, box: Gtk.ListBox, row: Gtk.ListBoxRow) -> None:
operation = row.props.name

if operation == Operation.ADD:
self._launch_editor()
elif operation == Operation.EDIT:
self._launch_editor_with_path()
launch_entity(get_project_path(), "")
elif operation == Operation.EDIT and self._entity is not None:
launch_entity(get_project_path(), self._entity.model.path)
elif operation == Operation.DELETE:
self._emit_deleted()

Expand Down
4 changes: 4 additions & 0 deletions src/gameeky/editor/widgets/scene_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@
<attribute name="action">app.save_as</attribute>
<attribute name="label" translatable="yes">Save _As…</attribute>
</item>
<item>
<attribute name="action">app.try</attribute>
<attribute name="label" translatable="yes">_Try It</attribute>
</item>
<item>
<attribute name="action">app.edit</attribute>
<attribute name="label" translatable="yes">_Settings</attribute>
Expand Down
12 changes: 3 additions & 9 deletions src/gameeky/launcher/widgets/project_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from gi.repository import Gtk, GLib, GObject

from ...common.utils import launch, quote, valid_file
from ...common.utils import launch_player, launch_scene, valid_file
from ...common.monitor import Monitor
from ...common.scanner import Description
from ...common.definitions import DEFAULT_SCENE
Expand Down Expand Up @@ -59,12 +59,6 @@ def __init__(self, path: str) -> None:
def _get_project_path(self, *path) -> str:
return os.path.join(self.path, *path)

def _launch(self, command: str, filename: str) -> None:
launch(
command,
f"--project_path={quote(self._get_project_path())} {quote(self._get_project_path(filename))}",
)

def _update_button(self) -> None:
self.play.props.sensitive = valid_file(self._get_project_path(DEFAULT_SCENE))

Expand All @@ -73,11 +67,11 @@ def __on_monitor_changed(self, monitor: Monitor) -> None:

@Gtk.Template.Callback("on_play_clicked")
def __on_play_clicked(self, button: Gtk.Button) -> None:
self._launch("dev.tchx84.Gameeky.Player", DEFAULT_SCENE)
launch_player(self.path, self._get_project_path(DEFAULT_SCENE))

@Gtk.Template.Callback("on_edit_clicked")
def __on_edit_clicked(self, button: Gtk.Button) -> None:
self._launch("dev.tchx84.Gameeky.Scene", DEFAULT_SCENE)
launch_scene(self.path, self._get_project_path(DEFAULT_SCENE))

@Gtk.Template.Callback("on_settings_clicked")
def __on_settings_clicked(self, button: Gtk.Button) -> None:
Expand Down