Skip to content

Commit

Permalink
dotnet format
Browse files Browse the repository at this point in the history
  • Loading branch information
CorruptComputer committed Jan 23, 2024
1 parent e5d1dee commit e054bde
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion BaldersGait/BaldersGaitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override void Load(ContainerBuilder builder)
// Services
builder.RegisterType<EnvironmentService>().As<IEnvironmentService>().SingleInstance();
builder.RegisterType<StateService>().As<IStateService>().SingleInstance();

//builder.RegisterType<PreferencesService>().As<IPreferencesService>().SingleInstance();

Check warning on line 17 in BaldersGait/BaldersGaitModule.cs

View workflow job for this annotation

GitHub Actions / Test

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)

// View Models
Expand Down
4 changes: 2 additions & 2 deletions BaldersGait/Models/State/BarberShop/BarberShopChair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class BarberShopChair

[JsonIgnore]
public bool ReadyToCollect => HairLength >= GetMaxHairLength();

public double GetHairGrowthWithScalingFactor(double baseHairGrowthPerTick)
{
return Math.Round(baseHairGrowthPerTick * HairGrowthScalingFactor, 3);
Expand All @@ -29,7 +29,7 @@ public bool IsProductionTooHigh(double baseHairGrowthPerTick)
{
return GetHairGrowthWithScalingFactor(baseHairGrowthPerTick) > GetMaxHairLength();
}

public double GetMaxHairLength()

Check warning on line 33 in BaldersGait/Models/State/BarberShop/BarberShopChair.cs

View workflow job for this annotation

GitHub Actions / Test

Remove this method and declare a constant for this value. (https://rules.sonarsource.com/csharp/RSPEC-3400)
{
// TODO: Add upgrades for this

Check warning on line 35 in BaldersGait/Models/State/BarberShop/BarberShopChair.cs

View workflow job for this annotation

GitHub Actions / Test

Complete the task associated to this 'TODO' comment. (https://rules.sonarsource.com/csharp/RSPEC-1135)
Expand Down
16 changes: 8 additions & 8 deletions BaldersGait/Models/State/BarberShopState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ public class BarberShopState
];

public int HairGrowthUpgrades { get; set; } = 0;

public int ChairScalingFactorUpgrades { get; set; } = 0;

public double HairCollected { get; set; } = 0;

public bool ClippersPurchased { get; set; } = false;


[JsonIgnore]

[JsonIgnore]
public double BaseHairPerTick => Math.Round(0.01 * (HairGrowthUpgrades + 1), 3);

public void TickMe()
{
Parallel.ForEach(Chairs.Where(x => x.Unlocked), seat =>
Expand All @@ -80,7 +80,7 @@ public void TickMe()

return;
}

// If we are full
if (seat.HairLength >= maxHairLength)
{
Expand All @@ -95,7 +95,7 @@ public void TickMe()
}
return;
}

// Else we can add it to the seats hair length
seat.HairLength = Math.Round(seat.HairLength + hairGrowth, 3);
});
Expand Down
2 changes: 1 addition & 1 deletion BaldersGait/Services/EnvironmentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public EnvironmentService()
}

_userdataDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BaldersGait");

if (!Directory.Exists(_userdataDirectory))
{
Directory.CreateDirectory(_userdataDirectory);
Expand Down
4 changes: 2 additions & 2 deletions BaldersGait/Services/Interface/IStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public interface IStateService
public BarberShopState GetBarberShopState();

public bool LoadState(bool resetState = false);

public bool SaveState();

public void TickState();
}
16 changes: 8 additions & 8 deletions BaldersGait/Services/StateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace BaldersGait.Services;
public class StateService : IStateService
{
private GameState GameState { get; set; } = new();

private const string SaveFileName = "GameState.1";
private string SaveFilePath => Path.Combine(_environmentService.GetUserdataDirectory(), SaveFileName);

private const string BackupFileName = "GameState.2";
private string BackupFilePath => Path.Combine(_environmentService.GetUserdataDirectory(), BackupFileName);

Expand All @@ -23,10 +23,10 @@ public class StateService : IStateService
public StateService(IEnvironmentService environmentService)
{
_environmentService = environmentService;

LoadState();
}

public BarberShopState GetBarberShopState()
{
return GameState.BarberShopState;
Expand Down Expand Up @@ -62,10 +62,10 @@ public bool LoadState(bool resetState = false)
}
}
}

Log.Information($"Creating new save.");
GameState = new();

return false;
}

Expand All @@ -77,15 +77,15 @@ public bool SaveState()
{
File.Move(SaveFilePath, BackupFilePath, overwrite: true);
}

File.WriteAllText(SaveFilePath, JsonSerializer.Serialize(GameState));
return true;
}
catch (Exception e) when (e is IOException)
{
Log.Error($"Error writing save.");
}

return false;
}

Expand Down
4 changes: 2 additions & 2 deletions BaldersGait/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public PanelBase CurrentPanel
this.RaiseAndSetIfChanged(ref _currentPanel, value);
}
}

public MainWindowViewModel(SidebarViewModel sidebar, IStateService stateService)
{
if (Current != null)
Expand All @@ -50,7 +50,7 @@ public MainWindowViewModel(SidebarViewModel sidebar, IStateService stateService)
SidebarButtonViewModel button = _sidebar.Buttons.First();

Check warning on line 50 in BaldersGait/ViewModels/MainWindowViewModel.cs

View workflow job for this annotation

GitHub Actions / Test

Indexing at 0 should be used instead of the "Enumerable" extension method "First" (https://rules.sonarsource.com/csharp/RSPEC-6608)
_currentPanel = button.PanelToOpen;
Log.Information($"Starting panel: {_currentPanel.PanelName}");

RxApp.TaskpoolScheduler.SchedulePeriodic(TimeSpan.FromMilliseconds(10), stateService.TickState);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class BarberShopChairViewModel(IStateService stateService, ChairNumbers c
public double MaxHair => ChairState.GetMaxHairLength();

public string HairGrowthLabel => $"Hair Growth:\n{stateService.GetBarberShopState().BaseHairPerTick * 60:F2}\" / second";

public string ScalingFactorLabel => $"Scaling factor:\nx{ChairState.HairGrowthScalingFactor}";

public string TotalGrowthLabel => $"Total Growth:\n{ChairState.GetHairGrowthWithScalingFactor(stateService.GetBarberShopState().BaseHairPerTick) * 60:F2}\" / second";

public string CurrentHairLabel => $"Current hair:\n{HairLength:F2}\" / {MaxHair:F2}\"";
Expand All @@ -38,19 +38,19 @@ public bool CutHair()

return true;
}

protected override void RefreshUIFromState()
{
this.RaisePropertyChanged(nameof(IsChairUnlocked));

this.RaisePropertyChanged(nameof(HairLength));
this.RaisePropertyChanged(nameof(MaxHair));

this.RaisePropertyChanged(nameof(HairGrowthLabel));
this.RaisePropertyChanged(nameof(ScalingFactorLabel));
this.RaisePropertyChanged(nameof(TotalGrowthLabel));
this.RaisePropertyChanged(nameof(CurrentHairLabel));

this.RaisePropertyChanged(nameof(ReadyToCollect));
this.RaisePropertyChanged(nameof(ProductionTooHigh));
}
Expand Down
24 changes: 12 additions & 12 deletions BaldersGait/ViewModels/Panels/BarberShop/BarberShopTopViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ namespace BaldersGait.ViewModels.Panels.BarberShop;

public class BarberShopTopViewModel(IStateService stateService) : ViewModelBase
{
public string PurchaseClippersButtonLabel => stateService.GetBarberShopState().ClippersPurchased ? "Clippers (purchased)" : "Purchase Clippers (500 Hair)" ;

public string PurchaseClippersButtonLabel => stateService.GetBarberShopState().ClippersPurchased ? "Clippers (purchased)" : "Purchase Clippers (500 Hair)";

public string IncreaseScalingFactorButtonLabel => $"[{stateService.GetBarberShopState().ChairScalingFactorUpgrades}] Increase Scaling Factor ({IncreaseScalingFactorCost} Hair)";
public string UnlockSeatButtonLabel => ChairsUnlocked == 8 ? "All Chairs Unlocked" : $"Unlock Chair {(ChairNumbers) ChairsUnlocked} ({UnlockChairCost} hair)";
public string UnlockSeatButtonLabel => ChairsUnlocked == 8 ? "All Chairs Unlocked" : $"Unlock Chair {(ChairNumbers)ChairsUnlocked} ({UnlockChairCost} hair)";
public string IncreaseGrowthButtonLabel => $"[{stateService.GetBarberShopState().HairGrowthUpgrades}] Increase Growth ({IncreaseGrowthCost} Hair)";

private int ChairsUnlocked => stateService.GetBarberShopState().Chairs.Count(s => s.Unlocked) + 1;
private int IncreaseScalingFactorCost => 500 * (stateService.GetBarberShopState().ChairScalingFactorUpgrades + 1);
private int UnlockChairCost => 200 * (ChairsUnlocked - 1);
Expand All @@ -32,17 +32,17 @@ public bool PurchaseClippers_Click()

return false;
}

public bool IncreaseScalingFactor_Click()
{
if (stateService.GetBarberShopState().HairCollected < IncreaseScalingFactorCost)
{
return false;
}

stateService.GetBarberShopState().HairCollected = Math.Round(stateService.GetBarberShopState().HairCollected - IncreaseScalingFactorCost, 3);
stateService.GetBarberShopState().ChairScalingFactorUpgrades++;

return true;
}

Expand All @@ -52,7 +52,7 @@ public bool UnlockChair_Click()
{
return false;
}

for (int i = stateService.GetBarberShopState().Chairs.Count(seat => seat.Unlocked); i < stateService.GetBarberShopState().Chairs.Count; i++)
{
if (!stateService.GetBarberShopState().Chairs[i].Unlocked)
Expand All @@ -65,7 +65,7 @@ public bool UnlockChair_Click()

return false;
}

public bool IncreaseGrowth_Click()
{
if (stateService.GetBarberShopState().HairCollected < IncreaseGrowthCost)
Expand All @@ -79,11 +79,11 @@ public bool IncreaseGrowth_Click()
return true;
}
#endregion

protected override void RefreshUIFromState()
{
this.RaisePropertyChanged(nameof(PurchaseClippersButtonLabel));

this.RaisePropertyChanged(nameof(IncreaseScalingFactorButtonLabel));
this.RaisePropertyChanged(nameof(UnlockSeatButtonLabel));
this.RaisePropertyChanged(nameof(IncreaseGrowthButtonLabel));
Expand Down
6 changes: 3 additions & 3 deletions BaldersGait/ViewModels/Panels/GameStatePanelViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ public bool SaveState_Click()
stateService.SaveState();
return true;
}

public bool LoadState_Click()
{
stateService.LoadState();
return true;
}

public bool ResetState_Click()
{
stateService.LoadState(resetState: true);
return true;
}
#endregion

protected override void RefreshUIFromState()
{
// Nothing to do
Expand Down
2 changes: 1 addition & 1 deletion BaldersGait/ViewModels/Panels/KnownIssuesPanelViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class KnownIssuesPanelViewModel : PanelBase
{
public override string PanelName => "Known Issues";
public override IBrush PanelButtonBackgroundColor { get; } = Brushes.SlateGray;

protected override void RefreshUIFromState()
{
// Nothing to do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class PlannedChangesPanelViewModel : PanelBase
{
public override string PanelName => "Planned Changes";
public override IBrush PanelButtonBackgroundColor { get; } = Brushes.SlateGray;

protected override void RefreshUIFromState()
{
// Nothing to do
Expand Down
2 changes: 1 addition & 1 deletion BaldersGait/ViewModels/Sidebar/SidebarButtonViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool OnClick()
Log.Information($"Opened panel: {PanelToOpen.PanelName}");
return true;
}

protected override void RefreshUIFromState()
{
this.RaisePropertyChanged(nameof(BackgroundColor));
Expand Down
6 changes: 3 additions & 3 deletions BaldersGait/ViewModels/Sidebar/SidebarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@

namespace BaldersGait.ViewModels.Sidebar;

public class SidebarViewModel(BarberShopPanelViewModel barberShopPanel, GameStatePanelViewModel gameStatePanel,
public class SidebarViewModel(BarberShopPanelViewModel barberShopPanel, GameStatePanelViewModel gameStatePanel,
PlannedChangesPanelViewModel plannedChangesPanel, KnownIssuesPanelViewModel knownIssuesPanel,
IStateService stateService)
: ViewModelBase
{
public string HairCollectedLabel => $"Hair collected:\n{stateService.GetBarberShopState().HairCollected:F2}";

public List<SidebarButtonViewModel> Buttons { get; } =
[
new(barberShopPanel),
new(gameStatePanel),
new(plannedChangesPanel),
new(knownIssuesPanel)
];

protected override void RefreshUIFromState()
{
this.RaisePropertyChanged(nameof(HairCollectedLabel));
Expand Down
2 changes: 1 addition & 1 deletion BaldersGait/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract class ViewModelBase : ReactiveObject
{
// Roughly 60 frames per second
private readonly TimeSpan _uiRefreshTimeSpan = TimeSpan.FromMilliseconds(16.66);

protected ViewModelBase()
{
RxApp.MainThreadScheduler.SchedulePeriodic(_uiRefreshTimeSpan, RefreshUIFromState);
Expand Down
2 changes: 1 addition & 1 deletion BaldersGait/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class MainWindow : Window
{
private const int SetHeight = 750;
private const int SetWidth = 1400;

public MainWindow()
{
Width = SetHeight;
Expand Down

0 comments on commit e054bde

Please sign in to comment.