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> MapFolders;
|
||||
public readonly MiniYaml LoadScreen;
|
||||
public readonly string DefaultOrderGenerator;
|
||||
|
||||
public readonly string[] SoundFormats = Array.Empty<string>();
|
||||
public readonly string[] SpriteFormats = Array.Empty<string>();
|
||||
@@ -90,7 +91,7 @@ namespace OpenRA
|
||||
"Include", "Metadata", "Folders", "MapFolders", "Packages", "Rules",
|
||||
"Sequences", "ModelSequences", "Cursors", "Chrome", "Assemblies", "ChromeLayout", "Weapons",
|
||||
"Voices", "Notifications", "Music", "Translations", "TileSets", "ChromeMetrics", "Missions", "Hotkeys",
|
||||
"ServerTraits", "LoadScreen", "SupportsMapsFrom", "SoundFormats", "SpriteFormats", "VideoFormats",
|
||||
"ServerTraits", "LoadScreen", "DefaultOrderGenerator", "SupportsMapsFrom", "SoundFormats", "SpriteFormats", "VideoFormats",
|
||||
"RequiresMods", "PackageFormats"
|
||||
};
|
||||
|
||||
@@ -161,6 +162,9 @@ namespace OpenRA
|
||||
|
||||
MapCompatibility = compat.ToArray();
|
||||
|
||||
if (yaml.ContainsKey("DefaultOrderGenerator"))
|
||||
DefaultOrderGenerator = yaml["DefaultOrderGenerator"].Value;
|
||||
|
||||
if (yaml.ContainsKey("PackageFormats"))
|
||||
PackageFormats = FieldLoader.GetValue<string[]>("PackageFormats", yaml["PackageFormats"].Value);
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using OpenRA.Effects;
|
||||
using OpenRA.FileFormats;
|
||||
@@ -33,6 +34,7 @@ namespace OpenRA
|
||||
readonly List<IEffect> unpartitionedEffects = new List<IEffect>();
|
||||
readonly List<ISync> syncedEffects = new List<ISync>();
|
||||
readonly GameSettings gameSettings;
|
||||
readonly ModData modData;
|
||||
|
||||
readonly Queue<Action<World>> frameEndActions = new Queue<Action<World>>();
|
||||
|
||||
@@ -143,6 +145,8 @@ namespace OpenRA
|
||||
// Hide the OrderManager from mod code
|
||||
public void IssueOrder(Order o) { OrderManager.IssueOrder(o); }
|
||||
|
||||
readonly Type defaultOrderGeneratorType;
|
||||
|
||||
IOrderGenerator orderGenerator;
|
||||
public IOrderGenerator OrderGenerator
|
||||
{
|
||||
@@ -160,7 +164,7 @@ namespace OpenRA
|
||||
public readonly ISelection Selection;
|
||||
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()
|
||||
{
|
||||
@@ -182,11 +186,20 @@ namespace OpenRA
|
||||
|
||||
internal World(ModData modData, Map map, OrderManager orderManager, WorldType type)
|
||||
{
|
||||
this.modData = modData;
|
||||
Type = type;
|
||||
OrderManager = orderManager;
|
||||
orderGenerator = new UnitOrderGenerator();
|
||||
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 gameSpeedName = orderManager.LobbyInfo.GlobalSettings.OptionOrDefault("gamespeed", gameSpeeds.DefaultSpeed);
|
||||
GameSpeed = gameSpeeds.Speeds[gameSpeedName];
|
||||
|
||||
Reference in New Issue
Block a user