Skip to content

Commit

Permalink
Merge pull request #38 from thomasfn/staging
Browse files Browse the repository at this point in the history
release 0.7.0
  • Loading branch information
thomasfn authored Dec 4, 2024
2 parents 66f77eb + 58d0081 commit b8d70fb
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 215 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

# CA1416: Validate platform compatibility
dotnet_diagnostic.CA1416.severity = silent

# Indentation and spacing
indent_size = 4
indent_style = space
tab_width = 4
18 changes: 9 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ jobs:
name: Build Mod
runs-on: ubuntu-latest
env:
MODKIT_VERSION: 0.11.0.2-beta-release-707
MODKIT_VERSION: 0.11.1.3-beta-release-795
ECO_BRANCH: staging
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core 7.0
uses: actions/setup-dotnet@v1
- uses: actions/checkout@v4
- name: Setup .NET Core 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'
- name: Fetch dependencies
run: dotnet restore ./EcoLawExtensionsMod/EcoLawExtensionsMod.csproj
env:
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1
- name: Cache Eco dlls
id: cache-eco-dlls
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ./eco-dlls
key: ${{ env.MODKIT_VERSION }}-ref-dlls
Expand All @@ -35,10 +35,10 @@ jobs:
env:
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1
- name: Upload build artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: mod-binaries-${{github.event.release.tag_name}}
path: EcoLawExtensionsMod/bin/Release/net7.0/EcoLawExtensionsMod.*
path: EcoLawExtensionsMod/bin/Release/net8.0/EcoLawExtensionsMod.*
deploy:
name: Upload Release Assets
needs:
Expand All @@ -47,7 +47,7 @@ jobs:
steps:
- name: Download build artifact (mod)
id: download-mod
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: mod-binaries-${{github.event.release.tag_name}}
- name: Upload release asset (mod)
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ on:

jobs:
build-mod:
name: Build Mod
runs-on: ubuntu-latest
env:
MODKIT_VERSION: 0.11.0.2-beta-release-707
MODKIT_VERSION: 0.11.1.3-beta-release-795
ECO_BRANCH: staging
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core 7.0
uses: actions/setup-dotnet@v1
- uses: actions/checkout@v4
- name: Setup .NET Core 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: '7.0.x'
dotnet-version: '8.0.x'
- name: Fetch dependencies
run: dotnet restore ./EcoLawExtensionsMod/EcoLawExtensionsMod.csproj
env:
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1
- name: Cache Eco dlls
id: cache-eco-dlls
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ./eco-dlls
key: ${{ env.MODKIT_VERSION }}-ref-dlls
Expand All @@ -35,7 +36,7 @@ jobs:
env:
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1
- name: Upload build artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: mod-binaries-staging
path: EcoLawExtensionsMod/bin/Release/net7.0/EcoLawExtensionsMod.*
path: EcoLawExtensionsMod/bin/Release/net8.0/EcoLawExtensionsMod.*
13 changes: 3 additions & 10 deletions EcoLawExtensionsMod/EcoLawExtensionsMod.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Eco.Mods.LawExtensions</RootNamespace>
</PropertyGroup>

Expand Down Expand Up @@ -38,16 +38,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Costura.Fody" Version="5.7.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Fody" Version="6.6.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Lib.Harmony" Version="2.2.1" />
<PackageReference Include="NetFabric.Hyperlinq.Abstractions" Version="1.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="ConcurrentHashSet" Version="1.3.0" />
</ItemGroup>

</Project>
9 changes: 0 additions & 9 deletions EcoLawExtensionsMod/FodyWeavers.xml

This file was deleted.

141 changes: 0 additions & 141 deletions EcoLawExtensionsMod/FodyWeavers.xsd

This file was deleted.

54 changes: 54 additions & 0 deletions EcoLawExtensionsMod/GameValues/CoordAt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Linq;

namespace Eco.Mods.LawExtensions
{
using Core.Controller;
using Core.Utils;
using Core.Utils.PropertyScanning;

using Shared.Localization;
using Shared.Networking;
using Shared.Utils;
using Shared.Math;

using Gameplay.Civics.GameValues;

[Eco, LocCategory("World"), LocDescription("The X coord of a location.")]
public class XCoordAt : GameValue<float>
{
[Eco, Advanced, LocDescription("The position to read the X coord of.")] public GameValue<Vector3i> Location { get; set; }

private Eval<float> FailNullSafeFloat<T>(Eval<T> eval, string paramName) =>
eval != null ? Eval.Make($"Invalid {Localizer.DoStr(paramName)} specified on {GetType().GetLocDisplayName()}: {eval.Message}", float.MinValue)
: Eval.Make($"{Localizer.DoStr(paramName)} not set on {GetType().GetLocDisplayName()}.", float.MinValue);

public override Eval<float> Value(IContextObject action)
{
var location = this.Location?.Value(action); if (location?.Val == null) return this.FailNullSafeFloat(location, nameof(this.Location));

var value = location.Val.X;
return Eval.Make($"{Text.StyledNum(value)} (X coord)", (float)value);
}
public override LocString Description() => Localizer.Do($"X coord");
}

[Eco, LocCategory("World"), LocDescription("The Z coord of a location.")]
public class ZCoordAt : GameValue<float>
{
[Eco, Advanced, LocDescription("The position to read the Z coord of.")] public GameValue<Vector3i> Location { get; set; }

private Eval<float> FailNullSafeFloat<T>(Eval<T> eval, string paramName) =>
eval != null ? Eval.Make($"Invalid {Localizer.DoStr(paramName)} specified on {GetType().GetLocDisplayName()}: {eval.Message}", float.MinValue)
: Eval.Make($"{Localizer.DoStr(paramName)} not set on {GetType().GetLocDisplayName()}.", float.MinValue);

public override Eval<float> Value(IContextObject action)
{
var location = this.Location?.Value(action); if (location?.Val == null) return this.FailNullSafeFloat(location, nameof(this.Location));

var value = location.Val.Z;
return Eval.Make($"{Text.StyledNum(value)} (Z coord)", (float)value);
}
public override LocString Description() => Localizer.Do($"Z coord");
}
}
18 changes: 14 additions & 4 deletions EcoLawExtensionsMod/GameValues/DistanceToClosestPlant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ public class DistanceToClosestPlant : GameValue<float>

[Eco, AllowNullInView, AllowEmpty, LocDescription("The plant to search for.")] public GamePickerList<PlantSpecies> PlantType { get; set; } = new ();

[Eco, Advanced, LocDescription("Whether to ignore plants at the target location.")] public GameValue<bool> IgnoreAtLocation { get; set; } = new No();

private Eval<float> FailNullSafeFloat<T>(Eval<T> eval, string paramName) =>
eval != null ? Eval.Make($"Invalid {Localizer.DoStr(paramName)} specified on {GetType().GetLocDisplayName()}: {eval.Message}", float.MinValue)
: Eval.Make($"{Localizer.DoStr(paramName)} not set on {GetType().GetLocDisplayName()}.", float.MinValue);

public override Eval<float> Value(IContextObject action)
{
var location = this.Location?.Value(action); if (location?.Val == null) return this.FailNullSafeFloat(location, nameof(this.Location));
var ignoreAtLocation = this.IgnoreAtLocation?.Value(action); if (ignoreAtLocation?.Val == null) return this.FailNullSafeFloat(ignoreAtLocation, nameof(this.IgnoreAtLocation));

var allRelevantPlants = EcoSim.PlantSim.All
.Where(x => PlantType.ContainsType(x.Species.GetType()));
Expand All @@ -40,10 +43,17 @@ public override Eval<float> Value(IContextObject action)
return Eval.Make($"{Text.Style(Text.Styles.Currency, "infinite")} (distance to nearest {PlantType.DescribeEntries(Localizer.DoStr(","))})", float.MaxValue);
}

var nearest = allRelevantPlants
.Select(x => (x, World.WrappedDistance(x.Position, location.Val)))
.OrderBy(x => x.Item2)
.FirstOrDefault();
var plantsWithDistances = allRelevantPlants
.Select(x => (x, World.WrappedDistance(x.Position, location.Val)));

if (ignoreAtLocation.Val)
{
plantsWithDistances = plantsWithDistances
.Where(x => x.Item2 > 0.0f);
}

var nearest = plantsWithDistances
.MinBy(x => x.Item2);

return Eval.Make($"{Text.StyledNum(nearest.Item2)} (distance to {nearest.x.Species.DisplayName})", nearest.Item2);
}
Expand Down
Loading

0 comments on commit b8d70fb

Please sign in to comment.