Unified Resource loading api, projectile weapon allows to configure spells.

统一资源加载的api,抛射体武器允许配置法术。
This commit is contained in:
Cold-Mint 2024-10-09 10:49:10 +08:00
parent d1c0f1e265
commit 929dfb5f2f
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
22 changed files with 65 additions and 37 deletions

View File

@ -1,5 +1,5 @@
#Register spells used by the projectile here. #Register items here.
#在这里注册抛射体使用的法术 #在这里注册物品
#Note: The id must be the same as the item id in the scene. Otherwise, an ArgumentException will be thrown. #Note: The id must be the same as the item id in the scene. Otherwise, an ArgumentException will be thrown.
#备注id必须和场景内的物品id保持一致。否则会抛出ArgumentException。 #备注id必须和场景内的物品id保持一致。否则会抛出ArgumentException。
#After you declare the id of the item, add the corresponding localized text to the csv file in the locals' folder. For example, if the id is a corresponding name is item_a and the corresponding description is item_a_desc. #After you declare the id of the item, add the corresponding localized text to the csv file in the locals' folder. For example, if the id is a corresponding name is item_a and the corresponding description is item_a_desc.

View File

@ -14,9 +14,9 @@ size = Vector2(49, 5.25)
[node name="StaffOfTheUndead" type="RigidBody2D"] [node name="StaffOfTheUndead" type="RigidBody2D"]
collision_layer = 8 collision_layer = 8
collision_mask = 34 collision_mask = 34
angular_damp = -1.0
script = ExtResource("1_w8hhv") script = ExtResource("1_w8hhv")
_numberSlots = 5 _numberSlots = 5
_spellList = PackedStringArray("necromancy")
_fireSequentially = true _fireSequentially = true
FiringIntervalAsMillisecond = 300 FiringIntervalAsMillisecond = 300
_recoilStrength = 5 _recoilStrength = 5

View File

@ -134,10 +134,8 @@ grow_vertical = 0
[node name="MiniMap" type="NinePatchRect" parent="Control"] [node name="MiniMap" type="NinePatchRect" parent="Control"]
layout_mode = 1 layout_mode = 1
offset_left = 983.0 offset_right = 150.0
offset_top = 480.0 offset_bottom = 150.0
offset_right = 1133.0
offset_bottom = 630.0
texture = ExtResource("1_h88bi") texture = ExtResource("1_h88bi")
patch_margin_left = 7 patch_margin_left = 7
patch_margin_top = 7 patch_margin_top = 7

View File

@ -153,10 +153,10 @@ public partial class HealthBarUi : HBoxContainer
{ {
base._Ready(); base._Ready();
NodeUtils.DeleteAllChild(this); NodeUtils.DeleteAllChild(this);
_heartEmpty = GD.Load<Texture2D>("res://sprites/ui/HeartEmpty.png"); _heartEmpty = ResourceLoader.Load<Texture2D>("res://sprites/ui/HeartEmpty.png");
_heartQuarter = GD.Load<Texture2D>("res://sprites/ui/HeartQuarter.png"); _heartQuarter = ResourceLoader.Load<Texture2D>("res://sprites/ui/HeartQuarter.png");
_heartHalf = GD.Load<Texture2D>("res://sprites/ui/HeartHalf.png"); _heartHalf = ResourceLoader.Load<Texture2D>("res://sprites/ui/HeartHalf.png");
_heartThreeFourths = GD.Load<Texture2D>("res://sprites/ui/HeartThreeFourths.png"); _heartThreeFourths = ResourceLoader.Load<Texture2D>("res://sprites/ui/HeartThreeFourths.png");
_heartFull = GD.Load<Texture2D>("res://sprites/ui/HeartFull.png"); _heartFull = ResourceLoader.Load<Texture2D>("res://sprites/ui/HeartFull.png");
} }
} }

View File

@ -121,14 +121,14 @@ public sealed partial class AiCharacter : CharacterTemplate
_bubbleMarker = GetNode<BubbleMarker>("BubbleMarker"); _bubbleMarker = GetNode<BubbleMarker>("BubbleMarker");
if (_bubbleMarker != null) if (_bubbleMarker != null)
{ {
using var plaintScene = GD.Load<PackedScene>("res://prefab/ui/plaint.tscn"); using var plaintScene = ResourceLoader.Load<PackedScene>("res://prefab/ui/plaint.tscn");
var plaint = NodeUtils.InstantiatePackedScene<Control>(plaintScene); var plaint = NodeUtils.InstantiatePackedScene<Control>(plaintScene);
if (plaint != null) if (plaint != null)
{ {
_bubbleMarker.AddBubble(PlaintBubbleId, plaint); _bubbleMarker.AddBubble(PlaintBubbleId, plaint);
} }
using var queryScene = GD.Load<PackedScene>("res://prefab/ui/query.tscn"); using var queryScene = ResourceLoader.Load<PackedScene>("res://prefab/ui/query.tscn");
var query = NodeUtils.InstantiatePackedScene<Control>(queryScene); var query = NodeUtils.InstantiatePackedScene<Control>(queryScene);
if (query != null) if (query != null)
{ {
@ -200,7 +200,7 @@ public sealed partial class AiCharacter : CharacterTemplate
//Set the resource path of the initial weapon and try to create the object of the initial weapon. //Set the resource path of the initial weapon and try to create the object of the initial weapon.
//设置了初始武器的资源路径,尝试创建初始武器的对象。 //设置了初始武器的资源路径,尝试创建初始武器的对象。
var packedScene = GD.Load<PackedScene>(initWeaponRes); var packedScene = ResourceLoader.Load<PackedScene>(initWeaponRes);
var weaponTemplate = NodeUtils.InstantiatePackedScene<WeaponTemplate>(packedScene); var weaponTemplate = NodeUtils.InstantiatePackedScene<WeaponTemplate>(packedScene);
if (weaponTemplate == null) if (weaponTemplate == null)
{ {

View File

@ -53,7 +53,7 @@ public partial class Player : CharacterTemplate
//Mount the camera. //Mount the camera.
//挂载相机。 //挂载相机。
var mainCameraPackedScene = GD.Load<PackedScene>("res://prefab/MainCamera.tscn"); var mainCameraPackedScene = ResourceLoader.Load<PackedScene>("res://prefab/MainCamera.tscn");
var camera2D = NodeUtils.InstantiatePackedScene<Camera2D>(mainCameraPackedScene); var camera2D = NodeUtils.InstantiatePackedScene<Camera2D>(mainCameraPackedScene);
if (camera2D != null) if (camera2D != null)
{ {

View File

@ -46,7 +46,7 @@ public partial class DamageNumberNodeSpawn : Marker2D
public override void _Ready() public override void _Ready()
{ {
base._Ready(); base._Ready();
_damageNumberPackedScene = GD.Load("res://prefab/ui/DamageNumber.tscn") as PackedScene; _damageNumberPackedScene = ResourceLoader.Load("res://prefab/ui/DamageNumber.tscn") as PackedScene;
_rootNode = GetNode<Node2D>("/root/Game/DamageNumberContainer"); _rootNode = GetNode<Node2D>("/root/Game/DamageNumberContainer");
//The horizontal velocity is in the X positive direction //The horizontal velocity is in the X positive direction
//水平速度的X正方向 //水平速度的X正方向

View File

@ -47,7 +47,7 @@ public partial class GuiFurniture : Furniture
{ {
GameSceneDepend.DynamicUiGroup?.RegisterControl(Path, () => GameSceneDepend.DynamicUiGroup?.RegisterControl(Path, () =>
{ {
var packedScene = GD.Load<PackedScene>(Path); var packedScene = ResourceLoader.Load<PackedScene>(Path);
return NodeUtils.InstantiatePackedScene<SpellEditorUi>(packedScene); return NodeUtils.InstantiatePackedScene<SpellEditorUi>(packedScene);
}); });
} }

View File

@ -5,7 +5,7 @@ namespace ColdMint.scripts.inventory;
public class ItemSlotContainerDisplay(Node rootNode) : ItemContainerDisplayTemplate public class ItemSlotContainerDisplay(Node rootNode) : ItemContainerDisplayTemplate
{ {
private readonly PackedScene? _packedScene = GD.Load<PackedScene>("res://prefab/ui/ItemSlot.tscn"); private readonly PackedScene? _packedScene = ResourceLoader.Load<PackedScene>("res://prefab/ui/ItemSlot.tscn");
protected override void AddItemDisplay() protected override void AddItemDisplay()
{ {

View File

@ -20,8 +20,8 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
public override void _Ready() public override void _Ready()
{ {
_backgroundTexture = GD.Load<Texture2D>("res://sprites/ui/ItemBarEmpty.png"); _backgroundTexture = ResourceLoader.Load<Texture2D>("res://sprites/ui/ItemBarEmpty.png");
_backgroundTextureWhenSelect = GD.Load<Texture2D>("res://sprites/ui/ItemBarFocus.png"); _backgroundTextureWhenSelect = ResourceLoader.Load<Texture2D>("res://sprites/ui/ItemBarFocus.png");
_backgroundTextureRect = _backgroundTextureRect =
GetNode<TextureRect>("BackgroundTexture"); GetNode<TextureRect>("BackgroundTexture");
_iconTextureRect = GetNode<TextureRect>("BackgroundTexture/IconTextureRect"); _iconTextureRect = GetNode<TextureRect>("BackgroundTexture/IconTextureRect");

View File

@ -62,7 +62,7 @@ public partial class Packsack : PickAbleTemplate
} }
GameSceneDepend.DynamicUiGroup?.RegisterControl(Path, () => GameSceneDepend.DynamicUiGroup?.RegisterControl(Path, () =>
{ {
var packedScene = GD.Load<PackedScene>(Path); var packedScene = ResourceLoader.Load<PackedScene>(Path);
return NodeUtils.InstantiatePackedScene<PacksackUi>(packedScene); return NodeUtils.InstantiatePackedScene<PacksackUi>(packedScene);
}); });
} }

View File

@ -18,9 +18,9 @@ public partial class ContributorLoader : UiLoaderTemplate
public override void InitializeData() public override void InitializeData()
{ {
_mainMenu = GD.Load<PackedScene>("res://scenes/mainMenu.tscn"); _mainMenu = ResourceLoader.Load<PackedScene>("res://scenes/mainMenu.tscn");
_packedScene = GD.Load<PackedScene>("res://prefab/ui/contributorGroup.tscn"); _packedScene = ResourceLoader.Load<PackedScene>("res://prefab/ui/contributorGroup.tscn");
_contributorGroup = GD.Load<PackedScene>("res://prefab/ui/contributorGroup.tscn"); _contributorGroup = ResourceLoader.Load<PackedScene>("res://prefab/ui/contributorGroup.tscn");
} }
public override void InitializeUi() public override void InitializeUi()

View File

@ -60,8 +60,8 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
public override void InitializeData() public override void InitializeData()
{ {
base.InitializeData(); base.InitializeData();
_mainMenu = GD.Load<PackedScene>("res://scenes/mainMenu.tscn"); _mainMenu = ResourceLoader.Load<PackedScene>("res://scenes/mainMenu.tscn");
_roomNodeScene = GD.Load<PackedScene>("res://prefab/ui/RoomNode.tscn"); _roomNodeScene = ResourceLoader.Load<PackedScene>("res://prefab/ui/RoomNode.tscn");
_defaultRoomName = TranslationServerUtils.Translate("ui_default_room_name"); _defaultRoomName = TranslationServerUtils.Translate("ui_default_room_name");
var folder = Config.GetLevelGraphExportDirectory(); var folder = Config.GetLevelGraphExportDirectory();
if (!Directory.Exists(folder)) if (!Directory.Exists(folder))

View File

@ -25,9 +25,9 @@ public partial class MainMenuLoader : UiLoaderTemplate
public override void InitializeData() public override void InitializeData()
{ {
_gameScene = GD.Load<PackedScene>("res://scenes/game.tscn"); _gameScene = ResourceLoader.Load<PackedScene>("res://scenes/game.tscn");
_contributor = GD.Load<PackedScene>("res://scenes/contributor.tscn"); _contributor = ResourceLoader.Load<PackedScene>("res://scenes/contributor.tscn");
_levelGraphEditor = GD.Load<PackedScene>("res://scenes/levelGraphEditor.tscn"); _levelGraphEditor = ResourceLoader.Load<PackedScene>("res://scenes/levelGraphEditor.tscn");
} }
public override void InitializeUi() public override void InitializeUi()

View File

@ -69,7 +69,7 @@ public partial class PacksackUi : UiLoaderTemplate
public override void InitializeData() public override void InitializeData()
{ {
_packedScene = GD.Load<PackedScene>("res://prefab/ui/ItemSlot.tscn"); _packedScene = ResourceLoader.Load<PackedScene>("res://prefab/ui/ItemSlot.tscn");
} }
private void BindItemContainer() private void BindItemContainer()

View File

@ -29,7 +29,7 @@ public partial class SplashScreenLoader : UiLoaderTemplate
public override void InitializeData() public override void InitializeData()
{ {
_mainMenuScene = GD.Load<PackedScene>("res://scenes/mainMenu.tscn"); _mainMenuScene = ResourceLoader.Load<PackedScene>("res://scenes/mainMenu.tscn");
} }
public override void InitializeUi() public override void InitializeUi()

View File

@ -32,7 +32,7 @@ public partial class AiCharacterSpawn : Marker2D, ISpawnMarker
{ {
return null; return null;
} }
var packedScene = GD.Load<PackedScene>(resPath); var packedScene = ResourceLoader.Load<PackedScene>(resPath);
if (packedScene == null) if (packedScene == null)
{ {
return null; return null;

View File

@ -24,7 +24,7 @@ public partial class PlayerSpawn : Marker2D, ISpawnMarker
public override void _Ready() public override void _Ready()
{ {
base._Ready(); base._Ready();
_playerPackedScene = GD.Load<PackedScene>("res://prefab/entitys/Character.tscn"); _playerPackedScene = ResourceLoader.Load<PackedScene>("res://prefab/entitys/Character.tscn");
EventBus.MapGenerationCompleteEvent += MapGenerationCompleteEvent; EventBus.MapGenerationCompleteEvent += MapGenerationCompleteEvent;
EventBus.GameReplayEvent += GameReplayEvent; EventBus.GameReplayEvent += GameReplayEvent;
} }

View File

@ -88,7 +88,7 @@ public static class RoomFactory
var room = new Room var room = new Room
{ {
RoomScene = GD.Load<PackedScene>(ResUtils.GetEditorResPath(resPath)), RoomScene = ResourceLoader.Load<PackedScene>(ResUtils.GetEditorResPath(resPath)),
EnterRoomEventHandlerId = enterRoomEventHandlerId, EnterRoomEventHandlerId = enterRoomEventHandlerId,
ExitRoomEventHandlerId = exitRoomEventHandlerId ExitRoomEventHandlerId = exitRoomEventHandlerId
}; };

View File

@ -42,7 +42,7 @@ public class NodeSpawnOnKillCharacterDecorator : IProjectileDecorator
return; return;
} }
var packedScene = GD.Load<PackedScene>(PackedScenePath); var packedScene = ResourceLoader.Load<PackedScene>(PackedScenePath);
var node2D = NodeUtils.InstantiatePackedScene<Node2D>(packedScene); var node2D = NodeUtils.InstantiatePackedScene<Node2D>(packedScene);
if (node2D == null) if (node2D == null)
{ {

View File

@ -34,7 +34,7 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell
base._Ready(); base._Ready();
if (!string.IsNullOrEmpty(_projectilePath)) if (!string.IsNullOrEmpty(_projectilePath))
{ {
_projectileScene = GD.Load<PackedScene>(_projectilePath); _projectileScene = ResourceLoader.Load<PackedScene>(_projectilePath);
} }
} }

View File

@ -31,6 +31,17 @@ public partial class ProjectileWeapon : WeaponTemplate
[Export] [Export]
private int _numberSlots; private int _numberSlots;
/// <summary>
/// <para>SpellList</para>
/// <para>法术列表</para>
/// </summary>
/// <remarks>
///<para>To make weapons out of the box, you need to configure pre-made spells here.</para>
///<para>为了使武器开箱即用,您需要在这里配置预制的法术。</para>
/// </remarks>
[Export]
private string[]? _spellList;
/// <summary> /// <summary>
/// <para>How many projectiles are generated per fire</para> /// <para>How many projectiles are generated per fire</para>
/// <para>每次开火生成多少个抛射体</para> /// <para>每次开火生成多少个抛射体</para>
@ -119,6 +130,25 @@ public partial class ProjectileWeapon : WeaponTemplate
{ {
SelfItemContainer = new UniversalItemContainer(_numberSlots); SelfItemContainer = new UniversalItemContainer(_numberSlots);
SelfItemContainer.AllowAddingItemByType(Config.ItemType.Spell); SelfItemContainer.AllowAddingItemByType(Config.ItemType.Spell);
//Reload pre-made spells.
//装填预制的法术。
if (_spellList is not { Length: > 0 }) return;
foreach (var spellId in _spellList)
{
if (string.IsNullOrEmpty(spellId))
{
continue;
}
var item = ItemTypeManager.CreateItem(spellId, this);
if (item == null)
{
continue;
}
if (SelfItemContainer.CanAddItem(item))
{
SelfItemContainer.AddItem(item);
}
}
} }
} }