From 55fed63caf39b53fc9a6332acbd3bd8f39df1bed Mon Sep 17 00:00:00 2001 From: Jovan Gerodetti Date: Fri, 5 Jan 2024 23:28:33 +0100 Subject: [PATCH] upgrade godot-rust-script (builtin hotreload) --- native/Cargo.lock | 74 ++++++++++++------- native/Cargo.toml | 17 +---- native/scripts/Cargo.toml | 12 --- native/src/lib.rs | 19 ++--- .../src/lib.rs => src/scripts/mod.rs} | 0 .../scripts}/particles/dust_particles.rs | 0 .../src => src/scripts}/particles/mod.rs | 0 .../scripts}/scene_object_registry.rs | 0 .../scripts}/spawner/car_spawner.rs | 7 +- .../src => src/scripts}/spawner/mod.rs | 0 native/src/terrain_builder.rs | 19 ++++- resources/Objects/Helis/Helicopter.tscn | 16 ++-- resources/Objects/Spawner/CarSpawner.tscn | 2 +- resources/TestScenes/test_track.tscn | 25 +++---- src/Objects/Particles/DustParticles.gd | 29 -------- src/Objects/Spawner/CarSpawner.gd | 35 --------- 16 files changed, 95 insertions(+), 160 deletions(-) delete mode 100644 native/scripts/Cargo.toml rename native/{scripts/src/lib.rs => src/scripts/mod.rs} (100%) rename native/{scripts/src => src/scripts}/particles/dust_particles.rs (100%) rename native/{scripts/src => src/scripts}/particles/mod.rs (100%) rename native/{scripts/src => src/scripts}/scene_object_registry.rs (100%) rename native/{scripts/src => src/scripts}/spawner/car_spawner.rs (90%) rename native/{scripts/src => src/scripts}/spawner/mod.rs (100%) delete mode 100644 src/Objects/Particles/DustParticles.gd delete mode 100644 src/Objects/Spawner/CarSpawner.gd diff --git a/native/Cargo.lock b/native/Cargo.lock index 1f074a9..d097304 100644 --- a/native/Cargo.lock +++ b/native/Cargo.lock @@ -114,6 +114,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "const-str" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aca749d3d3f5b87a0d6100509879f9cf486ab510803a4a4e1001da1ff61c2bd6" + [[package]] name = "const_panic" version = "0.2.8" @@ -242,6 +248,18 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "gensym" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "913dce4c5f06c2ea40fc178c06f777ac89fc6b1383e90c254fafb1abe4ba3c82" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", + "uuid", +] + [[package]] name = "getrandom" version = "0.2.10" @@ -268,7 +286,7 @@ checksum = "8e4afd9ad95555081e109fe1d21f2a30c691b5f0919c67dfa690a2e1eb6bd51c" [[package]] name = "godot" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=a5d17342b7b47e8af652a6a733f497c468bbd59a#a5d17342b7b47e8af652a6a733f497c468bbd59a" +source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" dependencies = [ "godot-core", "godot-macros", @@ -277,7 +295,7 @@ dependencies = [ [[package]] name = "godot-bindings" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=a5d17342b7b47e8af652a6a733f497c468bbd59a#a5d17342b7b47e8af652a6a733f497c468bbd59a" +source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" dependencies = [ "godot4-prebuilt", ] @@ -285,7 +303,7 @@ dependencies = [ [[package]] name = "godot-codegen" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=a5d17342b7b47e8af652a6a733f497c468bbd59a#a5d17342b7b47e8af652a6a733f497c468bbd59a" +source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" dependencies = [ "godot-bindings", "godot-fmt", @@ -299,7 +317,7 @@ dependencies = [ [[package]] name = "godot-core" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=a5d17342b7b47e8af652a6a733f497c468bbd59a#a5d17342b7b47e8af652a6a733f497c468bbd59a" +source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" dependencies = [ "glam", "godot-bindings", @@ -310,8 +328,9 @@ dependencies = [ [[package]] name = "godot-ffi" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=a5d17342b7b47e8af652a6a733f497c468bbd59a#a5d17342b7b47e8af652a6a733f497c468bbd59a" +source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" dependencies = [ + "gensym", "godot-bindings", "godot-codegen", "paste", @@ -320,7 +339,7 @@ dependencies = [ [[package]] name = "godot-fmt" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=a5d17342b7b47e8af652a6a733f497c468bbd59a#a5d17342b7b47e8af652a6a733f497c468bbd59a" +source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" dependencies = [ "proc-macro2", ] @@ -328,7 +347,7 @@ dependencies = [ [[package]] name = "godot-macros" version = "0.1.0" -source = "git+https://github.com/titannano/gdext?rev=a5d17342b7b47e8af652a6a733f497c468bbd59a#a5d17342b7b47e8af652a6a733f497c468bbd59a" +source = "git+https://github.com/titannano/gdext?rev=4ce4714#4ce4714b8871bf75e95d03401e44e3f1ccbdd7df" dependencies = [ "godot-bindings", "proc-macro2", @@ -339,20 +358,19 @@ dependencies = [ [[package]] name = "godot-rust-script" version = "0.1.0" -source = "git+https://github.com/titannano/godot-rust-script?rev=928159e6f6a73a249d5504ca6c136809b5ed07c0#928159e6f6a73a249d5504ca6c136809b5ed07c0" dependencies = [ "abi_stable", - "cfg-if", + "const-str", "godot", "godot-rust-script-derive", "itertools", + "once_cell", "rand", ] [[package]] name = "godot-rust-script-derive" version = "0.1.0" -source = "git+https://github.com/titannano/godot-rust-script?rev=928159e6f6a73a249d5504ca6c136809b5ed07c0#928159e6f6a73a249d5504ca6c136809b5ed07c0" dependencies = [ "darling", "proc-macro2", @@ -363,7 +381,7 @@ dependencies = [ [[package]] name = "godot4-prebuilt" version = "0.0.0" -source = "git+https://github.com/godot-rust/godot4-prebuilt?branch=4.1.1#fca6897dbfb1a2d9387f81491acd77f6f091b8c4" +source = "git+https://github.com/godot-rust/godot4-prebuilt?branch=4.2#9e60296be502e294dde3f245971f2868ce553677" [[package]] name = "hashbrown" @@ -479,18 +497,18 @@ dependencies = [ [[package]] name = "nanoserde" -version = "0.1.32" +version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "755e7965536bc54d7c9fba2df5ada5bf835b0443fd613f0a53fa199a301839d3" +checksum = "4a983d0b19ed0fcd803c4f04f9b20d5e6dd17e06d44d98742a0985ac45dab1bc" dependencies = [ "nanoserde-derive", ] [[package]] name = "nanoserde-derive" -version = "0.1.19" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed7a94da6c6181c35d043fc61c43ac96d3a5d739e7b8027f77650ba41504d6ab" +checksum = "d4dc96541767a4279572fdcf9f95af9cc1c9b2a2254e7a079203c81e206a9059" [[package]] name = "native" @@ -502,8 +520,8 @@ dependencies = [ "itertools", "lerp", "num", + "num_enum", "rayon", - "scripts", ] [[package]] @@ -622,6 +640,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + [[package]] name = "parking_lot" version = "0.12.1" @@ -792,15 +816,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "scripts" -version = "0.1.0" -dependencies = [ - "backtrace", - "godot-rust-script", - "num_enum", -] - [[package]] name = "semver" version = "1.0.20" @@ -905,6 +920,15 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "uuid" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +dependencies = [ + "getrandom", +] + [[package]] name = "venial" version = "0.5.0" diff --git a/native/Cargo.toml b/native/Cargo.toml index eb3a545..a57feb7 100644 --- a/native/Cargo.toml +++ b/native/Cargo.toml @@ -1,13 +1,3 @@ -[workspace] -resolver = "2" - -members = [ - "scripts", -] - -[workspace.dependencies] -godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "928159e6f6a73a249d5504ca6c136809b5ed07c0", default-features = false } - [package] name = "native" version = "0.4.0" @@ -17,11 +7,12 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -godot = { git = "https://github.com/titannano/gdext", rev = "a5d17342b7b47e8af652a6a733f497c468bbd59a" } +godot = { git = "https://github.com/titannano/gdext", rev = "4ce4714" } lerp = "0.4.0" backtrace = "0.3.64" num = "0.4.0" rayon = "1.5.1" itertools = "0.10.3" -godot-rust-script = { workspace = true, features = ["runtime"] } -scripts = { path = "./scripts" } +num_enum = "0.7.1" + +godot-rust-script = { git = "https://github.com/titannano/godot-rust-script", rev = "a2a5c018fcf0247f1d242ec2bf8a994cc975c1ee" } diff --git a/native/scripts/Cargo.toml b/native/scripts/Cargo.toml deleted file mode 100644 index 22abe60..0000000 --- a/native/scripts/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "scripts" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type = ["dylib", "rlib"] - -[dependencies] -godot-rust-script = { workspace = true, features = ["scripts"] } -backtrace = "0.3.64" -num_enum = "0.7.1" diff --git a/native/src/lib.rs b/native/src/lib.rs index fd0be0f..defe34c 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -1,27 +1,18 @@ +mod scripts; mod terrain_builder; -use std::cell::RefCell; - use godot::prelude::{gdextension, ExtensionLibrary, InitLevel}; -use godot_rust_script::{self, RustScriptExtensionLayer}; - -godot_rust_script::setup!(scripts); +use godot_rust_script; struct NativeLib; -thread_local! { - static RUST_SCRIPT_LAYER: RefCell = RefCell::new(godot_rust_script::init!()); -} - #[gdextension] unsafe impl ExtensionLibrary for NativeLib { fn on_level_init(level: InitLevel) { match level { InitLevel::Core => (), InitLevel::Servers => (), - InitLevel::Scene => { - RUST_SCRIPT_LAYER.with_borrow_mut(|layer| layer.initialize()); - } + InitLevel::Scene => godot_rust_script::init!(scripts), InitLevel::Editor => (), } } @@ -29,8 +20,8 @@ unsafe impl ExtensionLibrary for NativeLib { fn on_level_deinit(level: InitLevel) { match level { InitLevel::Editor => (), - InitLevel::Scene => RUST_SCRIPT_LAYER.with_borrow_mut(|layer| layer.deinitialize()), - InitLevel::Servers => {} + InitLevel::Scene => godot_rust_script::deinit!(), + InitLevel::Servers => (), InitLevel::Core => (), } } diff --git a/native/scripts/src/lib.rs b/native/src/scripts/mod.rs similarity index 100% rename from native/scripts/src/lib.rs rename to native/src/scripts/mod.rs diff --git a/native/scripts/src/particles/dust_particles.rs b/native/src/scripts/particles/dust_particles.rs similarity index 100% rename from native/scripts/src/particles/dust_particles.rs rename to native/src/scripts/particles/dust_particles.rs diff --git a/native/scripts/src/particles/mod.rs b/native/src/scripts/particles/mod.rs similarity index 100% rename from native/scripts/src/particles/mod.rs rename to native/src/scripts/particles/mod.rs diff --git a/native/scripts/src/scene_object_registry.rs b/native/src/scripts/scene_object_registry.rs similarity index 100% rename from native/scripts/src/scene_object_registry.rs rename to native/src/scripts/scene_object_registry.rs diff --git a/native/scripts/src/spawner/car_spawner.rs b/native/src/scripts/spawner/car_spawner.rs similarity index 90% rename from native/scripts/src/spawner/car_spawner.rs rename to native/src/scripts/spawner/car_spawner.rs index be219b2..5a357ef 100644 --- a/native/scripts/src/spawner/car_spawner.rs +++ b/native/src/scripts/spawner/car_spawner.rs @@ -12,7 +12,6 @@ use godot_rust_script::{ #[script(base = Node3D)] struct CarSpawner { default_car: Option>, - car: Option>, #[export] pub road_network_path: NodePath, @@ -31,10 +30,6 @@ impl CarSpawner { "res://resources/Objects/Vehicles/car_station_wagon.tscn", )) .map(|res| res.cast()); - - self.car = loader - .load(GString::from("res://src/Objects/Vehicles/Car.gd")) - .map(|res| res.cast()); } pub fn spawn_car(&mut self) { @@ -88,7 +83,7 @@ impl CarSpawner { timer.connect( StringName::from("timeout"), - Callable::from_object_method(self.base.clone(), "start_auto_spawn"), + Callable::from_object_method(&self.base, "start_auto_spawn"), ); self.timer.as_mut().unwrap() diff --git a/native/scripts/src/spawner/mod.rs b/native/src/scripts/spawner/mod.rs similarity index 100% rename from native/scripts/src/spawner/mod.rs rename to native/src/scripts/spawner/mod.rs diff --git a/native/src/terrain_builder.rs b/native/src/terrain_builder.rs index 325846e..4bd66cd 100644 --- a/native/src/terrain_builder.rs +++ b/native/src/terrain_builder.rs @@ -173,7 +173,7 @@ struct ThreadContext<'a> { } #[derive(GodotClass)] -#[class(base=RefCounted)] +#[class(base=RefCounted, init)] pub struct TerrainBuilder { tile_size: u8, city_size: u16, @@ -186,6 +186,23 @@ pub struct TerrainBuilder { #[godot_api] impl TerrainBuilder { + #[func] + fn new( + tilelist: Dictionary, + rotation: Gd, + materials: Dictionary, + ) -> Gd { + Gd::from_object(TerrainBuilder { + tile_size: 16, + city_size: 0, + tile_height: 8, + sea_level: 0, + rotation, + tilelist, + materials, + }) + } + #[func] fn set_city_size(&mut self, value: u16) { self.city_size = value; diff --git a/resources/Objects/Helis/Helicopter.tscn b/resources/Objects/Helis/Helicopter.tscn index aa74f3a..b736893 100644 --- a/resources/Objects/Helis/Helicopter.tscn +++ b/resources/Objects/Helis/Helicopter.tscn @@ -1,17 +1,17 @@ [gd_scene load_steps=8 format=3 uid="uid://dl34exjsm3sq4"] -[ext_resource type="Material" uid="uid://cjoloelf8ku4k" path="res://resources/Materials/dust_material.tres" id="1"] +[ext_resource type="Material" uid="uid://cjoloelf8ku4k" path="res://resources/Materials/dust_material.tres" id="2_8yiqd"] +[ext_resource type="Script" path="res://native/src/scripts/particles/dust_particles.rs" id="2_ocmjg"] [ext_resource type="Script" path="res://src/Objects/Helicopters/Helicopter.gd" id="3"] [ext_resource type="AnimationNodeStateMachine" uid="uid://xbcrg5mghpup" path="res://resources/Animations/HelicopterRotorSoundStates.tres" id="4_8iee2"] [ext_resource type="AnimationLibrary" uid="uid://uec74t4jqdxi" path="res://resources/Animations/Helicopter.tres" id="5_ayahk"] -[ext_resource type="Script" path="res://src/Objects/Particles/DustParticles.gd" id="12"] [sub_resource type="PhysicsMaterial" id="20"] friction = 0.5 bounce = 0.7 -[sub_resource type="QuadMesh" id="9"] -material = ExtResource("1") +[sub_resource type="QuadMesh" id="QuadMesh_e0n42"] +material = ExtResource("2_8yiqd") [node name="Helicopter" type="RigidBody3D" node_paths=PackedStringArray("child_engine_sound_tree", "child_dust_particles")] mass = 929.8 @@ -35,14 +35,12 @@ amount = 100 lifetime = 0.4 visibility_aabb = AABB(-8.76025, -1.34854, -8.13392, 17.451, 2.29104, 17.5903) draw_order = 2 -draw_pass_1 = SubResource("9") -script = ExtResource("12") +draw_pass_1 = SubResource("QuadMesh_e0n42") +script = ExtResource("2_ocmjg") +strength = null [node name="RotorAudioTree" type="AnimationTree" parent="."] root_node = NodePath(".") -libraries = { -"": ExtResource("5_ayahk") -} tree_root = ExtResource("4_8iee2") advance_expression_base_node = NodePath("") anim_player = NodePath("../RotorAudioPlayer") diff --git a/resources/Objects/Spawner/CarSpawner.tscn b/resources/Objects/Spawner/CarSpawner.tscn index 341cc63..54be663 100644 --- a/resources/Objects/Spawner/CarSpawner.tscn +++ b/resources/Objects/Spawner/CarSpawner.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://blyermwgncstx"] -[ext_resource type="Script" path="res://native/scripts/src/spawner/car_spawner.rs" id="1_c5pws"] +[ext_resource type="Script" path="res://native/src/scripts/spawner/car_spawner.rs" id="1_c5pws"] [sub_resource type="StandardMaterial3D" id="1"] albedo_color = Color(1, 0, 0, 1) diff --git a/resources/TestScenes/test_track.tscn b/resources/TestScenes/test_track.tscn index 9fcb0ec..704a8cc 100644 --- a/resources/TestScenes/test_track.tscn +++ b/resources/TestScenes/test_track.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=13 format=3 uid="uid://uvhjdh84glq8"] -[ext_resource type="PackedScene" uid="uid://rup3fivpcq5r" path="res://resources/Objects/Spawner/CarSpawner.tscn" id="1"] +[ext_resource type="PackedScene" uid="uid://blyermwgncstx" path="res://resources/Objects/Spawner/CarSpawner.tscn" id="1"] [ext_resource type="PackedScene" uid="uid://c6cmp45buruhr" path="res://resources/Objects/Networks/Road/left_right.tscn" id="2"] [ext_resource type="PackedScene" uid="uid://k8hd8bpyy0c3" path="res://resources/Objects/Networks/Road/bottom_right.tscn" id="3"] [ext_resource type="PackedScene" uid="uid://ctiydbpunmky5" path="res://resources/Objects/Networks/Road/top_bottom.tscn" id="4"] @@ -17,6 +17,7 @@ resource_name = "Scene" script/source = "extends Node3D const Building := preload(\"res://src/Objects/Map/Building.gd\") +const RoadNavigation := preload(\"res://src/Objects/Networks/RoadNavigation.gd\") func _ready() -> void: var building_ids = { @@ -37,9 +38,10 @@ func _ready() -> void: } var idx = 0 - var road_naviagtion := $Road + var road_naviagtion := $Road as RoadNavigation - for child in road_naviagtion.get_children(): + for item in road_naviagtion.get_children(): + var child := item as Node3D var node: Building match idx: @@ -77,7 +79,7 @@ func _ready() -> void: idx += 1 road_naviagtion.update_debug() - $CarSpawner.spawn_car() + ($CarSpawner as CarSpawner).spawn_car() " [node name="Node3D" type="Node3D"] @@ -131,26 +133,19 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 80, 0, 32) [node name="CSGBox3D" type="CSGBox3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 41.7865, -1, 6) -width = 128.791 -depth = 78.4864 +size = Vector3(128.791, 1, 78.4864) [node name="CSGBox2" type="CSGBox3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 48.0043, 3, 0) -width = 16.0 -height = 10.0 -depth = 25.0 +size = Vector3(16, 10, 25) [node name="CSGBox3" type="CSGBox3D" parent="."] transform = Transform3D(0.894934, -0.446198, 0, 0.446198, 0.894934, 0, 0, 0, 1, 34.2, -0.5, 0) -width = 18.0 -height = 10.0 -depth = 25.0 +size = Vector3(18, 10, 25) [node name="CSGBox4" type="CSGBox3D" parent="."] transform = Transform3D(0.894934, 0.446198, 0, -0.446198, 0.894934, 0, 0, 0, 1, 61.8294, -0.5, 0) -width = 18.0 -height = 10.0 -depth = 25.0 +size = Vector3(18, 10, 25) [node name="Camera3D" type="Camera3D" parent="."] transform = Transform3D(0.993568, -0.0886679, 0.0704306, 0, 0.621979, 0.783034, -0.113236, -0.777998, 0.617978, 46.1015, 40.9621, 52.5325) diff --git a/src/Objects/Particles/DustParticles.gd b/src/Objects/Particles/DustParticles.gd deleted file mode 100644 index 21eba55..0000000 --- a/src/Objects/Particles/DustParticles.gd +++ /dev/null @@ -1,29 +0,0 @@ -extends GPUParticles3D - -@export_range(0, 1) var strength: float : get = _get_strength, set = _set_strength - -func _ready() -> void: - self._set_strength(0) - -func _get_strength() -> float: - if not self.process_material is ParticleProcessMaterial: - return 0.0 - - var material: ParticleProcessMaterial = self.process_material - - return material.initial_velocity_min / 15.0 - -func _set_strength(value: float): - @warning_ignore("shadowed_variable_base_class") - var is_emitting := value > 0 - - if self.emitting != is_emitting: - self.emitting = is_emitting - - if not self.emitting: - return - - var mesh: PrimitiveMesh = self.draw_pass_1 - var material: StandardMaterial3D = mesh.material - - material.proximity_fade_distance = max(100 * (1 - value), 2) diff --git a/src/Objects/Spawner/CarSpawner.gd b/src/Objects/Spawner/CarSpawner.gd deleted file mode 100644 index efe6376..0000000 --- a/src/Objects/Spawner/CarSpawner.gd +++ /dev/null @@ -1,35 +0,0 @@ -extends Node3D - -const DefaultCar = preload("res://resources/Objects/Vehicles/car_station_wagon.tscn") -const Car := preload("res://src/Objects/Vehicles/Car.gd") - -@export var road_network_path: NodePath - -var timer: Timer - -func spawn_car() -> void: - var inst: Car = DefaultCar.instantiate() - - inst.road_network_path = self.road_network_path - - self.get_parent().add_child(inst) - inst.owner = get_tree().current_scene - inst.global_translate(self.global_transform.origin) - inst.activate() - - -func start_auto_spawn(): - if not self.timer: - self.timer = Timer.new() - self.add_child(self.timer, true) - self.timer.timeout.connect(self.spawn_car) - - self.spawn_car() - self.timer.start(2.0) - - -func stop_auto_spawn(): - if not self.timer: - return - - self.timer.stop()