Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f4dfccbc6 | |||
| 3c370e30a0 | |||
| 073a74bb22 |
@@ -160,11 +160,9 @@ libraries = {
|
||||
&"": SubResource("AnimationLibrary_54k4r")
|
||||
}
|
||||
|
||||
[node name="InteractionArea" parent="." instance=ExtResource("15_uo3dh")]
|
||||
[node name="InteractionArea" parent="." node_paths=PackedStringArray("_spritesToOutline") instance=ExtResource("15_uo3dh")]
|
||||
position = Vector2(18, -250)
|
||||
_sceneKeyProvider = null
|
||||
_saveId = "f99549a9-c97e-45a4-b3c9-4bac23fe6fe7"
|
||||
_outlineMaterial = null
|
||||
_spritesToOutline = [NodePath("../Duck rendered")]
|
||||
|
||||
[node name="CollisionShape3D" parent="InteractionArea/Area2D" index="0"]
|
||||
shape = SubResource("CircleShape2D_uo3dh")
|
||||
|
||||
@@ -6,3 +6,4 @@
|
||||
script = ExtResource("1_5dt1r")
|
||||
_fightRoomScenePath = "res://scenes/Babushka_scene_fight_world_room.tscn"
|
||||
_fightHappeningScene = "res://scenes/Babushka_scene_fight_happening.tscn"
|
||||
_nightEndScene = "res://scenes/Babushka_scene_indoor_vesnas_room.tscn"
|
||||
|
||||
@@ -34,7 +34,6 @@ Signal_Debugger="*res://addons/SignalVisualizer/Debugger/SignalDebugger.gd"
|
||||
FightWorldAutoload="*res://prefabs/fight/fight_world_autoload.tscn"
|
||||
FieldService="*res://scripts/CSharp/Common/Farming/FieldService.cs"
|
||||
SaveGameManager="*res://scripts/CSharp/Common/Savegame/SaveGameManager.cs"
|
||||
SettingsSaveController="*res://scripts/CSharp/Common/Savegame/SettingsSaveController.cs"
|
||||
|
||||
[dialogic]
|
||||
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://bopv10dqm1knc"]
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bopv10dqm1knc"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c6wnoif01ltld" path="res://scenes/Babushka_scene_startMenu.tscn" id="1_15ton"]
|
||||
[ext_resource type="Script" uid="uid://bbp0dyddwdbl8" path="res://scripts/CSharp/Common/Savegame/WindowSettingsSync.cs" id="2_d3jfo"]
|
||||
|
||||
[node name="BabushkaSceneBootstrap" type="Node2D"]
|
||||
|
||||
[node name="BabushkaSceneStartMenu" parent="." instance=ExtResource("1_15ton")]
|
||||
_sceneNamesToLoad = PackedStringArray("res://scenes/Babushka_scene_farm_outside_2d.tscn")
|
||||
|
||||
[node name="SceneParent" type="Node" parent="."]
|
||||
|
||||
[node name="WindowSettings" type="Node" parent="."]
|
||||
script = ExtResource("2_d3jfo")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=121 format=3 uid="uid://gigb28qk8t12"]
|
||||
[gd_scene load_steps=116 format=3 uid="uid://gigb28qk8t12"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="1_7wfwe"]
|
||||
[ext_resource type="Texture2D" uid="uid://8sr11ex30n0m" path="res://art/mockups/Kenney_Backgrounds/Samples/uncolored_hills.png" id="2_7b2ri"]
|
||||
@@ -38,6 +38,7 @@
|
||||
[ext_resource type="Resource" uid="uid://d1uuxp1lp4aro" path="res://resources/items/tomato_seed.tres" id="35_64mdn"]
|
||||
[ext_resource type="Texture2D" uid="uid://65e44yde224q" path="res://art/farm/Babushka_house_01.png" id="36_e5b7x"]
|
||||
[ext_resource type="Resource" uid="uid://duq7tshxv6uhp" path="res://resources/items/beet_seed.tres" id="36_fv1t2"]
|
||||
[ext_resource type="Texture2D" uid="uid://cyyxqmphcrjj" path="res://art/farm/farming/farmobjekte/tomaten/tomaten_template.png" id="36_l7ekk"]
|
||||
[ext_resource type="AudioStream" uid="uid://cfqg50am0swb7" path="res://audio/Music/Farming_90BPM_69Bars_Loop.wav" id="37_8ey8m"]
|
||||
[ext_resource type="AudioStream" uid="uid://dku1rq5cocisg" path="res://audio/Music/Farming_90BPM_69Bars.wav" id="37_di1ed"]
|
||||
[ext_resource type="Shader" uid="uid://braevmqauoek7" path="res://shader/swaying_plant.gdshader" id="37_taxvr"]
|
||||
@@ -78,7 +79,6 @@
|
||||
[ext_resource type="Script" uid="uid://dih1b0opgc3f7" path="res://scripts/GdScript/dialogic_start_specific.gd" id="77_l7ekk"]
|
||||
[ext_resource type="Resource" uid="uid://tt3d166mntmi" path="res://resources/low code/farming/var_sceneNameProvider.tres" id="77_xcwle"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1d2e7ely6hyw" path="res://prefabs/farm/base_field.tscn" id="78_xcwle"]
|
||||
[ext_resource type="Script" uid="uid://iquhbkr7pqeg" path="res://scripts/CSharp/Common/Savegame/SaveCheats.cs" id="79_065st"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_wtdui"]
|
||||
shader = ExtResource("13_7p0hq")
|
||||
@@ -236,20 +236,6 @@ shader_parameter/value_mult = 1.0
|
||||
shader_parameter/brightness_add = 0.0
|
||||
shader_parameter/contrast_mult = 1.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_065st"]
|
||||
resource_local_to_scene = true
|
||||
radius = 200.0
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_w1kgo"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_w1kgo"]
|
||||
resource_local_to_scene = true
|
||||
radius = 200.0
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_q1g8e"]
|
||||
viewport_path = NodePath("SubViewport")
|
||||
|
||||
[sub_resource type="AudioStreamPlaylist" id="AudioStreamPlaylist_ceriq"]
|
||||
loop = false
|
||||
stream_count = 1
|
||||
@@ -2257,6 +2243,7 @@ position = Vector2(-113.561, 193.035)
|
||||
shape = SubResource("RectangleShape2D_2vojv")
|
||||
|
||||
[node name="ducks" type="Node2D" parent="YSorted"]
|
||||
visible = false
|
||||
z_index = 1
|
||||
y_sort_enabled = true
|
||||
script = ExtResource("49_uxa2m")
|
||||
@@ -2268,24 +2255,12 @@ y_sort_enabled = false
|
||||
position = Vector2(4374, 2652)
|
||||
_penTarget = NodePath("../../pen/penSlot1")
|
||||
|
||||
[node name="CollisionShape3D" parent="YSorted/ducks/Duck2/InteractionArea/Area2D" index="0"]
|
||||
shape = SubResource("CircleShape2D_065st")
|
||||
|
||||
[node name="Duck rendered" parent="YSorted/ducks/Duck2" index="3"]
|
||||
texture = SubResource("ViewportTexture_w1kgo")
|
||||
|
||||
[node name="Duck3" parent="YSorted/ducks" node_paths=PackedStringArray("_penTarget") instance=ExtResource("62_i36hd")]
|
||||
z_index = 0
|
||||
y_sort_enabled = false
|
||||
position = Vector2(9259, 3194)
|
||||
_penTarget = NodePath("../../pen/penSlot2")
|
||||
|
||||
[node name="CollisionShape3D" parent="YSorted/ducks/Duck3/InteractionArea/Area2D" index="0"]
|
||||
shape = SubResource("CircleShape2D_w1kgo")
|
||||
|
||||
[node name="Duck rendered" parent="YSorted/ducks/Duck3" index="3"]
|
||||
texture = SubResource("ViewportTexture_q1g8e")
|
||||
|
||||
[node name="Duck4" parent="YSorted/ducks" node_paths=PackedStringArray("_penTarget") instance=ExtResource("62_i36hd")]
|
||||
z_index = 0
|
||||
y_sort_enabled = false
|
||||
@@ -2534,9 +2509,6 @@ script = ExtResource("76_l7ekk")
|
||||
_variableResource = ExtResource("77_xcwle")
|
||||
_payloadToSet = "farmOutside"
|
||||
|
||||
[node name="SaveGameCheat" type="Node" parent="."]
|
||||
script = ExtResource("79_065st")
|
||||
|
||||
[connection signal="FilledWateringCan" from="YSorted/Vesna" to="Audio/SFX/FillWater SFX2" method="PlayOneShot"]
|
||||
[connection signal="InteractedTool" from="YSorted/Well/InteractionArea" to="YSorted/Vesna" method="TryFillWateringCan"]
|
||||
[connection signal="SuccessfulPickUp" from="YSorted/CanGenericPickup" to="YSorted/Vesna" method="HandlePickUp"]
|
||||
@@ -2569,10 +2541,6 @@ script = ExtResource("79_065st")
|
||||
[editable path="YSorted/SeedPickup2"]
|
||||
[editable path="YSorted/SeedPickup2/PickupInteractionArea"]
|
||||
[editable path="YSorted/Blocker/InteractionArea"]
|
||||
[editable path="YSorted/ducks/Duck2"]
|
||||
[editable path="YSorted/ducks/Duck2/InteractionArea"]
|
||||
[editable path="YSorted/ducks/Duck3"]
|
||||
[editable path="YSorted/ducks/Duck3/InteractionArea"]
|
||||
[editable path="YSorted/trash/trashObject2"]
|
||||
[editable path="YSorted/trash/trashObject3"]
|
||||
[editable path="YSorted/trash/trashObject4"]
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://ceaa2qj2bmw43"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://ceaa2qj2bmw43"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cssdu8viimwm6" path="res://scripts/CSharp/Common/SceneTransition.cs" id="1_c6eln"]
|
||||
[ext_resource type="Texture2D" uid="uid://cugtxcfuds31r" path="res://art/indoor/Babushka_bg_01.png" id="2_j25a2"]
|
||||
[ext_resource type="Script" uid="uid://cldtt4atgymm5" path="res://scripts/CSharp/Common/Quest/QuestTrigger.cs" id="8_j25a2"]
|
||||
[ext_resource type="PackedScene" uid="uid://cqc72e4hq6bcd" path="res://prefabs/interactions/interaction_area_2d.tscn" id="8_phqdf"]
|
||||
[ext_resource type="Resource" uid="uid://csj15gnlx1jmx" path="res://resources/quests/demo/8_goto_bed.tres" id="9_heyef"]
|
||||
[ext_resource type="Script" uid="uid://puw74w6lmcvl" path="res://scripts/CSharp/Common/Fight/NightStarter.cs" id="10_j25a2"]
|
||||
[ext_resource type="Texture2D" uid="uid://cop1vjvhwlsec" path="res://art/indoor/room export/Room_01_shelf.png" id="13_11fdt"]
|
||||
[ext_resource type="PackedScene" uid="uid://c25udixd5m6l0" path="res://prefabs/characters/Player2D.tscn" id="18_3gevq"]
|
||||
[ext_resource type="Script" uid="uid://bqomwxclsbhd3" path="res://scripts/CSharp/Common/Camera/CameraController.cs" id="23_408bg"]
|
||||
@@ -120,9 +121,14 @@ _id = 0
|
||||
[node name="CollisionShape3D" parent="DoorInteraction/Area2D" index="0"]
|
||||
shape = SubResource("CircleShape2D_2spkc")
|
||||
|
||||
[node name="NightStarter" type="Node" parent="."]
|
||||
script = ExtResource("10_j25a2")
|
||||
_sceneIndexToLoad = 1
|
||||
|
||||
[connection signal="Interacted" from="BedInteraction" to="BedInteraction/QuestCompleter" method="Trigger"]
|
||||
[connection signal="InteractedTool" from="BedInteraction" to="." method="LoadSceneAtIndex"]
|
||||
[connection signal="Interacted" from="BedInteraction" to="NightStarter" method="StartNight"]
|
||||
[connection signal="Interacted" from="DoorInteraction" to="." method="LoadScene"]
|
||||
[connection signal="LoadScene" from="NightStarter" to="." method="LoadSceneAtIndex"]
|
||||
|
||||
[editable path="Vesna"]
|
||||
[editable path="BedInteraction"]
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
using Babushka.scripts.CSharp.Common.Services;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.CharacterControls;
|
||||
|
||||
[Tool]
|
||||
public partial class InteractionArea2D : Node2D, ISaveable
|
||||
public partial class InteractionArea2D : Node2D
|
||||
{
|
||||
[ExportGroup("Persistence")]
|
||||
[Export] public Babushka.scripts.CSharp.Low_Code.Variables.VariableResource _sceneKeyProvider;
|
||||
[Export] private string _saveId;
|
||||
|
||||
[ExportGroup("Settings")]
|
||||
[Export] private Area2D _area;
|
||||
[Export] private Label _label;
|
||||
[Export] private bool _active = true;
|
||||
@@ -25,7 +18,6 @@ public partial class InteractionArea2D : Node2D, ISaveable
|
||||
[Export] private int _id = -1; // TODO: remove
|
||||
|
||||
private Material[] _backupMaterials;
|
||||
private int _interactionCounter;
|
||||
|
||||
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
|
||||
|
||||
@@ -48,10 +40,9 @@ public partial class InteractionArea2D : Node2D, ISaveable
|
||||
{
|
||||
_backupMaterials = _spritesToOutline.Select(s => s.Material).ToArray();
|
||||
}
|
||||
|
||||
LoadFromSaveData();
|
||||
}
|
||||
|
||||
|
||||
public void OnPlayerEntered(Node2D player)
|
||||
{
|
||||
if (!_active || !InputService.Instance.InputEnabled)
|
||||
@@ -114,18 +105,11 @@ public partial class InteractionArea2D : Node2D, ISaveable
|
||||
}
|
||||
}
|
||||
|
||||
Interact();
|
||||
UpdateSaveData();
|
||||
EmitSignal(SignalName.InteractedTool, _id);
|
||||
EmitSignal(SignalName.Interacted);
|
||||
}
|
||||
}
|
||||
|
||||
private void Interact()
|
||||
{
|
||||
EmitSignal(SignalName.InteractedTool, _id);
|
||||
EmitSignal(SignalName.Interacted);
|
||||
_interactionCounter++;
|
||||
}
|
||||
|
||||
public void SetSpriteActiveState(bool success, int id) // TODO: remove
|
||||
{
|
||||
if (!_active)
|
||||
@@ -137,39 +121,4 @@ public partial class InteractionArea2D : Node2D, ISaveable
|
||||
_active = !_active;
|
||||
_label.Hide();
|
||||
}
|
||||
|
||||
#region SAVE AND LOAD
|
||||
|
||||
public void UpdateSaveData()
|
||||
{
|
||||
var payloadData = new Dictionary<string, Variant>
|
||||
{
|
||||
{ "interaction_counter", _interactionCounter }
|
||||
};
|
||||
|
||||
SavegameService.AppendDataToSave(_sceneKeyProvider.Payload.AsString(), _saveId, payloadData);
|
||||
}
|
||||
|
||||
public void LoadFromSaveData()
|
||||
{
|
||||
var sceneName = _sceneKeyProvider.Payload.AsString();
|
||||
var id = _saveId;
|
||||
int counter = 0;
|
||||
|
||||
Dictionary<string, Variant> save = SavegameService.GetSaveData(sceneName, id);
|
||||
if (save.Count > 0)
|
||||
{
|
||||
if (save.TryGetValue("interaction_counter", out Variant interactionCounterVar))
|
||||
{
|
||||
counter = interactionCounterVar.AsInt32();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < counter; i++)
|
||||
{
|
||||
Interact();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace Babushka.scripts.CSharp.Common.Farming;
|
||||
/// Defines the behaviour of the field, i.e. interactions, states and effects.
|
||||
/// </summary>
|
||||
[GlobalClass]
|
||||
public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
||||
public partial class FieldBehaviour2D : Sprite2D
|
||||
{
|
||||
[ExportGroup("Persistence")]
|
||||
[Export] public string SaveId = "";
|
||||
@@ -185,6 +185,10 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
||||
|
||||
public void UpdateSaveData()
|
||||
{
|
||||
var saveData = new SaveData();
|
||||
|
||||
saveData.SceneName = _sceneKeyProvider.Payload.AsString();
|
||||
saveData.Id = SaveId + _fieldIndex.Payload.AsString();
|
||||
var payloadData = new Dictionary<string, Variant>
|
||||
{
|
||||
{ "field_state", (int)FieldState }
|
||||
@@ -202,15 +206,17 @@ public partial class FieldBehaviour2D : Sprite2D, ISaveable
|
||||
);
|
||||
}
|
||||
|
||||
SavegameService.AppendDataToSave(_sceneKeyProvider.Payload.AsString(), SaveId + _fieldIndex.Payload.AsString(), payloadData);
|
||||
saveData.JsonPayload = Json.Stringify(payloadData, indent: "\t");
|
||||
|
||||
SavegameService.AppendSave(saveData);
|
||||
}
|
||||
|
||||
public void LoadFromSaveData()
|
||||
{
|
||||
var sceneName = _sceneKeyProvider.Payload.AsString();
|
||||
var id = SaveId + _fieldIndex.Payload.AsString();
|
||||
|
||||
Dictionary<string, Variant> save = SavegameService.GetSaveData(sceneName, id);
|
||||
string jsonPayload = SavegameService.GetSaveData(sceneName, id);
|
||||
Dictionary<string, Variant> save = Json.ParseString(jsonPayload).AsGodotDictionary<string, Variant>();
|
||||
|
||||
if (save.Count > 0)
|
||||
{
|
||||
|
||||
@@ -4,11 +4,8 @@ using Babushka.scripts.CSharp.Common.Util;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Fight.Actions;
|
||||
|
||||
public class BlobAttackAction : FighterAction
|
||||
public class BlobAttackAction(int damage = 3) : FighterAction
|
||||
{
|
||||
// settings
|
||||
private const int Damage = 3;
|
||||
|
||||
public override Variant<float, Func<bool>> GetAnimationEnd()
|
||||
{
|
||||
return 1;
|
||||
@@ -21,7 +18,7 @@ public class BlobAttackAction : FighterAction
|
||||
|
||||
public override void ExecuteAction()
|
||||
{
|
||||
FightWorld.Instance.allyFighters.vesnaFighter.AddHealth(-Damage);
|
||||
FightWorld.Instance.allyFighters.vesnaFighter.AddHealth(-damage);
|
||||
}
|
||||
|
||||
public override async Task AnimateAction(AllFightersVisual allFightersVisual)
|
||||
@@ -34,7 +31,7 @@ public class BlobAttackAction : FighterAction
|
||||
|
||||
await currentFighterVisual.AnimatePosToTarget(targetFighterVisual);
|
||||
_ = targetFighterVisual.AnimateHit();
|
||||
targetFighterVisual.SpawnDamageIndicatorNumber(Damage);
|
||||
targetFighterVisual.SpawnDamageIndicatorNumber(damage);
|
||||
await currentFighterVisual.AnimatePosToBase();
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ public class AllyFighters
|
||||
public FightWorld.Fighter vesnaFighter = new()
|
||||
{
|
||||
type = FightWorld.Fighter.Type.Vesna,
|
||||
maxHealth = 20,
|
||||
maxHealth = 60,
|
||||
availableActions =
|
||||
[
|
||||
new AllyAttackAction()
|
||||
|
||||
@@ -11,6 +11,7 @@ public partial class FightSceneSwitcher : Node
|
||||
[Export] private Node _sceneRoot = null!;
|
||||
[Export] private string _fightRoomScenePath = null!;
|
||||
[Export] private string _fightHappeningScene = null!;
|
||||
[Export] private string _nightEndScene = null!;
|
||||
|
||||
private void LoadNext()
|
||||
{
|
||||
@@ -36,6 +37,12 @@ public partial class FightSceneSwitcher : Node
|
||||
if (!FightWorld.Instance.currentRoom.paths.TryGetValue(pathIndex, out var nextRoom))
|
||||
throw new Exception("Trying to go down a non-existent path");
|
||||
|
||||
if (nextRoom.specialRoom == FightWorld.Room.Special.EndOfNight)
|
||||
{
|
||||
ExitFightWorld();
|
||||
return;
|
||||
}
|
||||
|
||||
FightWorld.Instance.currentRoom = nextRoom;
|
||||
LoadNext();
|
||||
}
|
||||
@@ -60,4 +67,10 @@ public partial class FightSceneSwitcher : Node
|
||||
FightWorld.Instance.fightHappeningData = null;
|
||||
LoadNext();
|
||||
}
|
||||
|
||||
public void ExitFightWorld()
|
||||
{
|
||||
SceneTransitionThreaded.Instance.ChangeSceneToFile(_nightEndScene);
|
||||
_ = UnloadAfterDelay();
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,14 @@ public partial class FightWorld : Node
|
||||
|
||||
public class Room
|
||||
{
|
||||
public enum Special
|
||||
{
|
||||
None,
|
||||
EndOfNight
|
||||
}
|
||||
public required Dictionary<int, Room> paths;
|
||||
public required List<FighterGroup> enemyGroups;
|
||||
public Special specialRoom = Special.None;
|
||||
}
|
||||
|
||||
public class FighterGroup
|
||||
@@ -66,7 +72,6 @@ public partial class FightWorld : Node
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
MyEnterTree();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -76,7 +81,7 @@ public partial class FightWorld : Node
|
||||
public FightHappeningData? fightHappeningData = null;
|
||||
public AllyFighters allyFighters = new();
|
||||
|
||||
public void MyEnterTree()
|
||||
public void ResetFightWorld()
|
||||
{
|
||||
Generate();
|
||||
currentRoom = world!.rooms[0];
|
||||
@@ -108,6 +113,13 @@ public partial class FightWorld : Node
|
||||
{
|
||||
rooms.Add(GenerateDisconnectedRoom());
|
||||
}
|
||||
|
||||
rooms.Add(new Room
|
||||
{
|
||||
paths = [],
|
||||
enemyGroups = [],
|
||||
specialRoom = Room.Special.EndOfNight
|
||||
});
|
||||
|
||||
// Connect rooms linearly
|
||||
for (var i = 0; i < rooms.Count - 1; i++)
|
||||
@@ -133,7 +145,7 @@ public partial class FightWorld : Node
|
||||
{
|
||||
var enemyGroups = new List<FighterGroup>();
|
||||
|
||||
var enemyGroupCount = GD.RandRange(1, 3);
|
||||
var enemyGroupCount = GD.RandRange(1, 2);
|
||||
|
||||
for (var i = 0; i < enemyGroupCount; i++)
|
||||
{
|
||||
@@ -150,7 +162,7 @@ public partial class FightWorld : Node
|
||||
fighters = []
|
||||
};
|
||||
|
||||
var enemyCount = GD.RandRange(1, 3);
|
||||
var enemyCount = GD.RandRange(2, 3);
|
||||
|
||||
for (var i = 0; i < enemyCount; i++)
|
||||
{
|
||||
@@ -178,10 +190,10 @@ public partial class FightWorld : Node
|
||||
{
|
||||
type = type,
|
||||
health = null,
|
||||
maxHealth = 12,
|
||||
maxHealth = GD.RandRange(8, 20),
|
||||
availableActions =
|
||||
[
|
||||
new BlobAttackAction()
|
||||
new BlobAttackAction(GD.RandRange(2, 5))
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using Babushka.scripts.CSharp.Common.Fight;
|
||||
|
||||
public partial class NightStarter : Node
|
||||
{
|
||||
[Export] private int _sceneIndexToLoad;
|
||||
|
||||
[Signal] public delegate void LoadSceneEventHandler(int index);
|
||||
|
||||
public void StartNight()
|
||||
{
|
||||
FightWorld.Instance.ResetFightWorld();
|
||||
EmitSignalLoadScene(_sceneIndexToLoad);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://puw74w6lmcvl
|
||||
@@ -3,11 +3,10 @@ using System;
|
||||
using Godot;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Babushka.scripts.CSharp.Common.Savegame;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class InventoryInstance : Node, ISaveable
|
||||
public partial class InventoryInstance : Node
|
||||
{
|
||||
private List<InventorySlot> _slots = new();
|
||||
public IReadOnlyList<InventorySlot> Slots => _slots;
|
||||
@@ -18,9 +17,6 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
[Signal]
|
||||
public delegate void InventoryContentsChangedEventHandler();
|
||||
|
||||
private const string SCENE_NAME = "inventory";
|
||||
private const string ID = "instace";
|
||||
|
||||
/// <summary>
|
||||
/// The total amount of Inventoryslots in the inventory (empty and occupied).
|
||||
/// </summary>
|
||||
@@ -46,19 +42,6 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
}
|
||||
}
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
LoadFromSaveData();
|
||||
InventoryContentsChanged += UpdateSaveData;
|
||||
SlotAmountChanged += UpdateSaveData;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
InventoryContentsChanged -= UpdateSaveData;
|
||||
SlotAmountChanged -= UpdateSaveData;
|
||||
}
|
||||
|
||||
public InventoryActionResult AddItem(ItemInstance newItem)
|
||||
{
|
||||
var result = AddItemAndStackRecursive(newItem, 0);
|
||||
@@ -173,50 +156,4 @@ public partial class InventoryInstance : Node, ISaveable
|
||||
{
|
||||
return items.All(HasItems);
|
||||
}
|
||||
|
||||
#region SAVE AND LOAD
|
||||
|
||||
public void UpdateSaveData()
|
||||
{
|
||||
var payloadData = new Godot.Collections.Dictionary<string, Variant>();
|
||||
|
||||
for (int i = 0; i < _slots.Count; i++)
|
||||
{
|
||||
if (!_slots[i].IsEmpty())
|
||||
{
|
||||
string key = i.ToString();
|
||||
string[] value = new string[2];
|
||||
value[0] = _slots[i].itemInstance.blueprint.ResourcePath;
|
||||
value[1] = _slots[i].itemInstance.amount.ToString();
|
||||
payloadData.Add(key,value);
|
||||
}
|
||||
}
|
||||
|
||||
SavegameService.AppendDataToSave(SCENE_NAME, ID, payloadData);
|
||||
}
|
||||
|
||||
public void LoadFromSaveData()
|
||||
{
|
||||
var sceneName = SCENE_NAME;
|
||||
var id = ID;
|
||||
|
||||
Godot.Collections.Dictionary<string, Variant> save = SavegameService.GetSaveData(sceneName, id);
|
||||
|
||||
if (save.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < _slots.Count; i++)
|
||||
{
|
||||
if (save.TryGetValue(i.ToString(), out Variant inventoryItemData))
|
||||
{
|
||||
string[] savePayload = inventoryItemData.AsStringArray();
|
||||
ItemResource resource = ResourceLoader.Load<ItemResource>(savePayload[0]);
|
||||
int _amount = int.Parse(savePayload[1]);
|
||||
|
||||
ItemInstance instance = new ItemInstance { blueprint = resource, amount = _amount };
|
||||
AddItem(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public partial class InventoryManager : Node
|
||||
}
|
||||
}
|
||||
|
||||
public InventoryInstance? playerInventory;
|
||||
public InventoryInstance playerInventory = new InventoryInstance();
|
||||
|
||||
private int _currentSelectedSlotIndex = 0;
|
||||
|
||||
@@ -34,9 +34,7 @@ public partial class InventoryManager : Node
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
playerInventory = new InventoryInstance();
|
||||
playerInventory.SlotAmount = 37;
|
||||
AddChild(playerInventory);
|
||||
}
|
||||
|
||||
public InventoryActionResult CreateItem(
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||
|
||||
/// <summary>
|
||||
/// Defines the behaviour of Nodes that have fields that should save / load to disk.
|
||||
/// </summary>
|
||||
public interface ISaveable
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds or updates the field data that shall be stored to disk.
|
||||
/// </summary>
|
||||
public void UpdateSaveData();
|
||||
|
||||
/// <summary>
|
||||
/// Loads the field data from disk.
|
||||
/// </summary>
|
||||
public void LoadFromSaveData();
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://bqapxuprxuj20
|
||||
@@ -1,15 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||
|
||||
[Tool]
|
||||
public partial class SaveCheats : Node
|
||||
{
|
||||
[ExportToolButton("ResetSave")] Callable _raiseAction => Callable.From(Reset);
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
SavegameService.Reset();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://iquhbkr7pqeg
|
||||
@@ -9,15 +9,6 @@ namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||
[Serializable]
|
||||
public class SaveData
|
||||
{
|
||||
// for future use in case the structure changes.
|
||||
public const int VERSION = 1;
|
||||
public int version { get; set; } = VERSION;
|
||||
|
||||
public bool IsVersionValid()
|
||||
{
|
||||
return VERSION == version;
|
||||
}
|
||||
|
||||
public string SceneName;
|
||||
public string Id;
|
||||
public string JsonPayload;
|
||||
|
||||
@@ -7,15 +7,12 @@ namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||
/// </summary>
|
||||
public partial class SaveGameManager : Node
|
||||
{
|
||||
public static string USER_DATA_FILE_PATH = "user://save_data/userData.json";
|
||||
|
||||
public static SaveGameManager? Instance { get; private set; } = null!;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
USER_DATA_FILE_PATH = ProjectSettings.GlobalizePath(USER_DATA_FILE_PATH);
|
||||
SavegameService.SavePath = USER_DATA_FILE_PATH;
|
||||
|
||||
SavegameService.Load();
|
||||
}
|
||||
|
||||
|
||||
@@ -9,32 +9,21 @@ namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||
/// Handles the saving and loading of game states.
|
||||
/// Holds the central SaveData object that serves as a temporary SaveFile.
|
||||
/// Automatically writes to disk on every scene change.
|
||||
/// Uses the Godot Json Serializer, which may implicitly convert integers to floats, so be careful when extending!
|
||||
/// </summary>
|
||||
public static class SavegameService
|
||||
{
|
||||
public static string SavePath = "";
|
||||
public static readonly string SavePath = "user://babushka_savegame.json";
|
||||
|
||||
public static Dictionary<string, string> SaveDatas = new ();
|
||||
|
||||
public static bool _loaded = false;
|
||||
|
||||
|
||||
public static void AppendDataToSave(string scenename, string id, Dictionary<string, Variant> payload)
|
||||
{
|
||||
var saveData = new SaveData();
|
||||
|
||||
saveData.SceneName = scenename;
|
||||
saveData.Id = id;
|
||||
saveData.JsonPayload = Json.Stringify(payload, indent: "\t");
|
||||
AppendSave(saveData);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds or overwrites an entry in the SaveData dictionary.
|
||||
/// </summary>
|
||||
/// <param name="saveData"></param>
|
||||
private static void AppendSave(SaveData saveData)
|
||||
public static void AppendSave(SaveData saveData)
|
||||
{
|
||||
string key = string.Concat(saveData.SceneName, "_", saveData.Id);
|
||||
|
||||
@@ -56,23 +45,21 @@ public static class SavegameService
|
||||
/// <param name="sceneName"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<string, Variant> GetSaveData(string sceneName, string id)
|
||||
public static string GetSaveData(string sceneName, string id)
|
||||
{
|
||||
Dictionary<string, Variant> saveData = new();
|
||||
string saveData = "";
|
||||
|
||||
string key = string.Concat(sceneName, "_", id);
|
||||
string saveDataString = "";
|
||||
|
||||
if (!_loaded)
|
||||
{
|
||||
GD.Print("SavegameService: SaveFile not loaded.");
|
||||
return saveData;
|
||||
}
|
||||
|
||||
|
||||
if (SaveDatas.ContainsKey(key))
|
||||
{
|
||||
saveDataString = SaveDatas[key];
|
||||
saveData = Json.ParseString(saveDataString).AsGodotDictionary<string, Variant>();
|
||||
saveData = SaveDatas[key];
|
||||
}
|
||||
|
||||
return saveData;
|
||||
@@ -85,20 +72,8 @@ public static class SavegameService
|
||||
public static void Save()
|
||||
{
|
||||
string json = Json.Stringify(SaveDatas, indent: "\t");
|
||||
|
||||
GD.Print(SavePath);
|
||||
// create cloud directory
|
||||
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(SavePath) ?? "");
|
||||
|
||||
try
|
||||
{
|
||||
using var file = FileAccess.Open(SavePath, FileAccess.ModeFlags.Write);
|
||||
file.StoreString(json);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
GD.Print(e.Message);
|
||||
}
|
||||
using var file = FileAccess.Open(SavePath, FileAccess.ModeFlags.Write);
|
||||
file.StoreString(json);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,15 +83,8 @@ public static class SavegameService
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!System.IO.File.Exists(SavePath))
|
||||
{
|
||||
SaveDatas = new();
|
||||
return;
|
||||
}
|
||||
|
||||
string saveDataJson = FileAccess.GetFileAsString(SavePath);
|
||||
SaveDatas = Json.ParseString(saveDataJson).AsGodotDictionary<string, string>();
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@@ -126,10 +94,4 @@ public static class SavegameService
|
||||
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
public static void Reset()
|
||||
{
|
||||
SaveDatas = new ();
|
||||
Save();
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||
|
||||
/// <summary>
|
||||
/// Data structure for device-specific settings that should be saved / loaded to disk.
|
||||
/// Will not be synced across devices.
|
||||
/// </summary>
|
||||
public class SettingsData
|
||||
{
|
||||
/// <summary>
|
||||
/// To be incremented (and migrated) on modification.
|
||||
/// </summary>
|
||||
public const int VERSION = 1;
|
||||
public int version { get; set; } = VERSION;
|
||||
|
||||
public bool IsVersionValid()
|
||||
{
|
||||
return VERSION == version;
|
||||
}
|
||||
|
||||
public double runtimeSeconds { get; set; }
|
||||
public int windowSizeX { get; set; } = 800;
|
||||
public int windowSizeY { get; set; } = 600;
|
||||
public int windowPositionX { get; set; } = 100;
|
||||
public int windowPositionY { get; set; } = 100;
|
||||
public bool windowBorderless { get; set; }
|
||||
public float volumeMaster { get; set; } = 1.0f;
|
||||
public float volumeFx { get; set; } = 1.0f;
|
||||
public float volumeMusic { get; set; } = 1.0f;
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://ol8xw1ekx0c2
|
||||
@@ -1,108 +0,0 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the saving and loading of local settings data.
|
||||
/// </summary>
|
||||
[GlobalClass]
|
||||
public partial class SettingsSaveController : Node
|
||||
{
|
||||
public static string SETTINGS_FILE_PATH = "user://userSettings.json";
|
||||
public static SettingsSaveController Instance;
|
||||
|
||||
public SettingsData? settings = new SettingsData();
|
||||
public SettingsData settingsDefault = new SettingsData();
|
||||
|
||||
public event Action OnSettingsReloaded;
|
||||
|
||||
private bool _loadedData;
|
||||
private DateTime _readyTime;
|
||||
|
||||
public bool LoadedData => _loadedData;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
SETTINGS_FILE_PATH = ProjectSettings.GlobalizePath(SETTINGS_FILE_PATH);
|
||||
_readyTime = DateTime.Now;
|
||||
Instance = this;
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (settings != null)
|
||||
settings.runtimeSeconds += (DateTime.Now - _readyTime).TotalSeconds;
|
||||
SaveSettings();
|
||||
Instance = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves Settings Data onto disk.
|
||||
/// </summary>
|
||||
public void SaveSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
string jsonString = JsonSerializer.Serialize(
|
||||
settings,
|
||||
new JsonSerializerOptions() { WriteIndented = true}
|
||||
);
|
||||
|
||||
System.IO.File.WriteAllText(SETTINGS_FILE_PATH, jsonString);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
GD.PrintErr("Error Saving Settings:", e);
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads Settings data from disk.
|
||||
/// </summary>
|
||||
public void LoadSettings()
|
||||
{
|
||||
_loadedData = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (!System.IO.File.Exists(SETTINGS_FILE_PATH))
|
||||
{
|
||||
settings = new SettingsData();
|
||||
}
|
||||
else
|
||||
{
|
||||
string jsonString = System.IO.File.ReadAllText(SETTINGS_FILE_PATH);
|
||||
SettingsData? loadedSettings = JsonSerializer.Deserialize<SettingsData>(jsonString);
|
||||
if (loadedSettings != null && !loadedSettings.IsVersionValid())
|
||||
{
|
||||
_loadedData = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
settings = loadedSettings;
|
||||
_loadedData = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
GD.PrintErr("Loading Error:", e);
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets Settings to default.
|
||||
/// </summary>
|
||||
public void ResetSettings()
|
||||
{
|
||||
settings = JsonSerializer.Deserialize<SettingsData>(JsonSerializer.Serialize<SettingsData>(settingsDefault));
|
||||
OnSettingsReloaded?.Invoke();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://cc7gnydmbcft7
|
||||
@@ -1,101 +0,0 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Savegame;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks important window settings and communicates with the <see cref="SettingsSaveController"/> to save/load them.
|
||||
/// </summary>
|
||||
public partial class WindowSettingsSync : Node
|
||||
{
|
||||
private Window window;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
window = GetWindow();
|
||||
window.SizeChanged += SaveWindowSize;
|
||||
|
||||
SyncSettings();
|
||||
SettingsSaveController.Instance.OnSettingsReloaded += SyncSettings;
|
||||
}
|
||||
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
SaveWindowPosition();
|
||||
SaveWindowBorderless();
|
||||
SaveWindowSize();
|
||||
SettingsSaveController.Instance.SaveSettings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get previous settings from settings-savefile, if available.
|
||||
/// </summary>
|
||||
public void SyncSettings()
|
||||
{
|
||||
if (!SettingsSaveController.Instance.LoadedData)
|
||||
{
|
||||
SaveWindowPosition();
|
||||
SaveWindowSize();
|
||||
SaveWindowBorderless();
|
||||
return;
|
||||
}
|
||||
|
||||
SettingsData? settingsData = SettingsSaveController.Instance.settings;
|
||||
if (settingsData != null)
|
||||
{
|
||||
window.Position = new Vector2I(settingsData.windowPositionX, settingsData.windowPositionY);
|
||||
ValidateWindowPosition();
|
||||
|
||||
window.Size = new Vector2I(settingsData.windowSizeX, settingsData.windowSizeY);
|
||||
window.Borderless = settingsData.windowBorderless;
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidateWindowPosition()
|
||||
{
|
||||
bool validWindowPosition = false;
|
||||
foreach (Rect2I displayRect in DisplayServer.GetDisplayCutouts())
|
||||
{
|
||||
if (displayRect.HasPoint(window.Position))
|
||||
{
|
||||
validWindowPosition = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!validWindowPosition)
|
||||
{
|
||||
window.MoveToCenter();
|
||||
SaveWindowPosition();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveWindowPosition()
|
||||
{
|
||||
SettingsData? settingsData = SettingsSaveController.Instance.settings;
|
||||
|
||||
if (settingsData != null)
|
||||
{
|
||||
settingsData.windowPositionX = window.Position.X;
|
||||
settingsData.windowPositionY = window.Position.Y;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveWindowSize()
|
||||
{
|
||||
SettingsData? settingsData = SettingsSaveController.Instance.settings;
|
||||
if (settingsData != null)
|
||||
{
|
||||
settingsData.windowSizeX = window.Size.X;
|
||||
settingsData.windowSizeY = window.Size.Y;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveWindowBorderless()
|
||||
{
|
||||
SettingsData? settingsData = SettingsSaveController.Instance.settings;
|
||||
if (settingsData != null)
|
||||
settingsData.windowBorderless = window.Borderless;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
uid://bbp0dyddwdbl8
|
||||
@@ -34,7 +34,6 @@ public partial class SceneTransition : Node
|
||||
|
||||
public void Quit()
|
||||
{
|
||||
SettingsSaveController.Instance.SaveSettings();
|
||||
GetTree().Quit();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user