feat: aetherbind, first source generator
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.GodotLume;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
public partial class GameServiceSource : RootServiceSource
|
||||
{
|
||||
[Export] private LevelsData _levelsData = null!;
|
||||
|
||||
protected override void Configure(Builder builder)
|
||||
{
|
||||
builder
|
||||
.AddSingleton<ICurrentLevel, CurrentLevel>()
|
||||
.AddInstance<ILevelDataProvider, LevelsData>(_levelsData)
|
||||
.AddValueProvider<ILevel, RootScope, LevelScope>()
|
||||
.AddValueProvider<ITargetCollector, LevelScope>()
|
||||
.AddValueProvider<ITargetSpawner, LevelScope>();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using GodotHostTest.Interfaces;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Level;
|
||||
|
||||
public class CurrentLevel : ICurrentLevel
|
||||
{
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
using Godot;
|
||||
using GodotHostTest.Interfaces;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Level;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class LevelData : Resource, ILevel
|
||||
@@ -0,0 +1,5 @@
|
||||
using OwofGames.GodotLume;
|
||||
|
||||
namespace GodotHostTest.Game.Level;
|
||||
|
||||
public class LevelScope : RootScope;
|
||||
@@ -1,9 +1,11 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Game.Target;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.GodotLume;
|
||||
using ServiceSource = GodotHostTest.AetherBind.ServiceSource;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Level;
|
||||
|
||||
public partial class LevelServiceSource : ServiceSource
|
||||
{
|
||||
@@ -0,0 +1,21 @@
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.GodotLume;
|
||||
|
||||
namespace GodotHostTest.Game.Level;
|
||||
|
||||
public static class LevelServices
|
||||
{
|
||||
public static void AddLevelServices(this Builder builder, LevelsData levelsData)
|
||||
{
|
||||
builder
|
||||
// current level / level data management
|
||||
.AddSingleton<ICurrentLevel, CurrentLevel>()
|
||||
.AddInstance<ILevelDataProvider, LevelsData>(levelsData)
|
||||
// value providers to send data into level scope
|
||||
.AddValueProvider<ILevel, RootScope, LevelScope>()
|
||||
// value provider for level scope setup
|
||||
.AddValueProvider<ITargetCollector, LevelScope>()
|
||||
.AddValueProvider<ITargetSpawner, LevelScope>();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using Godot;
|
||||
using GodotHostTest.Interfaces;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Level;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class LevelsData : Resource, ILevelDataProvider
|
||||
@@ -1,5 +0,0 @@
|
||||
using OwofGames.GodotLume;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
public class LevelScope : RootScope;
|
||||
@@ -1,16 +1,18 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Helpers;
|
||||
using GodotHostTest.Interfaces;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OwofGames.AetherBind;
|
||||
using R3;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Projectile;
|
||||
|
||||
[Injected]
|
||||
public partial class Projectile : Node2D
|
||||
{
|
||||
[Inject] private readonly ILogger<Projectile> _logger = null!;
|
||||
[Inject] private readonly IValueGetter<ITargetSpawner> _targetSpawner = null!;
|
||||
[Inject] private ILogger<Projectile> _logger = null!;
|
||||
[Inject] private IValueGetter<ITargetSpawner> _targetSpawner = null!;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
using GodotHostTest.Game.Level;
|
||||
using OwofGames.GodotLume;
|
||||
using RootServiceSource = GodotHostTest.AetherBind.RootServiceSource;
|
||||
|
||||
namespace GodotHostTest.Game.Root;
|
||||
|
||||
public partial class GameServiceSource : RootServiceSource
|
||||
{
|
||||
[Export] private LevelsData _levelsData = null!;
|
||||
|
||||
protected override void Configure(Builder builder)
|
||||
{
|
||||
builder.AddLevelServices(_levelsData);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.AetherBind;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Root;
|
||||
|
||||
[Injected]
|
||||
public partial class Root : Node2D
|
||||
{
|
||||
[Inject] private readonly ICurrentLevel _currentLevel = null!;
|
||||
[Inject] private readonly ILevelDataProvider _levelDataProvider = null!;
|
||||
[Inject] private readonly ISceneInstantiator _sceneInstantiator = null!;
|
||||
[Inject] private ICurrentLevel _currentLevel = null!;
|
||||
[Inject] private ILevelDataProvider _levelDataProvider = null!;
|
||||
[Export] private PackedScene _levelScene = null!;
|
||||
[Inject] private ISceneInstantiator _sceneInstantiator = null!;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -1,18 +1,20 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Helpers;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.AetherBind;
|
||||
using R3;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Score;
|
||||
|
||||
[Injected]
|
||||
public partial class Score : Control, IScore
|
||||
{
|
||||
[Inject] private readonly IValueGetter<ITargetSpawner> _targetSpawner = null!;
|
||||
[Export] private AnimationPlayer _animationPlayer = null!;
|
||||
[Export] private Label _label = null!;
|
||||
|
||||
private int _score;
|
||||
[Inject] private IValueGetter<ITargetSpawner> _targetSpawner = null!;
|
||||
|
||||
int IScore.Score => _score;
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.AetherBind;
|
||||
using GodotHostTest.Interfaces;
|
||||
using OwofGames.AetherBind;
|
||||
using R3;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Target;
|
||||
|
||||
[Injected]
|
||||
public partial class Target : Node2D, ITarget
|
||||
{
|
||||
private readonly Subject<Unit> _hit = new();
|
||||
|
||||
[Inject] private readonly IValueGetter<ITargetCollector> _targetCollector = null!;
|
||||
|
||||
private readonly Subject<Unit> _timedOut = new();
|
||||
[Export] public required Area2D CollisionArea;
|
||||
[Export] public required Sprite2D Image;
|
||||
[Export] public double TimeOutDurationInSeconds;
|
||||
[Export] public required Timer TimeOutTimer;
|
||||
|
||||
[Inject] private IValueGetter<ITargetCollector> _targetCollector = null!;
|
||||
|
||||
public Observable<Unit> TimedOut => _timedOut.AsObservable();
|
||||
|
||||
public Observable<Unit> Hit => _hit.AsObservable();
|
||||
@@ -4,15 +4,24 @@ using GodotHostTest.Helpers;
|
||||
using GodotHostTest.Interfaces;
|
||||
using R3;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Target;
|
||||
|
||||
public partial class TargetSpawner : Node2D, ITargetCollector, ITargetSpawner
|
||||
{
|
||||
private readonly List<ITarget> _availableTargets = [];
|
||||
|
||||
private readonly Subject<ITarget> _targetSpawned = new();
|
||||
[Export] public double TimeBetweenSpawns;
|
||||
|
||||
[Export] public required Timer Timer;
|
||||
|
||||
private readonly List<ITarget> _availableTargets = [];
|
||||
public void NewTarget(ITarget target)
|
||||
{
|
||||
_availableTargets.Add(target);
|
||||
target.Hit.Merge(target.TimedOut).Select(_ => target).Subscribe(MakeTargetAvailable).AddTo(this);
|
||||
}
|
||||
|
||||
public Observable<ITarget> TargetSpawned => _targetSpawned.AsObservable();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -44,18 +53,9 @@ public partial class TargetSpawner : Node2D, ITargetCollector, ITargetSpawner
|
||||
_targetSpawned.OnNext(target);
|
||||
}
|
||||
|
||||
public void NewTarget(ITarget target)
|
||||
{
|
||||
_availableTargets.Add(target);
|
||||
target.Hit.Merge(target.TimedOut).Select(_ => target).Subscribe(MakeTargetAvailable).AddTo(this);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
_targetSpawned.Dispose();
|
||||
}
|
||||
|
||||
private readonly Subject<ITarget> _targetSpawned = new();
|
||||
public Observable<ITarget> TargetSpawned => _targetSpawned.AsObservable();
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.AetherBind;
|
||||
using OwofGames.AetherBind;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
namespace GodotHostTest.Game.Turret;
|
||||
|
||||
[Injected]
|
||||
public partial class Turret : Sprite2D
|
||||
{
|
||||
[Inject] private readonly ISceneInstantiator _sceneInstantiator = null!;
|
||||
[Export] private PackedScene _projectilePackedScene = null!;
|
||||
[Inject] private ISceneInstantiator _sceneInstantiator = null!;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
+5
-5
@@ -1,11 +1,11 @@
|
||||
[gd_scene format=3 uid="uid://xfd48ep5qi1k"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dk578xnlxjwrr" path="res://Game/LevelServiceSource.cs" id="1_5saw1"]
|
||||
[ext_resource type="Script" uid="uid://dk578xnlxjwrr" path="res://Game/Level/LevelServiceSource.cs" id="1_5saw1"]
|
||||
[ext_resource type="PackedScene" uid="uid://3v8kq1rfwhmr" path="res://Game/target.tscn" id="1_y7rhs"]
|
||||
[ext_resource type="Script" uid="uid://cxfrtglku2gfa" path="res://Game/TargetSpawner.cs" id="2_5saw1"]
|
||||
[ext_resource type="Script" uid="uid://bgrjeadxhgmvi" path="res://Game/Score.cs" id="3_spj1u"]
|
||||
[ext_resource type="Script" uid="uid://cxfrtglku2gfa" path="res://Game/Target/TargetSpawner.cs" id="2_5saw1"]
|
||||
[ext_resource type="Script" uid="uid://bgrjeadxhgmvi" path="res://Game/Score/Score.cs" id="3_spj1u"]
|
||||
[ext_resource type="Texture2D" uid="uid://y1ros3y7hag2" path="res://icon.svg" id="4_esqs7"]
|
||||
[ext_resource type="Script" uid="uid://ce7gnp1lcrrdv" path="res://Game/Turret.cs" id="5_himod"]
|
||||
[ext_resource type="Script" uid="uid://ce7gnp1lcrrdv" path="res://Game/Turret/Turret.cs" id="5_himod"]
|
||||
[ext_resource type="PackedScene" uid="uid://brbufibn7hi3o" path="res://Game/projectile.tscn" id="6_sin03"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_bbjqm"]
|
||||
@@ -74,7 +74,7 @@ _data = {
|
||||
[node name="LevelScope" type="Node" parent="." unique_id=1267156771 node_paths=PackedStringArray("_targetSpawner", "InjectedNodes")]
|
||||
script = ExtResource("1_5saw1")
|
||||
_targetSpawner = NodePath("../Spawner")
|
||||
_serviceScope = "GodotHostTest.Game.LevelScope, godot-host-test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
|
||||
_serviceScope = "GodotHostTest.Game.Level.LevelScope, godot-host-test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
|
||||
InjectedNodes = [NodePath("../Target"), NodePath("../Target2"), NodePath("../Target3"), NodePath("../Target4"), NodePath("../Target5"), NodePath("../Target6"), NodePath("../Score"), NodePath("../Turret")]
|
||||
|
||||
[node name="Target" parent="." unique_id=2101558052 instance=ExtResource("1_y7rhs")]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[gd_resource type="Resource" script_class="LevelsData" format=3 uid="uid://c4ym7vrpgk4e6"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://ywe7vkywrdvk" path="res://Game/LevelData.cs" id="1_bkfnq"]
|
||||
[ext_resource type="Script" uid="uid://cl200m5rnkboq" path="res://Game/LevelsData.cs" id="1_e2ehm"]
|
||||
[ext_resource type="Script" uid="uid://ywe7vkywrdvk" path="res://Game/Level/LevelData.cs" id="1_bkfnq"]
|
||||
[ext_resource type="Script" uid="uid://cl200m5rnkboq" path="res://Game/Level/LevelsData.cs" id="1_e2ehm"]
|
||||
|
||||
[sub_resource type="Resource" id="Resource_bbjqm"]
|
||||
script = ExtResource("1_bkfnq")
|
||||
|
||||
Reference in New Issue
Block a user