Fix BibLayer style nits.

This commit is contained in:
Paul Chote
2013-07-24 17:21:55 +12:00
parent 7754357760
commit f95c19e5b2

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS) * Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -19,12 +19,12 @@ namespace OpenRA.Mods.RA.Buildings
{ {
class BibLayerInfo : ITraitInfo class BibLayerInfo : ITraitInfo
{ {
public readonly string[] BibTypes = {"bib3", "bib2", "bib1"}; public readonly string[] BibTypes = { "bib3", "bib2", "bib1" };
public readonly int[] BibWidths = {2,3,4}; public readonly int[] BibWidths = { 2, 3, 4 };
public object Create(ActorInitializer init) { return new BibLayer(init.self, this); } public object Create(ActorInitializer init) { return new BibLayer(init.self, this); }
} }
class BibLayer: IRenderOverlay, IWorldLoaded class BibLayer : IRenderOverlay, IWorldLoaded
{ {
World world; World world;
BibLayerInfo info; BibLayerInfo info;
@@ -36,10 +36,8 @@ namespace OpenRA.Mods.RA.Buildings
this.info = info; this.info = info;
bibSprites = info.BibTypes.Select(x => Game.modData.SpriteLoader.LoadAllSprites(x)).ToArray(); bibSprites = info.BibTypes.Select(x => Game.modData.SpriteLoader.LoadAllSprites(x)).ToArray();
self.World.ActorAdded += self.World.ActorAdded += a => DoBib(a, true);
a => { if (a.HasTrait<Bib>()) DoBib(a,true); }; self.World.ActorRemoved += a => DoBib(a, false);
self.World.ActorRemoved +=
a => { if (a.HasTrait<Bib>()) DoBib(a,false); };
} }
public void WorldLoaded(World w) public void WorldLoaded(World w)
@@ -50,18 +48,21 @@ namespace OpenRA.Mods.RA.Buildings
public void DoBib(Actor b, bool isAdd) public void DoBib(Actor b, bool isAdd)
{ {
if (!b.HasTrait<Bib>())
return;
var buildingInfo = b.Info.Traits.Get<BuildingInfo>(); var buildingInfo = b.Info.Traits.Get<BuildingInfo>();
var size = buildingInfo.Dimensions.X; var size = buildingInfo.Dimensions.X;
var bibOffset = buildingInfo.Dimensions.Y - 1; var bibOffset = buildingInfo.Dimensions.Y - 1;
int bib = Array.IndexOf(info.BibWidths,size); int bib = Array.IndexOf(info.BibWidths, size);
if (bib < 0) if (bib < 0)
{ {
Log.Write("debug", "Cannot bib {0}-wide building {1}", size, b.Info.Name); Log.Write("debug", "Cannot bib {0}-wide building {1}", size, b.Info.Name);
return; return;
} }
for (int i = 0; i < 2 * size; i++) for (var i = 0; i < 2 * size; i++)
{ {
var p = b.Location + new CVec(i % size, i / size + bibOffset); var p = b.Location + new CVec(i % size, i / size + bibOffset);
if (isAdd) if (isAdd)
@@ -71,10 +72,11 @@ namespace OpenRA.Mods.RA.Buildings
} }
} }
public void Render( WorldRenderer wr ) public void Render(WorldRenderer wr)
{ {
var pal = wr.Palette("terrain"); var pal = wr.Palette("terrain");
var cliprect = Game.viewport.WorldBounds(world); var cliprect = Game.viewport.WorldBounds(world);
foreach (var kv in tiles) foreach (var kv in tiles)
{ {
if (!cliprect.Contains(kv.Key.X, kv.Key.Y)) if (!cliprect.Contains(kv.Key.X, kv.Key.Y))