Merge pull request #8839 from RoosterDragon/test-sync-implementations
Test sync implementations
This commit is contained in:
@@ -30,7 +30,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public readonly uint ActorID;
|
public readonly uint ActorID;
|
||||||
|
|
||||||
[Sync] public Player Owner { get; set; }
|
public Player Owner { get; set; }
|
||||||
|
|
||||||
public bool IsInWorld { get; internal set; }
|
public bool IsInWorld { get; internal set; }
|
||||||
public bool Disposed { get; private set; }
|
public bool Disposed { get; private set; }
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ namespace OpenRA.Traits
|
|||||||
public object Create(ActorInitializer init) { return new Shroud(init.Self); }
|
public object Create(ActorInitializer init) { return new Shroud(init.Self); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Shroud
|
public class Shroud : ISync
|
||||||
{
|
{
|
||||||
[Sync] public bool Disabled;
|
[Sync] public bool Disabled;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.Effects
|
|||||||
public IEffect Create(ProjectileArgs args) { return new GravityBomb(this, args); }
|
public IEffect Create(ProjectileArgs args) { return new GravityBomb(this, args); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GravityBomb : IEffect
|
public class GravityBomb : IEffect, ISync
|
||||||
{
|
{
|
||||||
readonly GravityBombInfo info;
|
readonly GravityBombInfo info;
|
||||||
readonly Animation anim;
|
readonly Animation anim;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
@@ -19,23 +20,43 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
{
|
{
|
||||||
public void Run(Action<string> emitError, Action<string> emitWarning)
|
public void Run(Action<string> emitError, Action<string> emitWarning)
|
||||||
{
|
{
|
||||||
/* first, check all the types implementing ISync */
|
var modTypes = Game.ModData.ObjectCreator.GetTypes();
|
||||||
foreach (var t in Game.ModData.ObjectCreator.GetTypesImplementing<ISync>())
|
CheckTypesWithSyncableMembersImplementSyncInterface(modTypes, emitWarning);
|
||||||
if (!HasAnySyncFields(t))
|
CheckTypesImplementingSyncInterfaceHaveSyncableMembers(modTypes, emitWarning);
|
||||||
emitWarning("{0} has ISync but nothing marked with [Sync]".F(t.Name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasAnySyncFields(Type t)
|
static readonly Type SyncInterface = typeof(ISync);
|
||||||
|
|
||||||
|
static bool TypeImplementsSync(Type type)
|
||||||
{
|
{
|
||||||
var flags = BindingFlags.Public | BindingFlags.NonPublic
|
return type.GetInterfaces().Contains(SyncInterface);
|
||||||
| BindingFlags.Instance;
|
}
|
||||||
|
|
||||||
var fs = t.GetFields(flags);
|
static bool AnyTypeMemberIsSynced(Type type)
|
||||||
var ps = t.GetProperties(flags);
|
{
|
||||||
|
const BindingFlags Flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly;
|
||||||
|
while (type != null)
|
||||||
|
{
|
||||||
|
if (((MemberInfo[])type.GetFields(Flags)).Concat(type.GetProperties(Flags)).Any(x => x.HasAttribute<SyncAttribute>()))
|
||||||
|
return true;
|
||||||
|
type = type.BaseType;
|
||||||
|
}
|
||||||
|
|
||||||
return fs.Any(f => f.HasAttribute<SyncAttribute>()) ||
|
return false;
|
||||||
ps.Any(p => p.HasAttribute<SyncAttribute>()) ||
|
}
|
||||||
HasAnySyncFields(t.BaseType);
|
|
||||||
|
static void CheckTypesWithSyncableMembersImplementSyncInterface(IEnumerable<Type> types, Action<string> emitWarning)
|
||||||
|
{
|
||||||
|
foreach (var type in types)
|
||||||
|
if (!TypeImplementsSync(type) && AnyTypeMemberIsSynced(type))
|
||||||
|
emitWarning("{0} has members with the Sync attribute but does not implement ISync".F(type.FullName));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void CheckTypesImplementingSyncInterfaceHaveSyncableMembers(IEnumerable<Type> types, Action<string> emitWarning)
|
||||||
|
{
|
||||||
|
foreach (var type in types)
|
||||||
|
if (TypeImplementsSync(type) && !AnyTypeMemberIsSynced(type))
|
||||||
|
emitWarning("{0} implements ISync but does not use the Sync attribute on any members.".F(type.FullName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new ExternalCapturable(init.Self, this); }
|
public object Create(ActorInitializer init) { return new ExternalCapturable(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExternalCapturable : ITick
|
public class ExternalCapturable : ITick, ISync
|
||||||
{
|
{
|
||||||
[Sync] public int CaptureProgressTime = 0;
|
[Sync] public int CaptureProgressTime = 0;
|
||||||
[Sync] public Actor Captor;
|
[Sync] public Actor Captor;
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new ParaDrop(init.Self, this); }
|
public object Create(ActorInitializer init) { return new ParaDrop(init.Self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ParaDrop : ITick, INotifyRemovedFromWorld
|
public class ParaDrop : ITick, ISync, INotifyRemovedFromWorld
|
||||||
{
|
{
|
||||||
readonly ParaDropInfo info;
|
readonly ParaDropInfo info;
|
||||||
readonly Actor self;
|
readonly Actor self;
|
||||||
|
|||||||
Reference in New Issue
Block a user