mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:35:34 +00:00
Refactored switches and chests and mapping
This commit is contained in:
parent
295d32e66d
commit
cc5376e94e
14 changed files with 158 additions and 91 deletions
|
|
@ -6,3 +6,4 @@
|
|||
script = ExtResource("1_istlt")
|
||||
Item = 0
|
||||
Amount = 1
|
||||
Max = 1
|
||||
|
|
|
|||
|
|
@ -1,28 +1,43 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class Interactable : Area2D
|
||||
{
|
||||
[Export] public Activable Target { get; set; }
|
||||
[Export] public bool RequiresKeycard { get; set; }
|
||||
private InventoryManager _inventoryManager;
|
||||
[Export] public Array<LootItem> Requirements = new Array<LootItem>();
|
||||
|
||||
protected InventoryManager _inventoryManager;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
protected bool MeetsRequirements()
|
||||
{
|
||||
if (RequiresKeycard) {
|
||||
if (_inventoryManager.RedKeycard) {
|
||||
Target?.Activate();
|
||||
}
|
||||
}
|
||||
else
|
||||
if (Requirements.Any())
|
||||
{
|
||||
Target?.Activate();
|
||||
if (_inventoryManager.HasItems(Requirements.Select(x => x.Item).ToList()))
|
||||
{
|
||||
GD.Print($"Requirements for activation of {this.Name} successfully met: {string.Join(",", Requirements.Select(x => x.Item))} ");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print($"Requirements for activation of {this.Name} not met: {string.Join(",", Requirements.Select(x => x.Item))} ");
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual void Activate()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
[gd_scene load_steps=15 format=3 uid="uid://djf0y08ix66fn"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://djf0y08ix66fn"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/Interactable.cs" id="1_4p5d3"]
|
||||
[ext_resource type="Script" path="res://Scripts/Chest.cs" id="1_cwpn7"]
|
||||
[ext_resource type="Texture2D" uid="uid://qeh4ai8h6sw5" path="res://Sprites/Chest.png" id="2_w7a1a"]
|
||||
[ext_resource type="Script" path="res://Scripts/Pickupper.cs" id="3_qro6k"]
|
||||
[ext_resource type="Script" path="res://Scripts/Resources/LootItem.cs" id="4_rcd61"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_ihal6"]
|
||||
radius = 16.0
|
||||
|
|
@ -76,16 +74,10 @@ animations = [{
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_isrvb"]
|
||||
size = Vector2(12, 10)
|
||||
|
||||
[sub_resource type="Resource" id="Resource_0qq1f"]
|
||||
script = ExtResource("4_rcd61")
|
||||
Item = 3
|
||||
Amount = 10
|
||||
|
||||
[node name="Chest" type="Area2D" node_paths=PackedStringArray("Target") groups=["Interactable"]]
|
||||
[node name="Chest" type="Area2D" groups=["Interactable"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_4p5d3")
|
||||
Target = NodePath("Pickupper")
|
||||
script = ExtResource("1_cwpn7")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_ihal6")
|
||||
|
|
@ -102,7 +94,3 @@ gravity_scale = 0.0
|
|||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
|
||||
position = Vector2(0, -3)
|
||||
shape = SubResource("RectangleShape2D_isrvb")
|
||||
|
||||
[node name="Pickupper" type="Node2D" parent="."]
|
||||
script = ExtResource("3_qro6k")
|
||||
LootTable = [SubResource("Resource_0qq1f")]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://crph24e6e0v0q"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/Interactable.cs" id="1_g3j01"]
|
||||
[ext_resource type="Script" path="res://Scripts/Interactables/Switch.cs" id="1_alima"]
|
||||
[ext_resource type="Texture2D" uid="uid://d24g1qb40t72l" path="res://Sprites/Button_Small.png" id="2_7m30w"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_vvpve"]
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
[node name="ControlPad" type="Area2D" groups=["Interactable"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_g3j01")
|
||||
script = ExtResource("1_alima")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_vvpve")
|
||||
|
|
|
|||
11
Scenes/Interactable/control_pad_red_keycard.tscn
Normal file
11
Scenes/Interactable/control_pad_red_keycard.tscn
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cdr4m7pydqk6u"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://crph24e6e0v0q" path="res://Scenes/Interactable/Control_Pad.tscn" id="1_dv2sa"]
|
||||
[ext_resource type="Resource" uid="uid://dibquna7fww7t" path="res://Resources/Items/Red_Keycard.tres" id="2_mv5hn"]
|
||||
[ext_resource type="Texture2D" uid="uid://ch6nbhxgxxtf" path="res://Sprites/Red_Card_Reader.png" id="3_4xaqn"]
|
||||
|
||||
[node name="ControlPad" instance=ExtResource("1_dv2sa")]
|
||||
Requirements = [ExtResource("2_mv5hn")]
|
||||
|
||||
[node name="Sprite2D" parent="." index="1"]
|
||||
texture = ExtResource("3_4xaqn")
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cymtsmui4yo17"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://cymtsmui4yo17"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/Interactable.cs" id="1_q256v"]
|
||||
[ext_resource type="Resource" uid="uid://dibquna7fww7t" path="res://Resources/Items/Red_Keycard.tres" id="2_fqvgh"]
|
||||
[ext_resource type="Texture2D" uid="uid://ch6nbhxgxxtf" path="res://Sprites/Red_Card_Reader.png" id="2_xidhq"]
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_hhoab"]
|
||||
|
|
@ -10,7 +11,7 @@ radius = 12.0
|
|||
collision_layer = 4
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_q256v")
|
||||
RequiresKeycard = true
|
||||
Requirements = [ExtResource("2_fqvgh")]
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_hhoab")
|
||||
|
|
|
|||
|
|
@ -6,11 +6,10 @@
|
|||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_x0adl"]
|
||||
|
||||
[node name="ControlPad" type="Area2D" node_paths=PackedStringArray("Target") groups=["Interactable"]]
|
||||
[node name="ControlPad" type="Area2D" groups=["Interactable"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_8ev2v")
|
||||
Target = NodePath("Pickupper")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_x0adl")
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1,18 +1,26 @@
|
|||
namespace Cirno.Scripts;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
public partial class Chest : Activable
|
||||
namespace Cirno.Scripts;
|
||||
|
||||
public partial class Chest : Interactable
|
||||
{
|
||||
private InventoryManager inventoryManager;
|
||||
|
||||
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
inventoryManager.AddRedKeycard();
|
||||
GetParent().QueueFree();
|
||||
if (!MeetsRequirements()) return;
|
||||
foreach (var item in LootTable)
|
||||
{
|
||||
_inventoryManager.AddItem(item.Item, item.Amount);
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
}
|
||||
|
||||
}
|
||||
16
Scripts/Interactables/Switch.cs
Normal file
16
Scripts/Interactables/Switch.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Interactables;
|
||||
|
||||
public partial class Switch : Interactable
|
||||
{
|
||||
[Export] public Activable Target { get; set; }
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
if (MeetsRequirements())
|
||||
{
|
||||
Target?.Activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
||||
public partial class InventoryManager : Node2D
|
||||
{
|
||||
public bool RedKeycard { get; set; }
|
||||
|
||||
private List<LootItem> _items = new List<LootItem>();
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
|
|
@ -16,41 +21,53 @@ public partial class InventoryManager : Node2D
|
|||
{
|
||||
}
|
||||
|
||||
public bool HasItems(List<ItemTypes> items)
|
||||
{
|
||||
return items.Aggregate(false, (current, item) => current || HasItem(item));
|
||||
}
|
||||
|
||||
public bool HasItem(ItemTypes type)
|
||||
{
|
||||
return _items.Any(x => x.Item == type && x.Amount > 0);
|
||||
}
|
||||
|
||||
public bool AddItem(ItemTypes type, int amount = 1)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ItemTypes.KeycardRed:
|
||||
RedKeycard = true;
|
||||
GD.Print($"Red Keycard x{amount}");
|
||||
break;
|
||||
case ItemTypes.KeycardBlue:
|
||||
GD.Print($"Blue Keycard x{amount}");
|
||||
break;
|
||||
case ItemTypes.KeycardGreen:
|
||||
GD.Print($"Green Keycard x{amount}");
|
||||
break;
|
||||
case ItemTypes.Ammo:
|
||||
GD.Print($"Ammo x{amount}");
|
||||
break;
|
||||
case ItemTypes.Medkit:
|
||||
GD.Print($"Medkit x{amount}");
|
||||
break;
|
||||
case ItemTypes.CrabBomb:
|
||||
GD.Print($"CrabBomb x{amount}");
|
||||
break;
|
||||
case ItemTypes.Bomb:
|
||||
GD.Print($"Bomb x{amount}");
|
||||
break;
|
||||
case ItemTypes.Mine:
|
||||
GD.Print($"Mine x{amount}");
|
||||
break;
|
||||
case ItemTypes.Battery:
|
||||
GD.Print($"Battery x{amount}");
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
_items.Add(new LootItem() { Item = type, Amount = amount });
|
||||
GD.Print($"Added {type} x{amount}");
|
||||
// switch (type)
|
||||
// {
|
||||
// // case ItemTypes.KeycardRed:
|
||||
// // RedKeycard = true;
|
||||
// // GD.Print($"Red Keycard x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.KeycardBlue:
|
||||
// // GD.Print($"Blue Keycard x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.KeycardGreen:
|
||||
// // GD.Print($"Green Keycard x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Ammo:
|
||||
// // GD.Print($"Ammo x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Medkit:
|
||||
// // GD.Print($"Medkit x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.CrabBomb:
|
||||
// // GD.Print($"CrabBomb x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Bomb:
|
||||
// // GD.Print($"Bomb x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Mine:
|
||||
// // GD.Print($"Mine x{amount}");
|
||||
// // break;
|
||||
// // case ItemTypes.Battery:
|
||||
// // GD.Print($"Battery x{amount}");
|
||||
// // break;
|
||||
// // default:
|
||||
// // return false;
|
||||
// }
|
||||
|
||||
return true; // TODO: Return false if could not be added
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ public partial class Pickupper : Activable
|
|||
}
|
||||
|
||||
//inventoryManager.AddRedKeycard();
|
||||
GetParent().QueueFree(); // TODO: send a signal instead
|
||||
//GetParent().QueueFree(); // TODO: send a signal instead
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -7,4 +7,5 @@ public partial class LootItem : Resource
|
|||
{
|
||||
[Export] public ItemTypes Item;
|
||||
[Export] public int Amount;
|
||||
[Export] public int Max;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using Godot;
|
||||
using Cirno.Scripts.Interactables;
|
||||
using Godot;
|
||||
|
||||
[Tool]
|
||||
public partial class DoorButtonVisualizer : Node2D
|
||||
|
|
@ -36,7 +37,7 @@ public partial class DoorButtonVisualizer : Node2D
|
|||
// if (TargetPath == null || !Engine.IsEditorHint())
|
||||
// return;
|
||||
|
||||
if (_parent is not Interactable p) return;
|
||||
if (_parent is not Switch p) return;
|
||||
|
||||
if (p.Target == null) return;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue