Add weapon database and equipment component resources with associated services
This commit is contained in:
@@ -14,6 +14,8 @@ public class GodotInputService : IInputService
|
||||
public bool IsJumping { get; private set; }
|
||||
public GameCoreMath MoveDirection { get; private set; }
|
||||
public GameCoreMath LookDirection { get; private set; }
|
||||
public bool IsSwapWeaponNext { get; private set; }
|
||||
public bool IsSwapWeaponPrevious { get; private set; }
|
||||
|
||||
public void HandleInputEvent(InputEvent e)
|
||||
{
|
||||
@@ -38,10 +40,15 @@ public class GodotInputService : IInputService
|
||||
IsJumping = Input.IsActionJustPressed("jump");
|
||||
IsFiring = Input.IsActionPressed("fire");
|
||||
IsInteracting = Input.IsActionPressed("interact");
|
||||
IsSwapWeaponNext = Input.IsActionJustPressed("swap_weapon_next");
|
||||
IsSwapWeaponPrevious = Input.IsActionJustPressed("swap_weapon_previous");
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
LookDirection = GameCoreMath.Zero;
|
||||
|
||||
IsSwapWeaponNext = false;
|
||||
IsSwapWeaponPrevious = false;
|
||||
}
|
||||
}
|
||||
55
Code/Services/GodotWeaponDataService.cs
Normal file
55
Code/Services/GodotWeaponDataService.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Linq;
|
||||
using CryptonymThunder.Code.Factories;
|
||||
using CryptonymThunder.Code.Resources;
|
||||
using GameCore.Combat;
|
||||
using GameCore.Combat.Interfaces;
|
||||
using Godot;
|
||||
|
||||
namespace CryptonymThunder.Code.Services;
|
||||
|
||||
public class GodotWeaponDataService : IWeaponDataService
|
||||
{
|
||||
private readonly WeaponDatabase _database;
|
||||
private readonly EffectFactory _effectFactory;
|
||||
|
||||
public GodotWeaponDataService(WeaponDatabase database, EffectFactory effectFactory)
|
||||
{
|
||||
_database = database;
|
||||
_effectFactory = effectFactory;
|
||||
}
|
||||
|
||||
public WeaponData GetWeaponData(string weaponId)
|
||||
{
|
||||
if (!_database.WeaponData.TryGetValue(weaponId, out var weaponResource))
|
||||
{
|
||||
GD.PrintErr($"Weapon ID not found in database: {weaponId}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var fireCosts = weaponResource.FireCosts
|
||||
.Select(_effectFactory.Create)
|
||||
.OfType<ICostEffect>()
|
||||
.ToList();
|
||||
|
||||
var onFireEffects = weaponResource.OnFireEffects
|
||||
.Select(_effectFactory.Create)
|
||||
.ToList();
|
||||
|
||||
var onHitEffects = weaponResource.OnHitEffects
|
||||
.Select(_effectFactory.Create)
|
||||
.ToList();
|
||||
|
||||
return new WeaponData(
|
||||
weaponResource.FireRate,
|
||||
fireCosts,
|
||||
onFireEffects,
|
||||
onHitEffects
|
||||
);
|
||||
}
|
||||
|
||||
public bool TryGetWeaponData(string weaponId, out WeaponData weaponData)
|
||||
{
|
||||
weaponData = GetWeaponData(weaponId);
|
||||
return weaponData != null;
|
||||
}
|
||||
}
|
||||
1
Code/Services/GodotWeaponDataService.cs.uid
Normal file
1
Code/Services/GodotWeaponDataService.cs.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://4jlk57176ic5
|
||||
Reference in New Issue
Block a user