Skip to content

Commit

Permalink
Add Post-process delay for profile (new migration);
Browse files Browse the repository at this point in the history
Naming in profile runner;
Update SharpHook;
  • Loading branch information
Neakita committed Sep 26, 2023
1 parent 34ab4d8 commit 5e9f188
Show file tree
Hide file tree
Showing 21 changed files with 739 additions and 19 deletions.
2 changes: 1 addition & 1 deletion SharpHook.Test/SharpHook.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SharpHook" Version="4.2.1" />
<PackageReference Include="SharpHook" Version="5.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ public sealed class NewProfileDataDTO : NewProfileData
public string Description { get; }
public float DetectionThreshold { get; }
public float MouseSensitivity { get; }
public TimeSpan PostProcessDelay { get; }
public Weights Weights { get; }
public IReadOnlyList<ItemClass> ItemClasses { get; }

public NewProfileDataDTO(string name, string description, float detectionThreshold, float mouseSensitivity, Weights weights, IEnumerable<ItemClass> itemClasses)
public NewProfileDataDTO(string name, string description, float detectionThreshold, float mouseSensitivity, TimeSpan postProcessDelay, Weights weights, IEnumerable<ItemClass> itemClasses)
{
Name = name;
Description = description;
DetectionThreshold = detectionThreshold;
MouseSensitivity = mouseSensitivity;
PostProcessDelay = postProcessDelay;
Weights = weights;
ItemClasses = itemClasses.ToImmutableList();
}
Expand Down
2 changes: 1 addition & 1 deletion SightKeeper.Application/Profile/Creating/ProfileCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ProfileCreator(IValidator<NewProfileData> validator, ProfilesDataAccess p
public async Task<Profile> CreateProfile(NewProfileDataDTO data)
{
await _validator.ValidateAndThrowAsync(data);
Profile profile = new(data.Name, data.Description, data.DetectionThreshold, data.MouseSensitivity, data.Weights);
Profile profile = new(data.Name, data.Description, data.DetectionThreshold, data.MouseSensitivity, data.PostProcessDelay, data.Weights);
foreach (var itemClass in data.ItemClasses)
profile.AddItemClass(itemClass);
await _profilesDataAccess.AddProfile(profile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ public sealed class EditedProfileDataDTO : EditedProfileData
public string Description { get; }
public float DetectionThreshold { get; }
public float MouseSensitivity { get; }
public TimeSpan PostProcessDelay { get; }
public Weights Weights { get; }
public IReadOnlyList<ItemClass> ItemClasses { get; }

public EditedProfileDataDTO(Profile profile, string name, string description, float detectionThreshold, float mouseSensitivity, Weights weights, IEnumerable<ItemClass> itemClasses)
public EditedProfileDataDTO(Profile profile, string name, string description, float detectionThreshold, float mouseSensitivity, TimeSpan postProcessDelay, Weights weights, IEnumerable<ItemClass> itemClasses)
{
Profile = profile;
Name = name;
Description = description;
DetectionThreshold = detectionThreshold;
MouseSensitivity = mouseSensitivity;
PostProcessDelay = postProcessDelay;
Weights = weights;
ItemClasses = itemClasses.ToImmutableList();
}
Expand Down
1 change: 1 addition & 0 deletions SightKeeper.Application/Profile/Editing/ProfileEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public async Task ApplyChanges(EditedProfileDataDTO data)
profile.Description = data.Description;
profile.DetectionThreshold = data.DetectionThreshold;
profile.MouseSensitivity = data.MouseSensitivity;
profile.PostProcessDelay = data.PostProcessDelay;
profile.Weights = data.Weights;
profile.ClearItemClasses();
foreach (var itemClass in data.ItemClasses)
Expand Down
1 change: 1 addition & 0 deletions SightKeeper.Application/Profile/ProfileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface ProfileData
string Description { get; }
float DetectionThreshold { get; }
float MouseSensitivity { get; }
TimeSpan PostProcessDelay { get; }
Weights? Weights { get; }
IReadOnlyList<ItemClass> ItemClasses { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ public float MouseSensitivity
set => SetProperty(ref _mouseSensitivity, value);
}

public TimeSpan PostProcessDelay
{
get => _postProcessDelay;
set => SetProperty(ref _postProcessDelay, value);
}

ushort ProfileEditorViewModel.PostProcessDelay
{
get => (ushort)_postProcessDelay.TotalMilliseconds;
set => SetProperty(PostProcessDelay.TotalMilliseconds, value, newValue => _postProcessDelay = TimeSpan.FromMilliseconds(newValue));
}

public DataSet? DataSet
{
get => _dataSet;
Expand Down Expand Up @@ -112,7 +124,7 @@ protected AbstractProfileEditorVIewModel(IValidator<TProfileData> validator, Dat
private IReadOnlyCollection<Weights> _availableWeights = Array.Empty<Weights>();
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(AddItemClassCommand))]
private ItemClass? _itemClassToAdd;

private TimeSpan _postProcessDelay;

ICommand ProfileEditorViewModel.AddItemClassCommand => AddItemClassCommand;
[RelayCommand(CanExecute = nameof(CanAddItemClass))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public void SetData(Profile profile)
Description = profile.Description;
DetectionThreshold = profile.DetectionThreshold;
MouseSensitivity = profile.MouseSensitivity;
PostProcessDelay = profile.PostProcessDelay;
DataSet = profile.Weights.Library.DataSet;
Weights = profile.Weights;
_itemClasses.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public sealed partial class FakeProfileEditorViewModel : ViewModel, ProfileEdito
public string Description { get; set; } = "Some description.. lorem ipsum and all that stuff";
[ObservableProperty] private float _detectionThreshold = 0.6f;
[ObservableProperty] private float _mouseSensitivity = 1.5f;
public ushort PostProcessDelay { get; set; }
public DataSet? DataSet { get; set; }
public Weights? Weights { get; set; }
public IReadOnlyList<ItemClass> ItemClasses { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface ProfileEditorViewModel
string Description { get; set; }
float DetectionThreshold { get; set; }
float MouseSensitivity { get; set; }
ushort PostProcessDelay { get; set; }
DataSet? DataSet { get; set; }
Weights? Weights { get; set; }
IReadOnlyList<ItemClass> ItemClasses { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public FakeProfilesViewModel()
dataSet.Game = game;
var weights = dataSet.WeightsLibrary.CreateWeights(Array.Empty<byte>(), Array.Empty<byte>(), ModelSize.Small,
100, 0.5f, 0.4f, 0.3f, Enumerable.Empty<Asset>());
Profile profile1 = new("Profile", string.Empty, 0.5f, 2f, weights);
Profile profile2 = new("Profile with long name!", string.Empty, 0.3f, 3f, weights);
Profile profile1 = new("Profile", string.Empty, 0.5f, 2f, TimeSpan.FromMilliseconds(10), weights);
Profile profile2 = new("Profile with long name!", string.Empty, 0.3f, 3f, TimeSpan.FromMilliseconds(15), weights);
Profiles = new ProfileViewModel[]
{
new(profile1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private async Task CreateProfile()
if (result == ProfileEditorResult.Apply)
{
Guard.IsNotNull(viewModel.Weights);
NewProfileDataDTO data = new(viewModel.Name, viewModel.Description, viewModel.DetectionThreshold, viewModel.MouseSensitivity, viewModel.Weights, viewModel.ItemClasses);
NewProfileDataDTO data = new(viewModel.Name, viewModel.Description, viewModel.DetectionThreshold, viewModel.MouseSensitivity, viewModel.PostProcessDelay, viewModel.Weights, viewModel.ItemClasses);
await _profileCreator.CreateProfile(data);
}
}
Expand All @@ -91,7 +91,7 @@ private async Task EditProfile(ProfileViewModel profileViewModel)
if (result == ProfileEditorResult.Apply)
{
Guard.IsNotNull(viewModel.Weights);
EditedProfileDataDTO data = new(profileViewModel.Profile, viewModel.Name, viewModel.Description, viewModel.DetectionThreshold, viewModel.MouseSensitivity, viewModel.Weights, viewModel.ItemClasses);
EditedProfileDataDTO data = new(profileViewModel.Profile, viewModel.Name, viewModel.Description, viewModel.DetectionThreshold, viewModel.MouseSensitivity, viewModel.PostProcessDelay, viewModel.Weights, viewModel.ItemClasses);
await _profileEditor.ApplyChanges(data);
}
else if (result == ProfileEditorResult.Delete)
Expand Down
17 changes: 17 additions & 0 deletions SightKeeper.Avalonia/Views/Profiles/ProfileEditor.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@
Maximum="5"
Value="{Binding MouseSensitivity}"/>
</Grid>
<Grid ColumnDefinitions="Auto *">
<NumericUpDown Grid.Column="0"
Watermark="Post-process delay"
Value="{Binding PostProcessDelay}"
Minimum="0"
Maximum="100"
FormatString="{}{0} ms"
Increment="1"/>
<Slider Grid.Column="1"
Minimum="0"
IsSnapToTickEnabled="True"
TickFrequency="5"
TickPlacement="Outside"
Maximum="100"
Value="{Binding PostProcessDelay}"
ToolTip.Tip="{Binding PostProcessDelay, StringFormat=Post-process delay: {0} milliseconds}"/>
</Grid>
<StackPanel Orientation="Horizontal">
<ComboBox ItemsSource="{Binding AvailableItemClasses}"
SelectedItem="{Binding ItemClassToAdd}"/>
Expand Down
3 changes: 3 additions & 0 deletions SightKeeper.Data/Configuration/ProfileConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ public void Configure(EntityTypeBuilder<Profile> builder)
builder.HasIndex(profile => profile.Name).IsUnique();
builder.Navigation(profile => profile.Weights).AutoInclude();
builder.Navigation(profile => profile.ItemClasses).AutoInclude();
builder.Property(profile => profile.PostProcessDelay).HasConversion(
timeSpan => (ushort)timeSpan.TotalMilliseconds,
number => TimeSpan.FromMilliseconds(number));
}
}
Loading

0 comments on commit 5e9f188

Please sign in to comment.