diff --git a/prefabs/Player3D.tscn b/prefabs/Player3D.tscn index 5d0e495..bd8b651 100644 --- a/prefabs/Player3D.tscn +++ b/prefabs/Player3D.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=303 format=3 uid="uid://dbd1niu3tp8y5"] +[gd_scene load_steps=302 format=3 uid="uid://dbd1niu3tp8y5"] [ext_resource type="Script" uid="uid://b4ugrget2x6lb" path="res://scripts/CSharp/Common/CharacterControls/Player3D.cs" id="1_3trg2"] -[ext_resource type="Script" path="res://scripts/CSharp/Common/CharacterControls/VesnaBehaviour.cs" id="1_pkl5l"] [ext_resource type="Texture2D" uid="uid://duaideiajsu8r" path="res://art/characters/Vesna/babushka concept art vesna.png" id="2_3trg2"] [ext_resource type="PackedScene" uid="uid://biwd3jj65qrlh" path="res://prefabs/farm/base_field.tscn" id="2_oq5hi"] [ext_resource type="Texture2D" uid="uid://3pj2q7wtuion" path="res://art/farm/farming/farmobjekte/hoe.png" id="4_pkl5l"] @@ -1211,9 +1210,7 @@ animations = [{ "speed": 25.0 }] -[node name="Player3d" type="Node3D" node_paths=PackedStringArray("_farmingControls")] -script = ExtResource("1_pkl5l") -_farmingControls = NodePath("FarmingControls") +[node name="Player3d" type="Node3D"] [node name="CharacterBody3D" type="CharacterBody3D" parent="." node_paths=PackedStringArray("_camera", "_frontSpritesAnimated", "_sideSpritesAnimated", "_backSpritesAnimated")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.000654221, 0.102765, -0.00300497) diff --git a/prefabs/interactions/sprite_switcher_2d.tscn b/prefabs/interactions/sprite_switcher_2d.tscn index 00286a7..7de4017 100644 --- a/prefabs/interactions/sprite_switcher_2d.tscn +++ b/prefabs/interactions/sprite_switcher_2d.tscn @@ -3,20 +3,21 @@ [ext_resource type="Script" uid="uid://pemu31f6fe4l" path="res://scripts/CSharp/Common/SpriteSwitcher2D.cs" id="1_aktjx"] [ext_resource type="Texture2D" uid="uid://3pj2q7wtuion" path="res://art/farm/farming/farmobjekte/hoe.png" id="2_gxaiv"] -[node name="SpriteSwitcher2d" type="Node2D" node_paths=PackedStringArray("_firstSprite", "_secondSprite")] +[node name="SpriteSwitcher2d" type="Node2D" node_paths=PackedStringArray("_activeSprite", "_inactiveSprite")] script = ExtResource("1_aktjx") -_firstSprite = NodePath("FirstSprite") -_secondSprite = NodePath("SecondSprite") +_activeSprite = NodePath("ActiveSprite") +_inactiveSprite = NodePath("InactiveSprite") +_active = true -[node name="FirstSprite" type="Sprite2D" parent="."] -modulate = Color(0.00322664, 0.644252, 0.264198, 1) +[node name="ActiveSprite" type="Sprite2D" parent="."] +modulate = Color(0, 0.83, 0.332, 1) texture = ExtResource("2_gxaiv") region_enabled = true region_rect = Rect2(989, 189, 339, 1228) -[node name="SecondSprite" type="Sprite2D" parent="."] +[node name="InactiveSprite" type="Sprite2D" parent="."] visible = false -modulate = Color(1, 0, 0, 1) +modulate = Color(0.27, 0.27, 0.27, 1) texture = ExtResource("2_gxaiv") region_enabled = true region_rect = Rect2(1006, 197, 321, 1226) diff --git a/scenes/Babushka_scene_farm_outside_2d.tscn b/scenes/Babushka_scene_farm_outside_2d.tscn index 038f6f3..ae4f20e 100644 --- a/scenes/Babushka_scene_farm_outside_2d.tscn +++ b/scenes/Babushka_scene_farm_outside_2d.tscn @@ -113,16 +113,16 @@ position = Vector2(0, -296) motion_scale = Vector2(0.1, 0.1) motion_mirroring = Vector2(2048, 0) -[node name="Sprite2D" type="Sprite2D" parent="ParallaxBackground/background color layer"] +[node name="Sprite2D2" type="Sprite2D" parent="ParallaxBackground/background color layer"] modulate = Color(0.607706, 0.894469, 0.564721, 1) +position = Vector2(4096, 0) scale = Vector2(2, 2) texture = ExtResource("2_7b2ri") centered = false offset = Vector2(0, -100) -[node name="Sprite2D2" type="Sprite2D" parent="ParallaxBackground/background color layer"] +[node name="Sprite2D3" type="Sprite2D" parent="ParallaxBackground/background color layer"] modulate = Color(0.607706, 0.894469, 0.564721, 1) -position = Vector2(4096, 0) scale = Vector2(2, 2) texture = ExtResource("2_7b2ri") centered = false @@ -697,33 +697,36 @@ position = Vector2(12080, 3296) [node name="BaseField4" parent="." instance=ExtResource("26_vbdb2")] position = Vector2(12080, 2544) -[node name="Hoe Pickup" parent="." instance=ExtResource("27_klb81")] +[node name="Hoe Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")] position = Vector2(3264, 2120) rotation = 3.3074 +_sprites = NodePath("SpriteSwitcher2d") [node name="SpriteSwitcher2d" parent="Hoe Pickup" instance=ExtResource("28_p6n74")] scale = Vector2(0.5, 0.5) -[node name="Watercan Pickup" parent="." instance=ExtResource("27_klb81")] +[node name="Watercan Pickup" parent="." node_paths=PackedStringArray("_sprites") instance=ExtResource("27_klb81")] position = Vector2(6216, 2248) +_sprites = NodePath("SpriteSwitcher2d") +_id = 1 [node name="Label" parent="Watercan Pickup" index="1"] z_index = 1 [node name="SpriteSwitcher2d" parent="Watercan Pickup" instance=ExtResource("28_p6n74")] -[node name="FirstSprite" parent="Watercan Pickup/SpriteSwitcher2d" index="0"] +[node name="ActiveSprite" parent="Watercan Pickup/SpriteSwitcher2d" index="0"] texture = ExtResource("29_p6n74") -region_rect = Rect2(-2, 1119, 430, 301) +region_rect = Rect2(-2, 1135, 421, 292) -[node name="SecondSprite" parent="Watercan Pickup/SpriteSwitcher2d" index="1"] +[node name="InactiveSprite" parent="Watercan Pickup/SpriteSwitcher2d" index="1"] texture = ExtResource("29_p6n74") -region_rect = Rect2(1, 1127, 423, 301) +region_rect = Rect2(1, 1138, 418, 288) -[connection signal="Interacted" from="Hoe Pickup" to="Hoe Pickup/SpriteSwitcher2d" method="SwitchState"] -[connection signal="Switch" from="Hoe Pickup/SpriteSwitcher2d" to="YSorted/Player2d" method="ActivateHoe"] -[connection signal="Interacted" from="Watercan Pickup" to="Watercan Pickup/SpriteSwitcher2d" method="SwitchState"] -[connection signal="Switch" from="Watercan Pickup/SpriteSwitcher2d" to="YSorted/Player2d" method="ActivateWateringCan"] +[connection signal="PickedUpTool" from="YSorted/Player2d" to="Hoe Pickup" method="SetSpriteActiveState"] +[connection signal="PickedUpTool" from="YSorted/Player2d" to="Watercan Pickup" method="SetSpriteActiveState"] +[connection signal="Interacted" from="Hoe Pickup" to="YSorted/Player2d" method="ActivateTool"] +[connection signal="Interacted" from="Watercan Pickup" to="YSorted/Player2d" method="ActivateTool"] [editable path="Hoe Pickup"] [editable path="Watercan Pickup"] diff --git a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs index 400ec7b..2c541a3 100644 --- a/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs +++ b/scripts/CSharp/Common/CharacterControls/InteractionArea2D.cs @@ -6,10 +6,12 @@ public partial class InteractionArea2D : Node2D { [Export] private Area2D _area; [Export] private Label _label; + [Export] private SpriteSwitcher2D _sprites; [Export] private bool _showLabel = true; + [Export] private int _id; [Signal] - public delegate void InteractedEventHandler(); + public delegate void InteractedEventHandler(int id); public void OnPlayerEntered(Node2D player) { @@ -27,7 +29,15 @@ public partial class InteractionArea2D : Node2D if (@event.IsAction("interact") && @event.IsPressed() && _area.HasOverlappingBodies()) { _label.Hide(); - EmitSignal(SignalName.Interacted); + EmitSignal(SignalName.Interacted, _id); + } + } + + public void SetSpriteActiveState(bool success, int id) + { + if (_id == id) + { + _sprites.SwitchState(!success); } } } \ No newline at end of file diff --git a/scripts/CSharp/Common/Farming/FarmingControls2D.cs b/scripts/CSharp/Common/Farming/FarmingControls2D.cs index 69bb4e1..4e8edfe 100644 --- a/scripts/CSharp/Common/Farming/FarmingControls2D.cs +++ b/scripts/CSharp/Common/Farming/FarmingControls2D.cs @@ -17,11 +17,33 @@ public partial class FarmingControls2D : Node2D private int _toolId = -1; #region Tools - - public bool ActivateTool(bool activate, int toolId) + + /// + /// If no tool has been set, then set the current tool to the incoming tool id. + /// + /// The id of the tool to activate if possible + /// If the tool in question was activated. + public bool TryActivateTool(int toolId) { - if(_toolId < 0) - return false; + bool activate; + + //if our hands are empty, activate + if (_toolId == -1) + { + activate = true; + } + else + { + //if we're already carrying a tool, deactivate or fail return + if (_toolId == toolId) + { + activate = false; + } + else + { + return false; + } + } switch (toolId) { @@ -30,14 +52,14 @@ public partial class FarmingControls2D : Node2D break; case 1: _wateringCanSprite.Visible = activate; - break; default: _toolId = -1; break; } - _toolId = toolId; - return !activate; + + _toolId = activate ? toolId : -1; + return activate; } #endregion diff --git a/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs b/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs index 63afc76..fbf04a7 100644 --- a/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs +++ b/scripts/CSharp/Common/Farming/VesnaBehaviour2D.cs @@ -8,7 +8,7 @@ public partial class VesnaBehaviour2D : Node [Export] private FieldService2D _fieldParent; [Export] private FarmingControls2D _farmingControls; - [Signal] public delegate void ToolPickupEventHandler(bool success); + [Signal] public delegate void PickedUpToolEventHandler(bool success, int toolId); public override void _Ready() { @@ -17,20 +17,10 @@ public partial class VesnaBehaviour2D : Node #region Farming - public void ActivateHoe(bool activate) + public void ActivateTool(int toolId) { - ActivateTool(activate, 0); - } - - public void ActivateWateringCan(bool activate) - { - ActivateTool(activate, 1); - } - - private void ActivateTool(bool activate , int toolId) - { - bool activated = _farmingControls.ActivateTool(activate, toolId); - EmitSignal(SignalName.ToolPickup, activated); + bool activated = _farmingControls.TryActivateTool(toolId); + EmitSignal(SignalName.PickedUpTool, activated, toolId); } #endregion diff --git a/scripts/CSharp/Common/SpriteSwitcher2D.cs b/scripts/CSharp/Common/SpriteSwitcher2D.cs index 4f0bd7a..0740b67 100644 --- a/scripts/CSharp/Common/SpriteSwitcher2D.cs +++ b/scripts/CSharp/Common/SpriteSwitcher2D.cs @@ -7,30 +7,30 @@ namespace Babushka.scripts.CSharp.Common; /// public partial class SpriteSwitcher2D : Node2D { - [Export] private Sprite2D _firstSprite; - [Export] private Sprite2D _secondSprite; - [Export] private bool _state = true; - - [Signal] - public delegate void SwitchEventHandler(bool state); + [Export] private Sprite2D _activeSprite; + [Export] private Sprite2D _inactiveSprite; + [Export] private bool _active = false; public override void _Ready() { - SetState(); + SetSprites(); } - public void SwitchState() + /// + /// Switches the State of the Sprites to the opposite. + /// Emits Switch Signal. + /// + public void SwitchState(bool state) { - _state = !_state; - EmitSignal(SignalName.Switch, _state); - SetState(); + _active = state; + SetSprites(); } - - private void SetState() + + private void SetSprites() { - if(_firstSprite != null) - _firstSprite.Visible = _state; - if(_secondSprite != null) - _secondSprite.Visible = !_state; + if(_activeSprite != null) + _activeSprite.Visible = _active; + if(_inactiveSprite != null) + _inactiveSprite.Visible = !_active; } } \ No newline at end of file