Adjust when to load resources.

调整加载资源的时机。
This commit is contained in:
Cold-Mint 2024-10-11 17:22:31 +08:00
parent e21d37edce
commit 1fee1cce86
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
9 changed files with 27 additions and 31 deletions

View File

@ -55,6 +55,7 @@ shape = SubResource("RectangleShape2D_7tsse")
[node name="Marker2D" type="Marker2D" parent="."]
position = Vector2(260, 87)
script = ExtResource("1_y2vgj")
_resPathArray = null
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
navigation_polygon = SubResource("NavigationPolygon_rh1gx")

View File

@ -432,7 +432,7 @@ public partial class CharacterTemplate : CharacterBody2D
//您可以在这里补充更多类型对象的捡起状态处理。
if (pickAbleItemNode2D is PickAbleTemplate pickAbleTemplate)
{
pickAbleTemplate.LoadingResource();
pickAbleTemplate.LoadResource();
pickAbleTemplate.Owner = this;
pickAbleTemplate.Picked = true;
pickAbleTemplate.Freeze = true;
@ -797,7 +797,7 @@ public partial class CharacterTemplate : CharacterBody2D
{
return;
}
pickAbleTemplate.LoadingResource();
pickAbleTemplate.LoadResource();
pickAbleTemplate.Owner = this;
pickAbleTemplate.Picked = false;
//Setting an initial speed of 0 for items here prevents the problem of throwing items too fast.

View File

@ -49,9 +49,9 @@ public partial class Packsack : PickAbleTemplate
}
public override void _Ready()
public override void LoadResource()
{
base._Ready();
base.LoadResource();
if (SelfItemContainer == null)
{
var universalItemContainer = new UniversalItemContainer(NumberSlots);

View File

@ -18,9 +18,9 @@ public partial class ResignationCertificate : WeaponTemplate
Type = Config.DamageType.Magic
};
public override void _Ready()
public override void LoadResource()
{
base._Ready();
base.LoadResource();
_damage.CreateDamage();
_damage.Attacker = this;
}

View File

@ -1,8 +1,4 @@
using System;
using ColdMint.scripts.camp;
using ColdMint.scripts.character;
using ColdMint.scripts.damage;
using ColdMint.scripts.debug;
using ColdMint.scripts.inventory;
using ColdMint.scripts.utils;
using Godot;
@ -172,20 +168,20 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
}
private CollisionShape2D? _collisionShape2D;
/// <summary>
/// <para>Whether the resource has been loaded</para>
/// <para>是否已加载过资源了</para>
/// </summary>
private bool _loadedResource;
public override void _Ready()
public sealed override void _Ready()
{
LoadingResource();
LoadResource();
}
public void LoadingResource()
public virtual void LoadResource()
{
if (_loadedResource)
{

View File

@ -19,11 +19,6 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell
private string? _projectilePath;
private PackedScene? _projectileScene;
public sealed override void _Ready()
{
base._Ready();
LoadResource();
}
public override int ItemType
{
@ -35,14 +30,17 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell
return _projectileScene;
}
public virtual void LoadResource()
public override void LoadResource()
{
base.LoadResource();
if (_projectileScene == null && !string.IsNullOrEmpty(_projectilePath))
{
_projectileScene = ResourceLoader.Load<PackedScene>(_projectilePath);
}
}
public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon)
{

View File

@ -28,10 +28,10 @@ public partial class MeleeWeapon : WeaponTemplate
private readonly List<CharacterTemplate> _characterTemplates =
[
];
public override void _Ready()
public override void LoadResource()
{
base._Ready();
LogCat.Log("ready", LogCat.LogLabel.MeleeWeapon);
base.LoadResource();
_weaponDamageArea = GetNode<Area2D>("WeaponDamageArea");
_weaponDamageArea.InputPickable = false;
_weaponDamageArea.SetCollisionMaskValue(Config.LayerNumber.Player, true);
@ -45,7 +45,6 @@ public partial class MeleeWeapon : WeaponTemplate
_damageTemplate.MaxDamage = _maxDamage;
_damageTemplate.MinDamage = _minDamage;
_damageTemplate.Type = Config.DamageType.Physical;
LogCat.Log("success", LogCat.LogLabel.MeleeWeapon);
}
private void AreaExited(Node2D node2D)

View File

@ -122,9 +122,9 @@ public partial class ProjectileWeapon : WeaponTemplate
get => Config.ItemType.ProjectileWeapon;
}
public override void _Ready()
public override void LoadResource()
{
base._Ready();
base.LoadResource();
_marker2D = GetNode<Marker2D>("Marker2D");
if (SelfItemContainer == null)
{
@ -144,6 +144,8 @@ public partial class ProjectileWeapon : WeaponTemplate
{
continue;
}
//The spell is stored in memory and has not yet been loaded into the node tree. So we call the InvokeLoadResource method to initialize the resource.
//法术保存在内存中尚未加载到节点树。所以我们调用InvokeLoadResource方法来初始化资源。
spell.LoadResource();
if (SelfItemContainer.CanAddItem(item))
{

View File

@ -19,10 +19,10 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
/// </summary>
private AudioStreamPlayer2D? _audioStreamPlayer2D;
public override void _Ready()
public override void LoadResource()
{
base._Ready();
_audioStreamPlayer2D = GetNodeOrNull<AudioStreamPlayer2D>("Marker2D/AudioStreamPlayer2D");
base.LoadResource();
_audioStreamPlayer2D = GetNode<AudioStreamPlayer2D>("Marker2D/AudioStreamPlayer2D");
}
public override bool Use(Node2D? owner, Vector2 targetGlobalPosition)