Skip to content

Commit

Permalink
Rewrote vehicle bay command, worked some on vehicle spawning and signs.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielWillett committed Nov 9, 2024
1 parent e616b73 commit 878a9a3
Show file tree
Hide file tree
Showing 105 changed files with 2,002 additions and 1,914 deletions.
7 changes: 1 addition & 6 deletions Translation README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,9 @@ Abbreviation: 德国
• FormatTimeShort_HH_MM_SS "tshort2" Turns time to: 01:03:04, etc.
Time can be int, uint, float (all in seconds), or TimeSpan
```
Other formats are stored in the most prominant class of the interface (`UCPlayer` for `IPlayer`, `FOB` for `IDeployable`, etc.)
Other formats are stored in the most prominent class of the interface (`WarfarePlayer` for `IPlayer`, `Fob` for `IDeployable`, etc.)
<br>Anything that would work in `T[N].ToString(string, IFormatProvider)` will work here.

<br>**Color substitution from color dictionary**

`c$value$` will be replaced by the color `value` from the color dictionary on startup.
<br> Example: `You need 100 more <#b8ffc1>credits</color>.`

<br>**Conditional pluralization of existing terms**

`${p:arg:text}` will replace text with the plural version of text if `{arg}` is not one.
Expand Down
12 changes: 5 additions & 7 deletions UncreatedWarfare.Tests/SyntaxFormatterTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using System;
using Autofac;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Autofac;
using Microsoft.Extensions.Logging;
using NUnit.Framework;
using Uncreated.Warfare.Commands;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Interaction.Commands.Syntax;

namespace Uncreated.Warfare.Tests;
public class SyntaxFormatterTests
Expand Down
29 changes: 25 additions & 4 deletions UncreatedWarfare/Buildables/BuildableSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,18 @@ void IDisposable.Dispose()
}

/// <summary>
/// Save a barricade, or update the save if it's already saved.
/// Save a buildable or update the save if it's already saved.
/// </summary>
/// <returns><see langword="true"/> if the buildable was saved, <see langword="false"/> if it was just updated.</returns>
public UniTask<bool> SaveBuildableAsync(IBuildable buildable, CancellationToken token = default)
{
return buildable.IsStructure
? SaveStructureAsync(buildable.GetDrop<StructureDrop>(), token)
: SaveBarricadeAsync(buildable.GetDrop<BarricadeDrop>(), token);
}

/// <summary>
/// Save a barricade or update the save if it's already saved.
/// </summary>
/// <returns><see langword="true"/> if the barricade was saved, <see langword="false"/> if it was just updated.</returns>
public async UniTask<bool> SaveBarricadeAsync(BarricadeDrop barricade, CancellationToken token = default)
Expand Down Expand Up @@ -157,7 +168,7 @@ public async UniTask<bool> SaveBarricadeAsync(BarricadeDrop barricade, Cancellat
if (barricade.interactable is InteractableStorage storage)
{
await UniTask.SwitchToMainThread(token);

int ct = storage.items.getItemCount();

newSave.Items = new List<BuildableStorageItem>(ct);
Expand Down Expand Up @@ -256,7 +267,7 @@ public async UniTask<bool> SaveBarricadeAsync(BarricadeDrop barricade, Cancellat
}

/// <summary>
/// Save a structure, or update the save if it's already saved.
/// Save a structure or update the save if it's already saved.
/// </summary>
/// <returns><see langword="true"/> if the structure was saved, <see langword="false"/> if it was just updated.</returns>
public async UniTask<bool> SaveStructureAsync(StructureDrop structure, CancellationToken token = default)
Expand Down Expand Up @@ -300,7 +311,8 @@ public async UniTask<bool> SaveStructureAsync(StructureDrop structure, Cancellat
MeasurementTool.byteToAngle(MeasurementTool.angleToByte(rot.z))
),
MapId = _mapScheduler.Current,
Items = new List<BuildableStorageItem>(0)
Items = new List<BuildableStorageItem>(0),
State = Array.Empty<byte>()
};

BuildableInstanceId instanceId = new BuildableInstanceId
Expand Down Expand Up @@ -443,6 +455,15 @@ public UniTask<bool> DiscardStructureAsync(uint instanceId, CancellationToken to
return DiscardBuildableAsync(instanceId, true, token);
}

/// <summary>
/// Remove the save for a buildable.
/// </summary>
/// <returns><see langword="true"/> if the buildable's save was removed, otherwise <see langword="false"/>.</returns>
public UniTask<bool> DiscardBuildableAsync(IBuildable buildable, CancellationToken token = default)
{
return DiscardBuildableAsync(buildable.InstanceId, buildable.IsStructure, token);
}

/// <summary>
/// Remove the save for a buildable.
/// </summary>
Expand Down
26 changes: 21 additions & 5 deletions UncreatedWarfare/Buildables/IBuildable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using DanielWillett.ReflectionTools;
using System;
using System.Runtime.CompilerServices;
using DanielWillett.ReflectionTools;
using Uncreated.Warfare.Util;

namespace Uncreated.Warfare.Buildables;
Expand All @@ -9,7 +9,15 @@ namespace Uncreated.Warfare.Buildables;
/// Any structure or barricade. Can be <see cref="BuildableBarricade"/> or <see cref="BuildableStructure"/>.
/// </summary>
[CannotApplyEqualityOperator]
public interface IBuildable : IEquatable<IBuildable>, ITransformObject
public interface IBuildable :
IEquatable<IBuildable>,
IEquatable<BuildableBarricade>,
IEquatable<BarricadeDrop>,
IEquatable<BarricadeData>,
IEquatable<BuildableStructure>,
IEquatable<StructureDrop>,
IEquatable<StructureData>,
ITransformObject
{
/// <summary>
/// The instance ID of this buildable specific to it's buildable type.
Expand Down Expand Up @@ -95,7 +103,7 @@ TData GetItem<TData>() where TData : class
}

[CannotApplyEqualityOperator]
public class BuildableBarricade : IBuildable, IEquatable<BuildableBarricade>, IEquatable<BarricadeDrop>
public class BuildableBarricade : IBuildable
{
public uint InstanceId => Drop.instanceID;
public bool IsStructure => false;
Expand Down Expand Up @@ -152,16 +160,20 @@ Vector3 ITransformObject.Scale
set => throw new NotSupportedException();
}

public bool Equals(BarricadeData? other) => other is not null && other.instanceID == Drop.instanceID;
public bool Equals(BarricadeDrop? other) => other is not null && other.instanceID == Drop.instanceID;
public bool Equals(BuildableBarricade? other) => other is not null && other.Drop.instanceID == Drop.instanceID;
public bool Equals(IBuildable? other) => other is not null && !other.IsStructure && other.InstanceId == Drop.instanceID;
bool IEquatable<StructureData>.Equals(StructureData? other) => false;
bool IEquatable<StructureDrop>.Equals(StructureDrop? other) => false;
bool IEquatable<BuildableStructure>.Equals(BuildableStructure? other) => false;
public override bool Equals(object? obj) => obj is IBuildable b && Equals(b);
public override int GetHashCode() => unchecked ( (int)Drop.instanceID );
public override string ToString() => $"BuildableBarricade[InstanceId: {InstanceId} Asset itemName: {Asset.itemName} Asset GUID: {Asset.GUID:N} Owner: {Owner} Group: {Group} IsDead: {IsDead}]";
}

[CannotApplyEqualityOperator]
public class BuildableStructure : IBuildable, IEquatable<BuildableStructure>, IEquatable<StructureDrop>
public class BuildableStructure : IBuildable
{
public uint InstanceId => Drop.instanceID;
public bool IsStructure => true;
Expand Down Expand Up @@ -217,8 +229,12 @@ Vector3 ITransformObject.Scale
set => throw new NotSupportedException();
}

public bool Equals(StructureData? other) => other is not null && other.instanceID == Drop.instanceID;
public bool Equals(StructureDrop? other) => other is not null && other.instanceID == Drop.instanceID;
public bool Equals(BuildableStructure? other) => other is not null && other.Drop.instanceID == Drop.instanceID;
bool IEquatable<BarricadeData>.Equals(BarricadeData? other) => false;
bool IEquatable<BarricadeDrop>.Equals(BarricadeDrop? other) => false;
bool IEquatable<BuildableBarricade>.Equals(BuildableBarricade? other) => false;
public bool Equals(IBuildable? other) => other is not null && other.IsStructure && other.InstanceId == Drop.instanceID;
public override bool Equals(object? obj) => obj is IBuildable b && Equals(b);
public override int GetHashCode() => unchecked ( (int)Drop.instanceID );
Expand Down
4 changes: 2 additions & 2 deletions UncreatedWarfare/Commands/Help/CommandSyntaxFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Models.Localization;
using Uncreated.Warfare.Players.Permissions;
using Uncreated.Warfare.Util;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

public class CommandSyntaxFormatter : IDisposable
{
Expand Down
1 change: 1 addition & 0 deletions UncreatedWarfare/Commands/Help/HelpCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Interaction.Commands.Syntax;
using Uncreated.Warfare.Players.Permissions;
using Uncreated.Warfare.Translations;

Expand Down
4 changes: 2 additions & 2 deletions UncreatedWarfare/Commands/Help/ICommandDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Players.Permissions;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

/// <summary>
/// Defines information about a single command or sub-command.
Expand Down
3 changes: 2 additions & 1 deletion UncreatedWarfare/Commands/Help/ICommandFlagDescriptor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Uncreated.Warfare.Players.Permissions;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

/// <summary>
/// Describes a flag parameter (like '-e') for a command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
using System.Collections.Generic;
using Uncreated.Warfare.Players.Permissions;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

/// <summary>
/// Describes a command or parameter for a command (including sub-commands).
Expand Down
4 changes: 2 additions & 2 deletions UncreatedWarfare/Commands/Help/IMGUISyntaxWriter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Globalization;
using System.Text;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Util;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

public class IMGUISyntaxWriter : ISyntaxWriter
{
Expand Down
3 changes: 2 additions & 1 deletion UncreatedWarfare/Commands/Help/ISyntaxWriter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Text;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

/// <summary>
/// Non-thread-safe command syntax formatter/writer.
Expand Down
4 changes: 2 additions & 2 deletions UncreatedWarfare/Commands/Help/PlainTextSyntaxWriter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Globalization;
using System.Text;
using Uncreated.Warfare.Interaction.Commands;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

public class PlainTextSyntaxWriter : ISyntaxWriter
{
Expand Down
9 changes: 5 additions & 4 deletions UncreatedWarfare/Commands/Help/SyntaxColorPalette.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using DanielWillett.ReflectionTools;
using System;
using System.Collections.Generic;
using System.Linq;
using DanielWillett.ReflectionTools;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Players;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

public static class SyntaxColorPalette
{
public const char LookAtTargetInGameSymbol = 'ʘ';
Expand Down
4 changes: 2 additions & 2 deletions UncreatedWarfare/Commands/Help/TMProSyntaxWriter.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Globalization;
using System.Text;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Util;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

public class TMProSyntaxWriter : ISyntaxWriter
{
Expand Down
4 changes: 2 additions & 2 deletions UncreatedWarfare/Commands/Help/TerminalSyntaxWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using System;
using System.Globalization;
using System.Text;
using Uncreated.Warfare.Interaction.Commands;
using Uncreated.Warfare.Util;

namespace Uncreated.Warfare.Commands;
// ReSharper disable once CheckNamespace
namespace Uncreated.Warfare.Interaction.Commands.Syntax;

public class TerminalSyntaxWriter : ISyntaxWriter
{
Expand Down
Loading

0 comments on commit 878a9a3

Please sign in to comment.