feat: more plugin work and intra-scope communication
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
using GodotHostTest.Interfaces;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
public class CurrentLevel : ICurrentLevel
|
||||
{
|
||||
public int LevelNumber { get; private set; } = 1;
|
||||
|
||||
public void NextLevel()
|
||||
{
|
||||
LevelNumber++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
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>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using GodotHostTest.Interfaces;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class LevelData : Resource, ILevel
|
||||
{
|
||||
[Export] public double TimeBetweenSpawns;
|
||||
|
||||
TimeSpan ILevel.TimeBetweenSpawns => TimeSpan.FromSeconds(TimeBetweenSpawns);
|
||||
}
|
||||
+1
-1
@@ -2,4 +2,4 @@ using OwofGames.GodotLume;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
public class LevelScope: RootScope;
|
||||
public class LevelScope : RootScope;
|
||||
@@ -1 +0,0 @@
|
||||
uid://d18acsodp1s3i
|
||||
@@ -1,18 +1,16 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
public partial class LevelServiceSource : RootServiceSource
|
||||
public partial class LevelServiceSource : ServiceSource
|
||||
{
|
||||
[Export] private TargetSpawner _targetSpawner = null!;
|
||||
|
||||
protected override void Configure(IServiceCollection serviceCollection)
|
||||
{
|
||||
serviceCollection
|
||||
.AddSingleton<ITargetCollector>(_targetSpawner)
|
||||
.AddSingleton<ITargetSpawner>(_targetSpawner);
|
||||
}
|
||||
// protected override void ConfigureServices(IServiceCollection serviceCollection)
|
||||
// {
|
||||
// serviceCollection
|
||||
// .AddSingleton<ITargetCollector>(_targetSpawner)
|
||||
// .AddSingleton<ITargetSpawner>(_targetSpawner);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
using GodotHostTest.Interfaces;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class LevelsData : Resource, ILevelDataProvider
|
||||
{
|
||||
[Export] private LevelData[] _levelDataEntries = [];
|
||||
|
||||
public ILevel GetLevelData(int levelNumber)
|
||||
{
|
||||
var entry = _levelDataEntries[levelNumber];
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -1,15 +1,20 @@
|
||||
using Godot;
|
||||
using GodotHostTest.GodotDI;
|
||||
using GodotHostTest.Interfaces;
|
||||
|
||||
namespace GodotHostTest.Game;
|
||||
|
||||
public partial class Root : Node2D
|
||||
{
|
||||
[Inject] private readonly ICurrentLevel _currentLevel = null!;
|
||||
[Inject] private readonly ILevelDataProvider _levelDataProvider = null!;
|
||||
[Inject] private readonly ISceneInstantiator _sceneInstantiator = null!;
|
||||
[Export] private PackedScene _levelScene = null!;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
AddChild(_sceneInstantiator.Instantiate(_levelScene));
|
||||
var levelData = _levelDataProvider.GetLevelData(_currentLevel.LevelNumber);
|
||||
AddChild(_sceneInstantiator.Instantiate(_levelScene,
|
||||
(IValueSetter<ILevel> levelSetter) => { levelSetter.Set(levelData); }));
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -71,7 +71,7 @@ _data = {
|
||||
|
||||
[node name="Level" type="Node2D" unique_id=1331632726]
|
||||
|
||||
[node name="RootScope" type="Node" parent="." unique_id=1267156771 node_paths=PackedStringArray("_targetSpawner", "InjectedNodes")]
|
||||
[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"
|
||||
|
||||
Reference in New Issue
Block a user