push the check-synchash-doesn't-change pattern into a utility fn. furthur reduce the number of uses on Game.world

This commit is contained in:
Bob
2010-10-02 10:20:14 +12:00
committed by Paul Chote
parent f41aa474aa
commit 26d1db778e
9 changed files with 195 additions and 182 deletions

View File

@@ -6,14 +6,14 @@
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Orders;
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Orders;
using OpenRA.Traits;
namespace OpenRA.Widgets
@@ -109,9 +109,8 @@ namespace OpenRA.Widgets
public override string GetCursor(int2 pos)
{
var world = Game.world;
int sync = world.SyncHash();
try
{
return Sync.CheckSyncUnchanged( world, () =>
{
if (!world.GameHasStarted)
return "default";
@@ -122,29 +121,24 @@ namespace OpenRA.Widgets
Modifiers = Game.GetModifierKeys()
};
return Game.world.OrderGenerator.GetCursor( world, Game.viewport.ViewToWorld(mi).ToInt2(), mi );
}
finally
{
if( sync != world.SyncHash() )
throw new InvalidOperationException( "Desync in InputControllerWidget.GetCursor" );
}
return world.OrderGenerator.GetCursor( world, Game.viewport.ViewToWorld(mi).ToInt2(), mi );
} );
}
public override bool HandleKeyPressInner(KeyInput e)
{
if (e.Event == KeyInputEvent.Down)
{
if (e.KeyName.Length == 1 && char.IsDigit(e.KeyName[0]))
{
Game.world.Selection.DoControlGroup(Game.world, e.KeyName[0] - '0', e.Modifiers);
return true;
}
if (e.KeyChar == '\b')
{
GotoNextBase();
return true;
{
if (e.KeyName.Length == 1 && char.IsDigit(e.KeyName[0]))
{
Game.world.Selection.DoControlGroup(Game.world, e.KeyName[0] - '0', e.Modifiers);
return true;
}
if (e.KeyChar == '\b')
{
GotoNextBase();
return true;
}
}
return false;