Add MapClassification.Generated.
Generated maps are created at runtime using a mod-defined trait. They are embedded directly into replays and save games as they exist in memory only, and disappear after the game exits.
This commit is contained in:
committed by
Gustas Kažukauskas
parent
6be947bbf0
commit
979483b63c
@@ -20,6 +20,7 @@ using OpenRA.FileSystem;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -224,6 +225,45 @@ namespace OpenRA
|
||||
yield return mapPackage;
|
||||
}
|
||||
|
||||
public void GenerateMap(MapGenerationArgs args)
|
||||
{
|
||||
var p = previews[args.Uid];
|
||||
if (p.Class == MapClassification.Generated)
|
||||
return;
|
||||
|
||||
p.UpdateFromGenerationArgs(args);
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var generator = modData.DefaultRules.Actors[SystemActors.EditorWorld]
|
||||
.TraitInfos<IMapGeneratorInfo>()
|
||||
.FirstOrDefault(info => info.Type == args.Generator);
|
||||
|
||||
if (generator == null)
|
||||
throw new Exception($"Unknown map generator type {args.Generator}");
|
||||
|
||||
var map = generator.Generate(modData, args);
|
||||
|
||||
// Uid is generated when the map is saved
|
||||
map.Save(new ZipFileLoader.ReadWriteZipFile());
|
||||
|
||||
if (map.Uid != args.Uid)
|
||||
throw new InvalidOperationException("Map generation UID mismatch");
|
||||
|
||||
Game.RunAfterTick(() => p.UpdateFromMap(map.Package, MapClassification.Generated));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Write("debug", "Map generation failed with error:");
|
||||
Log.Write("debug", e);
|
||||
|
||||
p.UpdateFromGenerationArgs(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void QueryRemoteMapDetails(string repositoryUrl, IEnumerable<string> uids,
|
||||
Action<MapPreview> mapDetailsReceived = null, Action<MapPreview> mapQueryFailed = null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user