diff --git a/src/gameeky/common/utils.py b/src/gameeky/common/utils.py index 0cd54c0b..807a6055 100644 --- a/src/gameeky/common/utils.py +++ b/src/gameeky/common/utils.py @@ -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: @@ -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 diff --git a/src/gameeky/editor/scene.py b/src/gameeky/editor/scene.py index fbd1486f..091e861b 100644 --- a/src/gameeky/editor/scene.py +++ b/src/gameeky/editor/scene.py @@ -49,6 +49,7 @@ find_project_path, bytearray_to_string, launch_path, + launch_player, ) @@ -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) @@ -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) diff --git a/src/gameeky/editor/widgets/scene_entity_popover.py b/src/gameeky/editor/widgets/scene_entity_popover.py index 03e400e9..a977fedb 100644 --- a/src/gameeky/editor/widgets/scene_entity_popover.py +++ b/src/gameeky/editor/widgets/scene_entity_popover.py @@ -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): @@ -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 @@ -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() diff --git a/src/gameeky/editor/widgets/scene_window.ui b/src/gameeky/editor/widgets/scene_window.ui index 5c1f36a9..d0564c8d 100644 --- a/src/gameeky/editor/widgets/scene_window.ui +++ b/src/gameeky/editor/widgets/scene_window.ui @@ -304,6 +304,10 @@ app.save_as Save _As… + + app.try + _Try It + app.edit _Settings diff --git a/src/gameeky/launcher/widgets/project_row.py b/src/gameeky/launcher/widgets/project_row.py index 85366130..e21ca905 100644 --- a/src/gameeky/launcher/widgets/project_row.py +++ b/src/gameeky/launcher/widgets/project_row.py @@ -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 @@ -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)) @@ -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: