From b958cb33aeddff27657c73043a92c4d8548ec2c5 Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Tue, 19 Dec 2023 10:25:28 +0900 Subject: [PATCH 01/51] make initial empty godot project --- frontend/Saver-22b-godot/.gitattributes | 2 ++ frontend/Saver-22b-godot/.gitignore | 2 ++ frontend/Saver-22b-godot/icon.svg | 1 + frontend/Saver-22b-godot/icon.svg.import | 37 ++++++++++++++++++++++++ frontend/Saver-22b-godot/project.godot | 24 +++++++++++++++ 5 files changed, 66 insertions(+) create mode 100644 frontend/Saver-22b-godot/.gitattributes create mode 100644 frontend/Saver-22b-godot/.gitignore create mode 100644 frontend/Saver-22b-godot/icon.svg create mode 100644 frontend/Saver-22b-godot/icon.svg.import create mode 100644 frontend/Saver-22b-godot/project.godot diff --git a/frontend/Saver-22b-godot/.gitattributes b/frontend/Saver-22b-godot/.gitattributes new file mode 100644 index 00000000..8ad74f78 --- /dev/null +++ b/frontend/Saver-22b-godot/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/frontend/Saver-22b-godot/.gitignore b/frontend/Saver-22b-godot/.gitignore new file mode 100644 index 00000000..47091836 --- /dev/null +++ b/frontend/Saver-22b-godot/.gitignore @@ -0,0 +1,2 @@ +# Godot 4+ specific ignores +.godot/ diff --git a/frontend/Saver-22b-godot/icon.svg b/frontend/Saver-22b-godot/icon.svg new file mode 100644 index 00000000..b370ceb7 --- /dev/null +++ b/frontend/Saver-22b-godot/icon.svg @@ -0,0 +1 @@ + diff --git a/frontend/Saver-22b-godot/icon.svg.import b/frontend/Saver-22b-godot/icon.svg.import new file mode 100644 index 00000000..377a48c0 --- /dev/null +++ b/frontend/Saver-22b-godot/icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dnj5868p8yh07" +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/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot new file mode 100644 index 00000000..49839d14 --- /dev/null +++ b/frontend/Saver-22b-godot/project.godot @@ -0,0 +1,24 @@ +; 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="Saver-22b-godot" +config/features=PackedStringArray("4.2", "GL Compatibility") +config/icon="res://icon.svg" + +[dotnet] + +project/assembly_name="Saver-22b-godot" + +[rendering] + +renderer/rendering_method="gl_compatibility" +renderer/rendering_method.mobile="gl_compatibility" From e66f9295a4b3d4ff18b4b0b40c5290fd16706616 Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Tue, 19 Dec 2023 11:13:55 +0900 Subject: [PATCH 02/51] push initial main_scene --- frontend/Saver-22b-godot/main_scene.tscn | 38 ++++++++++++++++++++++++ frontend/Saver-22b-godot/project.godot | 7 +++++ 2 files changed, 45 insertions(+) create mode 100644 frontend/Saver-22b-godot/main_scene.tscn diff --git a/frontend/Saver-22b-godot/main_scene.tscn b/frontend/Saver-22b-godot/main_scene.tscn new file mode 100644 index 00000000..d3daee61 --- /dev/null +++ b/frontend/Saver-22b-godot/main_scene.tscn @@ -0,0 +1,38 @@ +[gd_scene format=3 uid="uid://4qejtaco6225"] + +[node name="Node2D" type="Node2D"] + +[node name="SubViewportContainer" type="SubViewportContainer" parent="."] +offset_right = 1920.0 +offset_bottom = 1080.0 +stretch = true + +[node name="SubViewport" type="SubViewport" parent="SubViewportContainer"] +handle_input_locally = false +size = Vector2i(1920, 1080) +render_target_update_mode = 4 + +[node name="Scene#1" type="ColorRect" parent="SubViewportContainer/SubViewport"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Scene#2" type="ColorRect" parent="SubViewportContainer/SubViewport"] +visible = false +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.862745, 0.862745, 0.862745, 1) + +[node name="Scene#3" type="ColorRect" parent="SubViewportContainer/SubViewport"] +visible = false +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0.639216, 0.639216, 0.639216, 1) diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index 49839d14..de10be1a 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -11,9 +11,16 @@ config_version=5 [application] config/name="Saver-22b-godot" +run/main_scene="res://main_scene.tscn" config/features=PackedStringArray("4.2", "GL Compatibility") config/icon="res://icon.svg" +[display] + +window/size/viewport_width=1920 +window/size/viewport_height=1080 +window/stretch/mode="viewport" + [dotnet] project/assembly_name="Saver-22b-godot" From 424e98aa0d591b7002f49df33a742f1a0f6613d7 Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Tue, 19 Dec 2023 12:22:49 +0900 Subject: [PATCH 03/51] add several scenes --- frontend/Saver-22b-godot/scenes/intro.tscn | 96 +++++++++++++++++++ frontend/Saver-22b-godot/scenes/main.tscn | 7 ++ .../scenes/select_village.tscn | 19 ++++ 3 files changed, 122 insertions(+) create mode 100644 frontend/Saver-22b-godot/scenes/intro.tscn create mode 100644 frontend/Saver-22b-godot/scenes/main.tscn create mode 100644 frontend/Saver-22b-godot/scenes/select_village.tscn diff --git a/frontend/Saver-22b-godot/scenes/intro.tscn b/frontend/Saver-22b-godot/scenes/intro.tscn new file mode 100644 index 00000000..ac155cfb --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/intro.tscn @@ -0,0 +1,96 @@ +[gd_scene format=3 uid="uid://cg773cnsx4rb0"] + +[node name="Intro" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -1.0 +offset_bottom = -1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Title" type="ColorRect" parent="."] +custom_minimum_size = Vector2(800, 250) +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -400.0 +offset_top = -240.0 +offset_right = 400.0 +offset_bottom = 10.0005 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0, 0, 0, 1) + +[node name="Label" type="Label" parent="Title"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_font_sizes/font_size = 70 +text = "SAVER 22B" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="QuitButtonContainer" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 2 +anchor_top = 1.0 +anchor_bottom = 1.0 +offset_left = 100.0 +offset_top = -280.0 +offset_right = 600.0 +offset_bottom = -160.0 +grow_vertical = 0 +color = Color(0, 0, 0, 1) + +[node name="Button" type="Button" parent="QuitButtonContainer"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_type_variation = &"FlatButton" +theme_override_font_sizes/font_size = 70 +text = "Quit" + +[node name="PlayButtonContainer" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -600.0 +offset_top = -280.0 +offset_right = -100.0 +offset_bottom = -160.0 +grow_horizontal = 0 +grow_vertical = 0 +color = Color(0, 0, 0, 1) + +[node name="Button" type="Button" parent="PlayButtonContainer"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_type_variation = &"FlatButton" +theme_override_font_sizes/font_size = 70 +text = "Play" diff --git a/frontend/Saver-22b-godot/scenes/main.tscn b/frontend/Saver-22b-godot/scenes/main.tscn new file mode 100644 index 00000000..7de7df03 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/main.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3 uid="uid://cjvywwt132ot5"] + +[ext_resource type="PackedScene" uid="uid://cg773cnsx4rb0" path="res://scenes/intro.tscn" id="1_hqty0"] + +[node name="Main" type="Node"] + +[node name="Intro" parent="." instance=ExtResource("1_hqty0")] diff --git a/frontend/Saver-22b-godot/scenes/select_village.tscn b/frontend/Saver-22b-godot/scenes/select_village.tscn new file mode 100644 index 00000000..79a0f6ad --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/select_village.tscn @@ -0,0 +1,19 @@ +[gd_scene format=3 uid="uid://cl8vvgnebwyi1"] + +[node name="SelectVillage" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -1.0 +offset_bottom = -1.0 +grow_horizontal = 2 +grow_vertical = 2 From 0e54ce7d7e9500c71450b53987b51ddf0e57bdaa Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Tue, 19 Dec 2023 12:23:05 +0900 Subject: [PATCH 04/51] remove main_scene and update project settings --- frontend/Saver-22b-godot/main_scene.tscn | 38 ------------------------ frontend/Saver-22b-godot/project.godot | 5 ++-- 2 files changed, 3 insertions(+), 40 deletions(-) delete mode 100644 frontend/Saver-22b-godot/main_scene.tscn diff --git a/frontend/Saver-22b-godot/main_scene.tscn b/frontend/Saver-22b-godot/main_scene.tscn deleted file mode 100644 index d3daee61..00000000 --- a/frontend/Saver-22b-godot/main_scene.tscn +++ /dev/null @@ -1,38 +0,0 @@ -[gd_scene format=3 uid="uid://4qejtaco6225"] - -[node name="Node2D" type="Node2D"] - -[node name="SubViewportContainer" type="SubViewportContainer" parent="."] -offset_right = 1920.0 -offset_bottom = 1080.0 -stretch = true - -[node name="SubViewport" type="SubViewport" parent="SubViewportContainer"] -handle_input_locally = false -size = Vector2i(1920, 1080) -render_target_update_mode = 4 - -[node name="Scene#1" type="ColorRect" parent="SubViewportContainer/SubViewport"] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 - -[node name="Scene#2" type="ColorRect" parent="SubViewportContainer/SubViewport"] -visible = false -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -color = Color(0.862745, 0.862745, 0.862745, 1) - -[node name="Scene#3" type="ColorRect" parent="SubViewportContainer/SubViewport"] -visible = false -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -color = Color(0.639216, 0.639216, 0.639216, 1) diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index de10be1a..320bd000 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -11,15 +11,16 @@ config_version=5 [application] config/name="Saver-22b-godot" -run/main_scene="res://main_scene.tscn" +run/main_scene="res://scenes/main.tscn" config/features=PackedStringArray("4.2", "GL Compatibility") +boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1) config/icon="res://icon.svg" [display] window/size/viewport_width=1920 window/size/viewport_height=1080 -window/stretch/mode="viewport" +window/stretch/mode="canvas_items" [dotnet] From ff0b490b7dd45e5cdb3196766ba828a24e25a2e3 Mon Sep 17 00:00:00 2001 From: Jiwon Date: Tue, 19 Dec 2023 16:03:01 +0900 Subject: [PATCH 05/51] Migrage use item & planting seed (#92) Migrage use item & planting seed --- .../Action/PlantingSeedActionTests.cs | 41 ++++--- .../Action/UseRandomSeedItemActionTests.cs | 115 ------------------ .../app/Savor22b/Action/PlantingSeedAction.cs | 51 ++++++-- .../Action/UseRandomSeedItemAction.cs | 97 --------------- .../app/Savor22b/GraphTypes/Query/Query.cs | 43 ++----- 5 files changed, 73 insertions(+), 274 deletions(-) delete mode 100644 backend/app/Savor22b.Tests/Action/UseRandomSeedItemActionTests.cs delete mode 100644 backend/app/Savor22b/Action/UseRandomSeedItemAction.cs diff --git a/backend/app/Savor22b.Tests/Action/PlantingSeedActionTests.cs b/backend/app/Savor22b.Tests/Action/PlantingSeedActionTests.cs index f20c9e76..06d43c02 100644 --- a/backend/app/Savor22b.Tests/Action/PlantingSeedActionTests.cs +++ b/backend/app/Savor22b.Tests/Action/PlantingSeedActionTests.cs @@ -6,7 +6,6 @@ namespace Savor22b.Tests.Action; using Savor22b.Action; using Savor22b.States; using Savor22b.Action.Exceptions; -using System.Collections.Immutable; public class PlantingSeedActionTests : ActionTests { @@ -18,8 +17,10 @@ public PlantingSeedActionTests() private InventoryState getInventoryState() { InventoryState inventoryState = new InventoryState(); - var newSeed = new SeedState(Guid.NewGuid(), 1); - inventoryState = inventoryState.AddSeed(newSeed); + + var itemState = new ItemState(Guid.NewGuid(), 1); + inventoryState = inventoryState.AddItem(itemState); + return inventoryState; } @@ -58,10 +59,12 @@ public void Execute_ValidAction() SignerAddress(), beforeRootState.Serialize() ); + var beforeSeedGuid = Guid.NewGuid(); PlantingSeedAction plantingSeedAction = new PlantingSeedAction( - beforeRootState.InventoryState.SeedStateList[0].StateID, - 0 + beforeSeedGuid, + 0, + beforeRootState.InventoryState.ItemStateList[0].StateID ); var random = new DummyRandom(1); @@ -80,8 +83,9 @@ public void Execute_ValidAction() ? new RootState(bdict) : throw new Exception(); - Assert.Equal(rootState.VillageState!.HouseFieldStates[0]!.InstalledSeedGuid, beforeRootState.InventoryState.SeedStateList[0].StateID); - Assert.Equal(rootState.InventoryState.SeedStateList.Count, 0); + Assert.Equal(rootState.VillageState!.HouseFieldStates[0]!.InstalledSeedGuid, beforeSeedGuid); + Assert.Equal(rootState.InventoryState.SeedStateList.Count, 1); + Assert.Equal(rootState.InventoryState.ItemStateList.Count, 0); } [Fact] @@ -98,10 +102,12 @@ public void Execute_InvalidVillageState() SignerAddress(), beforeRootState.Serialize() ); + var beforeSeedGuid = Guid.NewGuid(); PlantingSeedAction plantingSeedAction = new PlantingSeedAction( - beforeRootState.InventoryState.SeedStateList[0].StateID, - 1 + beforeSeedGuid, + 1, + beforeRootState.InventoryState.ItemStateList[0].StateID ); var random = new DummyRandom(1); @@ -130,10 +136,12 @@ public void Execute_InvalidFieldIndex() SignerAddress(), beforeRootState.Serialize() ); + var beforeSeedGuid = Guid.NewGuid(); PlantingSeedAction plantingSeedAction = new PlantingSeedAction( - beforeRootState.InventoryState.SeedStateList[0].StateID, - VillageState.HouseFieldCount + 1 + beforeSeedGuid, + VillageState.HouseFieldCount + 1, + beforeRootState.InventoryState.ItemStateList[0].StateID ); var random = new DummyRandom(1); @@ -152,7 +160,7 @@ public void Execute_InvalidFieldIndex() } [Fact] - public void Execute_InvalidSeedStateId() + public void Execute_InvalidItemStateId() { IAccountStateDelta beforeState = new DummyState(); @@ -162,15 +170,17 @@ public void Execute_InvalidSeedStateId() SignerAddress(), beforeRootState.Serialize() ); + var beforeSeedGuid = Guid.NewGuid(); PlantingSeedAction plantingSeedAction = new PlantingSeedAction( - Guid.NewGuid(), - 0 + beforeSeedGuid, + 0, + Guid.NewGuid() ); var random = new DummyRandom(1); - Assert.Throws(() => + Assert.Throws(() => { plantingSeedAction.Execute(new DummyActionContext { @@ -182,5 +192,4 @@ public void Execute_InvalidSeedStateId() }); }); } - } diff --git a/backend/app/Savor22b.Tests/Action/UseRandomSeedItemActionTests.cs b/backend/app/Savor22b.Tests/Action/UseRandomSeedItemActionTests.cs deleted file mode 100644 index 87817c67..00000000 --- a/backend/app/Savor22b.Tests/Action/UseRandomSeedItemActionTests.cs +++ /dev/null @@ -1,115 +0,0 @@ -namespace Savor22b.Tests.Action; - -using System; -using Libplanet.Crypto; -using Libplanet.State; -using Xunit; -using Savor22b.Action; -using Savor22b.States; -using Libplanet; - -public class UseRandomSeedItemActionTests : ActionTests -{ - public UseRandomSeedItemActionTests() { } - - [Fact] - public void UseRandomSeedItemActionExecute_AddsSeedToSeedStateList() - { - var seedStateID = Guid.NewGuid(); - var random = new DummyRandom(1); - var villageId = 1; - - IAccountStateDelta state = new DummyState(); - RootState beforeRootState = new RootState(); - InventoryState beforeInventoryState = new InventoryState(); - - var itemState = new ItemState(Guid.NewGuid(), 1); - beforeInventoryState = beforeInventoryState.AddItem(itemState); - - beforeRootState.SetInventoryState(beforeInventoryState); - beforeRootState.SetVillageState( - new VillageState(new HouseState(villageId, 0, 0, new KitchenState())) - ); - - state = state.SetState(SignerAddress(), beforeRootState.Serialize()); - - var action = new UseRandomSeedItemAction(seedStateID, itemState.StateID); - - state = action.Execute( - new DummyActionContext - { - PreviousStates = state, - Signer = SignerAddress(), - Random = random, - Rehearsal = false, - BlockIndex = 1, - } - ); - - var rootStateEncoded = state.GetState(SignerAddress()); - RootState rootState = rootStateEncoded is Bencodex.Types.Dictionary bdict - ? new RootState(bdict) - : throw new Exception(); - InventoryState inventoryState = rootState.InventoryState; - - Assert.Equal(inventoryState.SeedStateList.Count, 1); - Assert.Equal(inventoryState.ItemStateList.Count, 0); - } - - [Theory] - [InlineData(1)] - [InlineData(5)] - [InlineData(10)] - [InlineData(100)] - [InlineData(1000)] - [InlineData(10000)] - public void UseRandomSeedItemActionExecute_AddsSeedStateToExistsSeedsList( - int existsSeedsListLength - ) - { - int villageId = 1; - - IAccountStateDelta state = new DummyState(); - var itemState = new ItemState(Guid.NewGuid(), 1); - RootState rootState = new RootState(); - InventoryState beforeInventoryState = new InventoryState(); - - for (int i = 0; i < existsSeedsListLength; i++) - { - var newSeed = new SeedState(Guid.NewGuid(), 1); - beforeInventoryState = beforeInventoryState.AddSeed(newSeed); - } - - beforeInventoryState = beforeInventoryState.AddItem(itemState); - rootState.SetInventoryState(beforeInventoryState); - rootState.SetVillageState( - new VillageState(new HouseState(villageId, 0, 0, new KitchenState())) - ); - - state = state.SetState(SignerAddress(), rootState.Serialize()); - - var random = new DummyRandom(1); - - var action = new UseRandomSeedItemAction(Guid.NewGuid(), itemState.StateID); - - state = action.Execute( - new DummyActionContext - { - PreviousStates = state, - Signer = SignerAddress(), - Random = random, - Rehearsal = false, - BlockIndex = 1, - } - ); - - var afterRootStateEncoded = state.GetState(SignerAddress()); - - RootState afterRootState = afterRootStateEncoded is Bencodex.Types.Dictionary bdict - ? new RootState(bdict) - : throw new Exception(); - - Assert.Equal(existsSeedsListLength + 1, afterRootState.InventoryState.SeedStateList.Count); - Assert.Equal(afterRootState.InventoryState.ItemStateList.Count, 0); - } -} diff --git a/backend/app/Savor22b/Action/PlantingSeedAction.cs b/backend/app/Savor22b/Action/PlantingSeedAction.cs index fefa6c90..7448d553 100644 --- a/backend/app/Savor22b/Action/PlantingSeedAction.cs +++ b/backend/app/Savor22b/Action/PlantingSeedAction.cs @@ -16,13 +16,15 @@ public class PlantingSeedAction : SVRAction { public Guid SeedGuid; public int FieldIndex; + public Guid ItemStateIdToUse; public PlantingSeedAction() { } - public PlantingSeedAction(Guid seedGuid, int fieldIndex) + public PlantingSeedAction(Guid seedGuid, int fieldIndex, Guid itemStateIdToUse) { SeedGuid = seedGuid; FieldIndex = fieldIndex; + ItemStateIdToUse = itemStateIdToUse; } protected override IImmutableDictionary PlainValueInternal => @@ -30,12 +32,14 @@ public PlantingSeedAction(Guid seedGuid, int fieldIndex) { [nameof(SeedGuid)] = SeedGuid.Serialize(), [nameof(FieldIndex)] = FieldIndex.Serialize(), + [nameof(ItemStateIdToUse)] = ItemStateIdToUse.Serialize() }.ToImmutableDictionary(); protected override void LoadPlainValueInternal(IImmutableDictionary plainValue) { SeedGuid = plainValue[nameof(SeedGuid)].ToGuid(); FieldIndex = plainValue[nameof(FieldIndex)].ToInteger(); + ItemStateIdToUse = plainValue[nameof(ItemStateIdToUse)].ToGuid(); } public void checkAndRaisePlantingAble(RootState rootState) @@ -54,13 +58,36 @@ public void checkAndRaisePlantingAble(RootState rootState) { throw new FieldAlreadyOccupiedException("Field is already occupied"); } + } + + private Seed generateRandomSeed(IRandom random, int villageId) + { + int randomIndex; + var seeds = CsvDataHelper.GetSeedCSVData(); + var village = CsvDataHelper.GetVillageCharacteristicByVillageId(villageId)!; + + do + { + randomIndex = random.Next(0, seeds.Count); + } while (!village.AvailableSeedIdList.Contains(seeds[randomIndex].Id)); + + var randomSeedCsvData = seeds[randomIndex]; + + return randomSeedCsvData; + } - SeedState? seedState = rootState.InventoryState.GetSeedState(SeedGuid); + private InventoryState FindAndRemoveItem(InventoryState state) + { + var item = state.ItemStateList.Find(state => state.StateID == ItemStateIdToUse); - if (seedState is null) + if (item is null) { - throw new NotFoundDataException("Seed not found"); + throw new NotHaveRequiredException($"You don't have `{ItemStateIdToUse}` item"); } + + state = state.RemoveItem(ItemStateIdToUse); + + return state; } public override IAccountStateDelta Execute(IActionContext ctx) @@ -76,18 +103,22 @@ is Bencodex.Types.Dictionary rootStateEncoded checkAndRaisePlantingAble(rootState); InventoryState inventoryState = rootState.InventoryState; - SeedState seedState = rootState.InventoryState.GetSeedState(SeedGuid)!; + inventoryState = FindAndRemoveItem(inventoryState); - inventoryState = inventoryState.RemoveSeed(SeedGuid); - rootState.SetInventoryState(inventoryState); + Seed seedCsvData = generateRandomSeed( + ctx.Random, + rootState.VillageState!.HouseState.VillageID + ); + var seedState = new SeedState(SeedGuid, seedCsvData.Id); + inventoryState = inventoryState.AddSeed(seedState); - Seed seed = CsvDataHelper.GetSeedById(seedState.SeedID)!; + rootState.SetInventoryState(inventoryState); HouseFieldState houseFieldState = new HouseFieldState( SeedGuid, - seedState.SeedID, + seedCsvData.Id, ctx.BlockIndex, - seed.RequiredBlock + seedCsvData.RequiredBlock ); rootState.VillageState!.UpdateHouseFieldState(FieldIndex, houseFieldState); diff --git a/backend/app/Savor22b/Action/UseRandomSeedItemAction.cs b/backend/app/Savor22b/Action/UseRandomSeedItemAction.cs deleted file mode 100644 index a3116beb..00000000 --- a/backend/app/Savor22b/Action/UseRandomSeedItemAction.cs +++ /dev/null @@ -1,97 +0,0 @@ -namespace Savor22b.Action; - -using System.Collections.Immutable; -using Bencodex.Types; -using Libplanet.Action; -using Libplanet.Headless.Extensions; -using Libplanet.State; -using Savor22b.Action.Exceptions; -using Savor22b.States; -using Savor22b.Action.Util; - -[ActionType(nameof(UseRandomSeedItemAction))] -public class UseRandomSeedItemAction : SVRAction -{ - public Guid SeedStateID; - public Guid ItemStateIdToUse; - - public UseRandomSeedItemAction() { } - - public UseRandomSeedItemAction(Guid seedStateID, Guid itemStateIdToUse) - { - SeedStateID = seedStateID; - ItemStateIdToUse = itemStateIdToUse; - } - - protected override IImmutableDictionary PlainValueInternal => - new Dictionary() - { - [nameof(SeedStateID)] = SeedStateID.Serialize(), - [nameof(ItemStateIdToUse)] = ItemStateIdToUse.Serialize() - }.ToImmutableDictionary(); - - protected override void LoadPlainValueInternal(IImmutableDictionary plainValue) - { - SeedStateID = plainValue[nameof(SeedStateID)].ToGuid(); - ItemStateIdToUse = plainValue[nameof(ItemStateIdToUse)].ToGuid(); - } - - private SeedState generateRandomSeed(IRandom random, int villageId) - { - int randomIndex; - var seeds = CsvDataHelper.GetSeedCSVData(); - var village = CsvDataHelper.GetVillageCharacteristicByVillageId(villageId)!; - - do - { - randomIndex = random.Next(0, seeds.Count); - } while (!village.AvailableSeedIdList.Contains(seeds[randomIndex].Id)); - - var randomSeedData = seeds[randomIndex]; - var randomSeed = new SeedState(SeedStateID, randomSeedData.Id); - - return randomSeed; - } - - private InventoryState FindAndRemoveItem(InventoryState state) - { - var item = state.ItemStateList.Find(state => state.StateID == ItemStateIdToUse); - - if (item is null) - { - throw new NotHaveRequiredException($"You don't have `{ItemStateIdToUse}` item"); - } - - state = state.RemoveItem(ItemStateIdToUse); - - return state; - } - - public override IAccountStateDelta Execute(IActionContext ctx) - { - IAccountStateDelta states = ctx.PreviousStates; - - RootState rootState = states.GetState(ctx.Signer) - is Bencodex.Types.Dictionary rootStateEncoded - ? new RootState(rootStateEncoded) - : new RootState(); - - Validation.EnsureVillageStateExists(rootState); - - InventoryState inventoryState = rootState.InventoryState; - - SeedState seedState = generateRandomSeed( - ctx.Random, - rootState.VillageState!.HouseState.VillageID - ); - inventoryState = FindAndRemoveItem(inventoryState); - inventoryState = inventoryState.AddSeed(seedState); - - rootState.SetInventoryState(inventoryState); - - var encodedValue = rootState.Serialize(); - var statesWithUpdated = states.SetState(ctx.Signer, encodedValue); - - return statesWithUpdated; - } -} diff --git a/backend/app/Savor22b/GraphTypes/Query/Query.cs b/backend/app/Savor22b/GraphTypes/Query/Query.cs index 28631974..442bac85 100644 --- a/backend/app/Savor22b/GraphTypes/Query/Query.cs +++ b/backend/app/Savor22b/GraphTypes/Query/Query.cs @@ -164,41 +164,6 @@ swarm is null } ); - Field>( - "createAction_UseRandomSeedItem", - description: "Use Random Seed Item", - arguments: new QueryArguments( - new QueryArgument> - { - Name = "publicKey", - Description = "The base64-encoded public key for Transaction.", - }, - new QueryArgument> - { - Name = "itemStateID", - Description = "item state id to use", - } - ), - resolve: context => - { - var publicKey = new PublicKey( - ByteUtil.ParseHex(context.GetArgument("publicKey")) - ); - - var action = new UseRandomSeedItemAction( - Guid.NewGuid(), - context.GetArgument("itemStateID") - ); - - return new GetUnsignedTransactionHex( - action, - publicKey, - _blockChain, - _swarm - ).UnsignedTransactionHex; - } - ); - Field>( "createAction_BuyKitchenEquipment", description: "Buy kitchen equipment", @@ -252,6 +217,11 @@ swarm is null { Name = "fieldIndex", Description = "Target field Index", + }, + new QueryArgument> + { + Name = "itemStateIdToUse", + Description = "Item state id to use (Guid)", } ), resolve: context => @@ -262,7 +232,8 @@ swarm is null var action = new PlantingSeedAction( context.GetArgument("seedStateId"), - context.GetArgument("fieldIndex") + context.GetArgument("fieldIndex"), + context.GetArgument("itemStateIdToUse") ); return new GetUnsignedTransactionHex( From fe4f9389d0ee6ae6c949a87a54e6acb81ba7c5cb Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Tue, 19 Dec 2023 17:46:41 +0900 Subject: [PATCH 06/51] implement intro scene --- frontend/Saver-22b-godot/scenes/intro.tscn | 12 ++++++++---- frontend/Saver-22b-godot/scripts/intro.gd | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 frontend/Saver-22b-godot/scripts/intro.gd diff --git a/frontend/Saver-22b-godot/scenes/intro.tscn b/frontend/Saver-22b-godot/scenes/intro.tscn index ac155cfb..f4f31e27 100644 --- a/frontend/Saver-22b-godot/scenes/intro.tscn +++ b/frontend/Saver-22b-godot/scenes/intro.tscn @@ -1,4 +1,6 @@ -[gd_scene format=3 uid="uid://cg773cnsx4rb0"] +[gd_scene load_steps=2 format=3 uid="uid://cg773cnsx4rb0"] + +[ext_resource type="Script" path="res://scripts/intro.gd" id="1_0m54y"] [node name="Intro" type="Control"] layout_mode = 3 @@ -7,6 +9,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("1_0m54y") [node name="Background" type="ColorRect" parent="."] layout_mode = 1 @@ -29,7 +32,7 @@ anchor_bottom = 0.5 offset_left = -400.0 offset_top = -240.0 offset_right = 400.0 -offset_bottom = 10.0005 +offset_bottom = 10.0 grow_horizontal = 2 grow_vertical = 2 color = Color(0, 0, 0, 1) @@ -65,7 +68,6 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme_type_variation = &"FlatButton" theme_override_font_sizes/font_size = 70 text = "Quit" @@ -91,6 +93,8 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -theme_type_variation = &"FlatButton" theme_override_font_sizes/font_size = 70 text = "Play" + +[connection signal="button_down" from="QuitButtonContainer/Button" to="." method="_on_quit_button_button_down"] +[connection signal="button_down" from="PlayButtonContainer/Button" to="." method="_on_play_button_button_down"] diff --git a/frontend/Saver-22b-godot/scripts/intro.gd b/frontend/Saver-22b-godot/scripts/intro.gd new file mode 100644 index 00000000..72b2f3b2 --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/intro.gd @@ -0,0 +1,12 @@ +extends Control + +func _ready(): + print("intro scene ready") + +func _on_quit_button_button_down(): + print("quit button down") + get_tree().quit() + +func _on_play_button_button_down(): + print("play button down") + get_tree().change_scene_to_file("res://scenes/select_village.tscn") From 3976ef8970bc33453772c86b76789a5eae19e6bd Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Tue, 19 Dec 2023 17:46:52 +0900 Subject: [PATCH 07/51] implement select_village scene --- .../scenes/select_village.tscn | 137 +++++++++++++++++- .../Saver-22b-godot/scripts/select_village.gd | 15 ++ 2 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 frontend/Saver-22b-godot/scripts/select_village.gd diff --git a/frontend/Saver-22b-godot/scenes/select_village.tscn b/frontend/Saver-22b-godot/scenes/select_village.tscn index 79a0f6ad..bcdc9ba0 100644 --- a/frontend/Saver-22b-godot/scenes/select_village.tscn +++ b/frontend/Saver-22b-godot/scenes/select_village.tscn @@ -1,4 +1,6 @@ -[gd_scene format=3 uid="uid://cl8vvgnebwyi1"] +[gd_scene load_steps=2 format=3 uid="uid://cl8vvgnebwyi1"] + +[ext_resource type="Script" path="res://scripts/select_village.gd" id="1_uohty"] [node name="SelectVillage" type="Control"] layout_mode = 3 @@ -7,6 +9,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +script = ExtResource("1_uohty") [node name="Background" type="ColorRect" parent="."] layout_mode = 1 @@ -17,3 +20,135 @@ offset_top = -1.0 offset_bottom = -1.0 grow_horizontal = 2 grow_vertical = 2 + +[node name="LeftMarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 9 +anchor_bottom = 1.0 +offset_right = 810.0 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_bottom = 10 + +[node name="Background" type="ColorRect" parent="LeftMarginContainer"] +layout_mode = 2 +color = Color(0, 0, 0, 1) + +[node name="VillagesVBoxContainer" type="VBoxContainer" parent="LeftMarginContainer"] +layout_mode = 2 + +[node name="VillageMarginContainer" type="MarginContainer" parent="LeftMarginContainer/VillagesVBoxContainer"] +custom_minimum_size = Vector2(2.08165e-12, 200) +layout_mode = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 + +[node name="Background" type="ColorRect" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer"] +layout_mode = 2 + +[node name="Button" type="Button" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 50 +text = "Village #1 +(Households X/Y)" + +[node name="VillageMarginContainer2" type="MarginContainer" parent="LeftMarginContainer/VillagesVBoxContainer"] +custom_minimum_size = Vector2(2.08165e-12, 200) +layout_mode = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 + +[node name="Background" type="ColorRect" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer2"] +layout_mode = 2 + +[node name="Button" type="Button" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer2"] +layout_mode = 2 +theme_override_font_sizes/font_size = 50 +text = "Village #2 +(Households X/Y)" + +[node name="VillageMarginContainer3" type="MarginContainer" parent="LeftMarginContainer/VillagesVBoxContainer"] +custom_minimum_size = Vector2(2.08165e-12, 200) +layout_mode = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 + +[node name="Background" type="ColorRect" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer3"] +layout_mode = 2 + +[node name="Button" type="Button" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer3"] +layout_mode = 2 +theme_override_font_sizes/font_size = 50 +text = "Village #3 +(Households X/Y)" + +[node name="RightMarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 11 +anchor_left = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -1100.0 +grow_horizontal = 0 +grow_vertical = 2 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="Background" type="ColorRect" parent="RightMarginContainer"] +layout_mode = 2 +color = Color(0, 0, 0, 1) + +[node name="MarginContainer" type="MarginContainer" parent="RightMarginContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="ColorRect" type="ColorRect" parent="RightMarginContainer/MarginContainer"] +layout_mode = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="RightMarginContainer/MarginContainer"] +layout_mode = 2 + +[node name="VillageInfoMarginContainer" type="MarginContainer" parent="RightMarginContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="Label" type="Label" parent="RightMarginContainer/MarginContainer/VBoxContainer/VillageInfoMarginContainer"] +layout_mode = 2 +size_flags_vertical = 1 +theme_override_colors/font_color = Color(0, 0, 0, 1) +theme_override_font_sizes/font_size = 50 +text = "This village's name is \"평범한 도시 1\". +ID: 1 +World Position: 5, 1 +Size: 3 x 11 +House Count: 1" + +[node name="StartButtonMarginContainer" type="MarginContainer" parent="RightMarginContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 10 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="StartButton" type="Button" parent="RightMarginContainer/MarginContainer/VBoxContainer/StartButtonMarginContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 70 +text = "Start" + +[connection signal="button_down" from="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer/Button" to="." method="_on_village_button_button_down" binds= [0]] +[connection signal="button_down" from="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer2/Button" to="." method="_on_village_button_button_down" binds= [1]] +[connection signal="button_down" from="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer3/Button" to="." method="_on_village_button_button_down" binds= [2]] +[connection signal="button_down" from="RightMarginContainer/MarginContainer/VBoxContainer/StartButtonMarginContainer/StartButton" to="." method="_on_start_button_button_down"] diff --git a/frontend/Saver-22b-godot/scripts/select_village.gd b/frontend/Saver-22b-godot/scripts/select_village.gd new file mode 100644 index 00000000..be0e8db2 --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/select_village.gd @@ -0,0 +1,15 @@ +extends Control + +var selected_village_index: int + +func _ready(): + print("select_village scene ready") + +func _on_village_button_button_down(extra_arg_0): + var format_string = "village button down: %s" + print(format_string % 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) From 3cd32d890e471ae19050bcad92c91fe39d51dc4a Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Tue, 19 Dec 2023 17:47:19 +0900 Subject: [PATCH 08/51] remove useless main scene --- frontend/Saver-22b-godot/project.godot | 2 +- frontend/Saver-22b-godot/scenes/main.tscn | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 frontend/Saver-22b-godot/scenes/main.tscn diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index 320bd000..25edefc5 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -11,7 +11,7 @@ config_version=5 [application] config/name="Saver-22b-godot" -run/main_scene="res://scenes/main.tscn" +run/main_scene="res://scenes/intro.tscn" config/features=PackedStringArray("4.2", "GL Compatibility") boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1) config/icon="res://icon.svg" diff --git a/frontend/Saver-22b-godot/scenes/main.tscn b/frontend/Saver-22b-godot/scenes/main.tscn deleted file mode 100644 index 7de7df03..00000000 --- a/frontend/Saver-22b-godot/scenes/main.tscn +++ /dev/null @@ -1,7 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://cjvywwt132ot5"] - -[ext_resource type="PackedScene" uid="uid://cg773cnsx4rb0" path="res://scenes/intro.tscn" id="1_hqty0"] - -[node name="Main" type="Node"] - -[node name="Intro" parent="." instance=ExtResource("1_hqty0")] From 224e9247db18a725f2796cc6eab6b58f823d551f Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Tue, 19 Dec 2023 18:29:38 +0900 Subject: [PATCH 09/51] add temporary resource for village background nine patch image --- frontend/Saver-22b-godot/32x32-black-line.png | Bin 0 -> 144 bytes .../32x32-black-line.png.import | 34 ++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 frontend/Saver-22b-godot/32x32-black-line.png create mode 100644 frontend/Saver-22b-godot/32x32-black-line.png.import diff --git a/frontend/Saver-22b-godot/32x32-black-line.png b/frontend/Saver-22b-godot/32x32-black-line.png new file mode 100644 index 0000000000000000000000000000000000000000..693e497f101c81ca167aa64c1076e940bf7d3152 GIT binary patch literal 144 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}UY;(FArY;~ z2@(khIF|nBpYqp-ImJ+BgFzopr0M|At(*OVf literal 0 HcmV?d00001 diff --git a/frontend/Saver-22b-godot/32x32-black-line.png.import b/frontend/Saver-22b-godot/32x32-black-line.png.import new file mode 100644 index 00000000..d3918f2e --- /dev/null +++ b/frontend/Saver-22b-godot/32x32-black-line.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://c0dwyky4dbhth" +path="res://.godot/imported/32x32-black-line.png-7f1f5bf1a785648628ee6c0fe73c0830.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://32x32-black-line.png" +dest_files=["res://.godot/imported/32x32-black-line.png-7f1f5bf1a785648628ee6c0fe73c0830.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 From 837e0840e669ee613b224caf3931be1ba5d5bb6e Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Tue, 19 Dec 2023 18:30:02 +0900 Subject: [PATCH 10/51] add temporary VillageView scene --- .../Saver-22b-godot/scenes/VillageView.gd | 29 +++++++++++++++++++ .../Saver-22b-godot/scenes/VillageView.tscn | 20 +++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 frontend/Saver-22b-godot/scenes/VillageView.gd create mode 100644 frontend/Saver-22b-godot/scenes/VillageView.tscn diff --git a/frontend/Saver-22b-godot/scenes/VillageView.gd b/frontend/Saver-22b-godot/scenes/VillageView.gd new file mode 100644 index 00000000..9f444f94 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/VillageView.gd @@ -0,0 +1,29 @@ +class_name VillageViewClass +extends Node + +@export_group("Village model") +@export var width: int +@export var height: int +@export var worldX: int +@export var worldY: int + +@export_group("View nodes") +@export var bg: NinePatchRect + +# Called when the node enters the scene tree for the first time. +# 이건 Start의 성격일지 Awake의 성격일지 아직은 잘 모르겠음 +func _ready(): + pass # Replace with function body. + +# Called every frame. 'delta' is the elapsed time since the previous frame. +# 이게 업데이트구나 +func _process(delta): + pass + # var newView = VillageViewClass.new(1,2,3,4) 이런식으로 사용하려나 + +# 이게 생성자고 +func _init(width:int, height: int, worldX: int, worldY: int): + self.width = width + self.height = height + self.worldX = worldX + self.worldY = worldY diff --git a/frontend/Saver-22b-godot/scenes/VillageView.tscn b/frontend/Saver-22b-godot/scenes/VillageView.tscn new file mode 100644 index 00000000..6dc3fc14 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/VillageView.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=3 format=3 uid="uid://dpd6n3ur5g4y5"] + +[ext_resource type="Script" path="res://scenes/VillageView.gd" id="1_7d86k"] +[ext_resource type="Texture2D" uid="uid://c0dwyky4dbhth" path="res://32x32-black-line.png" id="1_q1xwp"] + +[node name="Main" type="Node"] + +[node name="Node" type="Node" parent="." node_paths=PackedStringArray("bg")] +script = ExtResource("1_7d86k") +bg = NodePath("VillageBackground_NinePatchRect") + +[node name="VillageBackground_NinePatchRect" type="NinePatchRect" parent="Node"] +texture_filter = 1 +offset_right = 40.0 +offset_bottom = 40.0 +texture = ExtResource("1_q1xwp") +patch_margin_left = 3 +patch_margin_top = 3 +patch_margin_right = 3 +patch_margin_bottom = 3 From 570404dbf7b02b195e3c6b80e910aaa3d070c10f Mon Sep 17 00:00:00 2001 From: moreal Date: Tue, 19 Dec 2023 18:16:48 +0900 Subject: [PATCH 11/51] Implement signer --- .../Saver-22b-godot/Saver-22b-godot.csproj | 13 +++++ frontend/Saver-22b-godot/Saver-22b-godot.sln | 19 +++++++ frontend/Saver-22b-godot/project.godot | 6 +- .../Saver-22b-godot/scripts/sign/Signer.cs | 56 +++++++++++++++++++ .../Saver-22b-godot/scripts/sign/Signer.gd | 19 +++++++ 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 frontend/Saver-22b-godot/Saver-22b-godot.csproj create mode 100644 frontend/Saver-22b-godot/Saver-22b-godot.sln create mode 100644 frontend/Saver-22b-godot/scripts/sign/Signer.cs create mode 100644 frontend/Saver-22b-godot/scripts/sign/Signer.gd diff --git a/frontend/Saver-22b-godot/Saver-22b-godot.csproj b/frontend/Saver-22b-godot/Saver-22b-godot.csproj new file mode 100644 index 00000000..61ee597a --- /dev/null +++ b/frontend/Saver-22b-godot/Saver-22b-godot.csproj @@ -0,0 +1,13 @@ + + + net6.0 + net7.0 + net8.0 + true + Saver22bgodot + + + + + + \ No newline at end of file diff --git a/frontend/Saver-22b-godot/Saver-22b-godot.sln b/frontend/Saver-22b-godot/Saver-22b-godot.sln new file mode 100644 index 00000000..b8cea360 --- /dev/null +++ b/frontend/Saver-22b-godot/Saver-22b-godot.sln @@ -0,0 +1,19 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saver-22b-godot", "Saver-22b-godot.csproj", "{FF5B7943-8988-4850-8752-AEBDBCFD113F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + ExportDebug|Any CPU = ExportDebug|Any CPU + ExportRelease|Any CPU = ExportRelease|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FF5B7943-8988-4850-8752-AEBDBCFD113F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FF5B7943-8988-4850-8752-AEBDBCFD113F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FF5B7943-8988-4850-8752-AEBDBCFD113F}.ExportDebug|Any CPU.ActiveCfg = ExportDebug|Any CPU + {FF5B7943-8988-4850-8752-AEBDBCFD113F}.ExportDebug|Any CPU.Build.0 = ExportDebug|Any CPU + {FF5B7943-8988-4850-8752-AEBDBCFD113F}.ExportRelease|Any CPU.ActiveCfg = ExportRelease|Any CPU + {FF5B7943-8988-4850-8752-AEBDBCFD113F}.ExportRelease|Any CPU.Build.0 = ExportRelease|Any CPU + EndGlobalSection +EndGlobal diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index 25edefc5..937de724 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -12,10 +12,14 @@ config_version=5 config/name="Saver-22b-godot" run/main_scene="res://scenes/intro.tscn" -config/features=PackedStringArray("4.2", "GL Compatibility") +config/features=PackedStringArray("4.2", "C#", "GL Compatibility") boot_splash/bg_color=Color(0.141176, 0.141176, 0.141176, 1) config/icon="res://icon.svg" +[autoload] + +GlobalSigner="*res://scripts/sign/Signer.gd" + [display] window/size/viewport_width=1920 diff --git a/frontend/Saver-22b-godot/scripts/sign/Signer.cs b/frontend/Saver-22b-godot/scripts/sign/Signer.cs new file mode 100644 index 00000000..901a7b9d --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/sign/Signer.cs @@ -0,0 +1,56 @@ +using Godot; +using System; +using Libplanet.Crypto; + +public partial class Signer : Node +{ + private readonly PrivateKey _privateKey; + + public Signer(string privateKeyHex) + : this(PrivateKey.FromString(privateKeyHex)) + { + } + + public Signer(PrivateKey privateKey) + { + _privateKey = privateKey; + } + + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } + + // Returns signature. + public string Sign(string unsignedTransaction) + { + return Convert.ToHexString(_privateKey.Sign(Convert.FromHexString(unsignedTransaction))); + } + + public string GetPublicKey() + { + return Convert.ToHexString(_privateKey.PublicKey.Format(false)); + } + + public string GetRaw() + { + return Convert.ToHexString(_privateKey.ToByteArray()); + } + + public string GetAddress() + { + return _privateKey.Address.ToString(); + } + + public static Signer Generate() + { + return new Signer( + new PrivateKey() + ); + } +} diff --git a/frontend/Saver-22b-godot/scripts/sign/Signer.gd b/frontend/Saver-22b-godot/scripts/sign/Signer.gd new file mode 100644 index 00000000..20e76d3d --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/sign/Signer.gd @@ -0,0 +1,19 @@ +extends Node; + +var signer + +func _ready(): + var script = load("res://scripts/sign/Signer.cs") + if FileAccess.file_exists("user://privkey"): + var f = FileAccess.open("user://privkey", FileAccess.READ) + var content = f.get_as_text() + signer = script.new(content) + f.close() + else: + signer = script.Generate() + var f = FileAccess.open("user://privkey", FileAccess.WRITE) + f.store_string(signer.GetRaw()) + f.close() + +func sign(unsignedTransaction: String) -> String: + return self.signer.Sign(unsignedTransaction) From 94df9dc624454e2c1d010210286fec1769cecda0 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Tue, 19 Dec 2023 18:59:03 +0900 Subject: [PATCH 12/51] =?UTF-8?q?=EC=98=A4=EB=8A=98=20=EB=B0=B0=EC=9A=B4?= =?UTF-8?q?=EA=B1=B0:=20gdscript=EB=8A=94=20=EC=98=A4=EB=B2=84=EB=A1=9C?= =?UTF-8?q?=EB=93=9C=EA=B0=80=20=EC=95=88=EB=90=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Saver-22b-godot/scenes/VillageView.gd | 13 +++++++------ frontend/Saver-22b-godot/scenes/VillageView.tscn | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/frontend/Saver-22b-godot/scenes/VillageView.gd b/frontend/Saver-22b-godot/scenes/VillageView.gd index 9f444f94..f5a0f4f0 100644 --- a/frontend/Saver-22b-godot/scenes/VillageView.gd +++ b/frontend/Saver-22b-godot/scenes/VillageView.gd @@ -13,7 +13,8 @@ extends Node # Called when the node enters the scene tree for the first time. # 이건 Start의 성격일지 Awake의 성격일지 아직은 잘 모르겠음 func _ready(): - pass # Replace with function body. + bg.size.x = width + bg.size.y = height # Called every frame. 'delta' is the elapsed time since the previous frame. # 이게 업데이트구나 @@ -22,8 +23,8 @@ func _process(delta): # var newView = VillageViewClass.new(1,2,3,4) 이런식으로 사용하려나 # 이게 생성자고 -func _init(width:int, height: int, worldX: int, worldY: int): - self.width = width - self.height = height - self.worldX = worldX - self.worldY = worldY +#func _init(width:int, height: int, worldX: int, worldY: int): + #self.width = width + #self.height = height + #self.worldX = worldX + #self.worldY = worldY diff --git a/frontend/Saver-22b-godot/scenes/VillageView.tscn b/frontend/Saver-22b-godot/scenes/VillageView.tscn index 6dc3fc14..f7847ae4 100644 --- a/frontend/Saver-22b-godot/scenes/VillageView.tscn +++ b/frontend/Saver-22b-godot/scenes/VillageView.tscn @@ -7,6 +7,8 @@ [node name="Node" type="Node" parent="." node_paths=PackedStringArray("bg")] script = ExtResource("1_7d86k") +width = 1000 +height = 500 bg = NodePath("VillageBackground_NinePatchRect") [node name="VillageBackground_NinePatchRect" type="NinePatchRect" parent="Node"] From 040b8e217950c10978fc62d09d3bae92780c69c1 Mon Sep 17 00:00:00 2001 From: Jiwon Date: Wed, 20 Dec 2023 11:29:14 +0900 Subject: [PATCH 13/51] SVR-207 Implement gql client (#95) * Implement GraphQLClient * Remove print codes --- .../Saver-22b-godot/Saver-22b-godot.csproj | 2 ++ frontend/Saver-22b-godot/gql/GraphQLClient.cs | 34 +++++++++++++++++++ frontend/Saver-22b-godot/gql/Queries.cs | 16 +++++++++ frontend/Saver-22b-godot/project.godot | 1 + 4 files changed, 53 insertions(+) create mode 100644 frontend/Saver-22b-godot/gql/GraphQLClient.cs create mode 100644 frontend/Saver-22b-godot/gql/Queries.cs diff --git a/frontend/Saver-22b-godot/Saver-22b-godot.csproj b/frontend/Saver-22b-godot/Saver-22b-godot.csproj index 61ee597a..f7c09546 100644 --- a/frontend/Saver-22b-godot/Saver-22b-godot.csproj +++ b/frontend/Saver-22b-godot/Saver-22b-godot.csproj @@ -8,6 +8,8 @@ + + \ No newline at end of file diff --git a/frontend/Saver-22b-godot/gql/GraphQLClient.cs b/frontend/Saver-22b-godot/gql/GraphQLClient.cs new file mode 100644 index 00000000..a2230fa5 --- /dev/null +++ b/frontend/Saver-22b-godot/gql/GraphQLClient.cs @@ -0,0 +1,34 @@ +using Godot; +using GraphQL.Client; +using GraphQL.Client.Http; +using GraphQL.Client.Serializer.Newtonsoft; +using System.Threading.Tasks; + +public partial class GraphQLClient : Node +{ + private GraphQLHttpClient client; + + public static GraphQLClient Instance { get; private set; } + + public override void _Ready() + { + Instance = this; + + client = new GraphQLHttpClient("http://localhost:38080/graphql", new NewtonsoftJsonSerializer()); + } + + public async Task QueryAsync(string query) + { + var request = new GraphQLHttpRequest { Query = query }; + var response = await client.SendQueryAsync(request); + if (response.Errors != null) + { + GD.Print("Error: ", response.Errors[0].Message); + } + // else + // { + // GD.Print("Response: ", response.Data); + // } + return response.Data; + } +} diff --git a/frontend/Saver-22b-godot/gql/Queries.cs b/frontend/Saver-22b-godot/gql/Queries.cs new file mode 100644 index 00000000..0a472ec1 --- /dev/null +++ b/frontend/Saver-22b-godot/gql/Queries.cs @@ -0,0 +1,16 @@ +namespace GQL { + public static class Queries + { + public static string GetVillages => @" + query { + villages { + id + name + width + height + worldX + worldY + } + }"; + } +} diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index 937de724..910cd05f 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -19,6 +19,7 @@ config/icon="res://icon.svg" [autoload] GlobalSigner="*res://scripts/sign/Signer.gd" +GraphQlClient="*res://gql/GraphQLClient.cs" [display] From c9721e0911ebe470de5585763f0ae5cb9cf256ee Mon Sep 17 00:00:00 2001 From: Jiwon Date: Wed, 20 Dec 2023 13:43:33 +0900 Subject: [PATCH 14/51] Add config (#97) --- frontend/Saver-22b-godot/.gitignore | 1 + frontend/Saver-22b-godot/Config.cs | 26 +++++++++++++++++++ frontend/Saver-22b-godot/gql/GraphQLClient.cs | 2 +- frontend/Saver-22b-godot/project.godot | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 frontend/Saver-22b-godot/Config.cs diff --git a/frontend/Saver-22b-godot/.gitignore b/frontend/Saver-22b-godot/.gitignore index 47091836..3cfcbf94 100644 --- a/frontend/Saver-22b-godot/.gitignore +++ b/frontend/Saver-22b-godot/.gitignore @@ -1,2 +1,3 @@ # Godot 4+ specific ignores .godot/ +config.json \ No newline at end of file diff --git a/frontend/Saver-22b-godot/Config.cs b/frontend/Saver-22b-godot/Config.cs new file mode 100644 index 00000000..242eac9c --- /dev/null +++ b/frontend/Saver-22b-godot/Config.cs @@ -0,0 +1,26 @@ +using Godot; +using System; +using System.IO; +using Newtonsoft.Json.Linq; + +public partial class Config : Node +{ + public string GraphQLUrl { get; private set; } + + public static Config Instance { get; private set; } + + public override void _Ready() + { + Instance = this; + LoadConfig(); + } + + public void LoadConfig() + { + string filePath = "res://config.json"; // 파일 경로 + string jsonText = File.ReadAllText(filePath); + JObject config = JObject.Parse(jsonText); + + GraphQLUrl = config["GraphQLUrl"].ToString(); + } +} diff --git a/frontend/Saver-22b-godot/gql/GraphQLClient.cs b/frontend/Saver-22b-godot/gql/GraphQLClient.cs index a2230fa5..380820e9 100644 --- a/frontend/Saver-22b-godot/gql/GraphQLClient.cs +++ b/frontend/Saver-22b-godot/gql/GraphQLClient.cs @@ -14,7 +14,7 @@ public override void _Ready() { Instance = this; - client = new GraphQLHttpClient("http://localhost:38080/graphql", new NewtonsoftJsonSerializer()); + client = new GraphQLHttpClient(Config.Instance.GraphQLUrl, new NewtonsoftJsonSerializer()); } public async Task QueryAsync(string query) diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index 910cd05f..efd79037 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" GraphQlClient="*res://gql/GraphQLClient.cs" +Config="*res://Config.cs" [display] From a4d6866438b8e8dbd8fad1a1037d6b4e55e6cd0f Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 14:56:24 +0900 Subject: [PATCH 15/51] temporary VillageView implement --- .../Saver-22b-godot/scenes/VillageView.tscn | 22 ----------- .../{scenes => village_view}/VillageView.gd | 37 ++++++++++++------- .../village_view/VillageView.tscn | 13 +++++++ 3 files changed, 37 insertions(+), 35 deletions(-) delete mode 100644 frontend/Saver-22b-godot/scenes/VillageView.tscn rename frontend/Saver-22b-godot/{scenes => village_view}/VillageView.gd (50%) create mode 100644 frontend/Saver-22b-godot/village_view/VillageView.tscn diff --git a/frontend/Saver-22b-godot/scenes/VillageView.tscn b/frontend/Saver-22b-godot/scenes/VillageView.tscn deleted file mode 100644 index f7847ae4..00000000 --- a/frontend/Saver-22b-godot/scenes/VillageView.tscn +++ /dev/null @@ -1,22 +0,0 @@ -[gd_scene load_steps=3 format=3 uid="uid://dpd6n3ur5g4y5"] - -[ext_resource type="Script" path="res://scenes/VillageView.gd" id="1_7d86k"] -[ext_resource type="Texture2D" uid="uid://c0dwyky4dbhth" path="res://32x32-black-line.png" id="1_q1xwp"] - -[node name="Main" type="Node"] - -[node name="Node" type="Node" parent="." node_paths=PackedStringArray("bg")] -script = ExtResource("1_7d86k") -width = 1000 -height = 500 -bg = NodePath("VillageBackground_NinePatchRect") - -[node name="VillageBackground_NinePatchRect" type="NinePatchRect" parent="Node"] -texture_filter = 1 -offset_right = 40.0 -offset_bottom = 40.0 -texture = ExtResource("1_q1xwp") -patch_margin_left = 3 -patch_margin_top = 3 -patch_margin_right = 3 -patch_margin_bottom = 3 diff --git a/frontend/Saver-22b-godot/scenes/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd similarity index 50% rename from frontend/Saver-22b-godot/scenes/VillageView.gd rename to frontend/Saver-22b-godot/village_view/VillageView.gd index f5a0f4f0..645367b7 100644 --- a/frontend/Saver-22b-godot/scenes/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -1,11 +1,11 @@ class_name VillageViewClass extends Node -@export_group("Village model") -@export var width: int -@export var height: int -@export var worldX: int -@export var worldY: int +var width: int +var height: int +var worldX: int +var worldY: int +var root_position: Vector2 @export_group("View nodes") @export var bg: NinePatchRect @@ -13,8 +13,7 @@ extends Node # Called when the node enters the scene tree for the first time. # 이건 Start의 성격일지 Awake의 성격일지 아직은 잘 모르겠음 func _ready(): - bg.size.x = width - bg.size.y = height + set_size() # Called every frame. 'delta' is the elapsed time since the previous frame. # 이게 업데이트구나 @@ -22,9 +21,21 @@ func _process(delta): pass # var newView = VillageViewClass.new(1,2,3,4) 이런식으로 사용하려나 -# 이게 생성자고 -#func _init(width:int, height: int, worldX: int, worldY: int): - #self.width = width - #self.height = height - #self.worldX = worldX - #self.worldY = worldY +func initialize(width: int, height: int, worldX: int, worldY: int, houses=[]): + self.width = width + self.height = height + self.worldX = worldX + self.worldY = worldY + set_size() + + for house in houses.filter(func (argc): argc is Vector2): + instantiate_house(house) + +func set_size(): + bg.size.x = width + bg.size.y = height + root_position = Vector2(width/2, height/2) + bg.set_position(root_position) + +func instantiate_house(pos: Vector2): + pass diff --git a/frontend/Saver-22b-godot/village_view/VillageView.tscn b/frontend/Saver-22b-godot/village_view/VillageView.tscn new file mode 100644 index 00000000..8314d469 --- /dev/null +++ b/frontend/Saver-22b-godot/village_view/VillageView.tscn @@ -0,0 +1,13 @@ +[gd_scene load_steps=2 format=3 uid="uid://dpd6n3ur5g4y5"] + +[ext_resource type="Script" path="res://village_view/TemporaryView.gd" id="1_n4pdo"] + +[node name="Control" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +pivot_offset = Vector2(960, 540) +script = ExtResource("1_n4pdo") From d9f6382a75a1eb889f5ce69ce9cffd0e0937cc32 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 14:57:25 +0900 Subject: [PATCH 16/51] real temp village view using example --- .../village_view/TemporaryView.gd | 9 +++++++ .../village_background_nine_patch_rect.tscn | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 frontend/Saver-22b-godot/village_view/TemporaryView.gd create mode 100644 frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn diff --git a/frontend/Saver-22b-godot/village_view/TemporaryView.gd b/frontend/Saver-22b-godot/village_view/TemporaryView.gd new file mode 100644 index 00000000..f84d4a66 --- /dev/null +++ b/frontend/Saver-22b-godot/village_view/TemporaryView.gd @@ -0,0 +1,9 @@ +extends Node +const village_view_node = preload("res://village_view/village_background_nine_patch_rect.tscn") + +# Called when the node enters the scene tree for the first time. +func _ready(): + var village_view_instance = village_view_node.instantiate() + village_view_instance.set_name("view") + add_child(village_view_instance) + village_view_instance.initialize(1000,500,0,0) diff --git a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn new file mode 100644 index 00000000..78ac7e4d --- /dev/null +++ b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=3 format=3 uid="uid://bnut6era2lyw3"] + +[ext_resource type="Texture2D" uid="uid://c0dwyky4dbhth" path="res://32x32-black-line.png" id="1_ig6sc"] +[ext_resource type="Script" path="res://village_view/VillageView.gd" id="2_1w4b1"] + +[node name="VillageBackground_NinePatchRect" type="NinePatchRect" node_paths=PackedStringArray("bg")] +texture_filter = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -960.0 +offset_top = -540.0 +offset_right = -920.0 +offset_bottom = -500.0 +grow_horizontal = 2 +grow_vertical = 2 +pivot_offset = Vector2(20, 20) +texture = ExtResource("1_ig6sc") +patch_margin_left = 3 +patch_margin_top = 3 +patch_margin_right = 3 +patch_margin_bottom = 3 +script = ExtResource("2_1w4b1") +bg = NodePath(".") From 14e2a27a36a9f349bec205e1eb1eafd4d4381a22 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 15:26:00 +0900 Subject: [PATCH 17/51] =?UTF-8?q?=EC=A7=84=EC=A7=9C=20=EC=A7=91=EB=93=A4?= =?UTF-8?q?=EA=B9=8C=EC=A7=80=20=EC=9D=B8=EC=9E=90=EB=A1=9C=20=EB=B0=9B?= =?UTF-8?q?=EA=B2=8C=20=ED=96=88=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Saver-22b-godot/village_view/TemporaryView.gd | 2 +- frontend/Saver-22b-godot/village_view/VillageView.gd | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/frontend/Saver-22b-godot/village_view/TemporaryView.gd b/frontend/Saver-22b-godot/village_view/TemporaryView.gd index f84d4a66..8a678ef7 100644 --- a/frontend/Saver-22b-godot/village_view/TemporaryView.gd +++ b/frontend/Saver-22b-godot/village_view/TemporaryView.gd @@ -6,4 +6,4 @@ func _ready(): var village_view_instance = village_view_node.instantiate() village_view_instance.set_name("view") add_child(village_view_instance) - village_view_instance.initialize(1000,500,0,0) + 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 645367b7..dddbceb4 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -27,8 +27,7 @@ func initialize(width: int, height: int, worldX: int, worldY: int, houses=[]): self.worldX = worldX self.worldY = worldY set_size() - - for house in houses.filter(func (argc): argc is Vector2): + for house in houses.filter(func (argc): return argc is Vector2): instantiate_house(house) func set_size(): @@ -38,4 +37,4 @@ func set_size(): bg.set_position(root_position) func instantiate_house(pos: Vector2): - pass + print("instantiate_house: ", pos) From 13cf0ab3d6e53650103276a30b52400ade346375 Mon Sep 17 00:00:00 2001 From: Jiwon Date: Wed, 20 Dec 2023 16:08:30 +0900 Subject: [PATCH 18/51] Implement gql client (re) (#99) --- .../Query/GetUnsignedTransactionHex.cs | 6 ++-- frontend/Saver-22b-godot/Config.cs | 26 -------------- frontend/Saver-22b-godot/gql/GraphQLClient.cs | 34 ------------------- frontend/Saver-22b-godot/gql/Queries.cs | 16 --------- frontend/Saver-22b-godot/gql/query.gd | 10 ++++++ .../Saver-22b-godot/gql/svr_gql_client.gd | 5 +++ frontend/Saver-22b-godot/project.godot | 9 +++-- .../scenes/install_kitchen_equipment.tscn | 21 ++++++++++++ frontend/Saver-22b-godot/scenes/intro.tscn | 6 +++- frontend/Saver-22b-godot/scripts/gql_test.gd | 27 +++++++++++++++ 10 files changed, 78 insertions(+), 82 deletions(-) delete mode 100644 frontend/Saver-22b-godot/Config.cs delete mode 100644 frontend/Saver-22b-godot/gql/GraphQLClient.cs delete mode 100644 frontend/Saver-22b-godot/gql/Queries.cs create mode 100644 frontend/Saver-22b-godot/gql/query.gd create mode 100644 frontend/Saver-22b-godot/gql/svr_gql_client.gd create mode 100644 frontend/Saver-22b-godot/scenes/install_kitchen_equipment.tscn create mode 100644 frontend/Saver-22b-godot/scripts/gql_test.gd diff --git a/backend/app/Savor22b/GraphTypes/Query/GetUnsignedTransactionHex.cs b/backend/app/Savor22b/GraphTypes/Query/GetUnsignedTransactionHex.cs index f3e3aa24..79f1a954 100644 --- a/backend/app/Savor22b/GraphTypes/Query/GetUnsignedTransactionHex.cs +++ b/backend/app/Savor22b/GraphTypes/Query/GetUnsignedTransactionHex.cs @@ -42,9 +42,9 @@ public GetUnsignedTransactionHex( _blockChain = blockChain; _swarm = swarm; -#if DEBUG - Signing(UnsignedTransactionHex); -#endif +// #if DEBUG +// Signing(UnsignedTransactionHex); +// #endif } public string UnsignedTransactionHex { get; private set; } diff --git a/frontend/Saver-22b-godot/Config.cs b/frontend/Saver-22b-godot/Config.cs deleted file mode 100644 index 242eac9c..00000000 --- a/frontend/Saver-22b-godot/Config.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Godot; -using System; -using System.IO; -using Newtonsoft.Json.Linq; - -public partial class Config : Node -{ - public string GraphQLUrl { get; private set; } - - public static Config Instance { get; private set; } - - public override void _Ready() - { - Instance = this; - LoadConfig(); - } - - public void LoadConfig() - { - string filePath = "res://config.json"; // 파일 경로 - string jsonText = File.ReadAllText(filePath); - JObject config = JObject.Parse(jsonText); - - GraphQLUrl = config["GraphQLUrl"].ToString(); - } -} diff --git a/frontend/Saver-22b-godot/gql/GraphQLClient.cs b/frontend/Saver-22b-godot/gql/GraphQLClient.cs deleted file mode 100644 index 380820e9..00000000 --- a/frontend/Saver-22b-godot/gql/GraphQLClient.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Godot; -using GraphQL.Client; -using GraphQL.Client.Http; -using GraphQL.Client.Serializer.Newtonsoft; -using System.Threading.Tasks; - -public partial class GraphQLClient : Node -{ - private GraphQLHttpClient client; - - public static GraphQLClient Instance { get; private set; } - - public override void _Ready() - { - Instance = this; - - client = new GraphQLHttpClient(Config.Instance.GraphQLUrl, new NewtonsoftJsonSerializer()); - } - - public async Task QueryAsync(string query) - { - var request = new GraphQLHttpRequest { Query = query }; - var response = await client.SendQueryAsync(request); - if (response.Errors != null) - { - GD.Print("Error: ", response.Errors[0].Message); - } - // else - // { - // GD.Print("Response: ", response.Data); - // } - return response.Data; - } -} diff --git a/frontend/Saver-22b-godot/gql/Queries.cs b/frontend/Saver-22b-godot/gql/Queries.cs deleted file mode 100644 index 0a472ec1..00000000 --- a/frontend/Saver-22b-godot/gql/Queries.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace GQL { - public static class Queries - { - public static string GetVillages => @" - query { - villages { - id - name - width - height - worldX - worldY - } - }"; - } -} diff --git a/frontend/Saver-22b-godot/gql/query.gd b/frontend/Saver-22b-godot/gql/query.gd new file mode 100644 index 00000000..645c0163 --- /dev/null +++ b/frontend/Saver-22b-godot/gql/query.gd @@ -0,0 +1,10 @@ +var get_villages_query = "query { + villages { + id + name + width + height + worldX + worldY + } +}" diff --git a/frontend/Saver-22b-godot/gql/svr_gql_client.gd b/frontend/Saver-22b-godot/gql/svr_gql_client.gd new file mode 100644 index 00000000..12099a28 --- /dev/null +++ b/frontend/Saver-22b-godot/gql/svr_gql_client.gd @@ -0,0 +1,5 @@ +extends GQLClient + +func _ready(): + print("client ready") + set_endpoint(false, "localhost", 38080, "/graphql") diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index efd79037..68894b15 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -19,8 +19,7 @@ config/icon="res://icon.svg" [autoload] GlobalSigner="*res://scripts/sign/Signer.gd" -GraphQlClient="*res://gql/GraphQLClient.cs" -Config="*res://Config.cs" +SvrGqlClient="*res://gql/svr_gql_client.gd" [display] @@ -32,6 +31,12 @@ window/stretch/mode="canvas_items" project/assembly_name="Saver-22b-godot" +[file_customization] + +folder_colors={ +"res://scenes/": "yellow" +} + [rendering] renderer/rendering_method="gl_compatibility" diff --git a/frontend/Saver-22b-godot/scenes/install_kitchen_equipment.tscn b/frontend/Saver-22b-godot/scenes/install_kitchen_equipment.tscn new file mode 100644 index 00000000..e2b425e7 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/install_kitchen_equipment.tscn @@ -0,0 +1,21 @@ +[gd_scene format=3 uid="uid://c7g8if1jb33im"] + +[node name="InstallKitchenEquipment" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -1.0 +offset_right = -1120.0 +offset_bottom = -581.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(1, 0.623529, 0, 1) diff --git a/frontend/Saver-22b-godot/scenes/intro.tscn b/frontend/Saver-22b-godot/scenes/intro.tscn index f4f31e27..ee4ce9f9 100644 --- a/frontend/Saver-22b-godot/scenes/intro.tscn +++ b/frontend/Saver-22b-godot/scenes/intro.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://cg773cnsx4rb0"] +[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/gql_test.gd" id="2_yxm3e"] [node name="Intro" type="Control"] layout_mode = 3 @@ -96,5 +97,8 @@ grow_vertical = 2 theme_override_font_sizes/font_size = 70 text = "Play" +[node name="gql_test" type="Node" parent="."] +script = ExtResource("2_yxm3e") + [connection signal="button_down" from="QuitButtonContainer/Button" to="." method="_on_quit_button_button_down"] [connection signal="button_down" from="PlayButtonContainer/Button" to="." method="_on_play_button_button_down"] diff --git a/frontend/Saver-22b-godot/scripts/gql_test.gd b/frontend/Saver-22b-godot/scripts/gql_test.gd new file mode 100644 index 00000000..4d3b39fd --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/gql_test.gd @@ -0,0 +1,27 @@ +extends Node + +var queryExecutor: GQLQueryExecuter + +# Called when the node enters the scene tree for the first time. +func _ready(): + var query = GQLQuery.new("villages").set_props([ + "id", + "name", + "width", + "height", + "worldX", + "worldY", + ]) + + queryExecutor = SvrGqlClient.query('query', {}, query) + queryExecutor.graphql_response.connect(self.graphql_response) + add_child(queryExecutor) + + queryExecutor.run({}) + +func graphql_response(data: Dictionary): + print(data) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass From 7153bb349a2d02ed184ab7d1b7aa3c034da0b838 Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 15:31:50 +0900 Subject: [PATCH 19/51] 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 20/51] 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 21/51] 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 From 455bf4e27880ccb71aa675c5751728e1dbc79d4d Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 17:10:35 +0900 Subject: [PATCH 22/51] add GodotGraphQL as submodule --- .gitmodules | 3 +++ frontend/Saver-22b-godot/addons/GodotGraphQL | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 frontend/Saver-22b-godot/addons/GodotGraphQL diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..0de08e14 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "frontend/Saver-22b-godot/addons/GodotGraphQL"] + path = frontend/Saver-22b-godot/addons/GodotGraphQL + url = https://github.com/Dracks/GodotGraphQL.git diff --git a/frontend/Saver-22b-godot/addons/GodotGraphQL b/frontend/Saver-22b-godot/addons/GodotGraphQL new file mode 160000 index 00000000..8a484863 --- /dev/null +++ b/frontend/Saver-22b-godot/addons/GodotGraphQL @@ -0,0 +1 @@ +Subproject commit 8a484863138eb0615d8260a0b1d9a97f4b4a5757 From bfc3434826824e65fe4c941961f332d627fbeb6e Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 17:11:08 +0900 Subject: [PATCH 23/51] fix GraphQL endpoint --- frontend/Saver-22b-godot/gql/svr_gql_client.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Saver-22b-godot/gql/svr_gql_client.gd b/frontend/Saver-22b-godot/gql/svr_gql_client.gd index 12099a28..ca53901e 100644 --- a/frontend/Saver-22b-godot/gql/svr_gql_client.gd +++ b/frontend/Saver-22b-godot/gql/svr_gql_client.gd @@ -2,4 +2,4 @@ extends GQLClient func _ready(): print("client ready") - set_endpoint(false, "localhost", 38080, "/graphql") + set_endpoint(false, "192.168.2.9", 38080, "/graphql") From 1afdc52bcd5491e39503d6109e23e49d793456ab Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 17:11:34 +0900 Subject: [PATCH 24/51] query villages --- .../scripts/global/scene_context.gd | 46 +------------------ .../Saver-22b-godot/scripts/scenes/intro.gd | 22 +++++++++ 2 files changed, 24 insertions(+), 44 deletions(-) diff --git a/frontend/Saver-22b-godot/scripts/global/scene_context.gd b/frontend/Saver-22b-godot/scripts/global/scene_context.gd index 9cabf3e1..431d531c 100644 --- a/frontend/Saver-22b-godot/scripts/global/scene_context.gd +++ b/frontend/Saver-22b-godot/scripts/global/scene_context.gd @@ -1,52 +1,10 @@ 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 set_villages(query_data: Dictionary): + villages = query_data.data.villages func get_selected_village(): return villages[selected_village_index] diff --git a/frontend/Saver-22b-godot/scripts/scenes/intro.gd b/frontend/Saver-22b-godot/scripts/scenes/intro.gd index 72b2f3b2..ada2e83d 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/intro.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/intro.gd @@ -2,6 +2,7 @@ extends Control func _ready(): print("intro scene ready") + _query_villages() func _on_quit_button_button_down(): print("quit button down") @@ -10,3 +11,24 @@ func _on_quit_button_button_down(): func _on_play_button_button_down(): print("play button down") get_tree().change_scene_to_file("res://scenes/select_village.tscn") + +func _query_villages(): + var query = GQLQuery.new("villages").set_props([ + "id", + "name", + "width", + "height", + "worldX", + "worldY", + GQLQuery.new("houses").set_props([ + "x", + "y", + "owner", + ]), + ]) + + var query_executor = SvrGqlClient.query('query', {}, query) + query_executor.graphql_response.connect(func(data): + SceneContext.set_villages(data)) + add_child(query_executor) + query_executor.run({}) From 1559ca1ecce42761f340a42241883eccf4c5a0d3 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 15:45:23 +0900 Subject: [PATCH 25/51] add sprites directory --- .../{ => sprites}/32x32-black-line.png | Bin .../{ => sprites}/32x32-black-line.png.import | 6 ++-- frontend/Saver-22b-godot/sprites/house.png | Bin 0 -> 333 bytes .../Saver-22b-godot/sprites/house.png.import | 34 ++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) rename frontend/Saver-22b-godot/{ => sprites}/32x32-black-line.png (100%) rename frontend/Saver-22b-godot/{ => sprites}/32x32-black-line.png.import (70%) create mode 100644 frontend/Saver-22b-godot/sprites/house.png create mode 100644 frontend/Saver-22b-godot/sprites/house.png.import diff --git a/frontend/Saver-22b-godot/32x32-black-line.png b/frontend/Saver-22b-godot/sprites/32x32-black-line.png similarity index 100% rename from frontend/Saver-22b-godot/32x32-black-line.png rename to frontend/Saver-22b-godot/sprites/32x32-black-line.png diff --git a/frontend/Saver-22b-godot/32x32-black-line.png.import b/frontend/Saver-22b-godot/sprites/32x32-black-line.png.import similarity index 70% rename from frontend/Saver-22b-godot/32x32-black-line.png.import rename to frontend/Saver-22b-godot/sprites/32x32-black-line.png.import index d3918f2e..5809c60c 100644 --- a/frontend/Saver-22b-godot/32x32-black-line.png.import +++ b/frontend/Saver-22b-godot/sprites/32x32-black-line.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://c0dwyky4dbhth" -path="res://.godot/imported/32x32-black-line.png-7f1f5bf1a785648628ee6c0fe73c0830.ctex" +path="res://.godot/imported/32x32-black-line.png-bc6c28e8447eddaa67f294959080df4f.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://32x32-black-line.png" -dest_files=["res://.godot/imported/32x32-black-line.png-7f1f5bf1a785648628ee6c0fe73c0830.ctex"] +source_file="res://sprites/32x32-black-line.png" +dest_files=["res://.godot/imported/32x32-black-line.png-bc6c28e8447eddaa67f294959080df4f.ctex"] [params] diff --git a/frontend/Saver-22b-godot/sprites/house.png b/frontend/Saver-22b-godot/sprites/house.png new file mode 100644 index 0000000000000000000000000000000000000000..4a1430f5408e94082b0330fd8f35477ecd36d141 GIT binary patch literal 333 zcmV-T0kZyyP)Px$2T4RhR9J=8mO&1LAPhynlR1#_EZ)N%hj8aT<}Ab;F`L1VX`!WHh}~%{@6px( z@bCz&3%o|c0buF`x2|KVKmdTxvXq2w6X4)Y5;X!PxLHCgpn;ntGy*m7G)E;O30UAH z-zv}wS4rglUlG1~Un|10xC*FuZkP*EpjX+|5~Kn*!dVF-uzD}{*U*3L+l+mi$$KIY zKaxbWmCAu*ymLta;EwZ>h(OKmOF)%CNhFnN0jmVKg}JI&z%i=t18Gk!!`Ljqi3}0w z6~hHoL)atSagGuA1CtYx2)N_yGF%ckCouhzuLGl2Mhngfki=A`BvcD-iFn}*`! Date: Wed, 20 Dec 2023 15:45:40 +0900 Subject: [PATCH 26/51] reflect moved resource path --- .../village_view/village_background_nine_patch_rect.tscn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn index 78ac7e4d..14a9f3e9 100644 --- a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn +++ b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=3 uid="uid://bnut6era2lyw3"] -[ext_resource type="Texture2D" uid="uid://c0dwyky4dbhth" path="res://32x32-black-line.png" id="1_ig6sc"] +[ext_resource type="Texture2D" uid="uid://c0dwyky4dbhth" path="res://sprites/32x32-black-line.png" id="1_ig6sc"] [ext_resource type="Script" path="res://village_view/VillageView.gd" id="2_1w4b1"] [node name="VillageBackground_NinePatchRect" type="NinePatchRect" node_paths=PackedStringArray("bg")] From bddd3d62641ced5939e1983c7f60c274b74e8937 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 15:55:19 +0900 Subject: [PATCH 27/51] =?UTF-8?q?=EC=A7=91=EC=9D=84=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=B4=EC=84=9C=20=EC=84=A4=EC=B9=98=ED=95=B4=EB=B3=B4?= =?UTF-8?q?=EC=95=98=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Saver-22b-godot/village_view/VillageView.gd | 5 +++++ .../Saver-22b-godot/village_view/house_texture_rect.tscn | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 frontend/Saver-22b-godot/village_view/house_texture_rect.tscn diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index da38f369..e122e830 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -10,6 +10,8 @@ var root_position: Vector2 @export_group("View nodes") @export var bg: NinePatchRect +const Origin_house = preload("res://village_view/house_texture_rect.tscn") + # Called when the node enters the scene tree for the first time. # 이건 Start의 성격일지 Awake의 성격일지 아직은 잘 모르겠음 func _ready(): @@ -47,3 +49,6 @@ func set_size(): func instantiate_house(pos: Vector2): print("instantiate_house: ", pos) + var house = Origin_house.instantiate() + add_child(house) + house.set_position(root_position + pos) diff --git a/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn b/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn new file mode 100644 index 00000000..70f1b78f --- /dev/null +++ b/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=3 uid="uid://cjvcx7fit5avb"] + +[ext_resource type="Texture2D" uid="uid://dajunmx26gvr5" path="res://sprites/house.png" id="1_4yb37"] + +[node name="House_TextureRect" type="TextureRect"] +offset_right = 40.0 +offset_bottom = 40.0 +texture = ExtResource("1_4yb37") From dc35cbb586ca8919a11e820c64bb3993092ceba1 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 17:54:08 +0900 Subject: [PATCH 28/51] =?UTF-8?q?=EB=A7=88=EC=9D=84=20=EC=82=AC=EC=9D=B4?= =?UTF-8?q?=EC=A6=88/=EC=9C=84=EC=B9=98=20=EB=A6=AC=EC=85=8B,=20=EC=A7=91?= =?UTF-8?q?=20=EC=9C=84=EC=B9=98=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Saver-22b-godot/village_view/VillageView.gd | 15 ++++++++------- .../village_background_nine_patch_rect.tscn | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index e122e830..9e38feff 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -11,6 +11,7 @@ var root_position: Vector2 @export var bg: NinePatchRect const Origin_house = preload("res://village_view/house_texture_rect.tscn") +const Coordinate_weight = 300 # Called when the node enters the scene tree for the first time. # 이건 Start의 성격일지 Awake의 성격일지 아직은 잘 모르겠음 @@ -25,11 +26,11 @@ func _process(delta): func initialize_by_village(village: Dictionary): initialize( - village.width * 50, - village.height * 50, + village.width * Coordinate_weight, + village.height * Coordinate_weight, village.worldX, village.worldY, - village.houses.map(func(house): return Vector2(house.x, house.y) * 50) + village.houses.map(func(house): return Vector2(house.x, house.y)) ) func initialize(width: int, height: int, worldX: int, worldY: int, houses=[]): @@ -44,11 +45,11 @@ func initialize(width: int, height: int, worldX: int, worldY: int, houses=[]): func set_size(): bg.size.x = width bg.size.y = height - root_position = Vector2(width/2, height/2) - bg.set_position(root_position) + bg.set_anchors_and_offsets_preset(Control.PRESET_CENTER, Control.PRESET_MODE_KEEP_SIZE) + root_position = get_tree().root.size / 2 func instantiate_house(pos: Vector2): print("instantiate_house: ", pos) var house = Origin_house.instantiate() - add_child(house) - house.set_position(root_position + pos) + bg.add_child(house) + house.set_global_position(root_position + pos * Coordinate_weight) diff --git a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn index 14a9f3e9..bf9b15d9 100644 --- a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn +++ b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn @@ -4,6 +4,7 @@ [ext_resource type="Script" path="res://village_view/VillageView.gd" id="2_1w4b1"] [node name="VillageBackground_NinePatchRect" type="NinePatchRect" node_paths=PackedStringArray("bg")] +z_index = -1000 texture_filter = 1 anchors_preset = 8 anchor_left = 0.5 From 21a3b34fa8b847774441289a5f9ea8201998e825 Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 18:16:10 +0900 Subject: [PATCH 29/51] separate select_village_village_button scene --- .../ui/select_village_village_button.gd | 27 +++++++++++++++++++ .../ui/select_village_village_button.tscn | 21 +++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 frontend/Saver-22b-godot/ui/select_village_village_button.gd create mode 100644 frontend/Saver-22b-godot/ui/select_village_village_button.tscn diff --git a/frontend/Saver-22b-godot/ui/select_village_village_button.gd b/frontend/Saver-22b-godot/ui/select_village_village_button.gd new file mode 100644 index 00000000..d1a0355b --- /dev/null +++ b/frontend/Saver-22b-godot/ui/select_village_village_button.gd @@ -0,0 +1,27 @@ +extends MarginContainer + +signal button_down(child_index: int) + +@onready var button = $Button + +var village: Dictionary + +func _ready(): + _update_button() + +func _update_button(): + if button == null: + return + + button.text = """%s + (House %d/%d)""" % [ + village.name, + village.houses.size(), + int(village.width) * int(village.height)] + +func set_village(village: Dictionary): + self.village = village + _update_button() + +func _on_button_button_down(): + button_down.emit(get_index()) diff --git a/frontend/Saver-22b-godot/ui/select_village_village_button.tscn b/frontend/Saver-22b-godot/ui/select_village_village_button.tscn new file mode 100644 index 00000000..d4f2ae09 --- /dev/null +++ b/frontend/Saver-22b-godot/ui/select_village_village_button.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=2 format=3 uid="uid://eddcwfe8kgp5"] + +[ext_resource type="Script" path="res://ui/select_village_village_button.gd" id="1_lhmfv"] + +[node name="SelectVillageVillageButton" type="MarginContainer"] +custom_minimum_size = Vector2(2.08165e-12, 200) +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +script = ExtResource("1_lhmfv") + +[node name="Background" type="ColorRect" parent="."] +layout_mode = 2 + +[node name="Button" type="Button" parent="."] +layout_mode = 2 +theme_override_font_sizes/font_size = 50 +text = "Village #1 +(Households X/Y)" + +[connection signal="button_down" from="Button" to="." method="_on_button_button_down"] From 46910c347b7c42d30032e04c2130f579579330cf Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Wed, 20 Dec 2023 18:16:32 +0900 Subject: [PATCH 30/51] bind real villages --- .../scenes/select_village.tscn | 65 +++---------------- .../scripts/scenes/select_village.gd | 26 ++++++-- 2 files changed, 30 insertions(+), 61 deletions(-) diff --git a/frontend/Saver-22b-godot/scenes/select_village.tscn b/frontend/Saver-22b-godot/scenes/select_village.tscn index 205721e0..6ee96b72 100644 --- a/frontend/Saver-22b-godot/scenes/select_village.tscn +++ b/frontend/Saver-22b-godot/scenes/select_village.tscn @@ -22,6 +22,7 @@ grow_horizontal = 2 grow_vertical = 2 [node name="LeftMarginContainer" type="MarginContainer" parent="."] +custom_minimum_size = Vector2(810, 2.08165e-12) layout_mode = 1 anchors_preset = 9 anchor_bottom = 1.0 @@ -38,54 +39,6 @@ color = Color(0, 0, 0, 1) [node name="VillagesVBoxContainer" type="VBoxContainer" parent="LeftMarginContainer"] layout_mode = 2 -[node name="VillageMarginContainer" type="MarginContainer" parent="LeftMarginContainer/VillagesVBoxContainer"] -custom_minimum_size = Vector2(2.08165e-12, 200) -layout_mode = 2 -theme_override_constants/margin_left = 10 -theme_override_constants/margin_top = 10 -theme_override_constants/margin_right = 10 - -[node name="Background" type="ColorRect" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer"] -layout_mode = 2 - -[node name="Button" type="Button" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer"] -layout_mode = 2 -theme_override_font_sizes/font_size = 50 -text = "Village #1 -(Households X/Y)" - -[node name="VillageMarginContainer2" type="MarginContainer" parent="LeftMarginContainer/VillagesVBoxContainer"] -custom_minimum_size = Vector2(2.08165e-12, 200) -layout_mode = 2 -theme_override_constants/margin_left = 10 -theme_override_constants/margin_top = 10 -theme_override_constants/margin_right = 10 - -[node name="Background" type="ColorRect" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer2"] -layout_mode = 2 - -[node name="Button" type="Button" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer2"] -layout_mode = 2 -theme_override_font_sizes/font_size = 50 -text = "Village #2 -(Households X/Y)" - -[node name="VillageMarginContainer3" type="MarginContainer" parent="LeftMarginContainer/VillagesVBoxContainer"] -custom_minimum_size = Vector2(2.08165e-12, 200) -layout_mode = 2 -theme_override_constants/margin_left = 10 -theme_override_constants/margin_top = 10 -theme_override_constants/margin_right = 10 - -[node name="Background" type="ColorRect" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer3"] -layout_mode = 2 - -[node name="Button" type="Button" parent="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer3"] -layout_mode = 2 -theme_override_font_sizes/font_size = 50 -text = "Village #3 -(Households X/Y)" - [node name="RightMarginContainer" type="MarginContainer" parent="."] layout_mode = 1 anchors_preset = 11 @@ -115,6 +68,7 @@ layout_mode = 2 [node name="VBoxContainer" type="VBoxContainer" parent="RightMarginContainer/MarginContainer"] layout_mode = 2 +theme_override_constants/separation = 0 [node name="VillageInfoMarginContainer" type="MarginContainer" parent="RightMarginContainer/MarginContainer/VBoxContainer"] layout_mode = 2 @@ -124,11 +78,15 @@ theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 10 theme_override_constants/margin_bottom = 10 -[node name="Label" type="Label" parent="RightMarginContainer/MarginContainer/VBoxContainer/VillageInfoMarginContainer"] +[node name="ScrollContainer" type="ScrollContainer" parent="RightMarginContainer/MarginContainer/VBoxContainer/VillageInfoMarginContainer"] layout_mode = 2 -size_flags_vertical = 1 + +[node name="Label" type="Label" parent="RightMarginContainer/MarginContainer/VBoxContainer/VillageInfoMarginContainer/ScrollContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 theme_override_colors/font_color = Color(0, 0, 0, 1) -theme_override_font_sizes/font_size = 50 +theme_override_font_sizes/font_size = 30 text = "This village's name is \"평범한 도시 1\". ID: 1 World Position: 5, 1 @@ -137,7 +95,7 @@ House Count: 1" [node name="StartButtonMarginContainer" type="MarginContainer" parent="RightMarginContainer/MarginContainer/VBoxContainer"] layout_mode = 2 -size_flags_vertical = 10 +size_flags_vertical = 8 theme_override_constants/margin_left = 10 theme_override_constants/margin_top = 10 theme_override_constants/margin_right = 10 @@ -148,7 +106,4 @@ layout_mode = 2 theme_override_font_sizes/font_size = 70 text = "Start" -[connection signal="button_down" from="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer/Button" to="." method="_on_village_button_button_down" binds= [0]] -[connection signal="button_down" from="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer2/Button" to="." method="_on_village_button_button_down" binds= [1]] -[connection signal="button_down" from="LeftMarginContainer/VillagesVBoxContainer/VillageMarginContainer3/Button" to="." method="_on_village_button_button_down" binds= [2]] [connection signal="button_down" from="RightMarginContainer/MarginContainer/VBoxContainer/StartButtonMarginContainer/StartButton" to="." method="_on_start_button_button_down"] diff --git a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd index 43e816c9..e0b84a90 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd @@ -1,16 +1,30 @@ extends Control -var selected_village_index: int +const SELECT_VILLAGE_VILLAGE_BUTTON = preload("res://ui/select_village_village_button.tscn") + +@onready var villages_v_box_container = $LeftMarginContainer/VillagesVBoxContainer +@onready var village_info_label = $RightMarginContainer/MarginContainer/VBoxContainer/VillageInfoMarginContainer/ScrollContainer/Label func _ready(): print("select_village scene ready") + for village in SceneContext.villages: + var button = SELECT_VILLAGE_VILLAGE_BUTTON.instantiate() + button.set_village(village) + button.button_down.connect(_on_village_button_button_down) + villages_v_box_container.add_child(button) + + _update_village_info_label() + +func _update_village_info_label(): + var json_string = JSON.stringify(SceneContext.get_selected_village(), "\t") + village_info_label.text = json_string -func _on_village_button_button_down(extra_arg_0): +func _on_village_button_button_down(village_index): var format_string = "village button down: %s" - print(format_string % extra_arg_0) - selected_village_index = extra_arg_0 + print(format_string % village_index) + SceneContext.selected_village_index = village_index + _update_village_info_label() func _on_start_button_button_down(): - print("start button down: %s" % selected_village_index) - SceneContext.selected_village_index = selected_village_index + print("start button down: %s" % SceneContext.selected_village_index) get_tree().change_scene_to_file("res://village_view/VillageView.tscn") From c7ba8179979a3f0be2416498b7663e528d39b905 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 19:11:37 +0900 Subject: [PATCH 31/51] =?UTF-8?q?=ED=95=98=EC=97=AC=ED=8A=BC=20=EB=AD=94?= =?UTF-8?q?=EA=B0=80=20=EB=A7=88=EC=9D=84=EC=9D=84=20=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=20=ED=95=A0=20=EC=88=98=20=EC=9E=88=EA=B2=8C=20?= =?UTF-8?q?=EB=90=90=EC=8A=B5=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Saver-22b-godot/village_view/TemporaryView.gd | 3 ++- frontend/Saver-22b-godot/village_view/VillageView.gd | 1 + .../Saver-22b-godot/village_view/VillageView.tscn | 9 +++++++-- .../village_background_nine_patch_rect.tscn | 12 ++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/frontend/Saver-22b-godot/village_view/TemporaryView.gd b/frontend/Saver-22b-godot/village_view/TemporaryView.gd index 0040752f..e95be06f 100644 --- a/frontend/Saver-22b-godot/village_view/TemporaryView.gd +++ b/frontend/Saver-22b-godot/village_view/TemporaryView.gd @@ -13,5 +13,6 @@ func _ready(): #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_by_village(village) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index 9e38feff..bfd5247f 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -45,6 +45,7 @@ func initialize(width: int, height: int, worldX: int, worldY: int, houses=[]): func set_size(): bg.size.x = width bg.size.y = height + bg.custom_minimum_size = bg.size bg.set_anchors_and_offsets_preset(Control.PRESET_CENTER, Control.PRESET_MODE_KEEP_SIZE) root_position = get_tree().root.size / 2 diff --git a/frontend/Saver-22b-godot/village_view/VillageView.tscn b/frontend/Saver-22b-godot/village_view/VillageView.tscn index 8314d469..19feb92b 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.tscn +++ b/frontend/Saver-22b-godot/village_view/VillageView.tscn @@ -2,12 +2,17 @@ [ext_resource type="Script" path="res://village_view/TemporaryView.gd" id="1_n4pdo"] -[node name="Control" type="Control"] -layout_mode = 3 +[node name="Control" type="ScrollContainer"] +clip_children = 1 +custom_minimum_size = Vector2(300, 300) anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 pivot_offset = Vector2(960, 540) +size_flags_horizontal = 3 +size_flags_vertical = 3 +horizontal_scroll_mode = 2 +vertical_scroll_mode = 2 script = ExtResource("1_n4pdo") diff --git a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn index bf9b15d9..5d38bfdf 100644 --- a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn +++ b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn @@ -6,18 +6,22 @@ [node name="VillageBackground_NinePatchRect" type="NinePatchRect" node_paths=PackedStringArray("bg")] z_index = -1000 texture_filter = 1 +custom_minimum_size = Vector2(40, 40) anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -960.0 -offset_top = -540.0 -offset_right = -920.0 -offset_bottom = -500.0 +offset_left = -150.0 +offset_top = -150.0 +offset_right = -110.0 +offset_bottom = -110.0 grow_horizontal = 2 grow_vertical = 2 pivot_offset = Vector2(20, 20) +size_flags_horizontal = 6 +size_flags_vertical = 6 +mouse_filter = 1 texture = ExtResource("1_ig6sc") patch_margin_left = 3 patch_margin_top = 3 From 46ab8bcb87e1b648fd1d28dd9e27d4a9d9188c88 Mon Sep 17 00:00:00 2001 From: Mizuki Date: Wed, 20 Dec 2023 12:06:30 +0900 Subject: [PATCH 32/51] Add LifeStone item, IsSuperFood property, and UseLifeStoneAction --- .../Extensions/BencodexExtensions.cs | 16 ++++ .../Action/UseLifeStoneActionTests.cs | 96 +++++++++++++++++++ .../app/Savor22b/Action/UseLifeStoneAction.cs | 75 +++++++++++++++ .../app/Savor22b/GraphTypes/Query/Query.cs | 37 ++++++- .../GraphTypes/Types/RefrigeratorStateType.cs | 6 ++ .../app/Savor22b/States/RefrigeratorState.cs | 12 ++- resources/savor22b/tabledata/item.csv | 1 + 7 files changed, 237 insertions(+), 6 deletions(-) create mode 100644 backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs create mode 100644 backend/app/Savor22b/Action/UseLifeStoneAction.cs diff --git a/backend/app/Libplanet.Headless/Extensions/BencodexExtensions.cs b/backend/app/Libplanet.Headless/Extensions/BencodexExtensions.cs index 091d4f12..17377326 100644 --- a/backend/app/Libplanet.Headless/Extensions/BencodexExtensions.cs +++ b/backend/app/Libplanet.Headless/Extensions/BencodexExtensions.cs @@ -83,6 +83,22 @@ public static long ToLong(this IValue serialized) => #endregion long + #region bool + + public static IValue Serialize(this bool boolean) => + (Text)boolean.ToString(); + + public static IValue Serialize(this bool? boolean) => + Serialize(Serialize, boolean); + + public static bool ToBoolean(this IValue serialized) => + bool.Parse(((Text)serialized).Value); + + public static bool? ToNullableBoolean(this IValue serialized) => + Deserialize(ToBoolean, serialized); + + #endregion bool + #region Text public static IValue Serialize(this string text) => diff --git a/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs b/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs new file mode 100644 index 00000000..98628d6b --- /dev/null +++ b/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs @@ -0,0 +1,96 @@ +namespace Savor22b.Tests.Action; + +using System; +using System.Collections.Immutable; +using Libplanet; +using Libplanet.State; +using Savor22b.Action; +using Savor22b.States; +using Xunit; + +public class UseLifeStoneActionTests : ActionTests +{ + private static readonly int LifeStoneItemId = 2; + + [Fact] + public void UseLifeStoneAction_Success() + { + var stateDelta = CreatePresetStateDelta(); + + var food = DeriveRootStateFromAccountStateDelta(stateDelta) + .InventoryState + .RefrigeratorStateList[0]; + + var action = new UseLifeStoneAction(food.StateID); + + stateDelta = action.Execute( + new DummyActionContext + { + PreviousStates = stateDelta, + Signer = SignerAddress(), + Random = random, + Rehearsal = false, + BlockIndex = 1, + } + ); + + food.IsSuperFood = true; + + var newInventoryState = DeriveRootStateFromAccountStateDelta(stateDelta).InventoryState; + + Assert.Equal(food, newInventoryState.RefrigeratorStateList[0]); + Assert.Empty(newInventoryState.ItemStateList); + } + + [Fact] + public void UseLifeStoneAction_AssertPresetStateDelta() + { + var stateDelta = CreatePresetStateDelta(); + var inventoryState = DeriveRootStateFromAccountStateDelta(stateDelta).InventoryState; + + Assert.Single(inventoryState.ItemStateList); + Assert.Equal(LifeStoneItemId, inventoryState.ItemStateList[0].ItemID); + Assert.Single(inventoryState.RefrigeratorStateList); + Assert.False(inventoryState.RefrigeratorStateList[0].IsSuperFood); + } + + private IAccountStateDelta CreatePresetStateDelta() + { + IAccountStateDelta state = new DummyState(); + Address signerAddress = SignerAddress(); + + var rootStateEncoded = state.GetState(signerAddress); + RootState rootState = rootStateEncoded is Bencodex.Types.Dictionary bdict + ? new RootState(bdict) + : new RootState(); + + InventoryState inventoryState = rootState.InventoryState; + + inventoryState = inventoryState.AddItem(new ItemState(Guid.NewGuid(), LifeStoneItemId)); + + var food = RefrigeratorState.CreateFood( + Guid.NewGuid(), + 1, + "D", + 1, + 1, + 1, + 1, + 1, + ImmutableList.Empty + ); + inventoryState = inventoryState.AddRefrigeratorItem(food); + + rootState.SetInventoryState(inventoryState); + + return state.SetState(signerAddress, rootState.Serialize()); + } + + private RootState DeriveRootStateFromAccountStateDelta(IAccountStateDelta stateDelta) { + var rootStateEncoded = stateDelta.GetState(SignerAddress()); + RootState rootState = rootStateEncoded is Bencodex.Types.Dictionary bdict + ? new RootState(bdict) + : throw new Exception(); + return rootState; + } +} diff --git a/backend/app/Savor22b/Action/UseLifeStoneAction.cs b/backend/app/Savor22b/Action/UseLifeStoneAction.cs new file mode 100644 index 00000000..3acc4c99 --- /dev/null +++ b/backend/app/Savor22b/Action/UseLifeStoneAction.cs @@ -0,0 +1,75 @@ +namespace Savor22b.Action; + +using System; +using System.Collections.Immutable; +using Bencodex.Types; +using Libplanet.Action; +using Libplanet.Headless.Extensions; +using Libplanet.State; +using Savor22b.Action.Exceptions; +using Savor22b.States; + +[ActionType(nameof(UseLifeStoneAction))] +public class UseLifeStoneAction : SVRAction +{ + public UseLifeStoneAction() + { + } + + public UseLifeStoneAction(Guid foodStateID) + { + FoodStateID = foodStateID; + } + + public Guid FoodStateID { get; private set; } + + protected override IImmutableDictionary PlainValueInternal => + new Dictionary() + { + [nameof(FoodStateID)] = FoodStateID.Serialize(), + }.ToImmutableDictionary(); + + public override IAccountStateDelta Execute(IActionContext context) + { + if (context.Rehearsal) + { + return context.PreviousStates; + } + + IAccountStateDelta states = context.PreviousStates; + + RootState rootState = states.GetState(context.Signer) is Dictionary rootStateEncoded + ? new RootState(rootStateEncoded) + : new RootState(); + + InventoryState inventoryState = rootState.InventoryState; + + var food = inventoryState.GetRefrigeratorItem(FoodStateID); + + if (food is null) + { + throw new NotFoundDataException($"NotFound `{FoodStateID}` food state id"); + } + + if (food.IsSuperFood) + { + throw new Exception($"Food `{FoodStateID}` is already Super Food."); + } + + var singleLifeStone = inventoryState.ItemStateList.First((e) => e.ItemID == 2); + if (singleLifeStone is null) + { + throw new Exception("No LifeStone is found in user's inventory."); + } + + food.IsSuperFood = true; + inventoryState = inventoryState.RemoveItem(singleLifeStone.StateID); + rootState.SetInventoryState(inventoryState); + return states.SetState(context.Signer, rootState.Serialize()); + } + + protected override void LoadPlainValueInternal(IImmutableDictionary plainValue) + { + FoodStateID = plainValue[nameof(FoodStateID)].ToGuid(); + } +} diff --git a/backend/app/Savor22b/GraphTypes/Query/Query.cs b/backend/app/Savor22b/GraphTypes/Query/Query.cs index 442bac85..59d26785 100644 --- a/backend/app/Savor22b/GraphTypes/Query/Query.cs +++ b/backend/app/Savor22b/GraphTypes/Query/Query.cs @@ -1,19 +1,16 @@ namespace Savor22b.GraphTypes.Query; -using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using GraphQL; using GraphQL.Types; using Libplanet; -using Libplanet.Action; using Libplanet.Assets; using Libplanet.Blockchain; using Libplanet.Crypto; using Libplanet.Net; -using Libplanet.Tx; using Savor22b.Action; using Savor22b.GraphTypes.Types; -using Savor22b.Model; +using Savor22b.States; public class Query : ObjectGraphType { @@ -451,6 +448,38 @@ swarm is null } ); + Field>( + "createAction_UseLifeStoneAction", + description: "Use LifeStone", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "publicKey", + Description = "The base64-encoded public key for Transaction.", + }, + new QueryArgument> + { + Name = "foodStateId", + Description = "Food state Id (Guid)", + } + ), + resolve: context => + { + var publicKey = new PublicKey( + ByteUtil.ParseHex(context.GetArgument("publicKey")) + ); + + var action = new UseLifeStoneAction(context.GetArgument("foodStateId")); + + return new GetUnsignedTransactionHex( + action, + publicKey, + _blockChain, + _swarm + ).UnsignedTransactionHex; + } + ); + AddField(new CalculateRelocationCostQuery()); AddField(new VillagesQuery(blockChain)); AddField(new ShopQuery()); diff --git a/backend/app/Savor22b/GraphTypes/Types/RefrigeratorStateType.cs b/backend/app/Savor22b/GraphTypes/Types/RefrigeratorStateType.cs index 09cc4bec..644cf416 100644 --- a/backend/app/Savor22b/GraphTypes/Types/RefrigeratorStateType.cs +++ b/backend/app/Savor22b/GraphTypes/Types/RefrigeratorStateType.cs @@ -62,6 +62,12 @@ public RefrigeratorStateType(BlockChain blockChain) resolve: context => context.Source.SPD ); + Field( + name: "isSuperFood", + description: "Check this food is SuperFood.", + resolve: context => context.Source.IsSuperFood + ); + Field( name: "isAvailable", description: "Check this food is available.", diff --git a/backend/app/Savor22b/States/RefrigeratorState.cs b/backend/app/Savor22b/States/RefrigeratorState.cs index 67546d48..746c7ce5 100644 --- a/backend/app/Savor22b/States/RefrigeratorState.cs +++ b/backend/app/Savor22b/States/RefrigeratorState.cs @@ -17,7 +17,8 @@ public RefrigeratorState( int atk, int spd, long? availableBlockIndex, - ImmutableList usedKitchenEquipmentStateIds + ImmutableList usedKitchenEquipmentStateIds, + bool isSuperFood = false ) { StateID = stateID; @@ -28,6 +29,7 @@ ImmutableList usedKitchenEquipmentStateIds DEF = def; ATK = atk; SPD = spd; + IsSuperFood = isSuperFood; AvailableBlockIndex = availableBlockIndex; UsedKitchenEquipmentStateIds = usedKitchenEquipmentStateIds; } @@ -92,6 +94,7 @@ public RefrigeratorState(Dictionary encoded) SPD = encoded[nameof(SPD)].ToInteger(); IngredientID = encoded[nameof(IngredientID)].ToNullableInteger(); FoodID = encoded[nameof(FoodID)].ToNullableInteger(); + IsSuperFood = encoded[nameof(IsSuperFood)].ToBoolean(); AvailableBlockIndex = encoded[nameof(AvailableBlockIndex)].ToNullableLong(); UsedKitchenEquipmentStateIds = ((List)encoded[nameof(UsedKitchenEquipmentStateIds)]) .Select(e => e.ToGuid()) @@ -114,6 +117,8 @@ public RefrigeratorState(Dictionary encoded) public int SPD { get; set; } + public bool IsSuperFood { get; set; } + public long? AvailableBlockIndex { get; set; } public ImmutableList UsedKitchenEquipmentStateIds { get; set; } @@ -130,6 +135,7 @@ public IValue Serialize() new KeyValuePair((Text)nameof(SPD), SPD.Serialize()), new KeyValuePair((Text)nameof(IngredientID), IngredientID.Serialize()), new KeyValuePair((Text)nameof(FoodID), FoodID.Serialize()), + new KeyValuePair((Text)nameof(IsSuperFood), IsSuperFood.Serialize()), new KeyValuePair( (Text)nameof(UsedKitchenEquipmentStateIds), new List(UsedKitchenEquipmentStateIds.Select(element => element.Serialize())) @@ -168,7 +174,8 @@ public override bool Equals(object obj) && HP == other.HP && DEF == other.DEF && ATK == other.ATK - && SPD == other.SPD; + && SPD == other.SPD + && IsSuperFood == other.IsSuperFood; } public override int GetHashCode() @@ -183,6 +190,7 @@ public override int GetHashCode() hash = hash * 23 + DEF.GetHashCode(); hash = hash * 23 + ATK.GetHashCode(); hash = hash * 23 + SPD.GetHashCode(); + hash = hash * 23 + IsSuperFood.GetHashCode(); return hash; } diff --git a/resources/savor22b/tabledata/item.csv b/resources/savor22b/tabledata/item.csv index f52266aa..cb414f36 100644 --- a/resources/savor22b/tabledata/item.csv +++ b/resources/savor22b/tabledata/item.csv @@ -1,2 +1,3 @@ ID,Name,Price 1,랜덤 종자 뽑기권,10 +2,생명석,100 From a689dd1d6b04f9a9dcb92b49525770fcc2281ec5 Mon Sep 17 00:00:00 2001 From: Mizuki Date: Wed, 20 Dec 2023 17:45:30 +0900 Subject: [PATCH 33/51] Add exception handlings & tests for UseLifeStoneAction --- .../Action/UseLifeStoneActionTests.cs | 65 ++++++++++++++++++- .../Exceptions/AlreadyIsSuperFoodException.cs | 10 +++ .../app/Savor22b/Action/UseLifeStoneAction.cs | 6 +- 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 backend/app/Savor22b/Action/Exceptions/AlreadyIsSuperFoodException.cs diff --git a/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs b/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs index 98628d6b..090564b3 100644 --- a/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs +++ b/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs @@ -5,6 +5,7 @@ namespace Savor22b.Tests.Action; using Libplanet; using Libplanet.State; using Savor22b.Action; +using Savor22b.Action.Exceptions; using Savor22b.States; using Xunit; @@ -42,19 +43,74 @@ public void UseLifeStoneAction_Success() Assert.Empty(newInventoryState.ItemStateList); } + [Fact] + public void UseLifeStoneAction_Fail_NoLifeStone() + { + var stateDelta = CreatePresetStateDelta(hasLifeStone: false); + + var food = DeriveRootStateFromAccountStateDelta(stateDelta) + .InventoryState + .RefrigeratorStateList[0]; + + var action = new UseLifeStoneAction(food.StateID); + + Assert.Throws( + () => action.Execute( + new DummyActionContext + { + PreviousStates = stateDelta, + Signer = SignerAddress(), + Random = random, + Rehearsal = false, + BlockIndex = 1, + } + ) + ); + } + + [Fact] + public void UseLifeStoneAction_Fail_AlreadyIsSuperFood() + { + var stateDelta = CreatePresetStateDelta(); + + var food = DeriveRootStateFromAccountStateDelta(stateDelta) + .InventoryState + .RefrigeratorStateList[0]; + + food.IsSuperFood = true; + + var action = new UseLifeStoneAction(food.StateID); + + Assert.Throws( + () => action.Execute( + new DummyActionContext + { + PreviousStates = stateDelta, + Signer = SignerAddress(), + Random = random, + Rehearsal = false, + BlockIndex = 1, + } + ) + ); + } + [Fact] public void UseLifeStoneAction_AssertPresetStateDelta() { var stateDelta = CreatePresetStateDelta(); var inventoryState = DeriveRootStateFromAccountStateDelta(stateDelta).InventoryState; - Assert.Single(inventoryState.ItemStateList); Assert.Equal(LifeStoneItemId, inventoryState.ItemStateList[0].ItemID); Assert.Single(inventoryState.RefrigeratorStateList); Assert.False(inventoryState.RefrigeratorStateList[0].IsSuperFood); + + stateDelta = CreatePresetStateDelta(hasLifeStone: false); + inventoryState = DeriveRootStateFromAccountStateDelta(stateDelta).InventoryState; + Assert.Empty(inventoryState.ItemStateList); } - private IAccountStateDelta CreatePresetStateDelta() + private IAccountStateDelta CreatePresetStateDelta(bool hasLifeStone = true) { IAccountStateDelta state = new DummyState(); Address signerAddress = SignerAddress(); @@ -66,7 +122,10 @@ private IAccountStateDelta CreatePresetStateDelta() InventoryState inventoryState = rootState.InventoryState; - inventoryState = inventoryState.AddItem(new ItemState(Guid.NewGuid(), LifeStoneItemId)); + if (hasLifeStone) + { + inventoryState = inventoryState.AddItem(new ItemState(Guid.NewGuid(), LifeStoneItemId)); + } var food = RefrigeratorState.CreateFood( Guid.NewGuid(), diff --git a/backend/app/Savor22b/Action/Exceptions/AlreadyIsSuperFoodException.cs b/backend/app/Savor22b/Action/Exceptions/AlreadyIsSuperFoodException.cs new file mode 100644 index 00000000..3bc15fb6 --- /dev/null +++ b/backend/app/Savor22b/Action/Exceptions/AlreadyIsSuperFoodException.cs @@ -0,0 +1,10 @@ +namespace Savor22b.Action.Exceptions; + +[Serializable] +public class AlreadyIsSuperFoodException : ActionException +{ + public AlreadyIsSuperFoodException(string message, int? errorCode = null) + : base(message, "AlreadyIsSuperFood", errorCode) + { + } +} diff --git a/backend/app/Savor22b/Action/UseLifeStoneAction.cs b/backend/app/Savor22b/Action/UseLifeStoneAction.cs index 3acc4c99..295be745 100644 --- a/backend/app/Savor22b/Action/UseLifeStoneAction.cs +++ b/backend/app/Savor22b/Action/UseLifeStoneAction.cs @@ -53,13 +53,13 @@ public override IAccountStateDelta Execute(IActionContext context) if (food.IsSuperFood) { - throw new Exception($"Food `{FoodStateID}` is already Super Food."); + throw new AlreadyIsSuperFoodException($"Food `{FoodStateID}` is already Super Food."); } - var singleLifeStone = inventoryState.ItemStateList.First((e) => e.ItemID == 2); + var singleLifeStone = inventoryState.ItemStateList.FirstOrDefault((e) => e.ItemID == 2); if (singleLifeStone is null) { - throw new Exception("No LifeStone is found in user's inventory."); + throw new NotHaveRequiredException("No LifeStone is found in user's inventory."); } food.IsSuperFood = true; From 3fd266339fa9253f286c91cb1d5839d925e6fce8 Mon Sep 17 00:00:00 2001 From: Mizuki Date: Wed, 20 Dec 2023 18:04:44 +0900 Subject: [PATCH 34/51] Fix UseLifeStoneActionTests --- .../Action/UseLifeStoneActionTests.cs | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs b/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs index 090564b3..353a8cf6 100644 --- a/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs +++ b/backend/app/Savor22b.Tests/Action/UseLifeStoneActionTests.cs @@ -54,8 +54,9 @@ public void UseLifeStoneAction_Fail_NoLifeStone() var action = new UseLifeStoneAction(food.StateID); - Assert.Throws( - () => action.Execute( + Assert.Throws(() => + { + action.Execute( new DummyActionContext { PreviousStates = stateDelta, @@ -64,8 +65,8 @@ public void UseLifeStoneAction_Fail_NoLifeStone() Rehearsal = false, BlockIndex = 1, } - ) - ); + ); + }); } [Fact] @@ -73,25 +74,29 @@ public void UseLifeStoneAction_Fail_AlreadyIsSuperFood() { var stateDelta = CreatePresetStateDelta(); - var food = DeriveRootStateFromAccountStateDelta(stateDelta) - .InventoryState - .RefrigeratorStateList[0]; + var rootState = DeriveRootStateFromAccountStateDelta(stateDelta); + var inventoryState = rootState.InventoryState; + var food = rootState.InventoryState.RefrigeratorStateList[0]; food.IsSuperFood = true; + rootState.SetInventoryState(inventoryState); + var action = new UseLifeStoneAction(food.StateID); - Assert.Throws( - () => action.Execute( - new DummyActionContext - { - PreviousStates = stateDelta, - Signer = SignerAddress(), - Random = random, - Rehearsal = false, - BlockIndex = 1, - } - ) + Assert.Throws(() => + { + action.Execute( + new DummyActionContext + { + PreviousStates = stateDelta.SetState(SignerAddress(), rootState.Serialize()), + Signer = SignerAddress(), + Random = random, + Rehearsal = false, + BlockIndex = 1, + } + ); + } ); } From 2c08f3de95e7013add99ac91133087c90c2d4cc2 Mon Sep 17 00:00:00 2001 From: moreal Date: Wed, 20 Dec 2023 20:13:28 +0900 Subject: [PATCH 35/51] Implement Inventory --- frontend/Saver-22b-godot/project.godot | 1 + .../scenes/inventory/Inventory.gd | 43 +++++++++++++++++++ .../Saver-22b-godot/scenes/inventory/Kind.gd | 18 ++++++++ .../Saver-22b-godot/scenes/inventory/Slot.gd | 14 ++++++ .../scenes/inventory/SlotModel.gd | 5 +++ .../scenes/inventory/inventory.tscn | 36 ++++++++++++++++ .../scenes/inventory/kind.tscn | 27 ++++++++++++ .../scenes/inventory/slot.tscn | 23 ++++++++++ .../scripts/global/inventory.gd | 9 ++++ 9 files changed, 176 insertions(+) create mode 100644 frontend/Saver-22b-godot/scenes/inventory/Inventory.gd create mode 100644 frontend/Saver-22b-godot/scenes/inventory/Kind.gd create mode 100644 frontend/Saver-22b-godot/scenes/inventory/Slot.gd create mode 100644 frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd create mode 100644 frontend/Saver-22b-godot/scenes/inventory/inventory.tscn create mode 100644 frontend/Saver-22b-godot/scenes/inventory/kind.tscn create mode 100644 frontend/Saver-22b-godot/scenes/inventory/slot.tscn create mode 100644 frontend/Saver-22b-godot/scripts/global/inventory.gd diff --git a/frontend/Saver-22b-godot/project.godot b/frontend/Saver-22b-godot/project.godot index fad1888e..50f721d6 100644 --- a/frontend/Saver-22b-godot/project.godot +++ b/frontend/Saver-22b-godot/project.godot @@ -21,6 +21,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" +GlobalInventory="*res://scripts/global/inventory.gd" [display] diff --git a/frontend/Saver-22b-godot/scenes/inventory/Inventory.gd b/frontend/Saver-22b-godot/scenes/inventory/Inventory.gd new file mode 100644 index 00000000..45b2ed72 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/Inventory.gd @@ -0,0 +1,43 @@ +extends Node + +class_name Inventory; + +const kind_scene = preload("res://scenes/inventory/kind.tscn"); +const slot_scene = preload("res://scenes/inventory/slot.tscn"); + +# Input: +# Godot이 지원하지 않아서 주석으로 타입을 남깁니다. +# Dictionary[String, Array[SlotModel]] +var data: Dictionary; + +# State: +var current_kind: String; + +# Derived: +var kinds: Array; +var current_slots: Array; + +# Called when the node enters the scene tree for the first time. +func _ready(): + assert (data.size() > 0); + + kinds = data.keys(); + current_kind = kinds[0] + current_slots = data[current_kind]; + + for kind in kinds: + var kind_instance := kind_scene.instantiate() + kind_instance.title = kind + kind_instance.enabled = kind == current_kind + $"./ColorRect/VBoxContainer/Kinds".add_child(kind_instance) + + for slot in current_slots: + var slot_instance := slot_scene.instantiate() + slot_instance.title = slot.title + slot_instance.icon = slot.icon + slot_instance.count = slot.count + $"./ColorRect/VBoxContainer/Slots".add_child(slot_instance) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/frontend/Saver-22b-godot/scenes/inventory/Kind.gd b/frontend/Saver-22b-godot/scenes/inventory/Kind.gd new file mode 100644 index 00000000..d66dff7f --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/Kind.gd @@ -0,0 +1,18 @@ +extends Node + +var title: String; +var enabled: bool; + +# Called when the node enters the scene tree for the first time. +func _ready(): + $"./Label".set_text(title) + if enabled: + $Label.label_settings.set_font_color(Color(255, 255, 255)) + $ColorRect.set_color(Color(0, 0, 0)) + else: + $Label.label_settings.set_font_color(Color(0, 0, 0)) + $ColorRect.set_color(Color(255, 255, 255)) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/frontend/Saver-22b-godot/scenes/inventory/Slot.gd b/frontend/Saver-22b-godot/scenes/inventory/Slot.gd new file mode 100644 index 00000000..0a93ae96 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/Slot.gd @@ -0,0 +1,14 @@ +extends Node + +var title: String; +var icon: String; +var count: int; + +# Called when the node enters the scene tree for the first time. +func _ready(): + $Title.set_text("%s - %d" % [title, count]) + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd b/frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd new file mode 100644 index 00000000..ed3c9928 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/SlotModel.gd @@ -0,0 +1,5 @@ +class_name SlotModel; + +var title: String; +var icon: String; +var count: int; diff --git a/frontend/Saver-22b-godot/scenes/inventory/inventory.tscn b/frontend/Saver-22b-godot/scenes/inventory/inventory.tscn new file mode 100644 index 00000000..6ae5583c --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/inventory.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=2 format=3 uid="uid://riiie4g746ea"] + +[ext_resource type="Script" path="res://scenes/inventory/Inventory.gd" id="1_swc55"] + +[node name="Inventory" type="Control"] +custom_minimum_size = Vector2(1000, 700) +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_swc55") + +[node name="ColorRect" type="ColorRect" parent="."] +custom_minimum_size = Vector2(1000, 800) +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="ColorRect"] +custom_minimum_size = Vector2(1000, 800) +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Kinds" type="HBoxContainer" parent="ColorRect/VBoxContainer"] +custom_minimum_size = Vector2(1000, 200) +layout_mode = 2 + +[node name="Slots" type="GridContainer" parent="ColorRect/VBoxContainer"] +custom_minimum_size = Vector2(1000, 500) +layout_mode = 2 + +[node name="CloseButton" type="TextureButton" parent="ColorRect/VBoxContainer"] +layout_mode = 2 diff --git a/frontend/Saver-22b-godot/scenes/inventory/kind.tscn b/frontend/Saver-22b-godot/scenes/inventory/kind.tscn new file mode 100644 index 00000000..f0c75567 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/kind.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=3 format=3 uid="uid://bjmiaawy6ktrp"] + +[ext_resource type="Script" path="res://scenes/inventory/Kind.gd" id="1_y1brs"] + +[sub_resource type="LabelSettings" id="LabelSettings_4vsh2"] + +[node name="Kind" type="Control"] +custom_minimum_size = Vector2(200, 100) +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_y1brs") + +[node name="ColorRect" type="ColorRect" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 +color = Color(0.2, 0.2, 0.2, 1) + +[node name="Label" type="Label" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 23.0 +label_settings = SubResource("LabelSettings_4vsh2") diff --git a/frontend/Saver-22b-godot/scenes/inventory/slot.tscn b/frontend/Saver-22b-godot/scenes/inventory/slot.tscn new file mode 100644 index 00000000..b6d8bd5b --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/inventory/slot.tscn @@ -0,0 +1,23 @@ +[gd_scene load_steps=2 format=3 uid="uid://b86kl35ac31iq"] + +[ext_resource type="Script" path="res://scenes/inventory/Slot.gd" id="1_jurhm"] + +[node name="Slot" type="Control"] +custom_minimum_size = Vector2(100, 100) +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_jurhm") + +[node name="Title" type="RichTextLabel" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Count" type="RichTextLabel" parent="."] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 diff --git a/frontend/Saver-22b-godot/scripts/global/inventory.gd b/frontend/Saver-22b-godot/scripts/global/inventory.gd new file mode 100644 index 00000000..925eca88 --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/global/inventory.gd @@ -0,0 +1,9 @@ +extends Node + +const inventory_scene = preload("res://scenes/inventory/inventory.tscn"); + +func open_inventory(data: Dictionary): + var inventory_instance := inventory_scene.instantiate() + inventory_instance.data = data; + + get_tree().root.add_child(inventory_instance) From 8784f73b1f2fec0be8c9c7657665acfa0cc152e9 Mon Sep 17 00:00:00 2001 From: Mizuki Date: Wed, 20 Dec 2023 20:43:49 +0900 Subject: [PATCH 36/51] Add userState grqphql query --- .../app/Savor22b/GraphTypes/Query/Query.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/backend/app/Savor22b/GraphTypes/Query/Query.cs b/backend/app/Savor22b/GraphTypes/Query/Query.cs index 59d26785..0883e8e4 100644 --- a/backend/app/Savor22b/GraphTypes/Query/Query.cs +++ b/backend/app/Savor22b/GraphTypes/Query/Query.cs @@ -49,6 +49,27 @@ public Query(BlockChain blockChain, Swarm? swarm = null) } ); + Field( + "userState", + description: "The specified address's user state", + arguments: new QueryArguments( + new QueryArgument> + { + Name = "address", + Description = "The account holder's 40-hex address", + } + ), + resolve: context => + { + var accountAddress = new Address(context.GetArgument("address")); + var rootStateEncoded = blockChain.GetState(accountAddress); + RootState rootState = rootStateEncoded is Bencodex.Types.Dictionary bdict + ? new RootState(bdict) + : new RootState(); + return rootState; + } + ); + // TODO: Move to Libplanet.Explorer or Node API. Field( "peerString", From 7968caa487c1fae86a4d927df5b15e34521afe45 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 20:50:33 +0900 Subject: [PATCH 37/51] =?UTF-8?q?=ED=94=BC=EB=B4=87=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=EC=9D=B4=20=EC=9E=98=20=EC=95=88=EB=A8=B9=ED=98=80=EC=84=9C=20?= =?UTF-8?q?=EC=A0=81=EB=8B=B9=ED=9E=88=20=ED=94=BC=EB=B4=87=20=EB=A7=9E?= =?UTF-8?q?=EC=B6=B0=EC=84=9C=20=EC=9E=98=20=EC=A7=91=EC=9D=84=20=EC=84=A4?= =?UTF-8?q?=EC=B9=98=ED=95=B4=EC=A3=BC=EC=97=88=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Saver-22b-godot/village_view/VillageView.gd | 4 +++- .../village_view/house_texture_rect.tscn | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index bfd5247f..2585d50c 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -39,6 +39,7 @@ func initialize(width: int, height: int, worldX: int, worldY: int, houses=[]): self.worldX = worldX self.worldY = worldY set_size() + for house in houses.filter(func (argc): return argc is Vector2): instantiate_house(house) @@ -53,4 +54,5 @@ func instantiate_house(pos: Vector2): print("instantiate_house: ", pos) var house = Origin_house.instantiate() bg.add_child(house) - house.set_global_position(root_position + pos * Coordinate_weight) + house.set_size(Vector2(Coordinate_weight, Coordinate_weight)) + house.set_global_position(pos * Coordinate_weight + root_position - Vector2(Coordinate_weight / 2, Coordinate_weight / 2)) diff --git a/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn b/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn index 70f1b78f..df27bdf9 100644 --- a/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn +++ b/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn @@ -3,6 +3,17 @@ [ext_resource type="Texture2D" uid="uid://dajunmx26gvr5" path="res://sprites/house.png" id="1_4yb37"] [node name="House_TextureRect" type="TextureRect"] -offset_right = 40.0 -offset_bottom = 40.0 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -20.0 +offset_top = -20.0 +offset_right = 20.0 +offset_bottom = 20.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 4 +size_flags_vertical = 4 texture = ExtResource("1_4yb37") From 76f3d8677ea2d993a113f894955b6ab07664560a Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Wed, 20 Dec 2023 21:01:15 +0900 Subject: [PATCH 38/51] =?UTF-8?q?(0,=200)=20=EC=A2=8C=ED=91=9C=EA=B0=80=20?= =?UTF-8?q?=EC=96=B4=EB=94=98=EC=A7=80=20=EB=AA=A8=EB=A5=B4=EA=B2=A0?= =?UTF-8?q?=EC=96=B4=EC=84=9C=20=ED=91=9C=EC=8B=9C=EC=9A=A9=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=AD=90=20=ED=95=98=EB=82=98=EB=A5=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=96=88=EC=8A=B5=EB=8B=88=EB=8B=A4...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Saver-22b-godot/sprites/mid.png | Bin 0 -> 318 bytes .../Saver-22b-godot/sprites/mid.png.import | 34 ++++++++++++++++++ .../village_background_nine_patch_rect.tscn | 19 +++++++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 frontend/Saver-22b-godot/sprites/mid.png create mode 100644 frontend/Saver-22b-godot/sprites/mid.png.import diff --git a/frontend/Saver-22b-godot/sprites/mid.png b/frontend/Saver-22b-godot/sprites/mid.png new file mode 100644 index 0000000000000000000000000000000000000000..c199b2f8fd93a657fdd173f31ffa9b5f0971da69 GIT binary patch literal 318 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}KRjI=Ln2!D zUf;`m$Uva&p}ydjnXF3_d6q3W>6deWN6?g4*nlHcrSNexPcoJuSjQs)(G9Hv%qZDb4SJubj^K}F8#%i70wN$d>kpEt*q?2@fK z`r#+j-KTdxdY`z-U(WF2j$}qxL198Q_bi2Lh4KNi505)HWOW4Cuxa#l91U(r>Iku6 zH&8Ar Date: Thu, 21 Dec 2023 11:30:48 +0900 Subject: [PATCH 39/51] give seeds and kitchenequips to user for demo purpose --- .../Action/PlaceUserHouseActionTests.cs | 21 +++++++++++++++ .../Savor22b/Action/PlaceUserHouseAction.cs | 26 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/backend/app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs b/backend/app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs index 60a38e49..379afba8 100644 --- a/backend/app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs +++ b/backend/app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs @@ -8,6 +8,7 @@ namespace Savor22b.Tests.Action; using Savor22b.Constants; using Libplanet.Assets; using Savor22b.Action.Exceptions; +using System.Collections.Immutable; public class PlaceUserHouseActionTests : ActionTests { @@ -54,6 +55,26 @@ is Bencodex.Types.Dictionary stateEncoded SignerAddress(), globalUserHouseState.UserHouse[$"{villageId},{targetX},{targetY}"] ); + + Assert.Equal(100, rootState.InventoryState.SeedStateList.Count); + Assert.Equal( + Enumerable.Repeat(10, 6).ToImmutableList(), + rootState.InventoryState.KitchenEquipmentStateList.Aggregate( + new Dictionary(), + (dict, curr) => + { + if (!dict.ContainsKey(curr.KitchenEquipmentID)) + { + dict.Add(curr.KitchenEquipmentID, 1); + } + else + { + dict[curr.KitchenEquipmentID]++; + } + return dict; + } + ).Values.ToImmutableList() + ); } private IAccountStateDelta createStateForRelocationHouse() diff --git a/backend/app/Savor22b/Action/PlaceUserHouseAction.cs b/backend/app/Savor22b/Action/PlaceUserHouseAction.cs index 14936b4e..6126fd7d 100644 --- a/backend/app/Savor22b/Action/PlaceUserHouseAction.cs +++ b/backend/app/Savor22b/Action/PlaceUserHouseAction.cs @@ -137,6 +137,32 @@ is Dictionary stateEncoded if (isInitialPlaceHouse) { PlaceInitialUserHouse(rootState); + + var inventoryState = rootState.InventoryState; + + for (int i = 0; i < 100; i++) + { + inventoryState = inventoryState.AddSeed( + new SeedState(ctx.Random.GenerateRandomGuid(), ctx.Random.Next() % 13) + ); + } + + var kitchenEquipments = CsvDataHelper.GetKitchenEquipmentCSVData(); + foreach (var k in kitchenEquipments) + { + for (int i = 0; i < 10; i++) + { + inventoryState = inventoryState.AddKitchenEquipmentItem( + new KitchenEquipmentState( + ctx.Random.GenerateRandomGuid(), + k.ID, + k.KitchenEquipmentCategoryID + ) + ); + } + } + + rootState.SetInventoryState(inventoryState); } else { From 63c630cd5160ff6cfc08121ecb57c99ec6afd152 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Thu, 21 Dec 2023 11:50:46 +0900 Subject: [PATCH 40/51] =?UTF-8?q?=ED=81=B4=EB=A6=AD=ED=95=9C=20=EA=B3=B3?= =?UTF-8?q?=EC=9D=84=20=EB=A7=88=EC=9D=84=20=EA=B8=B0=EC=A4=80=20=EC=A2=8C?= =?UTF-8?q?=ED=91=9C=EB=A1=9C=20=EC=96=B4=EB=94=98=EC=A7=80=20x,=20y?= =?UTF-8?q?=EB=A5=BC=20=EC=B0=8D=EA=B2=8C=20=EB=A7=8C=EB=93=A4=EC=97=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Saver-22b-godot/village_view/VillageView.gd | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index 2585d50c..32feaebe 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -18,11 +18,11 @@ const Coordinate_weight = 300 func _ready(): set_size() -# Called every frame. 'delta' is the elapsed time since the previous frame. -# 이게 업데이트구나 -func _process(delta): - pass - # var newView = VillageViewClass.new(1,2,3,4) 이런식으로 사용하려나 +# Mouse in viewport coordinates. +func _input(event): + if event is InputEventMouseButton and event.is_released(): + print("Mouse Click/Unclick at: ", event.position) + build_house(event.global_position) func initialize_by_village(village: Dictionary): initialize( @@ -56,3 +56,10 @@ func instantiate_house(pos: Vector2): bg.add_child(house) house.set_size(Vector2(Coordinate_weight, Coordinate_weight)) house.set_global_position(pos * Coordinate_weight + root_position - Vector2(Coordinate_weight / 2, Coordinate_weight / 2)) + +func build_house(pos: Vector2): + var relative_pos = pos - root_position + Vector2(Coordinate_weight / 2, Coordinate_weight / 2) + relative_pos /= Coordinate_weight + relative_pos.x = roundi(relative_pos.x) + relative_pos.y = roundi(relative_pos.y) + print("build house pos: ", relative_pos) From 195d736815723f7dabb6384b04f881a4223d97db Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Thu, 21 Dec 2023 11:56:21 +0900 Subject: [PATCH 41/51] =?UTF-8?q?=EB=A7=88=EC=9A=B0=EC=8A=A4=20=EC=A2=8C?= =?UTF-8?q?=ED=91=9C=EB=A5=BC=20bg=20=EC=98=A4=EB=B8=8C=EC=A0=9D=ED=8A=B8?= =?UTF-8?q?=20=EA=B8=B0=EC=A4=80=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Saver-22b-godot/village_view/VillageView.gd | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index 32feaebe..ce8f2037 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -22,7 +22,7 @@ func _ready(): func _input(event): if event is InputEventMouseButton and event.is_released(): print("Mouse Click/Unclick at: ", event.position) - build_house(event.global_position) + build_house() func initialize_by_village(village: Dictionary): initialize( @@ -57,9 +57,11 @@ func instantiate_house(pos: Vector2): house.set_size(Vector2(Coordinate_weight, Coordinate_weight)) house.set_global_position(pos * Coordinate_weight + root_position - Vector2(Coordinate_weight / 2, Coordinate_weight / 2)) -func build_house(pos: Vector2): - var relative_pos = pos - root_position + Vector2(Coordinate_weight / 2, Coordinate_weight / 2) +func build_house(): + var pos = bg.get_global_mouse_position() + var relative_pos = pos - root_position relative_pos /= Coordinate_weight relative_pos.x = roundi(relative_pos.x) relative_pos.y = roundi(relative_pos.y) print("build house pos: ", relative_pos) + print("root pos: ", root_position) From 24ec65702e9464b6f7d40ea3577167e1e4cd754b Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Thu, 21 Dec 2023 12:06:38 +0900 Subject: [PATCH 42/51] =?UTF-8?q?=EC=9D=B4=EB=B2=88=EC=97=94=20=EC=A7=84?= =?UTF-8?q?=EC=A7=9C=EB=A1=9C=20=EC=A2=8C=ED=91=9C=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EB=98=91=EB=B0=94=EB=A1=9C=20=EB=90=A9=EB=8B=88=EB=8B=A4=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A1=A4=ED=95=B4=EB=8F=84=20=EB=90=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Saver-22b-godot/village_view/VillageView.gd | 15 ++++++++++----- .../village_background_nine_patch_rect.tscn | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index ce8f2037..2f978a62 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -6,9 +6,11 @@ var height: int var worldX: int var worldY: int var root_position: Vector2 +var root_local_position: Vector2 @export_group("View nodes") @export var bg: NinePatchRect +@export var root_rect: TextureRect const Origin_house = preload("res://village_view/house_texture_rect.tscn") const Coordinate_weight = 300 @@ -20,7 +22,8 @@ func _ready(): # Mouse in viewport coordinates. func _input(event): - if event is InputEventMouseButton and event.is_released(): + var mouse_event = event as InputEventMouseButton + if mouse_event != null and mouse_event.is_released() and mouse_event.button_index == MOUSE_BUTTON_LEFT: print("Mouse Click/Unclick at: ", event.position) build_house() @@ -48,7 +51,8 @@ func set_size(): bg.size.y = height bg.custom_minimum_size = bg.size bg.set_anchors_and_offsets_preset(Control.PRESET_CENTER, Control.PRESET_MODE_KEEP_SIZE) - root_position = get_tree().root.size / 2 + root_position = get_tree().root.size / 2 + root_local_position = root_rect.global_position - bg.global_position func instantiate_house(pos: Vector2): print("instantiate_house: ", pos) @@ -58,10 +62,11 @@ func instantiate_house(pos: Vector2): house.set_global_position(pos * Coordinate_weight + root_position - Vector2(Coordinate_weight / 2, Coordinate_weight / 2)) func build_house(): - var pos = bg.get_global_mouse_position() - var relative_pos = pos - root_position + var pos = bg.get_local_mouse_position() + var relative_pos = pos - root_local_position relative_pos /= Coordinate_weight relative_pos.x = roundi(relative_pos.x) relative_pos.y = roundi(relative_pos.y) print("build house pos: ", relative_pos) - print("root pos: ", root_position) + print("root pos: ", root_local_position) + print("mouse pos: ", pos) diff --git a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn index 77d586de..43941447 100644 --- a/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn +++ b/frontend/Saver-22b-godot/village_view/village_background_nine_patch_rect.tscn @@ -4,7 +4,7 @@ [ext_resource type="Script" path="res://village_view/VillageView.gd" id="2_1w4b1"] [ext_resource type="Texture2D" uid="uid://bq1id6g5rr7by" path="res://sprites/mid.png" id="3_e4wt8"] -[node name="VillageBackground_NinePatchRect" type="NinePatchRect" node_paths=PackedStringArray("bg")] +[node name="VillageBackground_NinePatchRect" type="NinePatchRect" node_paths=PackedStringArray("bg", "root_rect")] z_index = -1000 texture_filter = 1 custom_minimum_size = Vector2(40, 40) @@ -30,6 +30,7 @@ patch_margin_right = 3 patch_margin_bottom = 3 script = ExtResource("2_1w4b1") bg = NodePath(".") +root_rect = NodePath("TextureRect") [node name="TextureRect" type="TextureRect" parent="."] texture_filter = 1 From 59a2488830fe7fdff387e9602623e27abb707099 Mon Sep 17 00:00:00 2001 From: sonohoshi Date: Thu, 21 Dec 2023 12:10:48 +0900 Subject: [PATCH 43/51] =?UTF-8?q?=EC=BB=A4=EB=A7=A8=EB=93=9C=EB=82=98=20?= =?UTF-8?q?=EC=BB=A8=ED=8A=B8=EB=A1=A4=20=ED=82=A4=EB=A5=BC=20=EA=B0=99?= =?UTF-8?q?=EC=9D=B4=20=EB=88=8C=EB=9F=AC=EC=95=BC=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EA=B0=80=20=EC=B0=8D=ED=9E=88=EA=B2=8C=20=ED=95=B4=EB=86=A8?= =?UTF-8?q?=EC=8A=B5=EB=8B=88=EB=8B=A4=20=EC=A0=9C=EB=8C=80=EB=A1=9C=20?= =?UTF-8?q?=EB=90=9C=20=EC=9D=B8=ED=92=8B=20=EC=A1=B0=EA=B1=B4=20=ED=95=84?= =?UTF-8?q?=ED=84=B0=EB=A7=81=EC=9D=B4=20=EC=96=B4=EB=A0=B5=EB=84=A4?= =?UTF-8?q?=EC=9A=94...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/Saver-22b-godot/village_view/VillageView.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index 2f978a62..7bbfa34d 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -23,7 +23,7 @@ func _ready(): # Mouse in viewport coordinates. func _input(event): var mouse_event = event as InputEventMouseButton - if mouse_event != null and mouse_event.is_released() and mouse_event.button_index == MOUSE_BUTTON_LEFT: + if mouse_event != null and mouse_event.is_released() and mouse_event.button_index == MOUSE_BUTTON_LEFT and mouse_event.is_command_or_control_pressed(): print("Mouse Click/Unclick at: ", event.position) build_house() From 54054c4a8718bb7a7b72805359e09e01eae5f97a Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Thu, 21 Dec 2023 13:01:19 +0900 Subject: [PATCH 44/51] implement farm #1 --- frontend/Saver-22b-godot/scenes/farm.tscn | 88 +++++++++++++++++++ .../Saver-22b-godot/scripts/scenes/farm.gd | 4 + .../Saver-22b-godot/ui/farm_slot_button.gd | 28 ++++++ .../Saver-22b-godot/ui/farm_slot_button.tscn | 20 +++++ 4 files changed, 140 insertions(+) create mode 100644 frontend/Saver-22b-godot/scenes/farm.tscn create mode 100644 frontend/Saver-22b-godot/scripts/scenes/farm.gd create mode 100644 frontend/Saver-22b-godot/ui/farm_slot_button.gd create mode 100644 frontend/Saver-22b-godot/ui/farm_slot_button.tscn diff --git a/frontend/Saver-22b-godot/scenes/farm.tscn b/frontend/Saver-22b-godot/scenes/farm.tscn new file mode 100644 index 00000000..67001138 --- /dev/null +++ b/frontend/Saver-22b-godot/scenes/farm.tscn @@ -0,0 +1,88 @@ +[gd_scene load_steps=2 format=3 uid="uid://vy5r0acj44oh"] + +[ext_resource type="Script" path="res://scripts/scenes/farm.gd" id="1_q2tum"] + +[node name="Farm" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_q2tum") + +[node name="ColorRect" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"] +layout_mode = 2 +theme_override_constants/separation = 0 + +[node name="ColorRect" type="ColorRect" parent="MarginContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 0.7 +color = Color(0, 0, 0, 1) + +[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/ColorRect"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="GridContainer" type="GridContainer" parent="MarginContainer/HBoxContainer/ColorRect/MarginContainer"] +layout_mode = 2 +theme_override_constants/h_separation = 10 +theme_override_constants/v_separation = 10 +columns = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 0.3 + +[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/HBoxContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 3 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/HBoxContainer/VBoxContainer/MarginContainer"] +layout_mode = 2 + +[node name="HomeButton" type="Button" parent="MarginContainer/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_font_sizes/font_size = 50 +text = "Home" + +[node name="InventoryButton" type="Button" parent="MarginContainer/HBoxContainer/VBoxContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +size_flags_vertical = 0 +theme_override_font_sizes/font_size = 50 +text = "Inventory" diff --git a/frontend/Saver-22b-godot/scripts/scenes/farm.gd b/frontend/Saver-22b-godot/scripts/scenes/farm.gd new file mode 100644 index 00000000..d5252b81 --- /dev/null +++ b/frontend/Saver-22b-godot/scripts/scenes/farm.gd @@ -0,0 +1,4 @@ +extends Control + +func _ready(): + print("farm scene ready") diff --git a/frontend/Saver-22b-godot/ui/farm_slot_button.gd b/frontend/Saver-22b-godot/ui/farm_slot_button.gd new file mode 100644 index 00000000..effed01b --- /dev/null +++ b/frontend/Saver-22b-godot/ui/farm_slot_button.gd @@ -0,0 +1,28 @@ +extends ColorRect + +signal button_down(child_index: int) + +@onready var button = $Button + +var farm_slot: Dictionary + +func _ready(): + _update_button() + +func _update_button(): + if button == null: + return + + button.text = """%s %s + (%d %s)""" % [ + "벼", + "자라는 중", + 1, + "블록 남음"] + +func set_farm_slot(farm_slot: Dictionary): + self.farm_slot = farm_slot + _update_button() + +func _on_button_button_down(): + button_down.emit(get_index()) diff --git a/frontend/Saver-22b-godot/ui/farm_slot_button.tscn b/frontend/Saver-22b-godot/ui/farm_slot_button.tscn new file mode 100644 index 00000000..5f930c51 --- /dev/null +++ b/frontend/Saver-22b-godot/ui/farm_slot_button.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=2 format=3 uid="uid://c0qm0ud7mwmwb"] + +[ext_resource type="Script" path="res://ui/farm_slot_button.gd" id="1_vqq1f"] + +[node name="FarmSlotButton" type="ColorRect"] +custom_minimum_size = Vector2(2.08165e-12, 200) +size_flags_horizontal = 3 +size_flags_vertical = 0 +script = ExtResource("1_vqq1f") + +[node name="Button" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_font_sizes/font_size = 50 +text = "[벼] 자라는 중 +[N 블록 남음]" From e9cee0a6509974f3e0cdbe50cda518ac766543a1 Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Thu, 21 Dec 2023 13:01:52 +0900 Subject: [PATCH 45/51] add Signer.signer_address --- frontend/Saver-22b-godot/scripts/sign/Signer.gd | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/Saver-22b-godot/scripts/sign/Signer.gd b/frontend/Saver-22b-godot/scripts/sign/Signer.gd index 20e76d3d..9bae0a38 100644 --- a/frontend/Saver-22b-godot/scripts/sign/Signer.gd +++ b/frontend/Saver-22b-godot/scripts/sign/Signer.gd @@ -1,6 +1,7 @@ extends Node; var signer +var signer_address func _ready(): var script = load("res://scripts/sign/Signer.cs") @@ -14,6 +15,8 @@ func _ready(): var f = FileAccess.open("user://privkey", FileAccess.WRITE) f.store_string(signer.GetRaw()) f.close() + + signer_address = signer.GetAddress() func sign(unsignedTransaction: String) -> String: return self.signer.Sign(unsignedTransaction) From bc0ea49327c79e3f7b2adec3864d533a4f557fca Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Thu, 21 Dec 2023 13:02:11 +0900 Subject: [PATCH 46/51] query userState --- frontend/Saver-22b-godot/scenes/intro.tscn | 6 +- .../scripts/global/scene_context.gd | 49 ++++++++++++ .../Saver-22b-godot/scripts/scenes/intro.gd | 80 ++++++++++++++++++- .../scripts/scenes/select_village.gd | 1 + 4 files changed, 128 insertions(+), 8 deletions(-) diff --git a/frontend/Saver-22b-godot/scenes/intro.tscn b/frontend/Saver-22b-godot/scenes/intro.tscn index 74c47cf3..30230aa6 100644 --- a/frontend/Saver-22b-godot/scenes/intro.tscn +++ b/frontend/Saver-22b-godot/scenes/intro.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=3 format=3 uid="uid://cg773cnsx4rb0"] +[gd_scene load_steps=2 format=3 uid="uid://cg773cnsx4rb0"] [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"] layout_mode = 3 @@ -97,8 +96,5 @@ grow_vertical = 2 theme_override_font_sizes/font_size = 70 text = "Play" -[node name="gql_test" type="Node" parent="."] -script = ExtResource("2_yxm3e") - [connection signal="button_down" from="QuitButtonContainer/Button" to="." method="_on_quit_button_button_down"] [connection signal="button_down" from="PlayButtonContainer/Button" to="." method="_on_play_button_button_down"] diff --git a/frontend/Saver-22b-godot/scripts/global/scene_context.gd b/frontend/Saver-22b-godot/scripts/global/scene_context.gd index 431d531c..700c3eb9 100644 --- a/frontend/Saver-22b-godot/scripts/global/scene_context.gd +++ b/frontend/Saver-22b-godot/scripts/global/scene_context.gd @@ -1,10 +1,59 @@ 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 +var user_state: Dictionary + +#func _ready(): + #var json = JSON.new() + #var error = json.parse(villages_json_string) + #if error != OK: + #print(error) + #else: + #villages = json.data.villages func set_villages(query_data: Dictionary): villages = query_data.data.villages +func set_user_state(query_data: Dictionary): + user_state = query_data.data.userState + func get_selected_village(): return villages[selected_village_index] diff --git a/frontend/Saver-22b-godot/scripts/scenes/intro.gd b/frontend/Saver-22b-godot/scripts/scenes/intro.gd index ada2e83d..ec87c59a 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/intro.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/intro.gd @@ -3,6 +3,7 @@ extends Control func _ready(): print("intro scene ready") _query_villages() + _query_user_state() func _on_quit_button_button_down(): print("quit button down") @@ -26,9 +27,82 @@ func _query_villages(): "owner", ]), ]) - + print(query.serialize()) var query_executor = SvrGqlClient.query('query', {}, query) - query_executor.graphql_response.connect(func(data): - SceneContext.set_villages(data)) + query_executor.graphql_response.connect( + func(data): + SceneContext.set_villages(data) + ) add_child(query_executor) query_executor.run({}) + +func _query_user_state(): + print("signer address: %s" % GlobalSigner.signer_address) + var query = GQLQuery.new("userState").set_args({ + "signer_address": "address", + }).set_props([ + GQLQuery.new("inventoryState").set_props([ + GQLQuery.new("seedStateList").set_props([ + "stateId", + "seedId", + "name", + ]), + GQLQuery.new("refrigeratorStateList").set_props([ + "stateId", + "ingredientId", + "foodID", + "name", + "grade", + "hp", + "attack", + "defense", + "speed", + "isSuperFood", + "isAvailable", + ]), + GQLQuery.new("kitchenEquipmentStateList").set_props([ + "stateId", + "equipmentId", + "equipmentName", + "blockTimeReductionPercent", + "equipmentCategoryId", + "equipmentCategoryName", + "equipmentCategoryType", + "isCooking", + "cookingEndBlockIndex", + GQLQuery.new("cookingFood").set_props([ + "stateId", + "ingredientId", + "foodID", + "name", + "grade", + "hp", + "attack", + "defense", + "speed", + "isSuperFood", + "isAvailable", + ]), + ]), + GQLQuery.new("itemStateList").set_props([ + "stateID", + "itemID", + "itemName", + ]), + ]), + ]) + print(query.serialize()) + var query_executor = SvrGqlClient.query( + 'query', + { + "signer_address": "String!", + }, + query) + query_executor.graphql_response.connect( + func(data): + SceneContext.set_user_state(data) + ) + add_child(query_executor) + query_executor.run({ + "signer_address": GlobalSigner.signer_address + }) diff --git a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd index e0b84a90..9db991cf 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd @@ -28,3 +28,4 @@ func _on_village_button_button_down(village_index): func _on_start_button_button_down(): print("start button down: %s" % SceneContext.selected_village_index) get_tree().change_scene_to_file("res://village_view/VillageView.tscn") + #get_tree().change_scene_to_file("res://scenes/farm.tscn") From 9576f5a75e9bd8923a5001cca91ccab99fb8d3e2 Mon Sep 17 00:00:00 2001 From: Kim sm Date: Thu, 21 Dec 2023 13:49:14 +0900 Subject: [PATCH 47/51] place house gql(real) (#109) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * place house unsigned transaction을 받아왔습니다 * dict에서 unsigned tx 가져왔고 * 집을 지을 수 있어요 컨트롤 클릭으로 집을 짓고 게임을 껐다 켜세요 --- frontend/Saver-22b-godot/gql/query.gd | 15 +++++++++++ .../Saver-22b-godot/gql/svr_gql_client.gd | 3 +++ .../village_view/VillageView.gd | 26 +++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/frontend/Saver-22b-godot/gql/query.gd b/frontend/Saver-22b-godot/gql/query.gd index 645c0163..2756ec31 100644 --- a/frontend/Saver-22b-godot/gql/query.gd +++ b/frontend/Saver-22b-godot/gql/query.gd @@ -8,3 +8,18 @@ var get_villages_query = "query { worldY } }" + +var place_house_query_format = "query { + createAction_PlaceUserHouse( + publicKey: {}, + villageId: {}, + x: {}, + y: {} + ) +}" + +var stage_tx_query_format = "mutation { + stageTransaction( + unsignedTransaction:\"%s\", + signature:\"%s\") +}" diff --git a/frontend/Saver-22b-godot/gql/svr_gql_client.gd b/frontend/Saver-22b-godot/gql/svr_gql_client.gd index ca53901e..ce3cda27 100644 --- a/frontend/Saver-22b-godot/gql/svr_gql_client.gd +++ b/frontend/Saver-22b-godot/gql/svr_gql_client.gd @@ -3,3 +3,6 @@ extends GQLClient func _ready(): print("client ready") set_endpoint(false, "192.168.2.9", 38080, "/graphql") + +func raw_mutation(query:String): + return GQLQueryExecuter.new(endpoint, use_ssl, Mutation.new(query)) diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index 7bbfa34d..5c39ce69 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -12,6 +12,7 @@ var root_local_position: Vector2 @export var bg: NinePatchRect @export var root_rect: TextureRect +const Gql_query = preload("res://gql/query.gd") const Origin_house = preload("res://village_view/house_texture_rect.tscn") const Coordinate_weight = 300 @@ -70,3 +71,28 @@ func build_house(): print("build house pos: ", relative_pos) print("root pos: ", root_local_position) print("mouse pos: ", pos) + print("public key: ", GlobalSigner.signer.GetPublicKey()) + var gql_query = Gql_query.new() + var query_string = gql_query.place_house_query_format.format([ + "\"%s\"" % GlobalSigner.signer.GetPublicKey(), + SceneContext.get_selected_village()["id"], + relative_pos.x, + relative_pos.y], "{}") + print(query_string) + + var query_executor = SvrGqlClient.raw(query_string) + query_executor.graphql_response.connect(func(data): + print("gql response: ", data) + var unsigned_tx = data["data"]["createAction_PlaceUserHouse"] + print("unsigned tx: ", unsigned_tx) + var signature = GlobalSigner.sign(unsigned_tx) + print("signed tx: ", signature) + var mutation_executor = SvrGqlClient.raw_mutation(gql_query.stage_tx_query_format % [unsigned_tx, signature]) + mutation_executor.graphql_response.connect(func(data): + print("mutation res: ", data) + ) + add_child(mutation_executor) + mutation_executor.run({}) + ) + add_child(query_executor) + query_executor.run({}) From a28efc6f5da574f82db8222ce126472f593ebca7 Mon Sep 17 00:00:00 2001 From: Mizuki Date: Thu, 21 Dec 2023 13:55:05 +0900 Subject: [PATCH 48/51] Fix initial seeding in PlaceUserHouseAction (#110) --- .../app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs | 4 ++++ backend/app/Savor22b/Action/PlaceUserHouseAction.cs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs b/backend/app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs index 379afba8..eb8743e5 100644 --- a/backend/app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs +++ b/backend/app/Savor22b.Tests/Action/PlaceUserHouseActionTests.cs @@ -57,6 +57,10 @@ is Bencodex.Types.Dictionary stateEncoded ); Assert.Equal(100, rootState.InventoryState.SeedStateList.Count); + Assert.All( + rootState.InventoryState.SeedStateList, + (seed) => Assert.True(seed.SeedID >= 1 && seed.SeedID <= 13) + ); Assert.Equal( Enumerable.Repeat(10, 6).ToImmutableList(), rootState.InventoryState.KitchenEquipmentStateList.Aggregate( diff --git a/backend/app/Savor22b/Action/PlaceUserHouseAction.cs b/backend/app/Savor22b/Action/PlaceUserHouseAction.cs index 6126fd7d..531899c0 100644 --- a/backend/app/Savor22b/Action/PlaceUserHouseAction.cs +++ b/backend/app/Savor22b/Action/PlaceUserHouseAction.cs @@ -143,7 +143,7 @@ is Dictionary stateEncoded for (int i = 0; i < 100; i++) { inventoryState = inventoryState.AddSeed( - new SeedState(ctx.Random.GenerateRandomGuid(), ctx.Random.Next() % 13) + new SeedState(ctx.Random.GenerateRandomGuid(), ctx.Random.Next() % 13 + 1) ); } From 8e12c329de833c608c6e7c88967432ce8c86f00d Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Thu, 21 Dec 2023 13:21:09 +0900 Subject: [PATCH 49/51] query villageState with userState --- .../Saver-22b-godot/scripts/scenes/intro.gd | 104 +++++++++++++++++- 1 file changed, 102 insertions(+), 2 deletions(-) diff --git a/frontend/Saver-22b-godot/scripts/scenes/intro.gd b/frontend/Saver-22b-godot/scripts/scenes/intro.gd index ec87c59a..9295d447 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/intro.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/intro.gd @@ -27,7 +27,6 @@ func _query_villages(): "owner", ]), ]) - print(query.serialize()) var query_executor = SvrGqlClient.query('query', {}, query) query_executor.graphql_response.connect( func(data): @@ -41,6 +40,108 @@ func _query_user_state(): var query = GQLQuery.new("userState").set_args({ "signer_address": "address", }).set_props([ + GQLQuery.new("villageState").set_props([ + GQLQuery.new("houseFieldStates").set_props([ + "installedSeedGuid", + "seedID", + "installedBlock", + "totalBlock", + "lastWeedBlock", + "weedRemovalCount", + "seedName", + "isHarvested", + "weedRemovalAble", + ]), + GQLQuery.new("houseState").set_props([ + "villageId", + "positionX", + "positionY", + GQLQuery.new("kitchenState").set_props([ + GQLQuery.new("firstApplianceSpace").set_props([ + "spaceNumber", + GQLQuery.new("installedKitchenEquipment").set_props([ + "stateId", + "equipmentId", + "equipmentName", + "blockTimeReductionPercent", + "equipmentCategoryId", + "equipmentCategoryName", + "equipmentCategoryType", + "isCooking", + "cookingEndBlockIndex", + GQLQuery.new("cookingFood").set_props([ + "stateId", + "ingredientId", + "foodID", + "name", + "grade", + "hp", + "attack", + "defense", + "speed", + "isSuperFood", + "isAvailable", + ]), + ]), + ]), + GQLQuery.new("secondApplianceSpace").set_props([ + "spaceNumber", + GQLQuery.new("installedKitchenEquipment").set_props([ + "stateId", + "equipmentId", + "equipmentName", + "blockTimeReductionPercent", + "equipmentCategoryId", + "equipmentCategoryName", + "equipmentCategoryType", + "isCooking", + "cookingEndBlockIndex", + GQLQuery.new("cookingFood").set_props([ + "stateId", + "ingredientId", + "foodID", + "name", + "grade", + "hp", + "attack", + "defense", + "speed", + "isSuperFood", + "isAvailable", + ]), + ]), + ]), + GQLQuery.new("thirdApplianceSpace").set_props([ + "spaceNumber", + GQLQuery.new("installedKitchenEquipment").set_props([ + "stateId", + "equipmentId", + "equipmentName", + "blockTimeReductionPercent", + "equipmentCategoryId", + "equipmentCategoryName", + "equipmentCategoryType", + "isCooking", + "cookingEndBlockIndex", + GQLQuery.new("cookingFood").set_props([ + "stateId", + "ingredientId", + "foodID", + "name", + "grade", + "hp", + "attack", + "defense", + "speed", + "isSuperFood", + "isAvailable", + ]), + ]), + ]), + ]), + "villageName", + ]) + ]), GQLQuery.new("inventoryState").set_props([ GQLQuery.new("seedStateList").set_props([ "stateId", @@ -91,7 +192,6 @@ func _query_user_state(): ]), ]), ]) - print(query.serialize()) var query_executor = SvrGqlClient.query( 'query', { From 1ca934926090cbb289fe61a28ca8999fb3149972 Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Thu, 21 Dec 2023 14:14:31 +0900 Subject: [PATCH 50/51] remove useless --- frontend/Saver-22b-godot/scripts/scenes/select_village.gd | 1 - frontend/Saver-22b-godot/village_view/TemporaryView.gd | 7 ------- 2 files changed, 8 deletions(-) diff --git a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd index 9db991cf..e0b84a90 100644 --- a/frontend/Saver-22b-godot/scripts/scenes/select_village.gd +++ b/frontend/Saver-22b-godot/scripts/scenes/select_village.gd @@ -28,4 +28,3 @@ func _on_village_button_button_down(village_index): func _on_start_button_button_down(): print("start button down: %s" % SceneContext.selected_village_index) get_tree().change_scene_to_file("res://village_view/VillageView.tscn") - #get_tree().change_scene_to_file("res://scenes/farm.tscn") diff --git a/frontend/Saver-22b-godot/village_view/TemporaryView.gd b/frontend/Saver-22b-godot/village_view/TemporaryView.gd index e95be06f..848b1edf 100644 --- a/frontend/Saver-22b-godot/village_view/TemporaryView.gd +++ b/frontend/Saver-22b-godot/village_view/TemporaryView.gd @@ -7,12 +7,5 @@ func _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)]) - add_child(village_view_instance) village_view_instance.initialize_by_village(village) From 47651b3db2a5017f76c7cce77dd1b96f7180dd6a Mon Sep 17 00:00:00 2001 From: Hyun Seungmin Date: Thu, 21 Dec 2023 14:21:01 +0900 Subject: [PATCH 51/51] wip --- .../village_view/VillageView.gd | 23 +++++++++++-------- .../village_view/house_texture_rect.gd | 7 ++++++ .../village_view/house_texture_rect.tscn | 19 ++++++++++++++- 3 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 frontend/Saver-22b-godot/village_view/house_texture_rect.gd diff --git a/frontend/Saver-22b-godot/village_view/VillageView.gd b/frontend/Saver-22b-godot/village_view/VillageView.gd index 5c39ce69..9eb5dcbb 100644 --- a/frontend/Saver-22b-godot/village_view/VillageView.gd +++ b/frontend/Saver-22b-godot/village_view/VillageView.gd @@ -26,7 +26,14 @@ func _input(event): var mouse_event = event as InputEventMouseButton if mouse_event != null and mouse_event.is_released() and mouse_event.button_index == MOUSE_BUTTON_LEFT and mouse_event.is_command_or_control_pressed(): print("Mouse Click/Unclick at: ", event.position) - build_house() + print("root pos: ", root_local_position) + var pos = bg.get_local_mouse_position() + print("mouse pos: ", pos) + var relative_pos = pos - root_local_position + relative_pos /= Coordinate_weight + relative_pos.x = roundi(relative_pos.x) + relative_pos.y = roundi(relative_pos.y) + build_house(relative_pos) func initialize_by_village(village: Dictionary): initialize( @@ -61,16 +68,14 @@ func instantiate_house(pos: Vector2): bg.add_child(house) house.set_size(Vector2(Coordinate_weight, Coordinate_weight)) house.set_global_position(pos * Coordinate_weight + root_position - Vector2(Coordinate_weight / 2, Coordinate_weight / 2)) + house.button_down.connect(func(house_pos): + #var village = SceneContext.get_selected_village() + #village.houses. + get_tree().change_scene_to_file("res://scenes/farm.tscn") + ) -func build_house(): - var pos = bg.get_local_mouse_position() - var relative_pos = pos - root_local_position - relative_pos /= Coordinate_weight - relative_pos.x = roundi(relative_pos.x) - relative_pos.y = roundi(relative_pos.y) +func build_house(relative_pos: Vector2): print("build house pos: ", relative_pos) - print("root pos: ", root_local_position) - print("mouse pos: ", pos) print("public key: ", GlobalSigner.signer.GetPublicKey()) var gql_query = Gql_query.new() var query_string = gql_query.place_house_query_format.format([ diff --git a/frontend/Saver-22b-godot/village_view/house_texture_rect.gd b/frontend/Saver-22b-godot/village_view/house_texture_rect.gd new file mode 100644 index 00000000..ddca3d80 --- /dev/null +++ b/frontend/Saver-22b-godot/village_view/house_texture_rect.gd @@ -0,0 +1,7 @@ +extends TextureRect + +signal button_down(position: Vector2) + +func _on_button_button_down(): + print(position) + button_down.emit(position) diff --git a/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn b/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn index df27bdf9..42432a29 100644 --- a/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn +++ b/frontend/Saver-22b-godot/village_view/house_texture_rect.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=2 format=3 uid="uid://cjvcx7fit5avb"] +[gd_scene load_steps=3 format=3 uid="uid://ccrlf3kfcisji"] [ext_resource type="Texture2D" uid="uid://dajunmx26gvr5" path="res://sprites/house.png" id="1_4yb37"] +[ext_resource type="Script" path="res://village_view/house_texture_rect.gd" id="2_hemgv"] [node name="House_TextureRect" type="TextureRect"] anchors_preset = 8 @@ -17,3 +18,19 @@ grow_vertical = 2 size_flags_horizontal = 4 size_flags_vertical = 4 texture = ExtResource("1_4yb37") +script = ExtResource("2_hemgv") + +[node name="Button" type="Button" parent="."] +layout_mode = 1 +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -6.0 +offset_bottom = 16.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_font_sizes/font_size = 10 +text = "Enter" + +[connection signal="button_down" from="Button" to="." method="_on_button_button_down"]