Simplify collection initialization
This commit is contained in:
committed by
atlimit8
parent
cae43808d9
commit
aa998a46d9
@@ -424,8 +424,10 @@ namespace OpenRA
|
|||||||
if (!dupKeys.TryGetValue(key, out var dupKeyMessages))
|
if (!dupKeys.TryGetValue(key, out var dupKeyMessages))
|
||||||
{
|
{
|
||||||
// Log the initial conflicting value already inserted:
|
// Log the initial conflicting value already inserted:
|
||||||
dupKeyMessages = new List<string>();
|
dupKeyMessages = new List<string>
|
||||||
dupKeyMessages.Add(logValue(d[key]));
|
{
|
||||||
|
logValue(d[key])
|
||||||
|
};
|
||||||
dupKeys.Add(key, dupKeyMessages);
|
dupKeys.Add(key, dupKeyMessages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -154,8 +154,10 @@ namespace OpenRA
|
|||||||
if (stringPool == null)
|
if (stringPool == null)
|
||||||
stringPool = new Dictionary<string, string>();
|
stringPool = new Dictionary<string, string>();
|
||||||
|
|
||||||
var levels = new List<List<MiniYamlNode>>();
|
var levels = new List<List<MiniYamlNode>>
|
||||||
levels.Add(new List<MiniYamlNode>());
|
{
|
||||||
|
new List<MiniYamlNode>()
|
||||||
|
};
|
||||||
|
|
||||||
var lineNo = 0;
|
var lineNo = 0;
|
||||||
foreach (var ll in lines)
|
foreach (var ll in lines)
|
||||||
@@ -323,8 +325,10 @@ namespace OpenRA
|
|||||||
var resolved = new Dictionary<string, MiniYaml>(tree.Count);
|
var resolved = new Dictionary<string, MiniYaml>(tree.Count);
|
||||||
foreach (var kv in tree)
|
foreach (var kv in tree)
|
||||||
{
|
{
|
||||||
var inherited = new Dictionary<string, MiniYamlNode.SourceLocation>();
|
var inherited = new Dictionary<string, MiniYamlNode.SourceLocation>
|
||||||
inherited.Add(kv.Key, default(MiniYamlNode.SourceLocation));
|
{
|
||||||
|
{ kv.Key, default(MiniYamlNode.SourceLocation) }
|
||||||
|
};
|
||||||
|
|
||||||
var children = ResolveInherits(kv.Value, tree, inherited);
|
var children = ResolveInherits(kv.Value, tree, inherited);
|
||||||
resolved.Add(kv.Key, new MiniYaml(kv.Value.Value, children));
|
resolved.Add(kv.Key, new MiniYaml(kv.Value.Value, children));
|
||||||
|
|||||||
@@ -77,10 +77,12 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
public string Serialize()
|
public string Serialize()
|
||||||
{
|
{
|
||||||
var data = new List<MiniYamlNode>();
|
var data = new List<MiniYamlNode>
|
||||||
data.Add(new MiniYamlNode("Handshake", null,
|
{
|
||||||
new[] { "Mod", "Version", "Password", "Fingerprint", "AuthSignature", "OrdersProtocol" }.Select(p => FieldSaver.SaveField(this, p)).ToList()));
|
new MiniYamlNode("Handshake", null,
|
||||||
data.Add(new MiniYamlNode("Client", FieldSaver.Save(Client)));
|
new[] { "Mod", "Version", "Password", "Fingerprint", "AuthSignature", "OrdersProtocol" }.Select(p => FieldSaver.SaveField(this, p)).ToList()),
|
||||||
|
new MiniYamlNode("Client", FieldSaver.Save(Client))
|
||||||
|
};
|
||||||
|
|
||||||
return data.WriteToString();
|
return data.WriteToString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -503,9 +503,11 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
var dy = rx + ry - fullSize.X - 1;
|
var dy = rx + ry - fullSize.X - 1;
|
||||||
var cell = new MPos(dx / 2, dy).ToCPos(map);
|
var cell = new MPos(dx / 2, dy).ToCPos(map);
|
||||||
|
|
||||||
var ar = new ActorReference((!int.TryParse(kv.Key, out var wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
|
var ar = new ActorReference((!int.TryParse(kv.Key, out var wpindex) || wpindex > 7) ? "waypoint" : "mpspawn")
|
||||||
ar.Add(new LocationInit(cell));
|
{
|
||||||
ar.Add(new OwnerInit("Neutral"));
|
new LocationInit(cell),
|
||||||
|
new OwnerInit("Neutral")
|
||||||
|
};
|
||||||
|
|
||||||
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
|
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + map.ActorDefinitions.Count, ar.Save()));
|
||||||
}
|
}
|
||||||
@@ -524,9 +526,11 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
var cell = new MPos(dx / 2, dy).ToCPos(map);
|
var cell = new MPos(dx / 2, dy).ToCPos(map);
|
||||||
var name = kv.Value.ToLowerInvariant();
|
var name = kv.Value.ToLowerInvariant();
|
||||||
|
|
||||||
var ar = new ActorReference(name);
|
var ar = new ActorReference(name)
|
||||||
ar.Add(new LocationInit(cell));
|
{
|
||||||
ar.Add(new OwnerInit("Neutral"));
|
new LocationInit(cell),
|
||||||
|
new OwnerInit("Neutral")
|
||||||
|
};
|
||||||
|
|
||||||
if (!map.Rules.Actors.ContainsKey(name))
|
if (!map.Rules.Actors.ContainsKey(name))
|
||||||
Console.WriteLine($"Ignoring unknown actor type: `{name}`");
|
Console.WriteLine($"Ignoring unknown actor type: `{name}`");
|
||||||
|
|||||||
@@ -100,9 +100,10 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
|
|
||||||
data.AppendLine($"\t\tId: {templateIndex}");
|
data.AppendLine($"\t\tId: {templateIndex}");
|
||||||
|
|
||||||
var images = new List<string>();
|
var images = new List<string>
|
||||||
|
{
|
||||||
images.Add($"{sectionFilename}{i:D2}.{extension}");
|
$"{sectionFilename}{i:D2}.{extension}"
|
||||||
|
};
|
||||||
for (var v = 'a'; v <= 'z'; v++)
|
for (var v = 'a'; v <= 'z'; v++)
|
||||||
{
|
{
|
||||||
var variant = $"{sectionFilename}{i:D2}{v}.{extension}";
|
var variant = $"{sectionFilename}{i:D2}{v}.{extension}";
|
||||||
|
|||||||
@@ -35,9 +35,10 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
if (!Context.World.Map.Rules.Actors.TryGetValue(actorType, out var ai))
|
if (!Context.World.Map.Rules.Actors.TryGetValue(actorType, out var ai))
|
||||||
throw new LuaException($"Unknown actor type '{actorType}'");
|
throw new LuaException($"Unknown actor type '{actorType}'");
|
||||||
|
|
||||||
var initDict = new TypeDictionary();
|
var initDict = new TypeDictionary
|
||||||
|
{
|
||||||
initDict.Add(new OwnerInit(owner));
|
new OwnerInit(owner)
|
||||||
|
};
|
||||||
|
|
||||||
if (entryLocation.HasValue)
|
if (entryLocation.HasValue)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -161,9 +161,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerNames.Contains(ownerName))
|
if (specificOwnerInfo != null && !specificOwnerInfo.ValidOwnerNames.Contains(ownerName))
|
||||||
ownerName = specificOwnerInfo.ValidOwnerNames.First();
|
ownerName = specificOwnerInfo.ValidOwnerNames.First();
|
||||||
|
|
||||||
var reference = new ActorReference(actor.Name);
|
var reference = new ActorReference(actor.Name)
|
||||||
reference.Add(new OwnerInit(ownerName));
|
{
|
||||||
reference.Add(new FactionInit(owner.Faction));
|
new OwnerInit(ownerName),
|
||||||
|
new FactionInit(owner.Faction)
|
||||||
|
};
|
||||||
|
|
||||||
var worldPx = wr.Viewport.ViewToWorldPx(Viewport.LastMousePos) - wr.ScreenPxOffset(actorCenterOffset);
|
var worldPx = wr.Viewport.ViewToWorldPx(Viewport.LastMousePos) - wr.ScreenPxOffset(actorCenterOffset);
|
||||||
var cell = wr.Viewport.ViewToWorld(wr.Viewport.WorldToViewPx(worldPx));
|
var cell = wr.Viewport.ViewToWorld(wr.Viewport.WorldToViewPx(worldPx));
|
||||||
|
|||||||
@@ -181,9 +181,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var actor = a.Actor;
|
var actor = a.Actor;
|
||||||
var td = new TypeDictionary();
|
var td = new TypeDictionary
|
||||||
td.Add(new OwnerInit(selectedOwner.Name));
|
{
|
||||||
td.Add(new FactionInit(selectedOwner.Faction));
|
new OwnerInit(selectedOwner.Name),
|
||||||
|
new FactionInit(selectedOwner.Faction)
|
||||||
|
};
|
||||||
foreach (var api in actor.TraitInfos<IActorPreviewInitInfo>())
|
foreach (var api in actor.TraitInfos<IActorPreviewInitInfo>())
|
||||||
foreach (var o in api.ActorPreviewInits(actor, ActorPreviewType.MapEditorSidebar))
|
foreach (var o in api.ActorPreviewInits(actor, ActorPreviewType.MapEditorSidebar))
|
||||||
td.Add(o);
|
td.Add(o);
|
||||||
|
|||||||
@@ -418,13 +418,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
? new Rectangle(0, 0, Game.Renderer.Resolution.Width, Game.Renderer.Resolution.Height)
|
? new Rectangle(0, 0, Game.Renderer.Resolution.Width, Game.Renderer.Resolution.Height)
|
||||||
: w.Parent.Bounds;
|
: w.Parent.Bounds;
|
||||||
|
|
||||||
var substitutions = new Dictionary<string, int>();
|
var substitutions = new Dictionary<string, int>
|
||||||
substitutions.Add("WINDOW_RIGHT", Game.Renderer.Resolution.Width);
|
{
|
||||||
substitutions.Add("WINDOW_BOTTOM", Game.Renderer.Resolution.Height);
|
{ "WINDOW_RIGHT", Game.Renderer.Resolution.Width },
|
||||||
substitutions.Add("PARENT_RIGHT", parentBounds.Width);
|
{ "WINDOW_BOTTOM", Game.Renderer.Resolution.Height },
|
||||||
substitutions.Add("PARENT_LEFT", parentBounds.Left);
|
{ "PARENT_RIGHT", parentBounds.Width },
|
||||||
substitutions.Add("PARENT_TOP", parentBounds.Top);
|
{ "PARENT_LEFT", parentBounds.Left },
|
||||||
substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
|
{ "PARENT_TOP", parentBounds.Top },
|
||||||
|
{ "PARENT_BOTTOM", parentBounds.Height }
|
||||||
|
};
|
||||||
|
|
||||||
var width = Evaluator.Evaluate(w.Width, substitutions);
|
var width = Evaluator.Evaluate(w.Width, substitutions);
|
||||||
var height = Evaluator.Evaluate(w.Height, substitutions);
|
var height = Evaluator.Evaluate(w.Height, substitutions);
|
||||||
|
|||||||
Reference in New Issue
Block a user