add initial multiplayer API (#480)
This commit is contained in:
parent
beb2f9c148
commit
a625e9bed7
|
@ -45,6 +45,9 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
|||
/// <summary>An API for managing console commands.</summary>
|
||||
public ICommandHelper ConsoleCommands { get; }
|
||||
|
||||
/// <summary>Provides multiplayer utilities.</summary>
|
||||
public IMultiplayerHelper Multiplayer { get; }
|
||||
|
||||
/// <summary>An API for reading translations stored in the mod's <c>i18n</c> folder, with one file per locale (like <c>en.json</c>) containing a flat key => value structure. Translations are fetched with locale fallback, so missing translations are filled in from broader locales (like <c>pt-BR.json</c> < <c>pt.json</c> < <c>default.json</c>).</summary>
|
||||
public ITranslationHelper Translation { get; }
|
||||
|
||||
|
@ -66,7 +69,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
|||
/// <param name="deprecationManager">Manages deprecation warnings.</param>
|
||||
/// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
|
||||
/// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
|
||||
public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, IContentHelper contentHelper, ICommandHelper commandHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, ITranslationHelper translationHelper, IEnumerable<IContentPack> contentPacks, Func<string, IManifest, IContentPack> createContentPack, DeprecationManager deprecationManager)
|
||||
public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, IContentHelper contentHelper, ICommandHelper commandHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, IEnumerable<IContentPack> contentPacks, Func<string, IManifest, IContentPack> createContentPack, DeprecationManager deprecationManager)
|
||||
: base(modID)
|
||||
{
|
||||
// validate directory
|
||||
|
@ -82,6 +85,7 @@ namespace StardewModdingAPI.Framework.ModHelpers
|
|||
this.ModRegistry = modRegistry ?? throw new ArgumentNullException(nameof(modRegistry));
|
||||
this.ConsoleCommands = commandHelper ?? throw new ArgumentNullException(nameof(commandHelper));
|
||||
this.Reflection = reflectionHelper ?? throw new ArgumentNullException(nameof(reflectionHelper));
|
||||
this.Multiplayer = multiplayer ?? throw new ArgumentNullException(nameof(multiplayer));
|
||||
this.Translation = translationHelper ?? throw new ArgumentNullException(nameof(translationHelper));
|
||||
this.ContentPacks = contentPacks.ToArray();
|
||||
this.CreateContentPack = createContentPack;
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
namespace StardewModdingAPI.Framework.ModHelpers
|
||||
{
|
||||
/// <summary>Provides multiplayer utilities.</summary>
|
||||
internal class MultiplayerHelper : BaseHelper, IMultiplayerHelper
|
||||
{
|
||||
/*********
|
||||
** Properties
|
||||
*********/
|
||||
/// <summary>SMAPI's core multiplayer utility.</summary>
|
||||
private readonly SMultiplayer Multiplayer;
|
||||
|
||||
|
||||
/*********
|
||||
** Public methods
|
||||
*********/
|
||||
/// <summary>Construct an instance.</summary>
|
||||
/// <param name="modID">The unique ID of the relevant mod.</param>
|
||||
/// <param name="multiplayer">SMAPI's core multiplayer utility.</param>
|
||||
public MultiplayerHelper(string modID, SMultiplayer multiplayer)
|
||||
: base(modID)
|
||||
{
|
||||
this.Multiplayer = multiplayer;
|
||||
}
|
||||
|
||||
/// <summary>Get a new multiplayer ID.</summary>
|
||||
public long GetNewID()
|
||||
{
|
||||
return this.Multiplayer.getNewID();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -126,6 +126,9 @@ namespace StardewModdingAPI.Framework
|
|||
/// <summary>SMAPI's content manager.</summary>
|
||||
public ContentCore ContentCore { get; private set; }
|
||||
|
||||
/// <summary>The game's core multiplayer utility.</summary>
|
||||
public SMultiplayer Multiplayer => (SMultiplayer)Game1.multiplayer;
|
||||
|
||||
/// <summary>Whether SMAPI should log more information about the game context.</summary>
|
||||
public bool VerboseLogging { get; set; }
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@ namespace StardewModdingAPI
|
|||
/// <summary>Metadata about loaded mods.</summary>
|
||||
IModRegistry ModRegistry { get; }
|
||||
|
||||
/// <summary>Provides multiplayer utilities.</summary>
|
||||
IMultiplayerHelper Multiplayer { get; }
|
||||
|
||||
/// <summary>An API for managing console commands.</summary>
|
||||
ICommandHelper ConsoleCommands { get; }
|
||||
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
namespace StardewModdingAPI
|
||||
{
|
||||
/// <summary>Provides multiplayer utilities.</summary>
|
||||
public interface IMultiplayerHelper : IModLinked
|
||||
{
|
||||
/// <summary>Get a new multiplayer ID.</summary>
|
||||
long GetNewID();
|
||||
}
|
||||
}
|
|
@ -807,6 +807,7 @@ namespace StardewModdingAPI
|
|||
IContentHelper contentHelper = new ContentHelper(contentCore, contentManager, metadata.DirectoryPath, manifest.UniqueID, metadata.DisplayName, monitor);
|
||||
IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, metadata.DisplayName, this.Reflection, this.DeprecationManager);
|
||||
IModRegistry modRegistryHelper = new ModRegistryHelper(manifest.UniqueID, this.ModRegistry, proxyFactory, monitor);
|
||||
IMultiplayerHelper multiplayerHelper = new MultiplayerHelper(manifest.UniqueID, this.GameInstance.Multiplayer);
|
||||
ITranslationHelper translationHelper = new TranslationHelper(manifest.UniqueID, manifest.Name, contentCore.GetLocale(), contentCore.Language);
|
||||
|
||||
IContentPack CreateTransitionalContentPack(string packDirPath, IManifest packManifest)
|
||||
|
@ -817,7 +818,7 @@ namespace StardewModdingAPI
|
|||
return new ContentPack(packDirPath, packManifest, packContentHelper, this.JsonHelper);
|
||||
}
|
||||
|
||||
modHelper = new ModHelper(manifest.UniqueID, metadata.DirectoryPath, jsonHelper, contentHelper, commandHelper, modRegistryHelper, reflectionHelper, translationHelper, contentPacks, CreateTransitionalContentPack, this.DeprecationManager);
|
||||
modHelper = new ModHelper(manifest.UniqueID, metadata.DirectoryPath, jsonHelper, contentHelper, commandHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, contentPacks, CreateTransitionalContentPack, this.DeprecationManager);
|
||||
}
|
||||
|
||||
// get mod instance
|
||||
|
|
|
@ -102,6 +102,7 @@
|
|||
<Compile Include="Framework\ModData\ParsedModDataRecord.cs" />
|
||||
<Compile Include="Framework\Models\ManifestContentPackFor.cs" />
|
||||
<Compile Include="Framework\Models\SMetadata.cs" />
|
||||
<Compile Include="Framework\ModHelpers\MultiplayerHelper.cs" />
|
||||
<Compile Include="Framework\ModLoading\Finders\EventFinder.cs" />
|
||||
<Compile Include="Framework\ModLoading\Finders\FieldFinder.cs" />
|
||||
<Compile Include="Framework\ModLoading\Finders\MethodFinder.cs" />
|
||||
|
@ -151,6 +152,7 @@
|
|||
<Compile Include="Framework\Utilities\PathUtilities.cs" />
|
||||
<Compile Include="IContentPack.cs" />
|
||||
<Compile Include="IManifestContentPackFor.cs" />
|
||||
<Compile Include="IMultiplayerHelper.cs" />
|
||||
<Compile Include="IReflectedField.cs" />
|
||||
<Compile Include="IReflectedMethod.cs" />
|
||||
<Compile Include="IReflectedProperty.cs" />
|
||||
|
|
Loading…
Reference in New Issue