Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
feat(nurturing): add race pause threshold config
Browse files Browse the repository at this point in the history
  • Loading branch information
NateScarlet committed Jun 16, 2021
1 parent 6373dae commit 0bb3e61
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 115 deletions.
6 changes: 5 additions & 1 deletion auto_derby/jobs/nurturing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import logging
import os
import time
from typing import List, Optional

Expand Down Expand Up @@ -203,10 +204,13 @@ def _choose_running_style(ctx: Context, race1: race.Race) -> None:
action.click(pos)


_PAUSE_IF_RACE_ORDER_GT = int(os.getenv("AUTO_DERBY_PAUSE_IF_RACE_ORDER_GT", "5"))


def _handle_race(ctx: Context, race1: Optional[race.Race] = None):
race1 = race1 or _current_race(ctx)
estimate_order = race1.estimate_order(ctx)
if estimate_order > 1:
if estimate_order > _PAUSE_IF_RACE_ORDER_GT:
close_msg = window.info(
"Race estimate result is No.%d\nplease learn skills before confirm in terminal"
% estimate_order
Expand Down
237 changes: 128 additions & 109 deletions auto_derby/launcher/launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,137 +2,156 @@
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace NateScarlet.AutoDerby {
public class JobOption {
public string Label
{ get; set; }

public string Value
{ get; set; }
}
namespace NateScarlet.AutoDerby
{
public class JobOption
{
public string Label
{ get; set; }

public class JobOptions : ObservableCollection<JobOption> {
public JobOptions() {
Add(new JobOption()
{
Label = "Nurturing",
Value = "nurturing",
});
Add(new JobOption()
{
Label = "Champions meeting",
Value = "champions_meeting",
});
Add(new JobOption()
{
Label = "Team race",
Value = "team_race",
});
Add(new JobOption()
{
Label = "Daily race: Money",
Value = "daily_race_money",
});
Add(new JobOption()
{
Label = "Daily race: SP",
Value = "daily_race_sp",
});
Add(new JobOption()
{
Label = "Legend race",
Value = "legend_race",
});
Add(new JobOption()
{
Label = "Roulette derby",
Value = "roulette_derby",
});
}
}
public string Value
{ get; set; }
}

public class DataContext: INotifyPropertyChanged {
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
public class JobOptions : ObservableCollection<JobOption>
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
public JobOptions()
{
Add(new JobOption()
{
Label = "Nurturing",
Value = "nurturing",
});
Add(new JobOption()
{
Label = "Champions meeting",
Value = "champions_meeting",
});
Add(new JobOption()
{
Label = "Team race",
Value = "team_race",
});
Add(new JobOption()
{
Label = "Daily race: Money",
Value = "daily_race_money",
});
Add(new JobOption()
{
Label = "Daily race: SP",
Value = "daily_race_sp",
});
Add(new JobOption()
{
Label = "Legend race",
Value = "legend_race",
});
Add(new JobOption()
{
Label = "Roulette derby",
Value = "roulette_derby",
});
}
}

private const string RegistryPath = @"Software\NateScarlet\auto-derby";

private RegistryKey key;

public DataContext()
public class DataContext : INotifyPropertyChanged
{
this.key = Registry.CurrentUser.OpenSubKey(RegistryPath, true);
if (this.key == null)
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
this.key = Registry.CurrentUser.CreateSubKey(RegistryPath);
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}

this.JobOptions1 = new JobOptions();
}
~DataContext()
{
key.Dispose();
}
private const string RegistryPath = @"Software\NateScarlet\auto-derby";

public string DefaultSingleModeChoicesDataPath;
public string SingleModeChoicesDataPath
{
get
private RegistryKey key;

public DataContext()
{
return (string)key.GetValue("SingleModeChoicesDataPath", DefaultSingleModeChoicesDataPath);
this.key = Registry.CurrentUser.OpenSubKey(RegistryPath, true);
if (this.key == null)
{
this.key = Registry.CurrentUser.CreateSubKey(RegistryPath);
}

this.JobOptions1 = new JobOptions();
}
set
~DataContext()
{
key.SetValue("SingleModeChoicesDataPath", value);
OnPropertyChanged("SingleModeChoicesDataPath");
key.Dispose();
}
}

public string DefaultPythonExecutablePath;
public string PythonExecutablePath
{
get
{
return (string)key.GetValue("PythonExecutablePath", DefaultPythonExecutablePath);
public string DefaultSingleModeChoicesDataPath;
public string SingleModeChoicesDataPath
{
get
{
return (string)key.GetValue("SingleModeChoicesDataPath", DefaultSingleModeChoicesDataPath);
}
set
{
key.SetValue("SingleModeChoicesDataPath", value);
OnPropertyChanged("SingleModeChoicesDataPath");
}
}
set
{
key.SetValue("PythonExecutablePath", value);
OnPropertyChanged("PythonExecutablePath");

public string DefaultPythonExecutablePath;
public string PythonExecutablePath
{
get
{
return (string)key.GetValue("PythonExecutablePath", DefaultPythonExecutablePath);
}
set
{
key.SetValue("PythonExecutablePath", value);
OnPropertyChanged("PythonExecutablePath");
}
}
}

public bool Debug
{
get
{
return (int)key.GetValue("Debug", 0) != 0;
public int PauseIfRaceOrderGt
{
get
{
return (int)key.GetValue("PauseIfRaceOrderGt", 5);
}
set
{
key.SetValue("PauseIfRaceOrderGt", value, RegistryValueKind.DWord);
OnPropertyChanged("PauseIfRaceOrderGt");
}
}
set
{
key.SetValue("Debug", value, RegistryValueKind.DWord);
OnPropertyChanged("Debug");

public bool Debug
{
get
{
return (int)key.GetValue("Debug", 0) != 0;
}
set
{
key.SetValue("Debug", value, RegistryValueKind.DWord);
OnPropertyChanged("Debug");
}
}
}


public string Job {
get
{
return (string)key.GetValue("Job", "nurturing");
}
set
{
key.SetValue("Job", value);
OnPropertyChanged("Job");
public string Job
{
get
{
return (string)key.GetValue("Job", "nurturing");
}
set
{
key.SetValue("Job", value);
OnPropertyChanged("Job");
}
}

public JobOptions JobOptions1
{ get; set; }
}

public JobOptions JobOptions1
{ get; set; }
}
}
4 changes: 3 additions & 1 deletion auto_derby/launcher/launcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if (-not $mainWindow.ShowDialog()) {
Exit 0
}

$data | Format-List -Property "Job", "Debug", "PythonExecutablePath", "SingleModeChoicesDataPath", @{
$data | Format-List -Property "Job", "Debug", "PythonExecutablePath", "SingleModeChoicesDataPath", "PauseIfRaceOrderGt", @{
Name = "Version"
Expression = { $version }
}, @{
Expand Down Expand Up @@ -127,6 +127,8 @@ if ($data.SingleModeChoicesDataPath) {
$env:AUTO_DERBY_SINGLE_MODE_CHOICE_PATH = $data.SingleModeChoicesDataPath
}

$env:AUTO_DERBY_PAUSE_IF_RACE_ORDER_GT = $data.PauseIfRaceOrderGt

& cmd.exe /c "`"$($Data.PythonExecutablePath)`" -m auto_derby $($data.Job) 2>&1"

Stop-Transcript
14 changes: 11 additions & 3 deletions auto_derby/launcher/launcher.xaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Auto Derby Launcher"
Height="300"
Height="400"
Width="500"
Topmost="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition Height="60" />
<RowDefinition Height="60" />
<RowDefinition Height="60" />
<RowDefinition />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
Expand Down Expand Up @@ -52,10 +53,17 @@
SelectedValue="{Binding Job}" />
</StackPanel>


<StackPanel Grid.Row="3">
<Label>Pause if race order greater than</Label>
<TextBox Text="{Binding PauseIfRaceOrderGt, UpdateSourceTrigger=PropertyChanged}"
MaxLines="1" />
</StackPanel>

<Button x:Name="startButton"
Grid.Row="3">Start</Button>
Grid.Row="4">Start</Button>

<StackPanel Grid.Row="4"
<StackPanel Grid.Row="5"
Margin="8"
VerticalAlignment="Center">
<CheckBox IsChecked="{Binding Debug}"
Expand Down
3 changes: 2 additions & 1 deletion single_mode_choices.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
"05315737b8edbc93c502fd19502e8798": 3,
"0c57971d61cf9aa3bb221b503fd0fb89": 2,
"1eb13ec64b9140bcd339dc2748c9f22d": 1,
"763c31918bfae201e4db1424b3667e27": 2
"763c31918bfae201e4db1424b3667e27": 2,
"4f22e778830ffe6ec708cc8d552a5dfc": 2
}

0 comments on commit 0bb3e61

Please sign in to comment.