mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-04 01:45:53 +00:00
2D Character and weapons
This commit is contained in:
parent
072f6d0ce6
commit
cc9c4e5aa1
37 changed files with 1115 additions and 91 deletions
|
|
@ -2,12 +2,13 @@
|
|||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Weapons;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Controllers;
|
||||
|
||||
public partial class PoolingManager : Node2D
|
||||
public partial class PoolingManager : Node
|
||||
{
|
||||
public static PoolingManager Instance { get; private set; }
|
||||
|
||||
|
|
@ -15,10 +16,10 @@ public partial class PoolingManager : Node2D
|
|||
|
||||
[Export] public bool DebugView { get; private set; } = false;
|
||||
|
||||
private readonly System.Collections.Generic.Dictionary<BulletResource, System.Collections.Generic.List<Bullet>>
|
||||
private readonly System.Collections.Generic.Dictionary<BulletResource, System.Collections.Generic.List<IBullet>>
|
||||
_activeBullets = new();
|
||||
|
||||
private readonly System.Collections.Generic.Dictionary<BulletResource, System.Collections.Generic.List<Bullet>>
|
||||
private readonly System.Collections.Generic.Dictionary<BulletResource, System.Collections.Generic.List<IBullet>>
|
||||
_inactiveBullets = new();
|
||||
|
||||
public override void _Ready()
|
||||
|
|
@ -26,7 +27,7 @@ public partial class PoolingManager : Node2D
|
|||
Instance = this;
|
||||
}
|
||||
|
||||
public Bullet SpawnBullet(BulletResource bulletResource, bool active = true)
|
||||
public IBullet SpawnBullet(BulletResource bulletResource, bool active = true)
|
||||
{
|
||||
// Look for bullet among the inactive ones
|
||||
// If present move it to active, set it as active and return it
|
||||
|
|
@ -53,27 +54,32 @@ public partial class PoolingManager : Node2D
|
|||
return bullet;
|
||||
}
|
||||
|
||||
public IEnumerable<Bullet> GetAllActiveBullets()
|
||||
public T SpawnBullet<T>(BulletResource bulletResource, bool active = true) where T : IBullet
|
||||
{
|
||||
return (T)SpawnBullet(bulletResource, active);
|
||||
}
|
||||
|
||||
public IEnumerable<IBullet> GetAllActiveBullets()
|
||||
{
|
||||
return _activeBullets.Values.SelectMany(list => list);
|
||||
}
|
||||
|
||||
public IEnumerable<Bullet> GetAllInActiveBullets()
|
||||
public IEnumerable<IBullet> GetAllInActiveBullets()
|
||||
{
|
||||
return _activeBullets.Values.SelectMany(list => list);
|
||||
}
|
||||
|
||||
public List<Bullet> GetActiveBulletsList(BulletResource resource)
|
||||
public List<IBullet> GetActiveBulletsList(BulletResource resource)
|
||||
{
|
||||
return GetOrCreateList(_activeBullets, resource);
|
||||
}
|
||||
|
||||
private List<Bullet> GetInactiveBulletsList(BulletResource resource)
|
||||
private List<IBullet> GetInactiveBulletsList(BulletResource resource)
|
||||
{
|
||||
return GetOrCreateList(_inactiveBullets, resource);
|
||||
}
|
||||
|
||||
public void DisableBullet(Bullet bullet)
|
||||
public void DisableBullet(IBullet bullet)
|
||||
{
|
||||
var activeBulletsList = GetActiveBulletsList(bullet.BulletInfo.OriginalBulletResource);
|
||||
|
||||
|
|
@ -106,7 +112,7 @@ public partial class PoolingManager : Node2D
|
|||
|
||||
}
|
||||
|
||||
private List<Bullet> GetOrCreateList(System.Collections.Generic.Dictionary<BulletResource, List<Bullet>> dict, BulletResource resource)
|
||||
private List<IBullet> GetOrCreateList(System.Collections.Generic.Dictionary<BulletResource, List<IBullet>> dict, BulletResource resource)
|
||||
{
|
||||
if (dict.TryGetValue(resource, out var list)) return list;
|
||||
list = [];
|
||||
|
|
@ -116,9 +122,11 @@ public partial class PoolingManager : Node2D
|
|||
|
||||
|
||||
|
||||
private Bullet InstantiateBullet(BulletResource bulletData)
|
||||
private IBullet InstantiateBullet(BulletResource bulletData)
|
||||
{
|
||||
var bullet = this.CreateChild<Bullet>(bulletData.BulletScene);
|
||||
var bullet = bulletData.BulletScene.Instantiate<Bullet>();
|
||||
this.AddChild(bullet);
|
||||
//this.CreateChild<Bullet>(bulletData.BulletScene);
|
||||
return bullet;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue