From 48feba50415d06baa121f42d7fc2deb3edb25076 Mon Sep 17 00:00:00 2001 From: Nordup Date: Thu, 1 Jun 2023 23:54:30 +0300 Subject: [PATCH] sandbox executable path --- .../resources/sandbox_executable.tres | 10 +++++++ project/the_gates/scenes/world.tscn | 5 ++-- .../scripts/loading/sandbox_executable.gd | 29 +++++++++++++++++++ .../scripts/loading/sandbox_manager.gd | 13 +++++---- 4 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 project/the_gates/resources/sandbox_executable.tres create mode 100644 project/the_gates/scripts/loading/sandbox_executable.gd diff --git a/project/the_gates/resources/sandbox_executable.tres b/project/the_gates/resources/sandbox_executable.tres new file mode 100644 index 0000000..75c9e0f --- /dev/null +++ b/project/the_gates/resources/sandbox_executable.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="SandboxExecutable" load_steps=2 format=3 uid="uid://cmb7xvbue74qa"] + +[ext_resource type="Script" path="res://the_gates/scripts/loading/sandbox_executable.gd" id="1_q0dqh"] + +[resource] +script = ExtResource("1_q0dqh") +linux = "Sandbox.x86_64" +linux_debug = "godot.linuxbsd.editor.dev.sandbox.x86_64.llvm" +windows = "Sandbox.exe" +windows_debug = "godot.linuxbsd.editor.dev.sandbox.x86_64.exe" diff --git a/project/the_gates/scenes/world.tscn b/project/the_gates/scenes/world.tscn index 78e3698..3b8c630 100644 --- a/project/the_gates/scenes/world.tscn +++ b/project/the_gates/scenes/world.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=36 format=3 uid="uid://kywrsqro3d5i"] +[gd_scene load_steps=37 format=3 uid="uid://kywrsqro3d5i"] [ext_resource type="Script" path="res://the_gates/scripts/loading/gate_loader.gd" id="1_coscx"] [ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://the_gates/resources/gate_events.res" id="2_ot8b0"] [ext_resource type="Script" path="res://the_gates/scripts/loading/sandbox_manager.gd" id="3_u7ft0"] [ext_resource type="Shader" path="res://the_gates/shaders/blur.gdshader" id="4_fnp53"] +[ext_resource type="Resource" uid="uid://cmb7xvbue74qa" path="res://the_gates/resources/sandbox_executable.tres" id="4_s0qgl"] [ext_resource type="PackedScene" uid="uid://ctam0fxigbefk" path="res://the_gates/scenes/components/search.tscn" id="4_sg0oy"] [ext_resource type="Texture2D" uid="uid://bpj05amcrq1cq" path="res://the_gates/textures/slide-up.png" id="4_x2j1m"] [ext_resource type="Script" path="res://the_gates/scripts/ui/world/world_ui.gd" id="4_xatjs"] @@ -82,7 +83,7 @@ gate_events = ExtResource("2_ot8b0") script = ExtResource("3_u7ft0") gate_events = ExtResource("2_ot8b0") render_result = NodePath("../WorldCanvas/RenderResult") -sandbox_executable = "godot.linuxbsd.editor.dev.sandbox.x86_64.llvm" +snbx_executable = ExtResource("4_s0qgl") [node name="WorldCanvas" type="Control" parent="."] layout_mode = 3 diff --git a/project/the_gates/scripts/loading/sandbox_executable.gd b/project/the_gates/scripts/loading/sandbox_executable.gd new file mode 100644 index 0000000..cbcf63d --- /dev/null +++ b/project/the_gates/scripts/loading/sandbox_executable.gd @@ -0,0 +1,29 @@ +extends Resource +class_name SandboxExecutable + +@export var linux: String +@export var linux_debug: String + +@export var windows: String +@export var windows_debug: String + +var path: String : + get = get_executable_path + + +func get_executable_path() -> String: + var executable_dir = OS.get_executable_path().get_base_dir() + "/" + return executable_dir + get_filename() + + +func get_filename() -> String: + if OS.is_debug_build(): + if OS.get_name() == "Windows": return windows_debug + else: return linux_debug + else: + if OS.get_name() == "Windows": return windows + else: return linux + + +func exists() -> bool: + return FileAccess.file_exists(path) diff --git a/project/the_gates/scripts/loading/sandbox_manager.gd b/project/the_gates/scripts/loading/sandbox_manager.gd index e2b9e67..b6ee43d 100644 --- a/project/the_gates/scripts/loading/sandbox_manager.gd +++ b/project/the_gates/scripts/loading/sandbox_manager.gd @@ -3,7 +3,7 @@ class_name SandboxManager @export var gate_events: GateEvents @export var render_result: RenderResult -@export var sandbox_executable: String +@export var snbx_executable: SandboxExecutable var sandbox_pid: int @@ -13,19 +13,20 @@ func _ready() -> void: func create_process(gate: Gate) -> void: - var executable_dir = OS.get_executable_path().get_base_dir() + "/" - var sandbox_path = executable_dir + sandbox_executable - var pack_file = ProjectSettings.globalize_path(gate.resource_pack) + if not snbx_executable.exists(): + Debug.logerr("Sandbox executable not found at " + snbx_executable.path); return + var pack_file = ProjectSettings.globalize_path(gate.resource_pack) var args = [ "--main-pack", pack_file, "--resolution", "%dx%d" % [render_result.width, render_result.height], "--fd-path", render_result.fd_path ] - Debug.logclr(sandbox_path + " " + " ".join(args), Color.DARK_VIOLET) - sandbox_pid = OS.create_process(sandbox_path, args) + Debug.logclr(snbx_executable.path + " " + " ".join(args), Color.DARK_VIOLET) + sandbox_pid = OS.create_process(snbx_executable.path, args) if OS.get_name() == "Windows": render_result.fd_path += "|" + str(sandbox_pid) + gate_events.gate_entered_emit()