From 7153bb349a2d02ed184ab7d1b7aa3c034da0b838 Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 15:31:50 +0900 Subject: [PATCH 1/3] move scripts --- frontend/Saver-22b-godot/scenes/intro.tscn | 2 +- frontend/Saver-22b-godot/scenes/select_village.tscn | 2 +- frontend/Saver-22b-godot/scripts/{ => scenes}/intro.gd | 0 .../scripts/{ => scenes}/select_village.gd | 9 +++++++-- 4 files changed, 9 insertions(+), 4 deletions(-) rename frontend/Saver-22b-godot/scripts/{ => scenes}/intro.gd (100%) rename frontend/Saver-22b-godot/scripts/{ => scenes}/select_village.gd (53%) 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/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 53% rename from frontend/Saver-22b-godot/scripts/select_village.gd rename to frontend/Saver-22b-godot/scripts/scenes/select_village.gd index be0e8db2..0fb6e836 100644 --- a/frontend/Saver-22b-godot/scripts/select_village.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd @@ -11,5 +11,10 @@ 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) + _go_to_village(selected_village_index) + +func _go_to_village(village_index): + var scene_path = "go to village: res://scenes/%s.tscn" % village_index + print(scene_path) + #get_tree().change_scene_to_file(scene_path) From ed52c32ca5f03cc1579fe14634d5ed1e55fb851d Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 16:13:51 +0900 Subject: [PATCH 2/3] autoload scene_context --- frontend/Saver-22b-godot/project.godot | 1 + .../scripts/global/scene_context.gd | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 frontend/Saver-22b-godot/scripts/global/scene_context.gd 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/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] From e90160f0b0aae4899e158b47a682815d6a01a0dc Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 16:14:37 +0900 Subject: [PATCH 3/3] change scene to village_view from select_village --- .../Saver-22b-godot/scripts/scenes/select_village.gd | 8 ++------ frontend/Saver-22b-godot/village_view/TemporaryView.gd | 10 +++++++++- frontend/Saver-22b-godot/village_view/VillageView.gd | 9 +++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd index 0fb6e836..43e816c9 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd @@ -12,9 +12,5 @@ func _on_village_button_button_down(extra_arg_0): func _on_start_button_button_down(): print("start button down: %s" % selected_village_index) - _go_to_village(selected_village_index) - -func _go_to_village(village_index): - var scene_path = "go to village: res://scenes/%s.tscn" % village_index - print(scene_path) - #get_tree().change_scene_to_file(scene_path) + 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