Browse Source

Improve type safety of event types and version bump

tags/v0.2.0
NGnius 4 years ago
parent
commit
d00bdc80ed
11 changed files with 34 additions and 26 deletions
  1. +0
    -6
      GamecraftModdingAPI/Events/DeterministicStepComposeEngineGroupsPatch.cs
  2. +3
    -3
      GamecraftModdingAPI/Events/EventEngineFactory.cs
  3. +1
    -1
      GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs
  4. +1
    -1
      GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs
  5. +1
    -1
      GamecraftModdingAPI/Events/IEventEmitterEngine.cs
  6. +5
    -3
      GamecraftModdingAPI/Events/ModEventEntityStruct.cs
  7. +3
    -3
      GamecraftModdingAPI/Events/SimpleEventEmitterEngine.cs
  8. +9
    -3
      GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs
  9. +1
    -4
      GamecraftModdingAPI/GamecraftModdingAPI.csproj
  10. +9
    -0
      GamecraftModdingAPI/Inventory/Hotbar.cs
  11. +1
    -1
      doxygen.conf

+ 0
- 6
GamecraftModdingAPI/Events/DeterministicStepComposeEngineGroupsPatch.cs 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));
}
}
}

+ 3
- 3
GamecraftModdingAPI/Events/EventEngineFactory.cs 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);


+ 1
- 1
GamecraftModdingAPI/Events/GameStateBuildEmitterEngine.cs 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;



+ 1
- 1
GamecraftModdingAPI/Events/GameStateSimulationEmitterEngine.cs 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;



+ 1
- 1
GamecraftModdingAPI/Events/IEventEmitterEngine.cs 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)


+ 5
- 3
GamecraftModdingAPI/Events/ModEventEntityStruct.cs 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; }
}
}

+ 3
- 3
GamecraftModdingAPI/Events/SimpleEventEmitterEngine.cs 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;


+ 9
- 3
GamecraftModdingAPI/Events/SimpleEventHandlerEngine.cs 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) { }
}
}

+ 1
- 4
GamecraftModdingAPI/GamecraftModdingAPI.csproj 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>

+ 9
- 0
GamecraftModdingAPI/Inventory/Hotbar.cs 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;


+ 1
- 1
doxygen.conf 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


Loading…
Cancel
Save