diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index 68894b15..fad1888e 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -20,6 +20,7 @@ config/icon="res://icon.svg" GlobalSigner="*res://scripts/sign/Signer.gd" SvrGqlClient="*res://gql/svr_gql_client.gd" +SceneContext="*res://scripts/global/scene_context.gd" [display] diff --git a/frontend/Saver-22b-godot/scenes/intro.tscn b/frontend/Saver-22b-godot/scenes/intro.tscn index ee4ce9f9..74c47cf3 100644 --- a/frontend/Saver-22b-godot/scenes/intro.tscn +++ b/frontend/Saver-22b-godot/scenes/intro.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://cg773cnsx4rb0"] -[ext_resource type="Script" path="res://scripts/intro.gd" id="1_0m54y"] +[ext_resource type="Script" path="res://scripts/scenes/intro.gd" id="1_0m54y"] [ext_resource type="Script" path="res://scripts/gql_test.gd" id="2_yxm3e"] [node name="Intro" type="Control"] diff --git a/frontend/Saver-22b-godot/scenes/select_village.tscn b/frontend/Saver-22b-godot/scenes/select_village.tscn index bcdc9ba0..205721e0 100644 --- a/frontend/Saver-22b-godot/scenes/select_village.tscn +++ b/frontend/Saver-22b-godot/scenes/select_village.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=2 format=3 uid="uid://cl8vvgnebwyi1"] -[ext_resource type="Script" path="res://scripts/select_village.gd" id="1_uohty"] +[ext_resource type="Script" path="res://scripts/scenes/select_village.gd" id="1_uohty"] [node name="SelectVillage" type="Control"] layout_mode = 3 diff --git a/frontend/Saver-22b-godot/scripts/global/scene_context.gd b/frontend/Saver-22b-godot/scripts/global/scene_context.gd new file mode 100644 index 00000000..9cabf3e1 --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/global/scene_context.gd @@ -0,0 +1,52 @@ +extends Node + +var villages_json_string := """{ + "villages": [ + { + "id": 1, + "name": "평범한 도시 1", + "width": 3, + "height": 11, + "worldX": 5, + "worldY": 1, + "houses": [ + { + "x": 1, + "y": 1, + "owner": "0x53103C2D7875D2f5f02AeC3075155e268a6e3A94" + } + ] + }, + { + "id": 2, + "name": "외로운 섬", + "width": 7, + "height": 13, + "worldX": -2, + "worldY": 7, + "houses": [] + }, + { + "id": 3, + "name": "정글", + "width": 3, + "height": 5, + "worldX": 1, + "worldY": -3, + "houses": [] + } + ] + }""" +var villages: Array +var selected_village_index := 0 + +func _ready(): + var json = JSON.new() + var error = json.parse(villages_json_string) + if error != OK: + print(error) + else: + villages = json.data.villages + +func get_selected_village(): + return villages[selected_village_index] diff --git a/frontend/Saver-22b-godot/scripts/intro.gd b/frontend/Saver-22b-godot/scripts/scenes/intro.gd similarity index 100% rename from frontend/Saver-22b-godot/scripts/intro.gd rename to frontend/Saver-22b-godot/scripts/scenes/intro.gd diff --git a/frontend/Saver-22b-godot/scripts/select_village.gd b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd similarity index 62% rename from frontend/Saver-22b-godot/scripts/select_village.gd rename to frontend/Saver-22b-godot/scripts/scenes/select_village.gd index be0e8db2..43e816c9 100644 --- a/frontend/Saver-22b-godot/scripts/select_village.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd @@ -11,5 +11,6 @@ func _on_village_button_button_down(extra_arg_0): selected_village_index = extra_arg_0 func _on_start_button_button_down(): - var format_string = "start button down: %s" - print(format_string % selected_village_index) + print("start button down: %s" % selected_village_index) + SceneContext.selected_village_index = selected_village_index + get_tree().change_scene_to_file("res://village_view/VillageView.tscn") diff --git a/frontend/Saver-22b-godot/village_view/TemporaryView.gd b/frontend/Saver-22b-godot/village_view/TemporaryView.gd index 8a678ef7..0040752f 100644 --- a/frontend/Saver-22b-godot/village_view/TemporaryView.gd +++ b/frontend/Saver-22b-godot/village_view/TemporaryView.gd @@ -3,7 +3,15 @@ const village_view_node = preload("res://village_view/village_background_nine_pa # Called when the node enters the scene tree for the first time. func _ready(): + print("village_view scene ready") + var village = SceneContext.get_selected_village() var village_view_instance = village_view_node.instantiate() village_view_instance.set_name("view") + #village_view_instance.initialize( + #1000, + #500, + #0, + #0, + #[Vector2(0,0),Vector2(1,0),Vector2(0,1),Vector2(1,1)]) + village_view_instance.initialize_by_village(village) add_child(village_view_instance) - village_view_instance.initialize(1000,500,0,0, [Vector2(0,0),Vector2(1,0),Vector2(0,1),Vector2(1,1)]) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index dddbceb4..da38f369 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -21,6 +21,15 @@ func _process(delta): pass # var newView = VillageViewClass.new(1,2,3,4) 이런식으로 사용하려나 +func initialize_by_village(village: Dictionary): + initialize( + village.width * 50, + village.height * 50, + village.worldX, + village.worldY, + village.houses.map(func(house): return Vector2(house.x, house.y) * 50) + ) + func initialize(width: int, height: int, worldX: int, worldY: int, houses=[]): self.width = width self.height = height