Skip to content

Commit

Permalink
Merge pull request #144 from dnqbob/rebase
Browse files Browse the repository at this point in the history
Rebase & Optimize FireShrapnelWarhead
  • Loading branch information
MustaphaTR authored Nov 25, 2023
2 parents e9a317f + f50afd7 commit dc26003
Show file tree
Hide file tree
Showing 225 changed files with 1,672 additions and 2,940 deletions.
42 changes: 36 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ csharp_style_prefer_top_level_statements = false
dotnet_diagnostic.IDE0210.severity = warning
dotnet_diagnostic.IDE0211.severity = warning

# IDE0290 Use primary constructor
#csharp_style_prefer_primary_constructors = true
dotnet_diagnostic.IDE0200.severity = silent # Requires C# 12

## Expression-bodied members

# IDE0021 Use expression body for constructors
Expand Down Expand Up @@ -427,10 +431,7 @@ dotnet_diagnostic.IDE0077.severity = warning

### Formatting Rules (IDE0055)
### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0055

# We may eventually wish to enforce this rule, however some existing formatting conflicts with the rule despite being reasonable.
# Additionally, the rule is buggy and likes to report spuriously after invoking Format Document in the IDE.
dotnet_diagnostic.IDE0055.severity = none
dotnet_diagnostic.IDE0055.severity = warning

#dotnet_sort_system_directives_first = true
#dotnet_separate_import_directive_groups = false
Expand All @@ -448,7 +449,7 @@ dotnet_diagnostic.IDE0055.severity = none
#csharp_indent_labels = one_less_than_current
#csharp_indent_block_contents = true
#csharp_indent_braces = false
#csharp_indent_case_contents_when_block = true
csharp_indent_case_contents_when_block = false

#csharp_space_after_cast = false
#csharp_space_after_keywords_in_control_flow_statements = true
Expand Down Expand Up @@ -638,6 +639,7 @@ dotnet_diagnostic.SA1649.severity = none # FileNameMustMatchTypeName
#### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/

# Below we enable specific rules by setting severity to warning.
# Rules are disabled by setting severity to silent (to still allow use in IDE) or none (to prevent all use).
# Rules are listed below with any options available.
# Options are commented out if they match the defaults.

Expand Down Expand Up @@ -724,6 +726,9 @@ dotnet_diagnostic.CA1417.severity = warning
# Use 'nameof' in place of string.
dotnet_diagnostic.CA1507.severity = warning

# Avoid redundant length argument.
dotnet_diagnostic.CA1514.severity = suggestion # TODO: Change to warning once using .NET 8 or later.

### Naming Rules
### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/naming-warnings

Expand Down Expand Up @@ -854,6 +859,23 @@ dotnet_diagnostic.CA1858.severity = warning
# Avoid using 'Enumerable.Any()' extension method.
dotnet_diagnostic.CA1860.severity = warning

# Prefer the 'IDictionary.TryAdd(TKey, TValue)' method.
dotnet_diagnostic.CA1864.severity = suggestion # TODO: Change to warning once using .NET 8 or later.

# Use 'string.Method(char)' instead of 'string.Method(string)' for string with single char.
dotnet_diagnostic.CA1865.severity = suggestion # TODO: Change to warning once using .NET 8 or later.
dotnet_diagnostic.CA1866.severity = suggestion # TODO: Change to warning once using .NET 8 or later.
dotnet_diagnostic.CA1867.severity = suggestion # TODO: Change to warning once using .NET 8 or later.

# Unnecessary call to 'Contains' for sets.
dotnet_diagnostic.CA1868.severity = suggestion # TODO: Change to warning once using .NET 8 or later.

# Cache and reuse 'JsonSerializerOptions' instances.
dotnet_diagnostic.CA1869.severity = suggestion # TODO: Change to warning once using .NET 8 or later.

# Use a cached 'SearchValues' instance.
dotnet_diagnostic.CA1870.severity = suggestion # TODO: Change to warning once using .NET 8 or later.

### Reliability Rules
### https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/reliability-warnings

Expand Down Expand Up @@ -899,6 +921,9 @@ dotnet_diagnostic.CA2207.severity = warning
# Instantiate argument exceptions correctly.
dotnet_diagnostic.CA2208.severity = warning

# Non-constant fields should not be visible.
dotnet_diagnostic.CA2211.severity = silent

# Dispose methods should call base class dispose.
dotnet_diagnostic.CA2215.severity = warning

Expand All @@ -913,7 +938,7 @@ dotnet_diagnostic.CA2231.severity = warning

# Provide correct arguments to formatting methods.
#dotnet_code_quality.CA2241.additional_string_formatting_methods =
dotnet_code_quality.CA2241.try_determine_additional_string_formatting_methods_automatically = true
#dotnet_code_quality.CA2241.try_determine_additional_string_formatting_methods_automatically = false
dotnet_diagnostic.CA2241.severity = warning

# Test for NaN correctly.
Expand Down Expand Up @@ -998,6 +1023,9 @@ dotnet_diagnostic.RCS1072.severity = warning
# Remove redundant constructor.
dotnet_diagnostic.RCS1074.severity = warning

# Optimize LINQ method call.
dotnet_diagnostic.RCS1077.severity = warning

# Use 'Count' property instead of 'Any' method.
dotnet_diagnostic.RCS1080.severity = warning

Expand Down Expand Up @@ -1142,3 +1170,5 @@ dotnet_diagnostic.RCS1236.severity = warning
# Use 'for' statement instead of 'while' statement.
dotnet_diagnostic.RCS1239.severity = warning

# Use element access.
dotnet_diagnostic.RCS1246.severity = warning
121 changes: 60 additions & 61 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Deploy Documentation

on:
push:
branches: [ bleed ]
tags: [ 'release-*', 'playtest-*' ]
workflow_dispatch:
inputs:
tag:
Expand All @@ -12,15 +15,46 @@ permissions:
contents: read # to fetch code (actions/checkout)

jobs:
prepare:
name: Prepare version strings
if: github.repository == 'openra/openra'
runs-on: ubuntu-22.04
steps:
- name: Prepare environment variables
run: |
if [ "${{ github.event_name }}" = "push" ]; then
if [ "${{ github.ref_type }}" = "tag" ]; then
VERSION_TYPE=`echo "${GITHUB_REF#refs/tags/}" | cut -d"-" -f1`
echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "VERSION_TYPE=$VERSION_TYPE" >> $GITHUB_ENV
else
echo "GIT_TAG=bleed" >> $GITHUB_ENV
echo "VERSION_TYPE=bleed" >> $GITHUB_ENV
fi
else
VERSION_TYPE=`echo "${{ github.event.inputs.tag }}" | cut -d"-" -f1`
echo "GIT_TAG=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
echo "VERSION_TYPE=$VERSION_TYPE" >> $GITHUB_ENV
fi
outputs:
git_tag: ${{ env.GIT_TAG }}
version_type: ${{ env.VERSION_TYPE }}

wiki:
name: Update Wiki
if: github.repository == 'openra/openra'
needs: prepare
if: github.repository == 'openra/openra' && needs.prepare.outputs.version_type != 'bleed'
runs-on: ubuntu-22.04
steps:
- name: Debug output
run: |
echo ${{ needs.prepare.outputs.git_tag }}
echo ${{ needs.prepare.outputs.version_type }}
- name: Clone Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.tag }}
ref: ${{ needs.prepare.outputs.git_tag }}

- name: Install .NET 6
uses: actions/setup-dotnet@v3
Expand All @@ -39,39 +73,39 @@ jobs:
path: wiki

- name: Update Wiki (Playtest)
if: startsWith(github.event.inputs.tag, 'playtest-')
env:
GIT_TAG: ${{ github.event.inputs.tag }}
if: startsWith(needs.prepare.outputs.git_tag, 'playtest-')
run: |
./utility.sh all --settings-docs "${GIT_TAG}" > "wiki/Settings (playtest).md"
./utility.sh all --settings-docs "${{ needs.prepare.outputs.git_tag }}" > "wiki/Settings (playtest).md"
- name: Update Wiki (Release)
if: startsWith(github.event.inputs.tag, 'release-')
env:
GIT_TAG: ${{ github.event.inputs.tag }}
if: startsWith(needs.prepare.outputs.git_tag, 'release-')
run: |
./utility.sh all --settings-docs "${GIT_TAG}" > "wiki/Settings.md"
./utility.sh all --settings-docs "${{ needs.prepare.outputs.git_tag }}" > "wiki/Settings.md"
- name: Push Wiki
env:
GIT_TAG: ${{ github.event.inputs.tag }}
run: |
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 ${GIT_TAG}"
git commit -m "Update auto-generated documentation for ${{ needs.prepare.outputs.git_tag }}"
git push origin master
docs:
name: Update docs.openra.net
needs: prepare
if: github.repository == 'openra/openra'
runs-on: ubuntu-22.04
steps:
- name: Debug output
run: |
echo ${{ needs.prepare.outputs.git_tag }}
echo ${{ needs.prepare.outputs.version_type }}
- name: Clone Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.tag }}
ref: ${{ needs.prepare.outputs.git_tag }}

- name: Install .NET 6
uses: actions/setup-dotnet@v3
Expand All @@ -82,62 +116,27 @@ jobs:
run: |
make all
- name: Clone docs.openra.net (Playtest)
if: startsWith(github.event.inputs.tag, 'playtest-')
uses: actions/checkout@v3
with:
repository: openra/docs
token: ${{ secrets.DOCS_TOKEN }}
path: docs
ref: playtest

- name: Clone docs.openra.net (Release)
if: startsWith(github.event.inputs.tag, 'release-')
# version_type is release/playtest/bleed - the name of the target branch.
- name: Clone docs.openra.net
uses: actions/checkout@v3
with:
repository: openra/docs
token: ${{ secrets.DOCS_TOKEN }}
path: docs
ref: release
ref: ${{ needs.prepare.outputs.version_type }}

- name: Update docs.openra.net (Playtest)
if: startsWith(github.event.inputs.tag, 'playtest-')
env:
GIT_TAG: ${{ github.event.inputs.tag }}
run: |
./utility.sh all --docs "${GIT_TAG}" | python3 ./packaging/format-docs.py > "docs/api/traits.md"
./utility.sh all --weapon-docs "${GIT_TAG}" | python3 ./packaging/format-docs.py > "docs/api/weapons.md"
./utility.sh all --sprite-sequence-docs "${GIT_TAG}" | python3 ./packaging/format-docs.py > "docs/api/sprite-sequences.md"
./utility.sh all --lua-docs "${GIT_TAG}" > "docs/api/lua.md"
- name: Update docs.openra.net (Release)
if: startsWith(github.event.inputs.tag, 'release-')
env:
GIT_TAG: ${{ github.event.inputs.tag }}
- name: Generate docs files
run: |
./utility.sh all --docs "${GIT_TAG}" | python3 ./packaging/format-docs.py > "docs/api/traits.md"
./utility.sh all --weapon-docs "${GIT_TAG}" | python3 ./packaging/format-docs.py > "docs/api/weapons.md"
./utility.sh all --sprite-sequence-docs "${GIT_TAG}" | python3 ./packaging/format-docs.py > "docs/api/sprite-sequences.md"
./utility.sh all --lua-docs "${GIT_TAG}" > "docs/api/lua.md"
- name: Commit docs.openra.net
env:
GIT_TAG: ${{ github.event.inputs.tag }}
./utility.sh all --docs "${{ needs.prepare.outputs.git_tag }}" | python3 ./packaging/format-docs.py > "docs/api/traits.md"
./utility.sh all --weapon-docs "${{ needs.prepare.outputs.git_tag }}" | python3 ./packaging/format-docs.py > "docs/api/weapons.md"
./utility.sh all --sprite-sequence-docs "${{ needs.prepare.outputs.git_tag }}" | python3 ./packaging/format-docs.py > "docs/api/sprite-sequences.md"
./utility.sh all --lua-docs "${{ needs.prepare.outputs.git_tag }}" > "docs/api/lua.md"
- name: Update docs.openra.net
run: |
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 ${GIT_TAG}"
- name: Push docs.openra.net (Release)
if: startsWith(github.event.inputs.tag, 'release-')
run: |
cd docs
git push origin release
- name: Push docs.openra.net (Playtest)
if: startsWith(github.event.inputs.tag, 'playtest-')
run: |
cd docs
git push origin playtest
git commit -m "Update auto-generated documentation for ${{ needs.prepare.outputs.git_tag }}"
git push origin ${{ needs.prepare.outputs.version_type }}
16 changes: 8 additions & 8 deletions OpenRA.Game/CVec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public CVec Clamp(Rectangle r)

public static readonly CVec[] Directions =
{
new CVec(-1, -1),
new CVec(-1, 0),
new CVec(-1, 1),
new CVec(0, -1),
new CVec(0, 1),
new CVec(1, -1),
new CVec(1, 0),
new CVec(1, 1),
new(-1, -1),
new(-1, 0),
new(-1, 1),
new(0, -1),
new(0, 1),
new(1, -1),
new(1, 0),
new(1, 1),
};

#region Scripting interface
Expand Down
10 changes: 10 additions & 0 deletions OpenRA.Game/Exts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ public static int IndexOf<T>(this T[] array, T value)
return Array.IndexOf(array, value);
}

public static T FirstOrDefault<T>(this T[] array, Predicate<T> match)
{
return Array.Find(array, match);
}

public static T FirstOrDefault<T>(this List<T> list, Predicate<T> match)
{
return list.Find(match);
}

public static T Random<T>(this IEnumerable<T> ts, MersenneTwister r)
{
return Random(ts, r, true);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/FileFormats/Png.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Png(Stream s)
var length = IPAddress.NetworkToHostOrder(s.ReadInt32());
var type = s.ReadASCII(4);
var content = s.ReadBytes(length);
/*var crc = */s.ReadInt32();
s.ReadInt32(); // crc

if (!headerParsed && type != "IHDR")
throw new InvalidDataException("Invalid PNG file - header does not appear first.");
Expand All @@ -76,7 +76,7 @@ public Png(Stream s)
Data = new byte[Width * Height * PixelStride];

var compression = ms.ReadUInt8();
/*var filter = */ms.ReadUInt8();
ms.ReadUInt8(); // filter
var interlace = ms.ReadUInt8();

if (compression != 0)
Expand Down
4 changes: 1 addition & 3 deletions OpenRA.Game/FileSystem/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ public bool Unmount(IReadOnlyPackage package)
explicitMounts.Remove(key);

// Mod packages aren't owned by us, so we shouldn't dispose them
if (modPackages.Contains(package))
modPackages.Remove(package);
else
if (!modPackages.Remove(package))
package.Dispose();
}
else
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/FileSystem/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ sealed class ZipFolder : IReadOnlyPackage

public ZipFolder(ReadOnlyZipFile parent, string path)
{
if (path.EndsWith("/", StringComparison.Ordinal))
if (path.EndsWith('/'))
path = path[..^1];

Name = path;
Expand Down
Loading

0 comments on commit dc26003

Please sign in to comment.