Skip to content

Commit

Permalink
Merge pull request #145 from dnqbob/rebase
Browse files Browse the repository at this point in the history
Rebase
  • Loading branch information
MustaphaTR authored Dec 9, 2023
2 parents 767e146 + 4da891d commit db809a8
Show file tree
Hide file tree
Showing 570 changed files with 5,376 additions and 1,694 deletions.
18 changes: 12 additions & 6 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@ jobs:
cd wiki
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add --all
git commit -m "Update auto-generated documentation for ${{ needs.prepare.outputs.git_tag }}"
git push origin master
git diff-index --quiet HEAD || \
(
git add --all && \
git commit -m "Update auto-generated documentation for ${{ needs.prepare.outputs.git_tag }}" && \
git push origin master
)
docs:
name: Update docs.openra.net
Expand Down Expand Up @@ -137,6 +140,9 @@ jobs:
cd docs
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add api/*.md
git commit -m "Update auto-generated documentation for ${{ needs.prepare.outputs.git_tag }}"
git push origin ${{ needs.prepare.outputs.version_type }}
git diff-index --quiet HEAD || \
(
git add api/*.md && \
git commit -m "Update auto-generated documentation for ${{ needs.prepare.outputs.git_tag }}" && \
git push origin ${{ needs.prepare.outputs.version_type }}
)
24 changes: 24 additions & 0 deletions OpenRA.Game/FieldLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
{ typeof(WAngle), ParseWAngle },
{ typeof(WRot), ParseWRot },
{ typeof(CPos), ParseCPos },
{ typeof(CPos[]), ParseCPosArray },
{ typeof(CVec), ParseCVec },
{ typeof(CVec[]), ParseCVecArray },
{ typeof(BooleanExpression), ParseBooleanExpression },
Expand Down Expand Up @@ -283,6 +284,29 @@ static object ParseCPos(string fieldName, Type fieldType, string value, MemberIn
return InvalidValueAction(value, fieldType, fieldName);
}

static object ParseCPosArray(string fieldName, Type fieldType, string value, MemberInfo field)
{
if (value != null)
{
var parts = value.Split(SplitComma);

if (parts.Length % 2 != 0)
return InvalidValueAction(value, fieldType, fieldName);

var vecs = new CPos[parts.Length / 2];
for (var i = 0; i < vecs.Length; i++)
{
if (int.TryParse(parts[2 * i], out var rx)
&& int.TryParse(parts[2 * i + 1], out var ry))
vecs[i] = new CPos(rx, ry);
}

return vecs;
}

return InvalidValueAction(value, fieldType, fieldName);
}

static object ParseCVec(string fieldName, Type fieldType, string value, MemberInfo field)
{
if (value != null)
Expand Down
27 changes: 24 additions & 3 deletions OpenRA.Game/FileFormats/Png.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Png(Stream s)
var data = new List<byte>();
Type = SpriteFrameType.Rgba32;

byte bitDepth = 8;
while (true)
{
var length = IPAddress.NetworkToHostOrder(s.ReadInt32());
Expand All @@ -66,7 +67,7 @@ public Png(Stream s)
Width = IPAddress.NetworkToHostOrder(ms.ReadInt32());
Height = IPAddress.NetworkToHostOrder(ms.ReadInt32());

var bitDepth = ms.ReadUInt8();
bitDepth = ms.ReadUInt8();
var colorType = (PngColorType)ms.ReadUInt8();
if (IsPaletted(bitDepth, colorType))
Type = SpriteFrameType.Indexed8;
Expand Down Expand Up @@ -136,14 +137,34 @@ public Png(Stream s)
{
var pxStride = PixelStride;
var rowStride = Width * pxStride;
var pixelsPerByte = 8 / bitDepth;
var sourceRowStride = Exts.IntegerDivisionRoundingAwayFromZero(rowStride, pixelsPerByte);

Span<byte> prevLine = new byte[rowStride];
for (var y = 0; y < Height; y++)
{
var filter = (PngFilter)ds.ReadUInt8();
ds.ReadBytes(Data, y * rowStride, rowStride);
ds.ReadBytes(Data, y * rowStride, sourceRowStride);
var line = Data.AsSpan(y * rowStride, rowStride);

// If the source has a bit depth of 1, 2 or 4 it packs multiple pixels per byte.
// Unpack to bit depth of 8, yielding 1 pixel per byte.
// This makes life easier for consumers of palleted data.
if (bitDepth < 8)
{
var mask = 0xFF >> (8 - bitDepth);
for (var i = sourceRowStride - 1; i >= 0; i--)
{
var packed = line[i];
for (var j = 0; j < pixelsPerByte; j++)
{
var dest = i * pixelsPerByte + j;
if (dest < line.Length) // Guard against last byte being only partially packed
line[dest] = (byte)(packed >> (8 - (j + 1) * bitDepth) & mask);
}
}
}

switch (filter)
{
case PngFilter.None:
Expand Down Expand Up @@ -269,7 +290,7 @@ enum PngFilter : byte { None, Sub, Up, Average, Paeth }

static bool IsPaletted(byte bitDepth, PngColorType colorType)
{
if (bitDepth == 8 && colorType == (PngColorType.Indexed | PngColorType.Color))
if (bitDepth <= 8 && colorType == (PngColorType.Indexed | PngColorType.Color))
return true;

if (bitDepth == 8 && colorType == (PngColorType.Color | PngColorType.Alpha))
Expand Down
5 changes: 3 additions & 2 deletions OpenRA.Game/FileSystem/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ZipFileLoader : IPackageLoader
{
const uint ZipSignature = 0x04034b50;

class ReadOnlyZipFile : IReadOnlyPackage
public class ReadOnlyZipFile : IReadOnlyPackage
{
public string Name { get; protected set; }
protected ZipFile pkg;
Expand Down Expand Up @@ -68,6 +68,7 @@ public bool Contains(string filename)
public void Dispose()
{
pkg?.Close();
GC.SuppressFinalize(this);
}

public IReadOnlyPackage OpenPackage(string filename, FileSystem context)
Expand All @@ -93,7 +94,7 @@ public IReadOnlyPackage OpenPackage(string filename, FileSystem context)
}
}

sealed class ReadWriteZipFile : ReadOnlyZipFile, IReadWritePackage
public sealed class ReadWriteZipFile : ReadOnlyZipFile, IReadWritePackage
{
readonly MemoryStream pkgStream = new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ProductionTooltipLogicCA(Widget widget, TooltipContainerWidget tooltipCon
return;

var tooltip = actor.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
var name = tooltip != null ? tooltip.Name : actor.Name;
var name = tooltip != null ? TranslationProvider.GetString(tooltip.Name) : actor.Name;
var buildable = BuildableInfo.GetTraitForQueue(actor, tooltipIcon.ProductionQueue?.Info.Type);

var cost = 0;
Expand Down Expand Up @@ -122,10 +122,10 @@ public ProductionTooltipLogicCA(Widget widget, TooltipContainerWidget tooltipCon
}

var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a))
.Where(s => !s.StartsWith("~", StringComparison.Ordinal) && !s.StartsWith("!", StringComparison.Ordinal));
.Where(s => !s.StartsWith('~') && !s.StartsWith('!')).Select(s => TranslationProvider.GetString(s)).ToList();

var requiresSize = int2.Zero;
if (prereqs.Any())
if (prereqs.Count > 0)
{
requiresLabel.Text = TranslationProvider.GetString(Requires, Translation.Arguments("prequisites", prereqs.JoinWith(", ")));
requiresSize = requiresFont.Measure(requiresLabel.Text);
Expand Down Expand Up @@ -174,7 +174,8 @@ public ProductionTooltipLogicCA(Widget widget, TooltipContainerWidget tooltipCon

var extrasSpacing = descLabel.Bounds.X / 2;

descLabel.Text = buildable.Description.Replace("\\n", "\n");
var desc = string.IsNullOrEmpty(buildable.Description) ? "" : TranslationProvider.GetString(buildable.Description);
descLabel.Text = desc;
var descSize = descFont.Measure(descLabel.Text);
descLabel.Bounds.Width = descSize.X;
descLabel.Bounds.Height = descSize.Y;
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Mods.AS/Widgets/Logic/Ingame/ActorIconTooltipLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ActorIconTooltipLogic(Widget widget, TooltipContainerWidget tooltipContai
if (!string.IsNullOrEmpty(descText))
descText += "\n";

descText += tooltipDesc.TooltipText.Replace("\\n", "\n");
descText += TranslationProvider.GetString(tooltipDesc.TooltipText);
}

descLabel.Text = descText;
Expand All @@ -71,7 +71,7 @@ public ActorIconTooltipLogic(Widget widget, TooltipContainerWidget tooltipContai
}
else if (buildable != null && !string.IsNullOrEmpty(buildable.Description))
{
descLabel.Text = buildable.Description.Replace("\\n", "\n");
descLabel.Text = TranslationProvider.GetString(buildable.Description);
descSize = descFont.Measure(descLabel.Text);
descLabel.Bounds.Width = descSize.X;
descLabel.Bounds.Height = descSize.Y + descLabelPadding;
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Mods.Common/Activities/FindAndDeliverResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public override bool Tick(Actor self)
// of the refinery entrance.
if (LastSearchFailed)
{
var lastproc = harv.DockClientManager.LastReservedHost;
var lastproc = harv.DockClientManager?.LastReservedHost;
if (lastproc != null)
{
var deliveryLoc = self.World.Map.CellContaining(lastproc.DockPosition);
Expand Down Expand Up @@ -172,7 +172,7 @@ public override bool Tick(Actor self)
else
{
searchRadius = harvInfo.SearchFromProcRadius;
var dock = harv.DockClientManager.LastReservedHost;
var dock = harv.DockClientManager?.LastReservedHost;
if (dock != null)
{
dockPos = dock.DockPosition;
Expand Down Expand Up @@ -248,7 +248,7 @@ public override IEnumerable<TargetLineNode> TargetLineNodes(Actor self)
else
{
var manager = harv.DockClientManager;
if (manager.ReservedHostActor != null)
if (manager?.ReservedHostActor != null)
yield return new TargetLineNode(Target.FromActor(manager.ReservedHostActor), manager.DockLineColor);
}
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Common/Activities/PickupUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected override void OnFirstRun(Actor self)
self.World.AddFrameEndTask(w =>
{
cargo.World.Remove(cargo);
carryable.Attached(cargo);
carryable.Attached(cargo, self);
carryall.AttachCarryable(self, cargo);
});
}
Expand Down
98 changes: 98 additions & 0 deletions OpenRA.Mods.Common/Graphics/BorderedRegionRenderable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* 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
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version. For more
* information, see COPYING.
*/
#endregion

using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Primitives;

namespace OpenRA.Mods.Common.Graphics
{
public readonly struct BorderedRegionRenderable : IRenderable, IFinalizedRenderable
{
enum Corner { TopLeft, TopRight, BottomRight, BottomLeft }

// Maps a cell offset to the index of the corner (in the 'Corner' arrays in the MapGrid.CellRamp structs)
// from which a border should be drawn. The index of the end corner will be (cornerIndex + 1) % 4.
static readonly Dictionary<CVec, int> Offset2CornerIndex = new()
{
{ new CVec(0, -1), (int)Corner.TopLeft },
{ new CVec(1, 0), (int)Corner.TopRight },
{ new CVec(0, 1), (int)Corner.BottomRight },
{ new CVec(-1, 0), (int)Corner.BottomLeft },
};

readonly CPos[] region;
readonly Color color, contrastColor;
readonly float width, contrastWidth;

public BorderedRegionRenderable(CPos[] region, Color color, float width, Color contrastColor, float contrastWidth)
{
this.region = region;
this.color = color;
this.contrastColor = contrastColor;
this.width = width;
this.contrastWidth = contrastWidth;
}

readonly WPos IRenderable.Pos { get { return WPos.Zero; } }
readonly int IRenderable.ZOffset { get { return 0; } }
readonly bool IRenderable.IsDecoration { get { return true; } }

IRenderable IRenderable.WithZOffset(int newOffset) { return new BorderedRegionRenderable(region, color, width, contrastColor, contrastWidth); }
IRenderable IRenderable.OffsetBy(in WVec offset) { return new BorderedRegionRenderable(region, color, width, contrastColor, contrastWidth); }
IRenderable IRenderable.AsDecoration() { return this; }

IFinalizedRenderable IRenderable.PrepareRender(WorldRenderer wr) { return this; }
void IFinalizedRenderable.Render(WorldRenderer wr) { Draw(wr, region, color, width, contrastColor, contrastWidth); }
void IFinalizedRenderable.RenderDebugGeometry(WorldRenderer wr) { }
Rectangle IFinalizedRenderable.ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; }

public static void Draw(WorldRenderer wr, CPos[] region, Color color, float width, Color constrastColor, float constrastWidth)
{
if (width == 0 && constrastWidth == 0)
return;

var map = wr.World.Map;
var cr = Game.Renderer.RgbaColorRenderer;

foreach (var c in region)
{
var mpos = c.ToMPos(map);
if (!map.Height.Contains(mpos) || wr.World.ShroudObscures(c))
continue;

var tile = map.Tiles[mpos];
var ti = map.Rules.TerrainInfo.GetTerrainInfo(tile);
var ramp = ti?.RampType ?? 0;

var corners = map.Grid.Ramps[ramp].Corners;
var pos = map.CenterOfCell(c) - new WVec(0, 0, map.Grid.Ramps[ramp].CenterHeightOffset);

foreach (var o in Offset2CornerIndex)
{
// If the neighboring cell is part of the region, don't draw a border between the cells.
if (region.Contains(c + o.Key))
continue;

var start = wr.Viewport.WorldToViewPx(wr.Screen3DPosition(pos + corners[o.Value]));
var end = wr.Viewport.WorldToViewPx(wr.Screen3DPosition(pos + corners[(o.Value + 1) % 4]));

if (constrastWidth > 0)
cr.DrawLine(start, end, constrastWidth, constrastColor);

if (width > 0)
cr.DrawLine(start, end, width, color);
}
}
}
}
}
18 changes: 9 additions & 9 deletions OpenRA.Mods.Common/Lint/CheckTranslationReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void TestTraits(Ruleset rules, Action<string> emitError, Action<string> testKey)
{
foreach (var traitInfo in actorInfo.Value.TraitInfos<TraitInfo>())
{
var fields = Utility.GetFields(traitInfo.GetType());
foreach (var field in fields)
var traitType = traitInfo.GetType();
foreach (var field in Utility.GetFields(traitType))
{
var translationReference = Utility.GetCustomAttributes<TranslationReferenceAttribute>(field, true).FirstOrDefault();
if (translationReference == null)
Expand All @@ -48,7 +48,7 @@ void TestTraits(Ruleset rules, Action<string> emitError, Action<string> testKey)
if (key == null)
{
if (!translationReference.Optional)
emitError($"Trait `{traitInfo.InstanceName}` on field `{field.Name}` has an empty translation reference.");
emitError($"Actor type `{actorInfo.Key}` has an empty translation reference in trait `{traitType.Name[..^4]}.{field.Name}`.");

continue;
}
Expand Down Expand Up @@ -245,8 +245,8 @@ void CheckUnusedKey(string key, string attribute, Action<string> emitWarning, st

if (!referencedKeys.Contains(keyWithAtrr))
emitWarning(isAttribute ?
$"Unused attribute `{attribute}` of key `{key}` in {file}." :
$"Unused key `{key}` in {file}.");
$"Unused attribute `{attribute}` of key `{key}` in {file}" :
$"Unused key `{key}` in {file}");
}

void CheckMessageValue(Pattern node, string key, string attribute, Action<string> emitWarning, string file)
Expand Down Expand Up @@ -291,8 +291,8 @@ void CheckMissingVariable(string key, string attribute, Action<string> emitError
foreach (var referencedVariable in referencedVariables)
if (!variableReferences.Contains(referencedVariable))
emitError(isAttribute ?
$"Missing variable `{referencedVariable}` for attribute `{attribute}` of key `{key}` in {file}." :
$"Missing variable `{referencedVariable}` for key `{key}` in {file}.");
$"Missing variable `{referencedVariable}` for attribute `{attribute}` of key `{key}` in {file}" :
$"Missing variable `{referencedVariable}` for key `{key}` in {file}");
}

void CheckVariableReference(string varName, string key, string attribute, Action<string> emitWarning, string file)
Expand All @@ -304,8 +304,8 @@ void CheckVariableReference(string varName, string key, string attribute, Action

if (!referencedVariablesPerKey.TryGetValue(keyWithAtrr, out var referencedVariables) || !referencedVariables.Contains(varName))
emitWarning(isAttribute ?
$"Unused variable `{varName}` for attribute `{attribute}` of key `{key}` in {file}." :
$"Unused variable `{varName}` for key `{key}` in {file}.");
$"Unused variable `{varName}` for attribute `{attribute}` of key `{key}` in {file}" :
$"Unused variable `{varName}` for key `{key}` in {file}");
}
}
}
Loading

0 comments on commit db809a8

Please sign in to comment.