Skip to content

Commit

Permalink
Use WorldViewortSizes.DefaultScale.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Dec 21, 2022
1 parent bb50771 commit 7eed99a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
20 changes: 5 additions & 15 deletions OpenRA.Mods.Mobius/Traits/World/RemasterTerrainRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ Rectangle ITiledTerrainRenderer.TemplateBounds(TerrainTemplateInfo template)
for (var x = 0; x < template.Size.X; x++)
{
var tile = new TerrainTile(template.Id, (byte)(i++));
var tileInfo = terrainInfo.GetTileInfo(tile);

// Empty tile
if (tileInfo == null)
if (!terrainInfo.TryGetTileInfo(tile, out var tileInfo))
continue;

var sprite = tileCache.TileSprite(tile, 0);
Expand All @@ -163,8 +160,7 @@ Rectangle ITiledTerrainRenderer.TemplateBounds(TerrainTemplateInfo template)

IEnumerable<IRenderable> ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr, TerrainTemplateInfo t, int2 origin, float scale)
{
var template = t as RemasterTerrainTemplateInfo;
if (template == null)
if (!(t is RemasterTerrainTemplateInfo template))
yield break;

var ts = map.Grid.TileSize;
Expand All @@ -176,10 +172,7 @@ IEnumerable<IRenderable> ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr,
for (var x = 0; x < template.Size.X; x++)
{
var tile = new TerrainTile(template.Id, (byte)i++);
var tileInfo = terrainInfo.GetTileInfo(tile);

// Empty tile
if (tileInfo == null)
if (!terrainInfo.TryGetTileInfo(tile, out var tileInfo))
continue;

var sprite = tileCache.TileSprite(tile, 0);
Expand All @@ -188,7 +181,7 @@ IEnumerable<IRenderable> ITiledTerrainRenderer.RenderUIPreview(WorldRenderer wr,

var u = gridType == MapGridType.Rectangular ? x : (x - y) / 2f;
var v = gridType == MapGridType.Rectangular ? y : (x + y) / 2f;
var offset = (scale * new float2(u * ts.Width, (v - 0.5f * tileInfo.Height) * ts.Height) - 0.5f * sprite.Size.XY).ToInt2();
var offset = (scale * new float2(u * ts.Width, (v - 0.5f * tileInfo.Height) * ts.Height) - 0.5f * scale * sprite.Size.XY).ToInt2();

yield return new UISpriteRenderable(sprite, WPos.Zero, origin + offset, 0, null, scale);
}
Expand All @@ -207,10 +200,7 @@ IEnumerable<IRenderable> ITiledTerrainRenderer.RenderPreview(WorldRenderer wr, T
for (var x = 0; x < template.Size.X; x++)
{
var tile = new TerrainTile(template.Id, (byte)i++);
var tileInfo = terrainInfo.GetTileInfo(tile);

// Empty tile
if (tileInfo == null)
if (!terrainInfo.TryGetTileInfo(tile, out var tileInfo))
continue;

var sprite = tileCache.TileSprite(tile, 0);
Expand Down
2 changes: 1 addition & 1 deletion mod.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
MOD_ID="cnc"

# The OpenRA engine version to use for this project.
ENGINE_VERSION="3cd311e0a3"
ENGINE_VERSION="2aaf0afc5f"

##############################################################################
# Packaging
Expand Down
3 changes: 3 additions & 0 deletions mods/cnc/mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ MapGrid:
Type: Rectangular
EnableFrameBufferDownscale: true

WorldViewportSizes:
DefaultScale: 0.1875

DefaultOrderGenerator: UnitOrderGenerator

SupportsMapsFrom: cnc
Expand Down

0 comments on commit 7eed99a

Please sign in to comment.