Improve type safety of event types and version bump

This commit is contained in:
NGnius 2020-04-02 13:08:05 -04:00
parent 2149458d96
commit d00bdc80ed
11 changed files with 34 additions and 26 deletions

View file

@ -29,12 +29,6 @@ namespace GamecraftModdingAPI.Events
{
stateSyncReg.buildModeInitializationEngines.Add(buildEngine);
stateSyncReg.simulationModeInitializationEngines.Add(simEngine);
}
public static MethodBase NopeTargetMethod()
{
return typeof(DeterministicStepCompositionRoot).GetMethods().First(m => m.Name == "ComposeEnginesGroups")
.MakeGenericMethod(typeof(object));
}
}
}

View file

@ -21,7 +21,7 @@ namespace GamecraftModdingAPI.Events
/// <param name="onActivated">The operation to do when the event is created</param>
/// <param name="onDestroyed">The operation to do when the event is destroyed (if applicable)</param>
/// <returns>The created object</returns>
public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, object type, Action onActivated, Action onDestroyed)
public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, int type, Action onActivated, Action onDestroyed)
{
var engine = new SimpleEventHandlerEngine(onActivated, onDestroyed, type, name);
EventManager.AddEventHandler(engine);
@ -36,7 +36,7 @@ namespace GamecraftModdingAPI.Events
/// <param name="onActivated">The operation to do when the event is created</param>
/// <param name="onDestroyed">The operation to do when the event is destroyed (if applicable)</param>
/// <returns>The created object</returns>
public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, object type, Action<EntitiesDB> onActivated, Action<EntitiesDB> onDestroyed)
public static SimpleEventHandlerEngine CreateAddSimpleHandler(string name, int type, Action<EntitiesDB> onActivated, Action<EntitiesDB> onDestroyed)
{
var engine = new SimpleEventHandlerEngine(onActivated, onDestroyed, type, name);
EventManager.AddEventHandler(engine);
@ -50,7 +50,7 @@ namespace GamecraftModdingAPI.Events
/// <param name="type">The type of event to emit</param>
/// <param name="isRemovable">Will removing this engine not break your code?</param>
/// <returns>The created object</returns>
public static SimpleEventEmitterEngine CreateAddSimpleEmitter(string name, object type, bool isRemovable = true)
public static SimpleEventEmitterEngine CreateAddSimpleEmitter(string name, int type, bool isRemovable = true)
{
var engine = new SimpleEventEmitterEngine(type, name, isRemovable);
EventManager.AddEventEmitter(engine);

View file

@ -17,7 +17,7 @@ namespace GamecraftModdingAPI.Events
public EntitiesDB entitiesDB { set; private get; }
public object type { get; } = EventType.BuildSwitchedTo;
public int type { get; } = (int)EventType.BuildSwitchedTo;
public bool isRemovable { get; } = false;

View file

@ -17,7 +17,7 @@ namespace GamecraftModdingAPI.Events
public EntitiesDB entitiesDB { set; private get; }
public object type { get; } = EventType.SimulationSwitchedTo;
public int type { get; } = (int)EventType.SimulationSwitchedTo;
public bool isRemovable { get; } = false;

View file

@ -18,7 +18,7 @@ namespace GamecraftModdingAPI.Events
/// <summary>
/// The type of event emitted
/// </summary>
object type { get; }
int type { get; }
/// <summary>
/// Whether the emitter can be removed with Manager.RemoveEventEmitter(name)

View file

@ -11,11 +11,13 @@ namespace GamecraftModdingAPI.Events
/// <summary>
/// The event entity struct
/// </summary>
public struct ModEventEntityStruct : IEntityStruct
public struct ModEventEntityStruct : IEntityStruct, INeedEGID
{
/// <summary>
/// The type of event that has been emitted
/// </summary>
public object type;
public int type;
public EGID ID { get; set; }
}
}

View file

@ -15,7 +15,7 @@ namespace GamecraftModdingAPI.Events
public class SimpleEventEmitterEngine : IEventEmitterEngine
{
public string Name { get; set; }
public object type { get; set; }
public int type { get; set; }
public bool isRemovable { get; }
@ -44,7 +44,7 @@ namespace GamecraftModdingAPI.Events
/// <param name="isRemovable">Will removing this engine not break your code?</param>
public SimpleEventEmitterEngine(EventType type, string name, bool isRemovable = true)
{
this.type = type;
this.type = (int)type;
this.Name = name;
this.isRemovable = isRemovable;
}
@ -55,7 +55,7 @@ namespace GamecraftModdingAPI.Events
/// <param name="type">The object to use for ModEventEntityStruct.type</param>
/// <param name="name">The name of this engine</param>
/// <param name="isRemovable">Will removing this engine not break your code?</param>
public SimpleEventEmitterEngine(object type, string name, bool isRemovable = true)
public SimpleEventEmitterEngine(int type, string name, bool isRemovable = true)
{
this.type = type;
this.Name = name;

View file

@ -13,7 +13,7 @@ namespace GamecraftModdingAPI.Events
/// </summary>
public class SimpleEventHandlerEngine : IEventHandlerEngine
{
public object type { get; set; }
public int type { get; set; }
public string Name { get; set; }
private bool isActivated = false;
@ -71,7 +71,7 @@ namespace GamecraftModdingAPI.Events
/// <param name="type">The type of event to handle</param>
/// <param name="name">The name of the engine</param>
/// <param name="simple">A useless parameter to use to avoid Python overload resolution errors</param>
public SimpleEventHandlerEngine(Action activated, Action removed, object type, string name, bool simple = true)
public SimpleEventHandlerEngine(Action activated, Action removed, int type, string name, bool simple = true)
: this((EntitiesDB _) => { activated.Invoke(); }, (EntitiesDB _) => { removed.Invoke(); }, type, name) { }
/// <summary>
@ -81,12 +81,18 @@ namespace GamecraftModdingAPI.Events
/// <param name="removed">The operation to do when the event is destroyed (if applicable)</param>
/// <param name="type">The type of event to handler</param>
/// <param name="name">The name of the engine</param>
public SimpleEventHandlerEngine(Action<EntitiesDB> activated, Action<EntitiesDB> removed, object type, string name)
public SimpleEventHandlerEngine(Action<EntitiesDB> activated, Action<EntitiesDB> removed, int type, string name)
{
this.type = type;
this.Name = name;
this.onActivated = activated;
this.onDestroyed = removed;
}
public SimpleEventHandlerEngine(Action activated, Action removed, EventType type, string name, bool simple = true)
: this((EntitiesDB _) => { activated.Invoke(); }, (EntitiesDB _) => { removed.Invoke(); }, (int)type, name) { }
public SimpleEventHandlerEngine(Action<EntitiesDB> activated, Action<EntitiesDB> removed, EventType type, string name, bool simple = true)
: this(activated, removed, (int)type, name) { }
}
}

View file

@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>0.1.4.0</Version>
<Version>0.2.0</Version>
<Authors>Exmods</Authors>
<PackageLicenseExpression>GNU General Public Licence 3+</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/modtainers/GamecraftModdingAPI</PackageProjectUrl>
@ -542,7 +542,4 @@
</ItemGroup>
<!--End Dependencies-->
<ItemGroup>
<Folder Include="Inventory\" />
</ItemGroup>
</Project>

View file

@ -13,6 +13,11 @@ namespace GamecraftModdingAPI.Inventory
{
private static HotbarEngine hotbarEngine = new HotbarEngine();
/// <summary>
/// Switch the block in the player's hand
/// </summary>
/// <param name="block">The block to switch to.</param>
/// <param name="playerID">The player. Omit this to use the local player.</param>
public static void EquipBlock(BlockIDs block, uint playerID = uint.MaxValue)
{
if (playerID == uint.MaxValue)
@ -25,6 +30,10 @@ namespace GamecraftModdingAPI.Inventory
// reason: the game expects a Dictionary entry for the tweaked stats
}
/// <summary>
/// Gets the block in the player's hand
/// </summary>
/// <returns>The equipped block.</returns>
public static BlockIDs GetEquippedBlock()
{
return HotbarSlotSelectionHandlerEnginePatch.EquippedPartID;

View file

@ -38,7 +38,7 @@ PROJECT_NAME = "GamecraftModdingAPI"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = "v0.1.4.0"
PROJECT_NUMBER = "v0.2.0"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a