Battle core from the game's settings
BattleCoreRegistry.GetActive: without an explicit battle.set_core the active game collection's settings["battle.core"] chooses the core (e.g. card_battle for cthangover and card_novel), then the first registered one.
This commit is contained in:
1 parent
13da8f87a2
commit
bbc75eeadd
1 file changed
+15
-3
@@ -2,6 +2,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using Cthangover.Core.Games;
|
||||||
using Cthangover.Core.Utils;
|
using Cthangover.Core.Utils;
|
||||||
|
|
||||||
namespace Cthangover.Core.Battle
|
namespace Cthangover.Core.Battle
|
||||||
@@ -16,6 +17,9 @@ namespace Cthangover.Core.Battle
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class BattleCoreRegistry
|
public class BattleCoreRegistry
|
||||||
{
|
{
|
||||||
|
/// <summary>Game collection setting naming the battle core of that game.</summary>
|
||||||
|
public const string GameSettingKey = "battle.core";
|
||||||
|
|
||||||
/// <summary>Singleton registry instance.</summary>
|
/// <summary>Singleton registry instance.</summary>
|
||||||
public static readonly BattleCoreRegistry Instance = new();
|
public static readonly BattleCoreRegistry Instance = new();
|
||||||
|
|
||||||
@@ -68,15 +72,23 @@ namespace Cthangover.Core.Battle
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a fresh instance of the active core type. Falls
|
/// Constructs a fresh instance of the active core type. Without an
|
||||||
/// back to the first registered core if no active ID was set.
|
/// explicit <c>battle.set_core</c> the active game's
|
||||||
/// Throws if no cores are registered at all.
|
/// <c>settings["battle.core"]</c> decides, then the first registered
|
||||||
|
/// core. Throws if no cores are registered at all.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IBattleCore GetActive()
|
public IBattleCore GetActive()
|
||||||
{
|
{
|
||||||
if (_activeCoreId != null && _cores.ContainsKey(_activeCoreId))
|
if (_activeCoreId != null && _cores.ContainsKey(_activeCoreId))
|
||||||
return (IBattleCore)Activator.CreateInstance(_cores[_activeCoreId]);
|
return (IBattleCore)Activator.CreateInstance(_cores[_activeCoreId]);
|
||||||
|
|
||||||
|
var gameCore = ActiveGame.GetSetting(GameSettingKey);
|
||||||
|
if (gameCore != null && _cores.ContainsKey(gameCore))
|
||||||
|
{
|
||||||
|
_activeCoreId = gameCore;
|
||||||
|
return (IBattleCore)Activator.CreateInstance(_cores[gameCore]);
|
||||||
|
}
|
||||||
|
|
||||||
var firstId = GetFirstCoreId();
|
var firstId = GetFirstCoreId();
|
||||||
if (firstId != null)
|
if (firstId != null)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user