Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
jhett12321 committed Sep 18, 2022
2 parents 2874b42 + d55b785 commit 53a4f7b
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 26 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## 8193.34.17
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.16...v8193.34.17

### Added
- NwCreature: Added `SittingObject` property.
- NwArea: Added `LoadScreen` property.
- ResourceManager: Added `CreateResourceDirectory`.

### Fixed
- NwBaseItem: Fixed `ItemClass` returning a type name instead of the item class name.
- Fixed a rare compile issue when using `ToNwObject` caused by exposed native types.

## 8193.34.16
https://github.com/nwn-dotnet/Anvil/compare/v8193.34.15...v8193.34.16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Anvil.API
{
public static class NativeObjectExtensions
internal static class NativeObjectExtensions
{
public static Effect? ToEffect(this CGameEffect? effect, bool memoryOwn)
{
Expand Down
9 changes: 9 additions & 0 deletions NWN.Anvil/src/main/API/Object/NwArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ public int ListenModifier
set => Area.m_nAreaListenModifier = value;
}

/// <summary>
/// Gets or sets the load screen for this area.
/// </summary>
public LoadScreenTableEntry LoadScreen
{
get => NwGameTables.LoadScreenTable[Area.m_nLoadScreenID];
set => Area.m_nLoadScreenID = (ushort)value.RowIndex;
}

/// <summary>
/// Gets or sets the area ambient color during night time.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions NWN.Anvil/src/main/API/Object/NwCreature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@ public NwRace Race

public sbyte ShieldCheckPenalty => (sbyte)Creature.m_pStats.m_nShieldCheckPenalty;

/// <summary>
/// Gets the placeable object (if any) that this creature is currently sitting in.
/// </summary>
public NwPlaceable? SittingObject => Creature.m_oidSittingObject.ToNwObject<NwPlaceable>();

/// <summary>
/// Gets or sets the size of this creature.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion NWN.Anvil/src/main/API/Ruleset/NwBaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ internal NwBaseItem(uint baseItemId, CNWBaseItem baseItemInfo)
/// Gets the ResRef of the item's model, or the base part of the resref.<br/>
/// This property is dependent on <see cref="ModelType"/>. See https://nwn.wiki/display/NWN1/baseitems.2da for more info.
/// </summary>
public string? ItemClass => BaseItemInfo.m_ItemClassResRefChunk.ToString();
public string? ItemClass => BaseItemInfo.m_ItemClassResRefChunk.ReadFixedLengthString();

/// <summary>
/// Gets the maximum number of "cast spell" properties items of this type can be given when designed in the Toolset.
Expand Down
26 changes: 26 additions & 0 deletions NWN.Anvil/src/main/API/TwoDimArray/Tables/LoadScreenTableEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Anvil.API
{
public sealed class LoadScreenTableEntry : ITwoDimArrayEntry
{
public int RowIndex { get; init; }

public string? Label { get; private set; }

public string? ScriptingName { get; private set; }

public string? BMPResRef { get; private set; }

public string? TileSet { get; private set; }

public StrRef? StrRef { get; private set; }

public void InterpretEntry(TwoDimArrayEntry entry)
{
Label = entry.GetString("Label");
ScriptingName = entry.GetString("ScriptingName");
BMPResRef = entry.GetString("BMPResRef");
TileSet = entry.GetString("TileSet");
StrRef = entry.GetStrRef("StrRef");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ private void LoadTables()
BodyBagTable = GetTable<BodyBagTableEntry>(arrays.m_pBodyBagTable);
EnvironmentPresetTable = GetTable<EnvironmentPreset>("environment.2da");
LightColorTable = GetTable<LightColorTableEntry>(arrays.m_pLightColorTable);
LoadScreenTable = GetTable<LoadScreenTableEntry>("loadscreens.2da");
ItemPropertyCostTables = GetTable<ItemPropertyCostTablesEntry>("iprp_costtable.2da");
ItemPropertyParamTables = GetTable<ItemPropertyParamTablesEntry>("iprp_paramtable.2da");
ItemPropertyItemMapTable = GetTable<ItemPropertyItemMapTableEntry>(arrays.m_pItemPropsTable);
Expand Down
5 changes: 5 additions & 0 deletions NWN.Anvil/src/main/API/TwoDimArray/Tables/NwGameTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public static partial class NwGameTables
/// </summary>
public static TwoDimArray<LightColorTableEntry> LightColorTable { get; private set; } = null!;

/// <summary>
/// Gets the loading screen table (loadscreens.2da)
/// </summary>
public static TwoDimArray<LoadScreenTableEntry> LoadScreenTable { get; private set; } = null!;

/// <summary>
/// Gets the belt parts table (parts_belt.2da)
/// </summary>
Expand Down
53 changes: 30 additions & 23 deletions NWN.Anvil/src/main/Services/Resources/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,36 @@ public ResourceManager()
tempAlias = CreateResourceDirectory(HomeStorage.ResourceTemp).ToExoString();
}

/// <summary>
/// Adds the specified folder as a valid resource directory for all ResMan requests.
/// </summary>
/// <param name="path">The path to add.</param>
/// <param name="detectChanges">True if changes to the folder contents should be tracked for updates.</param>
/// <returns>The assigned resman alias for the resource directory.</returns>
/// <exception cref="ArgumentOutOfRangeException">Thrown if the specified directory does not exist.</exception>
public string CreateResourceDirectory(string path, bool detectChanges = true)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentOutOfRangeException(nameof(path), "Path must not be empty or null.");
}

string alias = AliasBaseName + currentIndex + AliasSuffix;
uint priority = BasePriority + currentIndex;
CExoString exoAlias = alias.ToExoString();

Log.Info("Setting up resource directory: {Alias}:{Path} (Priority: {Priority})", alias, path, priority);

ExoBase.m_pcExoAliasList.Add(exoAlias, path.ToExoString());
ResMan.CreateDirectory(exoAlias);
ResMan.AddResourceDirectory(exoAlias, priority, detectChanges.ToInt());
ResMan.UpdateResourceDirectory(exoAlias);

currentIndex++;

return alias;
}

/// <summary>
/// Deletes the temporary resource with the specified name.
/// </summary>
Expand Down Expand Up @@ -189,29 +219,6 @@ void IDisposable.Dispose()
}
}

internal string CreateResourceDirectory(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentOutOfRangeException(nameof(path), "Path must not be empty or null.");
}

string alias = AliasBaseName + currentIndex + AliasSuffix;
uint priority = BasePriority + currentIndex;
CExoString exoAlias = alias.ToExoString();

Log.Info("Setting up resource directory: {Alias}:{Path} (Priority: {Priority})", alias, path, priority);

ExoBase.m_pcExoAliasList.Add(exoAlias, path.ToExoString());
ResMan.CreateDirectory(exoAlias);
ResMan.AddResourceDirectory(exoAlias, priority, true.ToInt());
ResMan.UpdateResourceDirectory(exoAlias);

currentIndex++;

return alias;
}

private byte[]? GetStandardResourceData(string name, ResRefType type)
{
if (TryGetNativeResource(name, type, out CRes? res))
Expand Down
2 changes: 1 addition & 1 deletion NWN.Anvil/src/main/Services/Scheduler/SchedulerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ScheduledTask ScheduleRepeating(Action action, TimeSpan schedule, TimeSpa
{
if (schedule <= TimeSpan.Zero)
{
throw new ArgumentOutOfRangeException(nameof(delay), $"{nameof(delay)} cannot be <= zero.");
throw new ArgumentOutOfRangeException(nameof(schedule), $"{nameof(schedule)} cannot be <= zero.");
}

if (action == null)
Expand Down

0 comments on commit 53a4f7b

Please sign in to comment.