Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: load village view temporary #100

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/Saver-22b-godot/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion frontend/Saver-22b-godot/scenes/intro.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion frontend/Saver-22b-godot/scenes/select_village.tscn
Original file line number Diff line number Diff line change
@@ -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
Expand Down
52 changes: 52 additions & 0 deletions frontend/Saver-22b-godot/scripts/global/scene_context.gd
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
Expand Up @@ -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")
10 changes: 9 additions & 1 deletion frontend/Saver-22b-godot/village_view/TemporaryView.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
9 changes: 9 additions & 0 deletions frontend/Saver-22b-godot/village_view/VillageView.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading