Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API changes in 13.0.0 #196

Closed
wants to merge 20 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using NWPluginAPI.Analyzers.Enums;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Editing;
using Microsoft.CodeAnalysis.Simplification;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Composition;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

Expand Down
10 changes: 5 additions & 5 deletions Analyzers/NwPluginAPI.Analyzers.Generator/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using PluginAPI.Events;
using PluginAPI.Events;
using System.Text;

StringBuilder builder = new StringBuilder();
Expand Down Expand Up @@ -35,19 +35,19 @@

foreach (var ev in EventManager.Events)
{
if (ev.Value.Parameters.Length == 0)
if (ev.Value.Parameters.Count == 0)
builder.AppendLine(" { " + (int)ev.Key + ", new Event() },");
else
{
builder.AppendLine(" { " + (int)ev.Key + ", new Event(");
for (int x = 0; x < ev.Value.Parameters.Length; x++)
for (int x = 0; x < ev.Value.Parameters.Count; x++)
{
var param = ev.Value.Parameters[x];

if (param.BaseType.IsArray)
builder.AppendLine(" new EventParameter(\"" + param.BaseType.GetElementType()?.FullName + "\", true, \"" + param.DefaultIdentifierName + "\")" + (x == (ev.Value.Parameters.Length - 1) ? ") }," : ","));
builder.AppendLine(" new EventParameter(\"" + param.BaseType.GetElementType()?.FullName + "\", true, \"" + param.DefaultIdentifierName + "\")" + (x == (ev.Value.Parameters.Count - 1) ? ") }," : ","));
else
builder.AppendLine(" new EventParameter(\"" + param.BaseType.FullName + "\", false, \"" + param.DefaultIdentifierName + "\")" + (x == (ev.Value.Parameters.Length - 1) ? ") }," : ","));
builder.AppendLine(" new EventParameter(\"" + param.BaseType.FullName + "\", false, \"" + param.DefaultIdentifierName + "\")" + (x == (ev.Value.Parameters.Count - 1) ? ") }," : ","));
}
}
}
Expand Down
206 changes: 206 additions & 0 deletions NwPluginAPI.Docs/log.txt

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions NwPluginAPI.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,32 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NwPluginAPI.Analyzers", "An
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NwPluginAPI.Analyzers.Generator", "Analyzers\NwPluginAPI.Analyzers.Generator\NwPluginAPI.Analyzers.Generator.csproj", "{9638A1ED-142B-4487-8DAA-A24E1F42E04C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NwPluginAPI.Docs", "NwPluginAPI.Docs\NwPluginAPI.Docs.csproj", "{3D50BC79-9168-47F3-9805-E0D7502916DF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NwPluginAPI.Docs", "NwPluginAPI.Docs\NwPluginAPI.Docs.csproj", "{3D50BC79-9168-47F3-9805-E0D7502916DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5079D346-050F-45DF-AF41-067C992CAAFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5079D346-050F-45DF-AF41-067C992CAAFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5079D346-050F-45DF-AF41-067C992CAAFC}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{5079D346-050F-45DF-AF41-067C992CAAFC}.Debug|Any CPU.Build.0 = Release|Any CPU
{5079D346-050F-45DF-AF41-067C992CAAFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5079D346-050F-45DF-AF41-067C992CAAFC}.Release|Any CPU.Build.0 = Release|Any CPU
{E0F1B55A-971A-418D-B45A-CB2C702B6364}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0F1B55A-971A-418D-B45A-CB2C702B6364}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0F1B55A-971A-418D-B45A-CB2C702B6364}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{E0F1B55A-971A-418D-B45A-CB2C702B6364}.Debug|Any CPU.Build.0 = Release|Any CPU
{E0F1B55A-971A-418D-B45A-CB2C702B6364}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0F1B55A-971A-418D-B45A-CB2C702B6364}.Release|Any CPU.Build.0 = Release|Any CPU
{4BE5D776-39A9-4532-9390-C59FB45E9571}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4BE5D776-39A9-4532-9390-C59FB45E9571}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4BE5D776-39A9-4532-9390-C59FB45E9571}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{4BE5D776-39A9-4532-9390-C59FB45E9571}.Debug|Any CPU.Build.0 = Release|Any CPU
{4BE5D776-39A9-4532-9390-C59FB45E9571}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4BE5D776-39A9-4532-9390-C59FB45E9571}.Release|Any CPU.Build.0 = Release|Any CPU
{9638A1ED-142B-4487-8DAA-A24E1F42E04C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9638A1ED-142B-4487-8DAA-A24E1F42E04C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9638A1ED-142B-4487-8DAA-A24E1F42E04C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9638A1ED-142B-4487-8DAA-A24E1F42E04C}.Release|Any CPU.Build.0 = Release|Any CPU
{3D50BC79-9168-47F3-9805-E0D7502916DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3D50BC79-9168-47F3-9805-E0D7502916DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3D50BC79-9168-47F3-9805-E0D7502916DF}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{3D50BC79-9168-47F3-9805-E0D7502916DF}.Debug|Any CPU.Build.0 = Release|Any CPU
{3D50BC79-9168-47F3-9805-E0D7502916DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3D50BC79-9168-47F3-9805-E0D7502916DF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
5 changes: 0 additions & 5 deletions NwPluginAPI/Commands/ReloadCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
using System.Linq;
using System.Reflection;
using PluginAPI.Core;
using PluginAPI.Core.Attributes;

namespace PluginAPI.Commands
{
using CommandSystem;
Expand Down
7 changes: 7 additions & 0 deletions NwPluginAPI/Core/Attributes/EventArgument.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System;

namespace PluginAPI.Core.Attributes
{
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class EventArgument : Attribute { }
}
4 changes: 3 additions & 1 deletion NwPluginAPI/Core/Attributes/PluginEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace PluginAPI.Core.Attributes
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class PluginEvent : Attribute
{
public ServerEventType EventType { get; }
public ServerEventType EventType { get; } = ServerEventType.None;

/// <summary>
/// Initializes a new instance of the <see cref="PluginEvent"/> class.
Expand All @@ -19,5 +19,7 @@ public PluginEvent(ServerEventType eventType)
{
EventType = eventType;
}

public PluginEvent() { }
}
}
34 changes: 34 additions & 0 deletions NwPluginAPI/Core/Attributes/PluginRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using PluginAPI.Enums;
using System;

namespace PluginAPI.Core.Attributes
{
/// <summary>
/// Marks the plugin role.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class PluginRole : Attribute
{
public RoleRegisterType RegisterType;
public int RoleId;

/// <summary>
/// Initializes a new instance of the <see cref="PluginRole"/> class.
/// </summary>
/// <param name="registerType">The type of registered role.</param>
public PluginRole(RoleRegisterType registerType)
{
RegisterType = registerType;
}

/// <summary>
/// Initializes a new instance of the <see cref="PluginRole"/> class.
/// </summary>
/// <param name="registerType">The type of registered role.</param>
public PluginRole(RoleRegisterType registerType, int roleId)
{
RegisterType = registerType;
RoleId = roleId;
}
}
}
3 changes: 0 additions & 3 deletions NwPluginAPI/Core/DamageManager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
namespace PluginAPI.Core
{
using Footprinting;
using PlayerStatsSystem;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// Manages damage for a player.
Expand Down
4 changes: 2 additions & 2 deletions NwPluginAPI/Core/Facility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static void Reset()
/// </summary>
public static void TurnOffAllLights(float duration = 0)
{
foreach (FlickerableLightController flickerableLightController in FlickerableLightController.Instances)
foreach (RoomLightController flickerableLightController in RoomLightController.Instances)
{
if (duration > 0)
{
Expand All @@ -180,7 +180,7 @@ public static void TurnOffAllLights(float duration = 0)
/// </summary>
public static void TurnOnAllLights()
{
foreach (FlickerableLightController flickerableLightController in FlickerableLightController.Instances)
foreach (RoomLightController flickerableLightController in RoomLightController.Instances)
{
flickerableLightController.NetworkLightsEnabled = true;
}
Expand Down
21 changes: 21 additions & 0 deletions NwPluginAPI/Core/Factories/Factory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ public T GetOrAdd(IGameComponent component)
return ent;
}

/// <summary>
/// Gets entity from factory.
/// </summary>
/// <param name="component">The game component.</param>
/// <returns>Entity.</returns>
public T Get(IGameComponent component)
{
if (Entities.TryGetValue(component, out T entity))
return entity;

if (component is ReferenceHub hb && hb.isLocalPlayer)
{
if (DefaultServer == null)
DefaultServer = Create(component);

return DefaultServer;
}

return default(T);
}

/// <summary>
/// Adds missing entity if not exists.
/// </summary>
Expand Down
10 changes: 8 additions & 2 deletions NwPluginAPI/Core/Factories/PlayerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace PluginAPI.Core.Factories
/// <summary>
/// A factory to create <see cref="IPlayer"/>'s.
/// </summary>
public class PlayerFactory : Factory<IPlayer>
public class PlayerFactory : Factory<Player>
{
public virtual Type BaseType { get; } = typeof(Player);

Expand All @@ -15,6 +15,12 @@ public class PlayerFactory : Factory<IPlayer>
/// </summary>
/// <param name="component">The <see cref="IGameComponent"/>.</param>
/// <returns>The created <see cref="IPlayer"/>.</returns>
public override IPlayer Create(IGameComponent component) => new Player(component);
public override Player Create(IGameComponent component)
{
if (component is ReferenceHub hub && hub.isLocalPlayer)
return new Server(hub);

return new Player(component);
}
}
}
8 changes: 4 additions & 4 deletions NwPluginAPI/Core/FactoryManager.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace PluginAPI.Core
namespace PluginAPI.Core
{
using System;
using System.Collections.Generic;
using Factories;
using Interfaces;
using Events;

/// <summary>
Expand Down Expand Up @@ -111,8 +110,9 @@ static void RemovePlayer(ReferenceHub obj)
{
foreach (var factory in PlayerFactories.Values)
{
if (!factory.Entities.TryGetValue(obj, out IPlayer plr))
continue;
var plr = factory.Get(obj);

if (plr == null) continue;

try
{
Expand Down
57 changes: 0 additions & 57 deletions NwPluginAPI/Core/Interfaces/IPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,66 +1,9 @@
namespace PluginAPI.Core.Interfaces
{
using UnityEngine;

/// <summary>
/// Defines a player.
/// </summary>
public interface IPlayer : IEntity
{
/// <summary>
/// Gets if player is dedicated server.
/// </summary>
bool IsServer { get; }

/// <summary>
/// Gets the player's <see cref="global::ReferenceHub"/>.
/// </summary>
ReferenceHub ReferenceHub { get; }

/// <summary>
/// Gets the player's <see cref="UnityEngine.GameObject"/>.
/// </summary>
GameObject GameObject { get; }

/// <summary>
/// Gets player temporary data storage.
/// </summary>
DataStorage TemporaryData { get; }

/// <summary>
/// Executed when player object is created.
/// </summary>
void OnStart();

/// <summary>
/// Executed when player object is destroyed.
/// </summary>
void OnDestroy();

/// <summary>
/// Executed every frame.
/// </summary>
void OnUpdate();

/// <summary>
/// Executed after all OnUpdate functions have been called.
/// </summary>
void OnLateUpdate();

/// <summary>
/// Executed with the frequency of the physics system.
/// <remarks>Unity's physics engine runs at 50hz by default.</remarks>
/// </summary>
void OnFixedUpdate();

/// <summary>
/// Gets the <see cref="UnityEngine.MonoBehaviour"/> and caches it.
/// </summary>
T GetComponent<T>(bool globalSearch = false) where T : MonoBehaviour;

/// <summary>
/// Gets the <see cref="UnityEngine.MonoBehaviour"/> and caches it.
/// </summary>
bool TryGetComponent<T>(out T component, bool globalSearch = false) where T : MonoBehaviour;
}
}
Loading
Loading