Prepare DeveloperMode code for trait-defined lobby options.

This commit is contained in:
Paul Chote
2016-04-20 09:20:42 +02:00
parent 1eba0bea13
commit 7e49ae7eb0
6 changed files with 134 additions and 117 deletions

View File

@@ -59,16 +59,26 @@ namespace OpenRA.Traits
public object Create(ActorInitializer init) { return new DeveloperMode(this); } public object Create(ActorInitializer init) { return new DeveloperMode(this); }
} }
public class DeveloperMode : IResolveOrder, ISync public class DeveloperMode : IResolveOrder, ISync, INotifyCreated
{ {
DeveloperModeInfo info; readonly DeveloperModeInfo info;
[Sync] public bool FastCharge; public bool Enabled { get; private set; }
[Sync] public bool AllTech;
[Sync] public bool FastBuild; [Sync] bool fastCharge;
[Sync] public bool DisableShroud; [Sync] bool allTech;
[Sync] public bool PathDebug; [Sync] bool fastBuild;
[Sync] public bool UnlimitedPower; [Sync] bool disableShroud;
[Sync] public bool BuildAnywhere; [Sync] bool pathDebug;
[Sync] bool unlimitedPower;
[Sync] bool buildAnywhere;
public bool FastCharge { get { return Enabled && fastCharge; } }
public bool AllTech { get { return Enabled && allTech; } }
public bool FastBuild { get { return Enabled && fastBuild; } }
public bool DisableShroud { get { return Enabled && disableShroud; } }
public bool PathDebug { get { return Enabled && pathDebug; } }
public bool UnlimitedPower { get { return Enabled && unlimitedPower; } }
public bool BuildAnywhere { get { return Enabled && buildAnywhere; } }
// Client side only // Client side only
public bool ShowCombatGeometry; public bool ShowCombatGeometry;
@@ -76,36 +86,42 @@ namespace OpenRA.Traits
public bool ShowDepthPreview; public bool ShowDepthPreview;
public bool ShowActorTags; public bool ShowActorTags;
public bool EnableAll; bool enableAll;
public DeveloperMode(DeveloperModeInfo info) public DeveloperMode(DeveloperModeInfo info)
{ {
this.info = info; this.info = info;
FastBuild = info.FastBuild; fastBuild = info.FastBuild;
FastCharge = info.FastCharge; fastCharge = info.FastCharge;
DisableShroud = info.DisableShroud; disableShroud = info.DisableShroud;
PathDebug = info.PathDebug; pathDebug = info.PathDebug;
UnlimitedPower = info.UnlimitedPower; unlimitedPower = info.UnlimitedPower;
BuildAnywhere = info.BuildAnywhere; buildAnywhere = info.BuildAnywhere;
ShowCombatGeometry = info.ShowCombatGeometry; ShowCombatGeometry = info.ShowCombatGeometry;
ShowDebugGeometry = info.ShowDebugGeometry; ShowDebugGeometry = info.ShowDebugGeometry;
ShowDepthPreview = info.ShowDepthPreview; ShowDepthPreview = info.ShowDepthPreview;
ShowActorTags = info.ShowActorTags; ShowActorTags = info.ShowActorTags;
} }
void INotifyCreated.Created(Actor self)
{
Enabled = self.World.LobbyInfo.GlobalSettings.AllowCheats || self.World.LobbyInfo.IsSinglePlayer;
}
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
{ {
if (!self.World.AllowDevCommands) if (!Enabled)
return; return;
switch (order.OrderString) switch (order.OrderString)
{ {
case "DevAll": case "DevAll":
{ {
EnableAll ^= true; enableAll ^= true;
AllTech = FastCharge = FastBuild = DisableShroud = UnlimitedPower = BuildAnywhere = EnableAll; allTech = fastCharge = fastBuild = disableShroud = unlimitedPower = buildAnywhere = enableAll;
if (EnableAll) if (enableAll)
{ {
self.Owner.Shroud.ExploreAll(); self.Owner.Shroud.ExploreAll();
@@ -126,19 +142,19 @@ namespace OpenRA.Traits
case "DevEnableTech": case "DevEnableTech":
{ {
AllTech ^= true; allTech ^= true;
break; break;
} }
case "DevFastCharge": case "DevFastCharge":
{ {
FastCharge ^= true; fastCharge ^= true;
break; break;
} }
case "DevFastBuild": case "DevFastBuild":
{ {
FastBuild ^= true; fastBuild ^= true;
break; break;
} }
@@ -162,7 +178,7 @@ namespace OpenRA.Traits
case "DevVisibility": case "DevVisibility":
{ {
DisableShroud ^= true; disableShroud ^= true;
self.Owner.Shroud.Disabled = DisableShroud; self.Owner.Shroud.Disabled = DisableShroud;
if (self.World.LocalPlayer == self.Owner) if (self.World.LocalPlayer == self.Owner)
self.World.RenderPlayer = DisableShroud ? null : self.Owner; self.World.RenderPlayer = DisableShroud ? null : self.Owner;
@@ -171,7 +187,7 @@ namespace OpenRA.Traits
case "DevPathDebug": case "DevPathDebug":
{ {
PathDebug ^= true; pathDebug ^= true;
break; break;
} }
@@ -189,13 +205,13 @@ namespace OpenRA.Traits
case "DevUnlimitedPower": case "DevUnlimitedPower":
{ {
UnlimitedPower ^= true; unlimitedPower ^= true;
break; break;
} }
case "DevBuildAnywhere": case "DevBuildAnywhere":
{ {
BuildAnywhere ^= true; buildAnywhere ^= true;
break; break;
} }

View File

@@ -85,11 +85,6 @@ namespace OpenRA
get { return OrderManager.Connection is ReplayConnection; } get { return OrderManager.Connection is ReplayConnection; }
} }
public bool AllowDevCommands
{
get { return LobbyInfo.GlobalSettings.AllowCheats || LobbyInfo.IsSinglePlayer; }
}
void SetLocalPlayer(Player localPlayer) void SetLocalPlayer(Player localPlayer)
{ {
if (localPlayer == null) if (localPlayer == null)

View File

@@ -24,10 +24,15 @@ namespace OpenRA.Mods.Common.Commands
public class DevCommands : IChatCommand, IWorldLoaded public class DevCommands : IChatCommand, IWorldLoaded
{ {
World world; World world;
DeveloperMode developerMode;
public void WorldLoaded(World w, WorldRenderer wr) public void WorldLoaded(World w, WorldRenderer wr)
{ {
world = w; world = w;
if (world.LocalPlayer != null)
developerMode = world.LocalPlayer.PlayerActor.Trait<DeveloperMode>();
var console = world.WorldActor.Trait<ChatCommands>(); var console = world.WorldActor.Trait<ChatCommands>();
var help = world.WorldActor.Trait<HelpCommand>(); var help = world.WorldActor.Trait<HelpCommand>();
@@ -55,7 +60,7 @@ namespace OpenRA.Mods.Common.Commands
if (world.LocalPlayer == null) if (world.LocalPlayer == null)
return; return;
if (!world.AllowDevCommands) if (!developerMode.Enabled)
{ {
Game.Debug("Cheats are disabled."); Game.Debug("Cheats are disabled.");
return; return;

View File

@@ -97,11 +97,12 @@ namespace OpenRA.Mods.Common.Traits
public void ResolveOrder(Actor self, Order order) public void ResolveOrder(Actor self, Order order)
{ {
if (!self.World.AllowDevCommands)
return;
if (order.OrderString == "DevLevelUp") if (order.OrderString == "DevLevelUp")
{ {
var developerMode = self.Owner.PlayerActor.Trait<DeveloperMode>();
if (!developerMode.Enabled)
return;
if ((int)order.ExtraData > 0) if ((int)order.ExtraData > 0)
GiveLevels((int)order.ExtraData); GiveLevels((int)order.ExtraData);
else else

View File

@@ -125,7 +125,7 @@ namespace OpenRA.Mods.Common.Traits
public override int GetBuildTime(ActorInfo unit, BuildableInfo bi = null) public override int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
{ {
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) if (developerMode.FastBuild)
return 0; return 0;
var time = unit.GetBuildTime() * Info.BuildSpeed / 100; var time = unit.GetBuildTime() * Info.BuildSpeed / 100;

View File

@@ -204,7 +204,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual IEnumerable<ActorInfo> AllItems() public virtual IEnumerable<ActorInfo> AllItems()
{ {
if (self.World.AllowDevCommands && developerMode.AllTech) if (developerMode.AllTech)
return producible.Keys; return producible.Keys;
return allProducibles; return allProducibles;
@@ -214,7 +214,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
if (!Enabled) if (!Enabled)
return Enumerable.Empty<ActorInfo>(); return Enumerable.Empty<ActorInfo>();
if (self.World.AllowDevCommands && developerMode.AllTech) if (developerMode.AllTech)
return producible.Keys; return producible.Keys;
return buildableProducibles; return buildableProducibles;
@@ -226,7 +226,7 @@ namespace OpenRA.Mods.Common.Traits
if (!producible.TryGetValue(actor, out ps)) if (!producible.TryGetValue(actor, out ps))
return false; return false;
return ps.Buildable || (self.World.AllowDevCommands && developerMode.AllTech); return ps.Buildable || developerMode.AllTech;
} }
public virtual void Tick(Actor self) public virtual void Tick(Actor self)
@@ -316,7 +316,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi = null) public virtual int GetBuildTime(ActorInfo unit, BuildableInfo bi = null)
{ {
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild) if (developerMode.FastBuild)
return 0; return 0;
var time = unit.GetBuildTime() * Info.BuildSpeed / 100; var time = unit.GetBuildTime() * Info.BuildSpeed / 100;