diff --git a/loading/serialization_custom_resources/.gitattributes b/loading/serialization_custom_resources/.gitattributes new file mode 100644 index 0000000000..8ad74f78d9 --- /dev/null +++ b/loading/serialization_custom_resources/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/loading/serialization_custom_resources/.gitignore b/loading/serialization_custom_resources/.gitignore new file mode 100644 index 0000000000..4709183670 --- /dev/null +++ b/loading/serialization_custom_resources/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/loading/serialization_custom_resources/game/character.gd b/loading/serialization_custom_resources/game/character.gd new file mode 100644 index 0000000000..495943b156 --- /dev/null +++ b/loading/serialization_custom_resources/game/character.gd @@ -0,0 +1,107 @@ +extends CharacterBody2D +class_name Character + +const CHARACTER_GROUP := &"characters" + +signal tagged(target : Character) + +var move_direction : Vector2 = Vector2.ZERO +var path_to_whose_it : NodePath = ^"" +var stunned : bool = false + +@export var character_name := "" +@export var player_controlled := false +@export var base_speed : float = 100 # pixels per second +@export var it_speed_multiplier : float = 2.0 +@export var stun_duration : float = 2.0 # seconds + +@onready var timer := $StunTimer as Timer +@onready var label := $Label as Label + + +func _ready() -> void: + label.text = character_name + + +func _physics_process(_delta: float) -> void: + if player_controlled: + move_direction = Input.get_vector("left", "right", "up", "down") + elif is_it(): + move_direction = position.direction_to(get_nearest_character().position) + else: + var whose_it := get_node(path_to_whose_it) as Character + move_direction = -1 * position.direction_to(whose_it.position) # move away from whose it + velocity = move_direction * get_speed() + var collided : bool = move_and_slide() + if not collided: + return + var collision : KinematicCollision2D = get_last_slide_collision() + var collieder = collision.get_collider() + if collieder is Character: + if is_it() and not stunned: + tagged.emit(collieder) + + +func is_it() -> bool: + return path_to_whose_it == get_path() + + +func stun(duration : float) -> void: + stunned = true + timer.wait_time = duration + timer.start() + + +func get_speed() -> float: + if stunned: + return 0.0 + else: + return base_speed * it_speed_multiplier if is_it() else base_speed + + +func get_nearest_character() -> Character: + var nearest_character : Character = self + var nearest_dist_squared := INF + var dist_squared := 0.0 + + var characters = get_tree().get_nodes_in_group(CHARACTER_GROUP) + for character in characters as Array[Character]: + dist_squared = position.distance_squared_to(character.position) + if dist_squared > 0.0001 and dist_squared < nearest_dist_squared: + nearest_dist_squared = dist_squared + nearest_character = character + return nearest_character + + +func serialize() -> CharacterResource: + var character_resource := CharacterResource.new() + character_resource.character_name = character_name + character_resource.position = position + character_resource.move_direction = move_direction + character_resource.base_speed = base_speed + character_resource.it_speed_multiplier = it_speed_multiplier + character_resource.path_to_whose_it = path_to_whose_it + character_resource.player_controlled = player_controlled + character_resource.stunned = stunned + character_resource.stun_duration = stun_duration + character_resource.stun_time_left = timer.time_left + return character_resource + + +func deserialize(character_resource : CharacterResource) -> void: + if character_resource.stun_time_left > 0: + timer.start(character_resource.stun_time_left) + stun_duration = character_resource.stun_duration + stunned = character_resource.stunned + player_controlled = character_resource.player_controlled + path_to_whose_it = character_resource.path_to_whose_it + it_speed_multiplier = character_resource.it_speed_multiplier + base_speed = character_resource.base_speed + move_direction = character_resource.move_direction + position = character_resource.position + character_name = character_resource.character_name + label.text = character_name + + +func _on_stun_timer_timeout() -> void: + stunned = false diff --git a/loading/serialization_custom_resources/game/character.tscn b/loading/serialization_custom_resources/game/character.tscn new file mode 100644 index 0000000000..6c0ac88326 --- /dev/null +++ b/loading/serialization_custom_resources/game/character.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=4 format=3 uid="uid://djbgtqgci6is1"] + +[ext_resource type="Texture2D" uid="uid://dkk04ow5f8clu" path="res://icon.svg" id="1_alri3"] +[ext_resource type="Script" path="res://game/character.gd" id="1_dtr8n"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_tjudb"] +size = Vector2(128, 128) + +[node name="Character" type="CharacterBody2D"] +collision_mask = 3 +motion_mode = 1 +script = ExtResource("1_dtr8n") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("1_alri3") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2(-0.5, 0.5) +shape = SubResource("RectangleShape2D_tjudb") + +[node name="StunTimer" type="Timer" parent="."] +one_shot = true + +[node name="Label" type="Label" parent="."] +offset_left = -64.0 +offset_top = 70.0 +offset_right = 64.0 +offset_bottom = 94.0 +horizontal_alignment = 1 + +[connection signal="timeout" from="StunTimer" to="." method="_on_stun_timer_timeout"] diff --git a/loading/serialization_custom_resources/game/prompt.gd b/loading/serialization_custom_resources/game/prompt.gd new file mode 100644 index 0000000000..4463ff6bba --- /dev/null +++ b/loading/serialization_custom_resources/game/prompt.gd @@ -0,0 +1,10 @@ +extends Label +class_name Prompt + + +func show_whose_it(it_name : String) -> void: + match it_name: + "you": + text = "Tag, you are it!" + _: + text = "Tag, {0} is it!".format([it_name]) diff --git a/loading/serialization_custom_resources/icon.svg b/loading/serialization_custom_resources/icon.svg new file mode 100644 index 0000000000..adc26df6c2 --- /dev/null +++ b/loading/serialization_custom_resources/icon.svg @@ -0,0 +1 @@ + diff --git a/loading/serialization_custom_resources/icon.svg.import b/loading/serialization_custom_resources/icon.svg.import new file mode 100644 index 0000000000..ef53dc7f66 --- /dev/null +++ b/loading/serialization_custom_resources/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dkk04ow5f8clu" +path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://icon.svg" +dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.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 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/loading/serialization_custom_resources/main.gd b/loading/serialization_custom_resources/main.gd new file mode 100644 index 0000000000..c3bbfec0a5 --- /dev/null +++ b/loading/serialization_custom_resources/main.gd @@ -0,0 +1,100 @@ +extends Node +class_name Referee + +var path_to_whose_it : NodePath + +@export_file("*.tres; resource", "*.json; json") var save_file : String = "" #haven't done json yet +@export_node_path("Character") var path_to_who_starts_as_it := ^"GameLayer/Player" + +@onready var player := %Player as Character +@onready var other_alice := %OtherAlice as Character +@onready var other_bob := %OtherBob as Character + +@onready var prompt := %Prompt as Prompt +@onready var file_dialogue := %FileDialogue as FileDialog + + +func _ready() -> void: + var whose_it := get_node(path_to_who_starts_as_it) as Character + update_whose_it(whose_it) + + if save_file != "": + open(save_file) + + +func _unhandled_input(event: InputEvent) -> void: + if event.is_action_pressed("save"): + file_dialogue.file_mode = FileDialog.FILE_MODE_SAVE_FILE + file_dialogue.visible = true + elif event.is_action_pressed("open"): + file_dialogue.file_mode = FileDialog.FILE_MODE_OPEN_FILE + file_dialogue.visible = true + + +func update_whose_it(whose_it : Character) -> void: + prompt.show_whose_it(whose_it.character_name) + path_to_whose_it = whose_it.get_path() + var characters = get_tree().get_nodes_in_group(Character.CHARACTER_GROUP) + for character in characters as Array[Character]: + character.path_to_whose_it = path_to_whose_it + + +func tag_character(character_tagged : Character) -> void: + character_tagged.stun(character_tagged.stun_duration) + update_whose_it(character_tagged) + + +func serialize() -> RefereeResource: + var referee_resource := RefereeResource.new() + referee_resource.path_to_whose_it = path_to_whose_it + referee_resource.path_to_who_starts_as_it = path_to_who_starts_as_it + referee_resource.player_resource = player.serialize() + referee_resource.other_alice_resource = other_alice.serialize() + referee_resource.other_bob_resource = other_bob.serialize() + referee_resource.prompt_text = prompt.text + return referee_resource + + +func deserialize(referee_resource : RefereeResource) -> void: + prompt.text = referee_resource.prompt_text + other_bob.deserialize(referee_resource.other_bob_resource) + other_alice.deserialize(referee_resource.other_alice_resource) + player.deserialize(referee_resource.player_resource) + path_to_who_starts_as_it = referee_resource.path_to_who_starts_as_it + path_to_whose_it = referee_resource.path_to_whose_it + update_whose_it(get_node(path_to_whose_it)) + + +func save(file_name : String) -> void: + var referee_resource : RefereeResource = serialize() + ResourceSaver.save(referee_resource, file_name) + + +func open(file_name : String) -> void: + var referee_resource := load(file_name) as RefereeResource + deserialize(referee_resource) + + +func _on_player_tagged(target : Character) -> void: + tag_character(target) + + +func _on_other_alice_tagged(target : Character) -> void: + tag_character(target) + + +func _on_other_bob_tagged(target : Character) -> void: + tag_character(target) + + +func _on_file_dialogue_file_selected(path: String) -> void: + match file_dialogue.file_mode: + FileDialog.FILE_MODE_SAVE_FILE: + save(path) + FileDialog.FILE_MODE_OPEN_FILE: + open(path) + + +func _on_file_dialogue_visibility_changed() -> void: + var pause : bool = file_dialogue.visible + $GameLayer.process_mode = Node.PROCESS_MODE_DISABLED if pause else Node.PROCESS_MODE_INHERIT diff --git a/loading/serialization_custom_resources/main.tscn b/loading/serialization_custom_resources/main.tscn new file mode 100644 index 0000000000..a34fd19de4 --- /dev/null +++ b/loading/serialization_custom_resources/main.tscn @@ -0,0 +1,150 @@ +[gd_scene load_steps=8 format=3 uid="uid://cp05uf3cq4l0y"] + +[ext_resource type="Script" path="res://main.gd" id="1_blvy8"] +[ext_resource type="PackedScene" uid="uid://djbgtqgci6is1" path="res://game/character.tscn" id="2_31os6"] +[ext_resource type="Script" path="res://game/prompt.gd" id="3_6d6ml"] + +[sub_resource type="Gradient" id="Gradient_7eig6"] +colors = PackedColorArray(1, 1, 1, 1, 0, 0, 0, 1) + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_5553q"] +gradient = SubResource("Gradient_7eig6") +fill_to = Vector2(0, 0) + +[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_qk5ug"] +resource_name = "Wall" +texture = SubResource("GradientTexture2D_5553q") +0:0/0 = 0 +0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +0:0/0/physics_layer_0/angular_velocity = 0.0 +0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +0:1/0 = 0 +0:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +0:1/0/physics_layer_0/angular_velocity = 0.0 +0:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +1:1/0 = 0 +1:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +1:1/0/physics_layer_0/angular_velocity = 0.0 +1:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +1:2/0 = 0 +1:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +1:2/0/physics_layer_0/angular_velocity = 0.0 +1:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +2:2/0 = 0 +2:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +2:2/0/physics_layer_0/angular_velocity = 0.0 +2:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +2:3/0 = 0 +2:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +2:3/0/physics_layer_0/angular_velocity = 0.0 +2:3/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +3:3/0 = 0 +3:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +3:3/0/physics_layer_0/angular_velocity = 0.0 +3:3/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +3:2/0 = 0 +3:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +3:2/0/physics_layer_0/angular_velocity = 0.0 +3:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +3:1/0 = 0 +3:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +3:1/0/physics_layer_0/angular_velocity = 0.0 +3:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +3:0/0 = 0 +3:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +3:0/0/physics_layer_0/angular_velocity = 0.0 +3:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +2:0/0 = 0 +2:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +2:0/0/physics_layer_0/angular_velocity = 0.0 +2:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +1:0/0 = 0 +1:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) +1:0/0/physics_layer_0/angular_velocity = 0.0 +1:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +2:1/0 = 0 +2:1/0/physics_layer_0/linear_velocity = Vector2(0, 0) +2:1/0/physics_layer_0/angular_velocity = 0.0 +2:1/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +0:2/0 = 0 +0:2/0/physics_layer_0/linear_velocity = Vector2(0, 0) +0:2/0/physics_layer_0/angular_velocity = 0.0 +0:2/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +0:3/0 = 0 +0:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +0:3/0/physics_layer_0/angular_velocity = 0.0 +0:3/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) +1:3/0 = 0 +1:3/0/physics_layer_0/linear_velocity = Vector2(0, 0) +1:3/0/physics_layer_0/angular_velocity = 0.0 +1:3/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) + +[sub_resource type="TileSet" id="TileSet_3a0qb"] +physics_layer_0/collision_layer = 2 +sources/0 = SubResource("TileSetAtlasSource_qk5ug") + +[node name="Main" type="Node"] +script = ExtResource("1_blvy8") + +[node name="GameLayer" type="CanvasLayer" parent="."] + +[node name="Player" parent="GameLayer" groups=["characters"] instance=ExtResource("2_31os6")] +unique_name_in_owner = true +position = Vector2(446, 538) +character_name = "you" +player_controlled = true + +[node name="OtherAlice" parent="GameLayer" groups=["characters"] instance=ExtResource("2_31os6")] +unique_name_in_owner = true +modulate = Color(1, 1, 0, 1) +position = Vector2(642, 316) +character_name = "Alice" + +[node name="OtherBob" parent="GameLayer" groups=["characters"] instance=ExtResource("2_31os6")] +unique_name_in_owner = true +modulate = Color(0.6, 0.470588, 0.901961, 1) +position = Vector2(853, 535) +character_name = "Bob" + +[node name="TileMap" type="TileMap" parent="GameLayer"] +tile_set = SubResource("TileSet_3a0qb") +format = 2 +layer_0/name = "Walls" +layer_0/modulate = Color(0, 1, 1, 1) +layer_0/tile_data = PackedInt32Array(11, 131072, 0, 12, 196608, 0, 13, 131072, 0, 14, 196608, 0, 15, 131072, 0, 16, 196608, 0, 17, 131072, 0, 18, 196608, 0, 19, 131072, 0, 20, 196608, 0, 21, 131072, 0, 22, 196608, 0, 23, 131072, 0, 24, 196608, 0, 25, 131072, 0, 26, 196608, 0, 27, 131072, 0, 28, 196608, 0, 29, 131072, 0, 30, 196608, 0, 31, 131072, 0, 32, 196608, 0, 33, 131072, 0, 34, 196608, 0, 35, 131072, 0, 36, 196608, 0, 37, 131072, 0, 38, 196608, 0, 39, 131072, 0, 40, 196608, 0, 41, 131072, 0, 42, 196608, 0, 43, 131072, 0, 44, 196608, 0, 45, 131072, 0, 46, 196608, 0, 47, 131072, 0, 48, 196608, 0, 49, 131072, 0, 50, 196608, 0, 51, 131072, 0, 52, 196608, 0, 53, 131072, 0, 54, 196608, 0, 55, 131072, 0, 56, 196608, 0, 57, 131072, 0, 58, 196608, 0, 59, 131072, 0, 60, 196608, 0, 61, 131072, 0, 62, 196608, 0, 63, 131072, 0, 64, 196608, 0, 65, 131072, 0, 66, 196608, 0, 67, 131072, 0, 68, 196608, 0, 69, 131072, 0, 70, 196608, 0, 71, 131072, 0, 72, 196608, 0, 73, 131072, 0, 74, 196608, 0, 75, 131072, 0, 76, 196608, 0, 77, 131072, 0, 78, 196608, 0, 79, 131072, 0, 80, 196608, 0, 81, 131072, 0, 82, 196608, 0, 83, 131072, 0, 84, 196608, 0, 65620, 196608, 1, 131156, 196608, 0, 196692, 196608, 1, 262228, 196608, 0, 327764, 196608, 1, 393300, 196608, 0, 458836, 196608, 1, 524372, 196608, 0, 589908, 196608, 1, 655444, 196608, 0, 720980, 196608, 1, 786516, 196608, 0, 852052, 196608, 1, 917588, 196608, 0, 983124, 196608, 1, 1048660, 196608, 0, 1114196, 196608, 1, 1179732, 196608, 0, 1245268, 196608, 1, 1310804, 196608, 0, 1376340, 196608, 1, 1441876, 196608, 0, 1507412, 196608, 1, 1572948, 196608, 0, 1638484, 196608, 1, 1704020, 196608, 0, 1769556, 196608, 1, 1835092, 196608, 0, 1900628, 196608, 1, 1966164, 196608, 0, 2031700, 196608, 1, 2097236, 196608, 0, 2162772, 196608, 1, 2228308, 196608, 0, 2293844, 196608, 1, 2359380, 196608, 0, 2424916, 196608, 1, 2490452, 196608, 0, 2555988, 196608, 1, 2621524, 196608, 0, 2687060, 196608, 1, 2752596, 196608, 0, 2818132, 196608, 1, 2883668, 196608, 0, 2949204, 196608, 1, 3014740, 196608, 0, 3080276, 196608, 1, 3080192, 131072, 1, 3080193, 196608, 1, 3080194, 131072, 1, 3080195, 196608, 1, 3080196, 131072, 1, 3080197, 196608, 1, 3080198, 131072, 1, 3080199, 196608, 1, 3080200, 131072, 1, 3080201, 196608, 1, 3080202, 131072, 1, 3080203, 196608, 1, 3080204, 131072, 1, 3080205, 196608, 1, 3080206, 131072, 1, 3080207, 196608, 1, 3080208, 131072, 1, 3080209, 196608, 1, 3080210, 131072, 1, 3080211, 196608, 1, 3080212, 131072, 1, 3080213, 196608, 1, 3080214, 131072, 1, 3080215, 196608, 1, 3080216, 131072, 1, 3080217, 196608, 1, 3080218, 131072, 1, 3080219, 196608, 1, 3080220, 131072, 1, 3080221, 196608, 1, 3080222, 131072, 1, 3080223, 196608, 1, 3080224, 131072, 1, 3080225, 196608, 1, 3080226, 131072, 1, 3080227, 196608, 1, 3080228, 131072, 1, 3080229, 196608, 1, 3080230, 131072, 1, 3080231, 196608, 1, 3080232, 131072, 1, 3080233, 196608, 1, 3080234, 131072, 1, 3080235, 196608, 1, 3080236, 131072, 1, 3080237, 196608, 1, 3080238, 131072, 1, 3080239, 196608, 1, 3080240, 131072, 1, 3080241, 196608, 1, 3080242, 131072, 1, 3080243, 196608, 1, 3080244, 131072, 1, 3080245, 196608, 1, 3080246, 131072, 1, 3080247, 196608, 1, 3080248, 131072, 1, 3080249, 196608, 1, 3080250, 131072, 1, 3080251, 196608, 1, 3080252, 131072, 1, 3080253, 196608, 1, 3080254, 131072, 1, 3080255, 196608, 1, 3080256, 131072, 1, 3080257, 196608, 1, 3080258, 131072, 1, 3080259, 196608, 1, 3080260, 131072, 1, 3080261, 196608, 1, 3080262, 131072, 1, 3080263, 196608, 1, 3080264, 131072, 1, 3080265, 196608, 1, 3080266, 131072, 1, 3080267, 196608, 1, 3080268, 131072, 1, 3080269, 196608, 1, 3080270, 131072, 1, 3080271, 196608, 1, 3080272, 131072, 1, 3080273, 196608, 1, 3080274, 131072, 1, 3080275, 131072, 1, 65536, 131072, 1, 131072, 131072, 0, 196608, 131072, 1, 262144, 131072, 0, 327680, 131072, 1, 393216, 131072, 0, 458752, 131072, 1, 524288, 131072, 0, 589824, 131072, 1, 655360, 131072, 0, 720896, 131072, 1, 786432, 131072, 0, 851968, 131072, 1, 917504, 131072, 0, 983040, 131072, 1, 1048576, 131072, 0, 1114112, 131072, 1, 1179648, 131072, 0, 1245184, 131072, 1, 1310720, 131072, 0, 1376256, 131072, 1, 1441792, 131072, 0, 1507328, 131072, 1, 1572864, 131072, 0, 1638400, 131072, 1, 1703936, 131072, 0, 1769472, 131072, 1, 1835008, 131072, 0, 1900544, 131072, 1, 1966080, 131072, 0, 2031616, 131072, 1, 2097152, 131072, 0, 2162688, 131072, 1, 2228224, 131072, 0, 2293760, 131072, 1, 2359296, 131072, 0, 2424832, 131072, 1, 2490368, 131072, 0, 2555904, 131072, 1, 2621440, 131072, 0, 2686976, 131072, 1, 2752512, 131072, 0, 2818048, 131072, 1, 2883584, 131072, 0, 2949120, 131072, 1, 3014656, 131072, 0, 1, 196608, 0, 2, 196608, 0, 3, 131072, 0, 4, 196608, 0, 5, 131072, 0, 6, 196608, 0, 7, 131072, 0, 8, 196608, 0, 9, 131072, 0, 10, 196608, 0, 65537, 196608, 1, 65538, 196608, 1, 65539, 131072, 1, 65540, 196608, 1, 65541, 131072, 1, 65542, 196608, 1, 65543, 131072, 1, 65544, 196608, 1, 65545, 131072, 1, 65546, 196608, 1, 65547, 131072, 1, 65548, 196608, 1, 65549, 131072, 1, 65550, 196608, 1, 65551, 131072, 1, 65552, 196608, 1, 65553, 131072, 1, 65554, 196608, 1, 65555, 131072, 1, 65556, 196608, 1, 65557, 131072, 1, 65558, 196608, 1, 65559, 131072, 1, 65560, 196608, 1, 65561, 131072, 1, 65562, 196608, 1, 65563, 131072, 1, 65564, 196608, 1, 65565, 131072, 1, 65566, 196608, 1, 65567, 131072, 1, 65568, 196608, 1, 65569, 131072, 1, 65570, 196608, 1, 65571, 131072, 1, 65572, 196608, 1, 65573, 131072, 1, 65574, 196608, 1, 65575, 131072, 1, 65576, 196608, 1, 65577, 131072, 1, 65578, 196608, 1, 65579, 131072, 1, 65580, 196608, 1, 65581, 131072, 1, 65582, 196608, 1, 65583, 131072, 1, 65584, 196608, 1, 65585, 131072, 1, 65586, 196608, 1, 65587, 131072, 1, 65588, 196608, 1, 65589, 131072, 1, 65590, 196608, 1, 65591, 131072, 1, 65592, 196608, 1, 65593, 131072, 1, 65594, 196608, 1, 65595, 131072, 1, 65596, 196608, 1, 65597, 131072, 1, 65598, 196608, 1, 65599, 131072, 1, 65600, 196608, 1, 65601, 131072, 1, 65602, 196608, 1, 65603, 131072, 1, 65604, 196608, 1, 65605, 131072, 1, 65606, 196608, 1, 65607, 131072, 1, 65608, 196608, 1, 65609, 131072, 1, 65610, 196608, 1, 65611, 131072, 1, 65612, 196608, 1, 65613, 131072, 1, 65614, 196608, 1, 65615, 131072, 1, 65616, 196608, 1, 65617, 131072, 1, 65618, 196608, 1, 65619, 131072, 1, 0, 131072, 0, 131073, 196608, 0, 196609, 196608, 1, 262145, 196608, 0, 327681, 196608, 1, 393217, 196608, 0, 458753, 196608, 1, 524289, 196608, 0, 589825, 196608, 1, 655361, 196608, 0, 720897, 196608, 1, 786433, 196608, 0, 851969, 196608, 1, 917505, 196608, 0, 983041, 196608, 1, 1048577, 196608, 0, 1114113, 196608, 1, 1179649, 196608, 0, 1245185, 196608, 1, 1310721, 196608, 0, 1376257, 196608, 1, 1441793, 196608, 0, 1507329, 196608, 1, 1572865, 196608, 0, 1638401, 196608, 1, 1703937, 196608, 0, 1769473, 196608, 1, 1835009, 196608, 0, 1900545, 196608, 1, 1966081, 196608, 0, 2031617, 196608, 1, 2097153, 196608, 0, 2162689, 196608, 1, 2228225, 196608, 0, 2293761, 196608, 1, 2359297, 196608, 0, 2424833, 196608, 1, 2490369, 196608, 0, 2555905, 196608, 1, 2621441, 196608, 0, 2686977, 196608, 1, 2752513, 196608, 0, 2818049, 196608, 1, 2883585, 196608, 0, 2949121, 196608, 1, 3014657, 196608, 0, 3014658, 131072, 0, 3014659, 196608, 0, 3014660, 131072, 0, 3014661, 196608, 0, 3014662, 131072, 0, 3014663, 196608, 0, 3014664, 131072, 0, 3014665, 196608, 0, 3014666, 131072, 0, 3014667, 196608, 0, 3014668, 131072, 0, 3014669, 196608, 0, 3014670, 131072, 0, 3014671, 196608, 0, 3014672, 131072, 0, 3014673, 196608, 0, 3014674, 131072, 0, 3014675, 196608, 0, 3014676, 131072, 0, 3014677, 196608, 0, 3014678, 131072, 0, 3014679, 196608, 0, 3014680, 131072, 0, 3014681, 196608, 0, 3014682, 131072, 0, 3014683, 196608, 0, 3014684, 131072, 0, 3014685, 196608, 0, 3014686, 131072, 0, 3014687, 196608, 0, 3014688, 131072, 0, 3014689, 196608, 0, 3014690, 131072, 0, 3014691, 196608, 0, 3014692, 131072, 0, 3014693, 196608, 0, 3014694, 131072, 0, 3014695, 196608, 0, 3014696, 131072, 0, 3014697, 196608, 0, 3014698, 131072, 0, 3014699, 196608, 0, 3014700, 131072, 0, 3014701, 196608, 0, 3014702, 131072, 0, 3014703, 196608, 0, 3014704, 131072, 0, 3014705, 196608, 0, 3014706, 131072, 0, 3014707, 196608, 0, 3014708, 131072, 0, 3014709, 196608, 0, 3014710, 131072, 0, 3014711, 196608, 0, 3014712, 131072, 0, 3014713, 196608, 0, 3014714, 131072, 0, 3014715, 196608, 0, 3014716, 131072, 0, 3014717, 196608, 0, 3014718, 131072, 0, 3014719, 196608, 0, 3014720, 131072, 0, 3014721, 196608, 0, 3014722, 131072, 0, 3014723, 196608, 0, 3014724, 131072, 0, 3014725, 196608, 0, 3014726, 131072, 0, 3014727, 196608, 0, 3014728, 131072, 0, 3014729, 196608, 0, 3014730, 131072, 0, 3014731, 196608, 0, 3014732, 131072, 0, 3014733, 196608, 0, 3014734, 131072, 0, 3014735, 196608, 0, 3014736, 131072, 0, 3014737, 196608, 0, 3014738, 131072, 0, 3014739, 131072, 0, 2883667, 131072, 0, 2949203, 131072, 1, 2752595, 131072, 0, 2818131, 131072, 1, 2621523, 131072, 0, 2687059, 131072, 1, 2490451, 131072, 0, 2555987, 131072, 1, 2359379, 131072, 0, 2424915, 131072, 1, 2228307, 131072, 0, 2293843, 131072, 1, 2097235, 131072, 0, 2162771, 131072, 1, 1966163, 131072, 0, 2031699, 131072, 1, 1835091, 131072, 0, 1900627, 131072, 1, 1704019, 131072, 0, 1769555, 131072, 1, 1572947, 131072, 0, 1638483, 131072, 1, 1441875, 131072, 0, 1507411, 131072, 1, 1310803, 131072, 0, 1376339, 131072, 1, 1179731, 131072, 0, 1245267, 131072, 1, 1048659, 131072, 0, 1114195, 131072, 1, 917587, 131072, 0, 983123, 131072, 1, 786515, 131072, 0, 852051, 131072, 1, 655443, 131072, 0, 720979, 131072, 1, 524371, 131072, 0, 589907, 131072, 1, 393299, 131072, 0, 458835, 131072, 1, 262227, 131072, 0, 327763, 131072, 1, 131155, 131072, 0, 196691, 131072, 1) + +[node name="UILayer" type="CanvasLayer" parent="."] + +[node name="Prompt" type="Label" parent="UILayer"] +unique_name_in_owner = true +anchors_preset = 10 +anchor_right = 1.0 +offset_bottom = 140.0 +grow_horizontal = 2 +theme_override_font_sizes/font_size = 32 +text = "Tag, you are it!" +horizontal_alignment = 1 +vertical_alignment = 1 +script = ExtResource("3_6d6ml") + +[node name="Intructions" type="Label" parent="UILayer"] +offset_left = 60.0 +offset_top = 120.0 +offset_right = 181.0 +offset_bottom = 146.0 +text = "Intructions +move: wasd/arrowkeys +save: ctrl + s +open: ctrl + o" + +[node name="FileDialogue" type="FileDialog" parent="UILayer"] +unique_name_in_owner = true +position = Vector2i(291, 180) +size = Vector2i(784, 392) +filters = PackedStringArray("*.tres; resource") + +[connection signal="tagged" from="GameLayer/Player" to="." method="_on_player_tagged"] +[connection signal="tagged" from="GameLayer/OtherAlice" to="." method="_on_other_alice_tagged"] +[connection signal="tagged" from="GameLayer/OtherBob" to="." method="_on_other_bob_tagged"] +[connection signal="file_selected" from="UILayer/FileDialogue" to="." method="_on_file_dialogue_file_selected"] +[connection signal="visibility_changed" from="UILayer/FileDialogue" to="." method="_on_file_dialogue_visibility_changed"] diff --git a/loading/serialization_custom_resources/project.godot b/loading/serialization_custom_resources/project.godot new file mode 100644 index 0000000000..0628667c01 --- /dev/null +++ b/loading/serialization_custom_resources/project.godot @@ -0,0 +1,68 @@ +; Engine configuration file. +; It's best edited using the editor UI and not directly, +; since the parameters that go here are not all obvious. +; +; Format: +; [section] ; section goes between [] +; param=value ; assign values to parameters + +config_version=5 + +[application] + +config/name="SavingTutorial" +run/main_scene="res://main.tscn" +config/features=PackedStringArray("4.0", "GL Compatibility") +config/icon="res://icon.svg" + +[display] + +window/size/viewport_width=1366 +window/size/viewport_height=768 + +[input] + +left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} +up={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) +] +} +down={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +] +} +save={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"command_or_control_autoremap":true,"alt_pressed":false,"shift_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +] +} +open={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"command_or_control_autoremap":true,"alt_pressed":false,"shift_pressed":false,"pressed":false,"keycode":0,"physical_keycode":79,"key_label":0,"unicode":111,"echo":false,"script":null) +] +} + +[layer_names] + +2d_physics/layer_1="characters" +2d_physics/layer_2="walls" + +[rendering] + +renderer/rendering_method="gl_compatibility" +renderer/rendering_method.mobile="gl_compatibility" diff --git a/loading/serialization_custom_resources/save_files/first_save.tres b/loading/serialization_custom_resources/save_files/first_save.tres new file mode 100644 index 0000000000..6562601ac4 --- /dev/null +++ b/loading/serialization_custom_resources/save_files/first_save.tres @@ -0,0 +1,52 @@ +[gd_resource type="Resource" script_class="RefereeResource" load_steps=6 format=3 uid="uid://gmxiboapmwbn"] + +[ext_resource type="Script" path="res://saving/character_resource.gd" id="1_ejgby"] +[ext_resource type="Script" path="res://saving/referee_resource.gd" id="2_8vmsp"] + +[sub_resource type="Resource" id="Resource_i0qnr"] +script = ExtResource("1_ejgby") +character_name = "Alice" +position = Vector2(698.258, 252.281) +move_direction = Vector2(0.661847, -0.749639) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/Player") +player_controlled = false +stunned = false +stun_duration = 2.0 +stun_time_left = 0.0 + +[sub_resource type="Resource" id="Resource_v1ijj"] +script = ExtResource("1_ejgby") +character_name = "Bob" +position = Vector2(937.998, 534.374) +move_direction = Vector2(0.999973, -0.00736911) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/Player") +player_controlled = false +stunned = false +stun_duration = 2.0 +stun_time_left = 0.0 + +[sub_resource type="Resource" id="Resource_2ij7d"] +script = ExtResource("1_ejgby") +character_name = "you" +position = Vector2(446, 538) +move_direction = Vector2(0, 0) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/Player") +player_controlled = true +stunned = false +stun_duration = 2.0 +stun_time_left = 0.0 + +[resource] +script = ExtResource("2_8vmsp") +path_to_whose_it = NodePath("/root/Main/GameLayer/Player") +path_to_who_starts_as_it = NodePath("GameLayer/Player") +player_resource = SubResource("Resource_2ij7d") +other_alice_resource = SubResource("Resource_i0qnr") +other_bob_resource = SubResource("Resource_v1ijj") +prompt_text = "Tag, you are it!" diff --git a/loading/serialization_custom_resources/save_files/second_save.tres b/loading/serialization_custom_resources/save_files/second_save.tres new file mode 100644 index 0000000000..3b8c4a88ab --- /dev/null +++ b/loading/serialization_custom_resources/save_files/second_save.tres @@ -0,0 +1,52 @@ +[gd_resource type="Resource" script_class="RefereeResource" load_steps=6 format=3] + +[ext_resource type="Script" path="res://saving/character_resource.gd" id="1_0m0y7"] +[ext_resource type="Script" path="res://saving/referee_resource.gd" id="2_gtr8h"] + +[sub_resource type="Resource" id="Resource_gii1e"] +script = ExtResource("1_0m0y7") +character_name = "Alice" +position = Vector2(1020.12, 95.576) +move_direction = Vector2(0.741983, -0.670418) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/Player") +player_controlled = false +stunned = false +stun_duration = 2.0 +stun_time_left = 0.0 + +[sub_resource type="Resource" id="Resource_qcq7a"] +script = ExtResource("1_0m0y7") +character_name = "Bob" +position = Vector2(1264.42, 638.053) +move_direction = Vector2(0.933169, 0.359438) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/Player") +player_controlled = false +stunned = false +stun_duration = 2.0 +stun_time_left = 0.0 + +[sub_resource type="Resource" id="Resource_vmr5q"] +script = ExtResource("1_0m0y7") +character_name = "you" +position = Vector2(672.301, 408.364) +move_direction = Vector2(0, 0) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/Player") +player_controlled = true +stunned = false +stun_duration = 2.0 +stun_time_left = 0.0 + +[resource] +script = ExtResource("2_gtr8h") +path_to_whose_it = NodePath("/root/Main/GameLayer/Player") +path_to_who_starts_as_it = NodePath("GameLayer/Player") +player_resource = SubResource("Resource_vmr5q") +other_alice_resource = SubResource("Resource_gii1e") +other_bob_resource = SubResource("Resource_qcq7a") +prompt_text = "Tag, you are it!" diff --git a/loading/serialization_custom_resources/save_files/third_save.tres b/loading/serialization_custom_resources/save_files/third_save.tres new file mode 100644 index 0000000000..3a9049be93 --- /dev/null +++ b/loading/serialization_custom_resources/save_files/third_save.tres @@ -0,0 +1,52 @@ +[gd_resource type="Resource" script_class="RefereeResource" load_steps=6 format=3] + +[ext_resource type="Script" path="res://saving/character_resource.gd" id="1_h1ono"] +[ext_resource type="Script" path="res://saving/referee_resource.gd" id="2_78op6"] + +[sub_resource type="Resource" id="Resource_w1yqq"] +script = ExtResource("1_h1ono") +character_name = "Alice" +position = Vector2(1264.42, 95.576) +move_direction = Vector2(-0.877135, 0.480243) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/OtherAlice") +player_controlled = false +stunned = true +stun_duration = 2.0 +stun_time_left = 0.416701 + +[sub_resource type="Resource" id="Resource_kvrvr"] +script = ExtResource("1_h1ono") +character_name = "Bob" +position = Vector2(1264.42, 671.499) +move_direction = Vector2(0, 1) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/OtherAlice") +player_controlled = false +stunned = false +stun_duration = 2.0 +stun_time_left = 0.0 + +[sub_resource type="Resource" id="Resource_afe07"] +script = ExtResource("1_h1ono") +character_name = "you" +position = Vector2(1026.77, 225.695) +move_direction = Vector2(0, 0) +base_speed = 100.0 +it_speed_multiplier = 2.0 +path_to_whose_it = NodePath("/root/Main/GameLayer/OtherAlice") +player_controlled = true +stunned = false +stun_duration = 2.0 +stun_time_left = 0.0 + +[resource] +script = ExtResource("2_78op6") +path_to_whose_it = NodePath("/root/Main/GameLayer/OtherAlice") +path_to_who_starts_as_it = NodePath("GameLayer/Player") +player_resource = SubResource("Resource_afe07") +other_alice_resource = SubResource("Resource_w1yqq") +other_bob_resource = SubResource("Resource_kvrvr") +prompt_text = "Tag, Alice is it!" diff --git a/loading/serialization_custom_resources/saving/character_resource.gd b/loading/serialization_custom_resources/saving/character_resource.gd new file mode 100644 index 0000000000..3dd99fd9ed --- /dev/null +++ b/loading/serialization_custom_resources/saving/character_resource.gd @@ -0,0 +1,17 @@ +extends Resource +class_name CharacterResource + +@export var character_name : String + +@export_group("Kinematic Variables") +@export var position : Vector2 +@export var move_direction : Vector2 +@export var base_speed : float # pixels per second +@export var it_speed_multiplier : float + +@export_group("Game Variables") +@export_node_path("Character") var path_to_whose_it : NodePath +@export var player_controlled : bool +@export var stunned : bool +@export var stun_duration : float # seconds +@export var stun_time_left : float # seconds diff --git a/loading/serialization_custom_resources/saving/referee_resource.gd b/loading/serialization_custom_resources/saving/referee_resource.gd new file mode 100644 index 0000000000..81e5e099c7 --- /dev/null +++ b/loading/serialization_custom_resources/saving/referee_resource.gd @@ -0,0 +1,11 @@ +extends Resource +class_name RefereeResource + +@export_node_path("Character") var path_to_whose_it : NodePath +@export_node_path("Character") var path_to_who_starts_as_it : NodePath + +@export var player_resource : CharacterResource +@export var other_alice_resource : CharacterResource +@export var other_bob_resource : CharacterResource + +@export var prompt_text : String