Replace metadata of items with export vars
This commit is contained in:
parent
e307a58299
commit
dde7bb16ca
|
@ -11,11 +11,6 @@ collision_layer = 8
|
|||
collision_mask = 38
|
||||
script = ExtResource("1_8ehup")
|
||||
Id = "packsack"
|
||||
metadata/Id = "Packsack"
|
||||
metadata/MaxStackQuantity = 1
|
||||
metadata/Icon = ExtResource("2_e1ale")
|
||||
metadata/Name = "packsack"
|
||||
metadata/Description = "packsack_desc"
|
||||
|
||||
[node name="Player" type="Sprite2D" parent="."]
|
||||
texture = ExtResource("2_e1ale")
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[ext_resource type="Texture2D" uid="uid://e6670ykyq145" path="res://sprites/weapon/staffOfTheUndead.png" id="1_ms3us"]
|
||||
[ext_resource type="Script" path="res://scripts/item/weapon/ProjectileWeapon.cs" id="1_w8hhv"]
|
||||
[ext_resource type="Texture2D" uid="uid://b2blj0yf4ohx3" path="res://icon.svg" id="2_l5lni"]
|
||||
[ext_resource type="PackedScene" uid="uid://c01av43yk1q71" path="res://prefab/projectile/curseOfTheUndead.tscn" id="2_34250"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_obcq2"]
|
||||
size = Vector2(49, 5)
|
||||
|
@ -14,14 +14,9 @@ size = Vector2(49, 5.25)
|
|||
collision_layer = 8
|
||||
collision_mask = 34
|
||||
script = ExtResource("1_w8hhv")
|
||||
ProjectileScenes = [ExtResource("2_34250")]
|
||||
Id = "staff_of_the_undead"
|
||||
metadata/Projectiles = PackedStringArray("res://prefab/projectile/curseOfTheUndead.tscn")
|
||||
metadata/Name = "staff_of_the_undead"
|
||||
metadata/FiringIntervalArray = PackedInt64Array(5000, 500, 250)
|
||||
metadata/Icon = ExtResource("2_l5lni")
|
||||
metadata/ID = "StaffOfTheUndead"
|
||||
metadata/MaxStackQuantity = 1
|
||||
metadata/Description = "staff_of_the_undead_desc"
|
||||
|
||||
[node name="DamageArea2D" type="Area2D" parent="."]
|
||||
collision_layer = 8
|
||||
|
|
|
@ -24,31 +24,35 @@ public partial class ProjectileWeapon : WeaponTemplate
|
|||
/// </summary>
|
||||
private Marker2D? _marker2D;
|
||||
|
||||
/// <summary>
|
||||
/// <para>List of projectiles</para>
|
||||
/// <para>抛射体列表</para>
|
||||
/// </summary>
|
||||
private string[]? _projectiles;
|
||||
// /// <summary>
|
||||
// /// <para>List of projectiles</para>
|
||||
// /// <para>抛射体列表</para>
|
||||
// /// </summary>
|
||||
// private string[]? _projectiles;
|
||||
//
|
||||
// private Dictionary<string, PackedScene>? _projectileCache;
|
||||
|
||||
[Export] protected PackedScene[] ProjectileScenes { get; set; } = [];
|
||||
|
||||
private Dictionary<string, PackedScene>? _projectileCache;
|
||||
private Node2D? _projectileContainer;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_marker2D = GetNode<Marker2D>("Marker2D");
|
||||
_projectileCache = new Dictionary<string, PackedScene>();
|
||||
_projectiles = GetMeta("Projectiles", "").AsStringArray();
|
||||
foreach (var projectileItem in _projectiles)
|
||||
{
|
||||
var packedScene = GD.Load<PackedScene>(projectileItem);
|
||||
if (packedScene == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
_projectileCache.Add(projectileItem, packedScene);
|
||||
}
|
||||
// _projectileCache = new Dictionary<string, PackedScene>();
|
||||
// _projectiles = GetMeta("Projectiles", "").AsStringArray();
|
||||
// foreach (var projectileItem in _projectiles)
|
||||
// {
|
||||
// var packedScene = GD.Load<PackedScene>(projectileItem);
|
||||
// if (packedScene == null)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// _projectileCache.Add(projectileItem, packedScene);
|
||||
// }
|
||||
|
||||
_projectileContainer = GetNode("/root/Game/ProjectileContainer") as Node2D;
|
||||
}
|
||||
|
@ -56,13 +60,10 @@ public partial class ProjectileWeapon : WeaponTemplate
|
|||
|
||||
protected override void DoFire(Node2D? owner, Vector2 enemyGlobalPosition)
|
||||
{
|
||||
if (_projectileCache == null || _projectiles == null || owner == null || _projectileContainer == null ||
|
||||
_marker2D == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (owner == null || _projectileContainer == null || _marker2D == null) return;
|
||||
|
||||
if (_projectiles.IsEmpty())
|
||||
//空列表检查
|
||||
if (ProjectileScenes is [])
|
||||
{
|
||||
LogCat.LogError("projectiles_is_empty");
|
||||
return;
|
||||
|
@ -70,7 +71,8 @@ public partial class ProjectileWeapon : WeaponTemplate
|
|||
|
||||
//Get the first projectile
|
||||
//获取第一个抛射体
|
||||
var projectileScene = _projectileCache[_projectiles[0]];
|
||||
var projectileScene = ProjectileScenes[0];
|
||||
// var projectileScene = _projectileCache[_projectiles[0]];
|
||||
var projectile = NodeUtils.InstantiatePackedScene<ProjectileTemplate>(projectileScene, _projectileContainer);
|
||||
if (projectile == null) return;
|
||||
projectile.Owner = owner;
|
||||
|
|
Loading…
Reference in New Issue
Block a user