Skip to content

Commit

Permalink
Fix code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreisser committed Sep 30, 2017
1 parent bb9877e commit 0b7ee51
Show file tree
Hide file tree
Showing 20 changed files with 286 additions and 286 deletions.
28 changes: 14 additions & 14 deletions TTMouseclickSimulator/Core/Actions/CompoundAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class CompoundAction : AbstractActionContainer

private readonly Random rng = new Random();

public override sealed IList<IAction> SubActions => actionList;
public override sealed IList<IAction> SubActions => this.actionList;


/// <summary>
Expand Down Expand Up @@ -74,29 +74,29 @@ public override sealed async Task RunAsync(IInteractionProvider provider)
int[] randomOrder = null;

Func<int> getNextActionIndex;
if (type == CompoundActionType.Sequential)
if (this.type == CompoundActionType.Sequential)
getNextActionIndex = () =>
(!loop && currentIdx + 1 == actionList.Count) ? -1
: currentIdx = (currentIdx + 1) % actionList.Count;
else if (type == CompoundActionType.RandomIndex)
getNextActionIndex = () => rng.Next(actionList.Count);
(!this.loop && currentIdx + 1 == this.actionList.Count) ? -1
: currentIdx = (currentIdx + 1) % this.actionList.Count;
else if (this.type == CompoundActionType.RandomIndex)
getNextActionIndex = () => this.rng.Next(this.actionList.Count);
else
{
randomOrder = new int[actionList.Count];
randomOrder = new int[this.actionList.Count];
getNextActionIndex = () =>
{
if (!loop && currentIdx + 1 == actionList.Count)
if (!this.loop && currentIdx + 1 == this.actionList.Count)
return -1;

currentIdx = (currentIdx + 1) % actionList.Count;
currentIdx = (currentIdx + 1) % this.actionList.Count;
if (currentIdx == 0)
{
// Generate a new order array.
for (int i = 0; i < randomOrder.Length; i++)
randomOrder[i] = i;
for (int i = 0; i < randomOrder.Length; i++)
{
int rIdx = rng.Next(randomOrder.Length - i);
int rIdx = this.rng.Next(randomOrder.Length - i);
int tmp = randomOrder[i];
randomOrder[i] = randomOrder[i + rIdx];
randomOrder[i + rIdx] = tmp;
Expand Down Expand Up @@ -125,7 +125,7 @@ public override sealed async Task RunAsync(IInteractionProvider provider)
OnSubActionStartedOrStopped(nextIdx);
try
{
IAction action = actionList[nextIdx];
var action = this.actionList[nextIdx];
await action.RunAsync(provider);
}
finally
Expand All @@ -134,7 +134,7 @@ public override sealed async Task RunAsync(IInteractionProvider provider)
}

// After running an action, wait.
int waitInterval = rng.Next(minimumPauseDuration, maximumPauseDuration);
int waitInterval = this.rng.Next(this.minimumPauseDuration, this.maximumPauseDuration);
OnActionInformationUpdated($"Pausing {waitInterval} ms");

await provider.WaitAsync(waitInterval);
Expand All @@ -150,8 +150,8 @@ public override sealed async Task RunAsync(IInteractionProvider provider)
}


public override string ToString() => $"Compound – Type: {type}, "
+ $"MinPause: {minimumPauseDuration}, MaxPause: {maximumPauseDuration}, Loop: {loop}";
public override string ToString() => $"Compound – Type: {this.type}, "
+ $"MinPause: {this.minimumPauseDuration}, MaxPause: {this.maximumPauseDuration}, Loop: {this.loop}";


public enum CompoundActionType : int
Expand Down
10 changes: 5 additions & 5 deletions TTMouseclickSimulator/Core/Actions/LoopAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ public LoopAction(IAction action, int? count = null)
this.count = count;
}

public override IList<IAction> SubActions => new List<IAction>() { action };
public override IList<IAction> SubActions => new List<IAction>() { this.action };

public override sealed async Task RunAsync(IInteractionProvider provider)
{
OnSubActionStartedOrStopped(0);
try
{
for (int i = 0; !count.HasValue || i < count.Value; i++)
for (int i = 0; !this.count.HasValue || i < this.count.Value; i++)
{
for (;;)
{
try
{
provider.EnsureNotCanceled();
OnActionInformationUpdated($"Iteration {i + 1}/{count?.ToString() ?? "∞"}");
await action.RunAsync(provider);
OnActionInformationUpdated($"Iteration {i + 1}/{this.count?.ToString() ?? "∞"}");
await this.action.RunAsync(provider);
}
catch (Exception ex) when (!(ex is SimulatorCanceledException))
{
Expand All @@ -61,6 +61,6 @@ public override sealed async Task RunAsync(IInteractionProvider provider)
}


public override string ToString() => $"Loop – Count: {count?.ToString() ?? "∞"}";
public override string ToString() => $"Loop – Count: {this.count?.ToString() ?? "∞"}";
}
}
8 changes: 4 additions & 4 deletions TTMouseclickSimulator/Core/Environment/IScreenshotContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ public byte GetValueFromIndex(int index)
{
switch (index) {
case 0:
return r;
return this.r;
case 1:
return g;
return this.g;
case 2:
return b;
return this.b;
default:
throw new ArgumentOutOfRangeException(nameof(index));
}
}

public System.Windows.Media.Color ToColor() => System.Windows.Media.Color.FromArgb(255, r, g, b);
public System.Windows.Media.Color ToColor() => System.Windows.Media.Color.FromArgb(255, this.r, this.g, this.b);
}
}
4 changes: 2 additions & 2 deletions TTMouseclickSimulator/Core/Environment/WindowParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct WindowPosition
public Size Size { get; set; }


public Coordinates RelativeToAbsoluteCoordinates(Coordinates c) => Coordinates.Add(c);
public Coordinates RelativeToAbsoluteCoordinates(Coordinates c) => this.Coordinates.Add(c);
}

public struct Coordinates
Expand All @@ -31,7 +31,7 @@ public Coordinates(int x, int y)
this.Y = y;
}

public Coordinates Add(Coordinates c) => new Coordinates(X + c.X, Y + c.Y);
public Coordinates Add(Coordinates c) => new Coordinates(this.X + c.X, this.Y + c.Y);
}

public struct Size
Expand Down
18 changes: 9 additions & 9 deletions TTMouseclickSimulator/Core/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Simulator(IntPtr windowHandle, IAction mainAction, AbstractWindowsEnviron
this.mainAction = mainAction;
this.environmentInterface = environmentInterface;

provider = new StandardInteractionProvider(this, windowHandle, environmentInterface, out cancelCallback);
this.provider = new StandardInteractionProvider(this, windowHandle, environmentInterface, out this.cancelCallback);
}

/// <summary>
Expand All @@ -47,31 +47,31 @@ public Simulator(IntPtr windowHandle, IAction mainAction, AbstractWindowsEnviron
/// <returns></returns>
public async Task RunAsync()
{
if (canceled)
if (this.canceled)
throw new InvalidOperationException("The simulator has already been canceled.");

try
{
using (provider)
using (this.provider)
{
OnSimulatorStarted();

// InitializeAsync() does not need to be in the try block because it has its own.
await provider.InitializeAsync();
await this.provider.InitializeAsync();

for (;;)
{
try
{
// Run the action.
await mainAction.RunAsync(provider);
await this.mainAction.RunAsync(this.provider);

// Normally the main action would be a CompoundAction that never returns, but
// it is possible that the action will return normally.
}
catch (Exception ex) when (!(ex is SimulatorCanceledException))
{
await provider.CheckRetryForExceptionAsync(ExceptionDispatchInfo.Capture(ex));
await this.provider.CheckRetryForExceptionAsync(ExceptionDispatchInfo.Capture(ex));
continue;
}
break;
Expand All @@ -81,7 +81,7 @@ public async Task RunAsync()
}
finally
{
canceled = true;
this.canceled = true;
OnSimulatorStopped();
}
}
Expand All @@ -93,8 +93,8 @@ public async Task RunAsync()
/// </summary>
public void Cancel()
{
canceled = true;
cancelCallback();
this.canceled = true;
this.cancelCallback();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public DoodlePanelAction(DoodlePanelButton button)

public override async Task RunAsync(IInteractionProvider provider)
{
Coordinates c = new Coordinates(1397, 206 + (int)button * 49);
var c = new Coordinates(1397, 206 + (int)this.button * 49);
await MouseHelpers.DoSimpleMouseClickAsync(provider, c, VerticalScaleAlignment.Right);
}


public override string ToString() => $"Doodle Panel – Button: {button}";
public override string ToString() => $"Doodle Panel – Button: {this.button}";


public enum DoodlePanelButton : int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,18 @@ public override sealed async Task RunAsync(IInteractionProvider provider)
// Then, wait until we find a window displaying the caught fish
// or the specified number of seconds has passed.
OnActionInformationUpdated("Waiting for the fish result dialog…");
Stopwatch sw = new Stopwatch();
var sw = new Stopwatch();
sw.Start();

bool found = false;
while (!found && sw.ElapsedMilliseconds <= WaitingForFishResultDialogTime)
while (!found && sw.ElapsedMilliseconds <= this.WaitingForFishResultDialogTime)
{
await provider.WaitAsync(500);

// Get a current screenshot.
var screenshot = provider.GetCurrentWindowScreenshot();

foreach (Coordinates c in fishResultDialogCoordinates)
foreach (var c in fishResultDialogCoordinates)
{
var cc = screenshot.WindowPosition.ScaleCoordinates(
c, MouseHelpers.ReferenceWindowSize);
Expand All @@ -93,7 +93,7 @@ public override sealed async Task RunAsync(IInteractionProvider provider)
/// <returns></returns>
protected async Task StartCastFishingRodAsync(IInteractionProvider provider)
{
Coordinates coords = new Coordinates(800, 846);
var coords = new Coordinates(800, 846);
var pos = provider.GetCurrentWindowPosition();
coords = pos.ScaleCoordinates(coords,
MouseHelpers.ReferenceWindowSize);
Expand Down Expand Up @@ -168,21 +168,21 @@ public byte GetValueFromIndex(int index)
switch (index)
{
case 0:
return ToleranceR;
return this.ToleranceR;
case 1:
return ToleranceG;
return this.ToleranceG;
case 2:
return ToleranceB;
return this.ToleranceB;
default:
throw new ArgumentOutOfRangeException(nameof(index));
}
}

public Tolerance(byte toleranceR, byte toleranceG, byte toleranceB)
{
ToleranceR = toleranceR;
ToleranceG = toleranceG;
ToleranceB = toleranceB;
this.ToleranceR = toleranceR;
this.ToleranceG = toleranceG;
this.ToleranceB = toleranceB;
}

public Tolerance(byte tolerance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AutomaticFishingAction : AbstractFishingRodAction

public AutomaticFishingAction(int[] scan1, int[] scan2, byte[] bubbleColorRgb, byte[] toleranceRgb)
{
spotData = new FishingSpotData(
this.spotData = new FishingSpotData(
new Coordinates(scan1[0], scan1[1]),
new Coordinates(scan2[0], scan2[1]),
new ScreenshotColor(bubbleColorRgb[0], bubbleColorRgb[1], bubbleColorRgb[2]),
Expand Down Expand Up @@ -43,15 +43,15 @@ protected override sealed async Task FinishCastFishingRodAsync(IInteractionProvi
// TODO: The fish bubble detection should be changed so that it does not scan
// for a specific color, but instead checks that for a point if the color is
// darker than the neighbor pixels (in some distance).
for (int y = spotData.Scan1.Y; y <= spotData.Scan2.Y && !newCoords.HasValue; y += scanStep)
for (int y = this.spotData.Scan1.Y; y <= this.spotData.Scan2.Y && !newCoords.HasValue; y += scanStep)
{
for (int x = spotData.Scan1.X; x <= spotData.Scan2.X; x += scanStep)
for (int x = this.spotData.Scan1.X; x <= this.spotData.Scan2.X; x += scanStep)
{
var c = new Coordinates(x, y);
c = screenshot.WindowPosition.ScaleCoordinates(c,
MouseHelpers.ReferenceWindowSize);
if (CompareColor(spotData.BubbleColor, screenshot.GetPixel(c),
spotData.Tolerance))
if (CompareColor(this.spotData.BubbleColor, screenshot.GetPixel(c),
this.spotData.Tolerance))
{
newCoords = new Coordinates(x + 20, y + 20);
var scaledCoords = screenshot.WindowPosition.ScaleCoordinates(
Expand Down Expand Up @@ -132,6 +132,6 @@ protected override sealed async Task FinishCastFishingRodAsync(IInteractionProvi


public override string ToString() => $"Automatic Fishing – "
+ $"Color: [{spotData.BubbleColor.r}, {spotData.BubbleColor.g}, {spotData.BubbleColor.b}]";
+ $"Color: [{this.spotData.BubbleColor.r}, {this.spotData.BubbleColor.g}, {this.spotData.BubbleColor.b}]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class QuitFishingAction : AbstractAction
{
public override sealed async Task RunAsync(IInteractionProvider provider)
{
Coordinates c = new Coordinates(1503, 1086);
var c = new Coordinates(1503, 1086);
await MouseHelpers.DoSimpleMouseClickAsync(provider, c);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class SellFishAction : AbstractAction
{
public override sealed async Task RunAsync(IInteractionProvider provider)
{
Coordinates c = new Coordinates(1159, 911);
var c = new Coordinates(1159, 911);
await MouseHelpers.DoSimpleMouseClickAsync(provider, c);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class StraightFishingAction : AbstractFishingRodAction
protected override sealed async Task FinishCastFishingRodAsync(IInteractionProvider provider)
{
// Simply cast the fishing rod straight, without checking for bubbles.
Coordinates coords = new Coordinates(800, 1009);
var coords = new Coordinates(800, 1009);
var pos = provider.GetCurrentWindowPosition();
coords = pos.ScaleCoordinates(coords,
MouseHelpers.ReferenceWindowSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override sealed async Task RunAsync(IInteractionProvider provider)
await provider.WaitAsync(200);

// Click on the jellybean fields.
foreach (int jellybean in jellybeanCombination)
foreach (int jellybean in this.jellybeanCombination)
{
var c = new Coordinates((int)Math.Round(560 + jellybean * 60.5), 514);
await MouseHelpers.DoSimpleMouseClickAsync(provider, c,
Expand All @@ -56,12 +56,12 @@ await MouseHelpers.DoSimpleMouseClickAsync(provider, c,

public override string ToString()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < jellybeanCombination.Length; i++)
var sb = new StringBuilder();
for (int i = 0; i < this.jellybeanCombination.Length; i++)
{
if (i > 0)
sb.Append(", ");
sb.Append(jellybeanColors[jellybeanCombination[i]]);
sb.Append(jellybeanColors[this.jellybeanCombination[i]]);
}

return $"Plant Flower – JellyBeans: {sb.ToString()}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public PressKeyAction(AbstractWindowsEnvironment.VirtualKeyShort key, int durati

public override sealed async Task RunAsync(IInteractionProvider provider)
{
provider.PressKey(key);
provider.PressKey(this.key);
// Use a accurate timer for measuring the time after we need to release the key.
await provider.WaitAsync(duration, true);
provider.ReleaseKey(key);
await provider.WaitAsync(this.duration, true);
provider.ReleaseKey(this.key);
}


public override string ToString() => $"Press Key – Key: {key}, Duration: {duration}";
public override string ToString() => $"Press Key – Key: {this.key}, Duration: {this.duration}";
}
}
Loading

0 comments on commit 0b7ee51

Please sign in to comment.