diff --git a/addons/pronto/behaviors/CodeBehavior.gd b/addons/pronto/behaviors/CodeBehavior.gd index 5a18a78d..b38106f6 100644 --- a/addons/pronto/behaviors/CodeBehavior.gd +++ b/addons/pronto/behaviors/CodeBehavior.gd @@ -29,6 +29,7 @@ func lines(): ## Executes the code provided in [member CodeBehavior.evaluate] and emits the [signal CodeBehavior.after] signal afterwards. func execute(args: Array = []): + print("executing ", self) assert(args.size() == arguments.size(), "Argument names and values for eval need to have the same size.") var result = await evaluate.run(args, self) after.emit(result) diff --git a/addons/pronto/behaviors/ValueBehavior.gd b/addons/pronto/behaviors/ValueBehavior.gd index 0ab54176..61a594ec 100644 --- a/addons/pronto/behaviors/ValueBehavior.gd +++ b/addons/pronto/behaviors/ValueBehavior.gd @@ -44,6 +44,7 @@ var float_step_size:float = 1: var float_value:float = 0: set(val): + print("Setting", val) if(!value_init): float_default = snapped(val, float_step_size) value_init = true @@ -158,7 +159,11 @@ func _get_property_list(): func _ready(): super._ready() renamed.connect(queue_redraw) - G.put(name, float_value) + var loaded_value = G.at(name) + if (loaded_value): + float_value = loaded_value + else: + G.put(name, float_value) value_changed.emit(G.at(name)) func _forward_canvas_draw_over_viewport(viewport_control: Control): diff --git a/addons/pronto/helpers/G.gd b/addons/pronto/helpers/G.gd index c8e68881..efc5fbf4 100644 --- a/addons/pronto/helpers/G.gd +++ b/addons/pronto/helpers/G.gd @@ -7,6 +7,7 @@ extends Node var values = {} var _store_update = {} +var current_root = null func put(name: String, value: Variant): _put(name, value) @@ -45,14 +46,19 @@ func _register_store(store: StoreBehavior, prop: String): func _ready(): if not Engine.is_editor_hint(): maybe_add_value_user_interface() + get_tree().tree_changed.connect(maybe_add_value_user_interface) + func maybe_add_value_user_interface(): + if (current_root and current_root.get_ref()): return + current_root = weakref(get_tree().current_scene) if not Utils.all_nodes_that(get_tree().root, func (node): return node is PrototypingUIBehavior).is_empty(): return + await get_tree().process_frame var ui = PrototypingUIBehavior.new() ui.name = 'Config' # Place the PrototypingUI in its own CanvasLayer var canvasLayer = CanvasLayer.new() canvasLayer.add_child(ui) - add_child(canvasLayer) + get_tree().current_scene.add_child(canvasLayer) diff --git a/project.godot b/project.godot index f2454e65..3ad27743 100644 --- a/project.godot +++ b/project.godot @@ -11,6 +11,7 @@ config_version=5 [application] config/name="pronto" +run/main_scene="res://prototypes/game-test-PUI/game-test-PUI.tscn" config/features=PackedStringArray("4.2", "Forward Plus") run/low_processor_mode=true config/icon="res://icon.svg" diff --git a/prototypes/game-test-PUI/game-test-PUI.tscn b/prototypes/game-test-PUI/game-test-PUI.tscn new file mode 100644 index 00000000..7f4134a1 --- /dev/null +++ b/prototypes/game-test-PUI/game-test-PUI.tscn @@ -0,0 +1,54 @@ +[gd_scene load_steps=9 format=3 uid="uid://chj6nkvr0sh3x"] + +[ext_resource type="Script" path="res://addons/pronto/behaviors/ExportBehavior.gd" id="1"] +[ext_resource type="Script" path="res://addons/pronto/behaviors/CodeBehavior.gd" id="2_m18cy"] +[ext_resource type="Script" path="res://addons/pronto/helpers/ConnectionScript.gd" id="3_qub70"] +[ext_resource type="Script" path="res://addons/pronto/behaviors/PlaceholderBehavior.gd" id="4_x8ykv"] +[ext_resource type="Texture2D" uid="uid://bhos8bn4u0qp8" path="res://addons/pronto/icons/MissingTexture.svg" id="5_6wfp8"] +[ext_resource type="Script" path="res://addons/pronto/behaviors/ValueBehavior.gd" id="9_b7gob"] + +[sub_resource type="GDScript" id="GDScript_8ds22"] +script/source = "@tool +extends U +@warning_ignore(\"unused_parameter\") +func run(): + print(\"Before\") + print(get_parent().get_tree().reload_current_scene()) + print(\"Restarting Game\") +" + +[sub_resource type="Resource" id="Resource_5iqmk"] +script = ExtResource("3_qub70") +nested_script = SubResource("GDScript_8ds22") +argument_names = [] +return_value = true + +[node name="Node2D" type="Node2D"] + +[node name="ExportBehavior" type="Node2D" parent="."] +position = Vector2(576, 324) +script = ExtResource("1") +title = "Test" +authors = PackedStringArray("Julian") +description = "Testing Prototyping UI and persistency between restarts." + +[node name="Reload Game" type="Node2D" parent="ExportBehavior"] +position = Vector2(-28.2843, 28.2843) +script = ExtResource("2_m18cy") +evaluate = SubResource("Resource_5iqmk") + +[node name="RigidBody2D" type="RigidBody2D" parent="."] +position = Vector2(129, 25) + +[node name="PlaceholderBehavior" type="Node2D" parent="RigidBody2D"] +script = ExtResource("4_x8ykv") +sprite_texture = ExtResource("5_6wfp8") +placeholder_size = Vector2(20, 20) + +[node name="ValueBehavior" type="Node2D" parent="RigidBody2D/PlaceholderBehavior"] +position = Vector2(447, 299) +script = ExtResource("9_b7gob") +float_min = 0.0 +float_max = 100.0 +float_value = 88.0 +float_step_size = 1.0 diff --git a/prototypes/game-test-PUI/game_info.json b/prototypes/game-test-PUI/game_info.json new file mode 100644 index 00000000..28608880 --- /dev/null +++ b/prototypes/game-test-PUI/game_info.json @@ -0,0 +1,7 @@ +{ + "authors": [ + "" + ], + "time": "2023-11-08", + "title": "Test" +} \ No newline at end of file diff --git a/prototypes/game-test-PUI/thumbnail.png b/prototypes/game-test-PUI/thumbnail.png new file mode 100644 index 00000000..c6d57256 Binary files /dev/null and b/prototypes/game-test-PUI/thumbnail.png differ diff --git a/prototypes/game-test-PUI/thumbnail.png.import b/prototypes/game-test-PUI/thumbnail.png.import new file mode 100644 index 00000000..77b75579 --- /dev/null +++ b/prototypes/game-test-PUI/thumbnail.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://enk0drpv1764" +path="res://.godot/imported/thumbnail.png-7b00f17db0f0351e6b68de14ac130b90.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://prototypes/game-test-PUI/thumbnail.png" +dest_files=["res://.godot/imported/thumbnail.png-7b00f17db0f0351e6b68de14ac130b90.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1