Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/TehPers.Core.Api/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,4 @@ public static IEnumerable<T> Yield<T>(this T item)
}
}
}
}
}
117 changes: 109 additions & 8 deletions src/TehPers.Core.Api/Items/NamespacedKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ public static NamespacedKey SdvClothing(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Clothing, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a clothing item in the SDV namespace.
/// </summary>
/// <param name="id">The id of the clothing item.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvClothing(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Clothing, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a wallpaper item in the SDV namespace.
/// </summary>
Expand All @@ -166,6 +176,16 @@ public static NamespacedKey SdvWallpaper(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Wallpaper, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a wallpaper item in the SDV namespace.
/// </summary>
/// <param name="id">The id of the wallpaper item.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvWallpaper(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Wallpaper, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a flooring item in the SDV namespace.
/// </summary>
Expand All @@ -176,6 +196,16 @@ public static NamespacedKey SdvFlooring(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Flooring, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a flooring item in the SDV namespace.
/// </summary>
/// <param name="id">The id of the flooring item.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvFlooring(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Flooring, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for boots in the SDV namespace.
/// </summary>
Expand All @@ -186,6 +216,16 @@ public static NamespacedKey SdvBoots(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Boots, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for boots in the SDV namespace.
/// </summary>
/// <param name="id">The id of the boots.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvBoots(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Boots, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a hat in the SDV namespace.
/// </summary>
Expand All @@ -196,6 +236,16 @@ public static NamespacedKey SdvHat(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Hat, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a hat in the SDV namespace.
/// </summary>
/// <param name="id">The index of the hat.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvHat(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Hat, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a weapon in the SDV namespace.
/// </summary>
Expand All @@ -206,6 +256,16 @@ public static NamespacedKey SdvWeapon(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Weapon, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a weapon in the SDV namespace.
/// </summary>
/// <param name="id">The id of the weapon.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvWeapon(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Weapon, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a furniture item in the SDV namespace.
/// </summary>
Expand All @@ -216,6 +276,17 @@ public static NamespacedKey SdvFurniture(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Furniture, parentSheetIndex.ToString());
}


/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a furniture item in the SDV namespace.
/// </summary>
/// <param name="id">The id of the furniture item.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvFurniture(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Furniture, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a craftable item in the SDV namespace.
/// </summary>
Expand All @@ -226,6 +297,16 @@ public static NamespacedKey SdvBigCraftable(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.BigCraftable, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a craftable item in the SDV namespace.
/// </summary>
/// <param name="id">The id of the craftable item.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvBigCraftable(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.BigCraftable, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a ring in the SDV namespace.
/// </summary>
Expand All @@ -236,6 +317,16 @@ public static NamespacedKey SdvRing(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Ring, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a ring in the SDV namespace.
/// </summary>
/// <param name="id">The id of the ring.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvRing(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Ring, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for an object in the SDV namespace.
/// </summary>
Expand All @@ -246,6 +337,16 @@ public static NamespacedKey SdvObject(int parentSheetIndex)
return NamespacedKey.SdvCustom(ItemTypes.Object, parentSheetIndex.ToString());
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for an object in the SDV namespace.
/// </summary>
/// <param name="id">The id of the object.</param>
/// <returns>The resulting <see cref="NamespacedKey"/>.</returns>
public static NamespacedKey SdvObject(string id)
{
return NamespacedKey.SdvCustom(ItemTypes.Object, id);
}

/// <summary>
/// Creates a <see cref="NamespacedKey"/> for a custom item in the SDV namespace.
/// </summary>
Expand All @@ -259,14 +360,14 @@ public static NamespacedKey SdvCustom(string itemType, string key)

internal class TypeConverter : System.ComponentModel.TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(
ITypeDescriptorContext context,
CultureInfo culture,
ITypeDescriptorContext? context,
CultureInfo? culture,
object value
)
{
Expand All @@ -278,22 +379,22 @@ object value
return base.ConvertFrom(context, culture, value)!;
}

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
public override bool CanConvertTo(ITypeDescriptorContext? context, Type destinationType)
{
return destinationType == typeof(string)
|| base.CanConvertTo(context, destinationType);
}

public override object ConvertTo(
ITypeDescriptorContext context,
CultureInfo culture,
object value,
ITypeDescriptorContext? context,
CultureInfo? culture,
object? value,
Type destinationType
)
{
if (value is NamespacedKey key && destinationType == typeof(string))
{
return key.ToString();
return key;
}

return base.ConvertTo(context, culture, value, destinationType)!;
Expand Down
31 changes: 13 additions & 18 deletions src/TehPers.Core.Api/TehPers.Core.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
<EnableModDeploy>False</EnableModDeploy>
<EnableModZip>False</EnableModZip>
<Nullable>Enable</Nullable>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\TehPers.Core.Api.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Ninject" Version="3.3.5" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.1" />
</ItemGroup>

<ItemGroup>
<Reference Include="$(GamePath)/smapi-internal/Newtonsoft.Json.dll" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<EnableHarmony>true</EnableHarmony>
<EnableModDeploy>False</EnableModDeploy>
<EnableModZip>False</EnableModZip>
<Nullable>Enable</Nullable>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\TehPers.Core.Api.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Ninject" Version="3.3.5" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>
23 changes: 10 additions & 13 deletions src/TehPers.Core.SourceGen/TehPers.Core.SourceGen.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- TODO: is this needed? -->
<LangVersion>preview</LangVersion>
<Nullable>Enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<!-- TODO: is this needed? -->
<LangVersion>preview</LangVersion>
<Nullable>Enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.1.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3" PrivateAssets="all" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions src/TehPers.Core/Content/GameAssetProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public GameAssetProvider(IModHelper helper)
this.contentHelper = helper.GameContent;
}

public T Load<T>(string path)
where T : notnull
public T Load<T>(string path) where T : notnull
{
return this.contentHelper.Load<T>(path);
}
Expand Down
41 changes: 32 additions & 9 deletions src/TehPers.Core/Integrations/JsonAssets/IJsonAssetsApi.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,38 @@
using System.Collections.Generic;
using StardewModdingAPI;
using System;
using System.Collections.Generic;

namespace TehPers.Core.Integrations.JsonAssets
{
public interface IJsonAssetsApi
{
IDictionary<string, int> GetAllObjectIds();
IDictionary<string, int> GetAllCropIds();
IDictionary<string, int> GetAllFruitTreeIds();
IDictionary<string, int> GetAllBigCraftableIds();
IDictionary<string, int> GetAllHatIds();
IDictionary<string, int> GetAllWeaponIds();
IDictionary<string, int> GetAllClothingIds();
/// <summary>Load a folder as a Json Assets content pack.</summary>
/// <param name="path">The absolute path to the content pack folder.</param>
void LoadAssets(string path);

/// <summary>Load a folder as a Json Assets content pack.</summary>
/// <param name="path">The absolute path to the content pack folder.</param>
/// <param name="translations">The translations to use for <c>TranslationKey</c> fields, or <c>null</c> to load the content pack's <c>i18n</c> folder if present.</param>
void LoadAssets(string path, ITranslationHelper translations);

string GetObjectId(string name);
string GetCropId(string name);
string GetFruitTreeId(string name);
string GetBigCraftableId(string name);
string GetHatId(string name);
string GetWeaponId(string name);
string GetClothingId(string name);

List<string> GetAllObjectsFromContentPack(string cp);
List<string> GetAllCropsFromContentPack(string cp);
List<string> GetAllFruitTreesFromContentPack(string cp);
List<string> GetAllBigCraftablesFromContentPack(string cp);
List<string> GetAllHatsFromContentPack(string cp);
List<string> GetAllWeaponsFromContentPack(string cp);
List<string> GetAllClothingFromContentPack(string cp);
List<string> GetAllBootsFromContentPack(string cp);

event EventHandler ItemsRegistered;
event EventHandler AddedItemsToShop;
}
}
}
Loading