-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
322 dependency injection and inversion of control (#323)
* Add basic DI framework * Add ITurnProcessor interface * Delete some obsolete comments * Apply DI to the TurnProcessor in the TechnologyTest * Implement DI for the TurnProcessor instances used in the game itself * Reorganize some comments * Move TurnProcessor to a new FrEee.Processes project * Put DI configuration code in its own root project * Make IModObject actually implement IDisposable * Add IAI interface for the AIs, but I'm not sure what to do about C# vs. Python scripts so I'l leave it at that for now * Move Configuration class where it belongs * DI the battles * Order commands are now in DI * DI for notes commands * Fix incorrect name for IAddOrderCommand * DI for design commands * Add DIRoot for easier access to common services * Fleet commands get DI'd * Actually use the DI for fleet commands * Remove access to implementation details of game features from the Blazor UI, just to be safe. Prepare to do so for the WinForms UI but we can't do that quite yet; have to clean some stuff up first. * DI the waypoint commands * Use DI for message commands * Minister commands; fix copypasta namespaces * Remove PrivateAssets="all" from root project reference since it didn't seem to do anything * Make private assets restriction more granular * Update DI framework package * Get rid of overarching disable transitive referencves for Blazor project too, it's now in the individual feature projects * Actually inject the minister command factory * Extract more properties into IBattle interface * Remove dependencies on concrete classes for fleet commands rom UI
- Loading branch information
Showing
144 changed files
with
1,945 additions
and
823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.GameState; | ||
using FrEee.Serialization; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FrEee.Gameplay.Commands; | ||
|
||
/// <summary> | ||
/// A generic command. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
[Serializable] | ||
public abstract class Command<T> : ICommand<T> | ||
where T : IReferrable | ||
{ | ||
protected Command(T target) | ||
{ | ||
Issuer = Empire.Current; | ||
Executor = target; | ||
} | ||
|
||
[DoNotSerialize] | ||
public T Executor { get { return executor; } set { executor = value; } } | ||
|
||
IReferrable ICommand.Executor | ||
{ | ||
get { return Executor; } | ||
} | ||
|
||
public long ExecutorID { get { return executor.ID; } } | ||
|
||
public bool IsDisposed { get; set; } | ||
|
||
[DoNotSerialize] | ||
public Empire Issuer { get { return issuer; } set { issuer = value; } } | ||
|
||
public virtual IEnumerable<IReferrable> NewReferrables | ||
{ | ||
get | ||
{ | ||
yield break; | ||
} | ||
} | ||
|
||
protected GameReference<T> executor { get; set; } | ||
|
||
private GameReference<Empire> issuer { get; set; } | ||
|
||
public abstract void Execute(); | ||
|
||
public virtual void ReplaceClientIDs(IDictionary<long, long> idmap, ISet<IPromotable> done = null) | ||
{ | ||
if (done == null) | ||
done = new HashSet<IPromotable>(); | ||
if (!done.Contains(this)) | ||
{ | ||
done.Add(this); | ||
issuer.ReplaceClientIDs(idmap, done); | ||
executor.ReplaceClientIDs(idmap, done); | ||
foreach (var r in NewReferrables.OfType<IPromotable>()) | ||
r.ReplaceClientIDs(idmap, done); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../Objects/Commands/ICreateDesignCommand.cs → .../Commands/Designs/ICreateDesignCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
FrEee.Core.Domain/Gameplay/Commands/Designs/IDesignCommandFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.Civilization.Orders; | ||
using FrEee.Objects.GameState; | ||
using FrEee.Objects.Vehicles; | ||
|
||
namespace FrEee.Gameplay.Commands.Designs; | ||
|
||
/// <summary> | ||
/// Builds various types of commands used for managing vehicle designs. | ||
public interface IDesignCommandFactory | ||
{ | ||
ICreateDesignCommand CreateDesign<T>(IDesign<T> design) | ||
where T : IVehicle; | ||
|
||
ISetObsoleteFlagCommand SetObsoleteFlag(IDesign design, bool isObsolete); | ||
} |
25 changes: 25 additions & 0 deletions
25
FrEee.Core.Domain/Gameplay/Commands/Designs/ISetObsoleteFlagCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.Vehicles; | ||
|
||
namespace FrEee.Gameplay.Commands.Designs; | ||
|
||
/// <summary> | ||
/// A command to mark a design as obsolete or not obsolete. | ||
/// </summary> | ||
public interface ISetObsoleteFlagCommand : ICommand<IDesign> | ||
{ | ||
/// <summary> | ||
/// The design to set the flag on if it's already knwon by the server. | ||
/// </summary> | ||
IDesign Design { get; } | ||
|
||
/// <summary> | ||
/// The design to set the flag on if it's only in the library and not in the game or it's a brand new design. | ||
/// </summary> | ||
IDesign NewDesign { get; set; } | ||
|
||
/// <summary> | ||
/// The flag state to set. | ||
/// </summary> | ||
bool IsObsolete { get; set; } | ||
} |
File renamed without changes.
17 changes: 17 additions & 0 deletions
17
FrEee.Core.Domain/Gameplay/Commands/Fleets/ICreateFleetCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.Space; | ||
|
||
namespace FrEee.Gameplay.Commands.Fleets; | ||
public interface ICreateFleetCommand | ||
: ICommand<Empire> | ||
{ | ||
/// <summary> | ||
/// The fleet to create. | ||
/// </summary> | ||
Fleet Fleet { get; set; } | ||
|
||
/// <summary> | ||
/// The sector to place the fleet in. | ||
/// </summary> | ||
Sector Sector { get; } | ||
} |
8 changes: 8 additions & 0 deletions
8
FrEee.Core.Domain/Gameplay/Commands/Fleets/IDisbandFleetCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.Space; | ||
|
||
namespace FrEee.Gameplay.Commands.Fleets; | ||
public interface IDisbandFleetCommand | ||
: ICommand<Fleet> | ||
{ | ||
} |
24 changes: 24 additions & 0 deletions
24
FrEee.Core.Domain/Gameplay/Commands/Fleets/IFleetCommandFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FrEee.Objects.Space; | ||
|
||
namespace FrEee.Gameplay.Commands.Fleets; | ||
|
||
/// <summary> | ||
/// Builds various types of commands used for managing fleets. | ||
/// </summary> | ||
public interface IFleetCommandFactory | ||
{ | ||
ICreateFleetCommand CreateFleet(Fleet fleet, Sector sector); | ||
|
||
IDisbandFleetCommand DisbandFleet(Fleet fleet); | ||
|
||
IJoinFleetCommand JoinFleet(IMobileSpaceObject vehicle, Fleet fleet); | ||
|
||
IJoinFleetCommand JoinFleet(IMobileSpaceObject vehicle, ICreateFleetCommand command); | ||
|
||
ILeaveFleetCommand LeaveFleet(IMobileSpaceObject vehicle); | ||
} |
16 changes: 16 additions & 0 deletions
16
FrEee.Core.Domain/Gameplay/Commands/Fleets/IJoinFleetCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using FrEee.Objects.Space; | ||
|
||
namespace FrEee.Gameplay.Commands.Fleets; | ||
public interface IJoinFleetCommand | ||
: ICommand<IMobileSpaceObject> | ||
{ | ||
/// <summary> | ||
/// The command that creates the fleet to join (if the fleet is newly created on the client side). | ||
/// </summary> | ||
ICreateFleetCommand CreateFleetCommand { get; set; } | ||
|
||
/// <summary> | ||
/// The fleet to join. | ||
/// </summary> | ||
Fleet Fleet { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
FrEee.Core.Domain/Gameplay/Commands/Fleets/ILeaveFleetCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.Space; | ||
|
||
namespace FrEee.Gameplay.Commands.Fleets; | ||
public interface ILeaveFleetCommand | ||
: ICommand<IMobileSpaceObject> | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FrEee.Gameplay.Commands; | ||
|
||
/// <summary> | ||
/// Builds various types of <see cref="ICommand"> used by the game. | ||
/// </summary> | ||
public interface ICommandFactory | ||
{ | ||
// TODO: split these out into separate factories for each category and add parameters | ||
ICommand Research(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.Civilization.Orders; | ||
|
||
namespace FrEee.Gameplay.Commands; | ||
|
||
/// <summary> | ||
/// A command which enables or disables something. | ||
/// </summary> | ||
public interface IToggleCommand | ||
: ICommand | ||
{ | ||
/// <summary> | ||
/// Is the toggle enabled or disabled? | ||
/// </summary> | ||
bool IsToggleEnabled { get; set; } | ||
} |
11 changes: 11 additions & 0 deletions
11
FrEee.Core.Domain/Gameplay/Commands/Messages/IDeleteMessageCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FrEee.Gameplay.Commands.Messages; | ||
public interface IDeleteMessageCommand | ||
: IMessageCommand | ||
{ | ||
} |
15 changes: 15 additions & 0 deletions
15
FrEee.Core.Domain/Gameplay/Commands/Messages/IMessageCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.Civilization.Diplomacy.Messages; | ||
|
||
namespace FrEee.Gameplay.Commands.Messages; | ||
|
||
public interface IMessageCommand | ||
: ICommand<Empire> | ||
{ | ||
IMessage Message { get; } | ||
} |
19 changes: 19 additions & 0 deletions
19
FrEee.Core.Domain/Gameplay/Commands/Messages/IMessageCommandFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FrEee.Objects.Civilization; | ||
using FrEee.Objects.Civilization.Diplomacy.Messages; | ||
|
||
namespace FrEee.Gameplay.Commands.Messages; | ||
|
||
/// <summary> | ||
/// Builds commands allowing players to manage diplomatic messages. | ||
/// </summary> | ||
public interface IMessageCommandFactory | ||
{ | ||
IDeleteMessageCommand DeleteMessage(IMessage message); | ||
|
||
ISendMessageCommand SendMessage(IMessage message); | ||
} |
11 changes: 11 additions & 0 deletions
11
FrEee.Core.Domain/Gameplay/Commands/Messages/ISendMessageCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FrEee.Gameplay.Commands.Messages; | ||
public interface ISendMessageCommand | ||
: IMessageCommand | ||
{ | ||
} |
Oops, something went wrong.