Allow mods to replace UnitOrderGenerator with their own default.
This commit is contained in:
@@ -79,6 +79,7 @@ namespace OpenRA
|
|||||||
public readonly IReadOnlyDictionary<string, string> Packages;
|
public readonly IReadOnlyDictionary<string, string> Packages;
|
||||||
public readonly IReadOnlyDictionary<string, string> MapFolders;
|
public readonly IReadOnlyDictionary<string, string> MapFolders;
|
||||||
public readonly MiniYaml LoadScreen;
|
public readonly MiniYaml LoadScreen;
|
||||||
|
public readonly string DefaultOrderGenerator;
|
||||||
|
|
||||||
public readonly string[] SoundFormats = Array.Empty<string>();
|
public readonly string[] SoundFormats = Array.Empty<string>();
|
||||||
public readonly string[] SpriteFormats = Array.Empty<string>();
|
public readonly string[] SpriteFormats = Array.Empty<string>();
|
||||||
@@ -90,7 +91,7 @@ namespace OpenRA
|
|||||||
"Include", "Metadata", "Folders", "MapFolders", "Packages", "Rules",
|
"Include", "Metadata", "Folders", "MapFolders", "Packages", "Rules",
|
||||||
"Sequences", "ModelSequences", "Cursors", "Chrome", "Assemblies", "ChromeLayout", "Weapons",
|
"Sequences", "ModelSequences", "Cursors", "Chrome", "Assemblies", "ChromeLayout", "Weapons",
|
||||||
"Voices", "Notifications", "Music", "Translations", "TileSets", "ChromeMetrics", "Missions", "Hotkeys",
|
"Voices", "Notifications", "Music", "Translations", "TileSets", "ChromeMetrics", "Missions", "Hotkeys",
|
||||||
"ServerTraits", "LoadScreen", "SupportsMapsFrom", "SoundFormats", "SpriteFormats", "VideoFormats",
|
"ServerTraits", "LoadScreen", "DefaultOrderGenerator", "SupportsMapsFrom", "SoundFormats", "SpriteFormats", "VideoFormats",
|
||||||
"RequiresMods", "PackageFormats"
|
"RequiresMods", "PackageFormats"
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -161,6 +162,9 @@ namespace OpenRA
|
|||||||
|
|
||||||
MapCompatibility = compat.ToArray();
|
MapCompatibility = compat.ToArray();
|
||||||
|
|
||||||
|
if (yaml.ContainsKey("DefaultOrderGenerator"))
|
||||||
|
DefaultOrderGenerator = yaml["DefaultOrderGenerator"].Value;
|
||||||
|
|
||||||
if (yaml.ContainsKey("PackageFormats"))
|
if (yaml.ContainsKey("PackageFormats"))
|
||||||
PackageFormats = FieldLoader.GetValue<string[]>("PackageFormats", yaml["PackageFormats"].Value);
|
PackageFormats = FieldLoader.GetValue<string[]>("PackageFormats", yaml["PackageFormats"].Value);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Effects;
|
using OpenRA.Effects;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
@@ -33,6 +34,7 @@ namespace OpenRA
|
|||||||
readonly List<IEffect> unpartitionedEffects = new List<IEffect>();
|
readonly List<IEffect> unpartitionedEffects = new List<IEffect>();
|
||||||
readonly List<ISync> syncedEffects = new List<ISync>();
|
readonly List<ISync> syncedEffects = new List<ISync>();
|
||||||
readonly GameSettings gameSettings;
|
readonly GameSettings gameSettings;
|
||||||
|
readonly ModData modData;
|
||||||
|
|
||||||
readonly Queue<Action<World>> frameEndActions = new Queue<Action<World>>();
|
readonly Queue<Action<World>> frameEndActions = new Queue<Action<World>>();
|
||||||
|
|
||||||
@@ -143,6 +145,8 @@ namespace OpenRA
|
|||||||
// Hide the OrderManager from mod code
|
// Hide the OrderManager from mod code
|
||||||
public void IssueOrder(Order o) { OrderManager.IssueOrder(o); }
|
public void IssueOrder(Order o) { OrderManager.IssueOrder(o); }
|
||||||
|
|
||||||
|
readonly Type defaultOrderGeneratorType;
|
||||||
|
|
||||||
IOrderGenerator orderGenerator;
|
IOrderGenerator orderGenerator;
|
||||||
public IOrderGenerator OrderGenerator
|
public IOrderGenerator OrderGenerator
|
||||||
{
|
{
|
||||||
@@ -160,7 +164,7 @@ namespace OpenRA
|
|||||||
public readonly ISelection Selection;
|
public readonly ISelection Selection;
|
||||||
public readonly IControlGroups ControlGroups;
|
public readonly IControlGroups ControlGroups;
|
||||||
|
|
||||||
public void CancelInputMode() { OrderGenerator = new UnitOrderGenerator(); }
|
public void CancelInputMode() { OrderGenerator = (IOrderGenerator)modData.ObjectCreator.CreateBasic(defaultOrderGeneratorType); }
|
||||||
|
|
||||||
public bool ToggleInputMode<T>() where T : IOrderGenerator, new()
|
public bool ToggleInputMode<T>() where T : IOrderGenerator, new()
|
||||||
{
|
{
|
||||||
@@ -182,11 +186,20 @@ namespace OpenRA
|
|||||||
|
|
||||||
internal World(ModData modData, Map map, OrderManager orderManager, WorldType type)
|
internal World(ModData modData, Map map, OrderManager orderManager, WorldType type)
|
||||||
{
|
{
|
||||||
|
this.modData = modData;
|
||||||
Type = type;
|
Type = type;
|
||||||
OrderManager = orderManager;
|
OrderManager = orderManager;
|
||||||
orderGenerator = new UnitOrderGenerator();
|
|
||||||
Map = map;
|
Map = map;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(modData.Manifest.DefaultOrderGenerator))
|
||||||
|
throw new InvalidDataException("mod.yaml must define a DefaultOrderGenerator");
|
||||||
|
|
||||||
|
defaultOrderGeneratorType = modData.ObjectCreator.FindType(modData.Manifest.DefaultOrderGenerator);
|
||||||
|
if (defaultOrderGeneratorType == null)
|
||||||
|
throw new InvalidDataException($"{modData.Manifest.DefaultOrderGenerator} is not a valid DefaultOrderGenerator");
|
||||||
|
|
||||||
|
orderGenerator = (IOrderGenerator)modData.ObjectCreator.CreateBasic(defaultOrderGeneratorType);
|
||||||
|
|
||||||
var gameSpeeds = modData.Manifest.Get<GameSpeeds>();
|
var gameSpeeds = modData.Manifest.Get<GameSpeeds>();
|
||||||
var gameSpeedName = orderManager.LobbyInfo.GlobalSettings.OptionOrDefault("gamespeed", gameSpeeds.DefaultSpeed);
|
var gameSpeedName = orderManager.LobbyInfo.GlobalSettings.OptionOrDefault("gamespeed", gameSpeeds.DefaultSpeed);
|
||||||
GameSpeed = gameSpeeds.Speeds[gameSpeedName];
|
GameSpeed = gameSpeeds.Speeds[gameSpeedName];
|
||||||
|
|||||||
@@ -223,6 +223,8 @@ MapGrid:
|
|||||||
TileSize: 24,24
|
TileSize: 24,24
|
||||||
Type: Rectangular
|
Type: Rectangular
|
||||||
|
|
||||||
|
DefaultOrderGenerator: UnitOrderGenerator
|
||||||
|
|
||||||
SupportsMapsFrom: cnc
|
SupportsMapsFrom: cnc
|
||||||
|
|
||||||
SoundFormats: Aud, Wav
|
SoundFormats: Aud, Wav
|
||||||
|
|||||||
@@ -204,6 +204,8 @@ Fonts:
|
|||||||
Missions:
|
Missions:
|
||||||
d2k|missions.yaml
|
d2k|missions.yaml
|
||||||
|
|
||||||
|
DefaultOrderGenerator: UnitOrderGenerator
|
||||||
|
|
||||||
SupportsMapsFrom: d2k
|
SupportsMapsFrom: d2k
|
||||||
|
|
||||||
SoundFormats: Aud, Wav
|
SoundFormats: Aud, Wav
|
||||||
|
|||||||
@@ -226,6 +226,8 @@ MapGrid:
|
|||||||
TileSize: 24,24
|
TileSize: 24,24
|
||||||
Type: Rectangular
|
Type: Rectangular
|
||||||
|
|
||||||
|
DefaultOrderGenerator: UnitOrderGenerator
|
||||||
|
|
||||||
SupportsMapsFrom: ra
|
SupportsMapsFrom: ra
|
||||||
|
|
||||||
SoundFormats: Aud, Wav
|
SoundFormats: Aud, Wav
|
||||||
|
|||||||
@@ -256,6 +256,8 @@ Fonts:
|
|||||||
Size: 32
|
Size: 32
|
||||||
Ascender: 24
|
Ascender: 24
|
||||||
|
|
||||||
|
DefaultOrderGenerator: UnitOrderGenerator
|
||||||
|
|
||||||
SupportsMapsFrom: ts
|
SupportsMapsFrom: ts
|
||||||
|
|
||||||
SoundFormats: Aud, Wav
|
SoundFormats: Aud, Wav
|
||||||
|
|||||||
Reference in New Issue
Block a user