Skip to content

Commit

Permalink
Merge pull request #248 from Toufool/dev
Browse files Browse the repository at this point in the history
v2.2.0 release
  • Loading branch information
Avasam authored Jul 21, 2023
2 parents dbf50f9 + 2287470 commit 30e46ae
Show file tree
Hide file tree
Showing 45 changed files with 2,307 additions and 1,645 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
python-version: "3.11"
- run: pip install add-trailing-comma
- name: Analysing the code with add-trailing-comma
run: add-trailing-comma $(git ls-files '**.py*') --py36-plus
run: add-trailing-comma $(git ls-files '**.py*')
Pyright:
runs-on: windows-latest
strategy:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
__pycache__/

# Distribution / packaging
.venv/
env/
build/
dist/
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
# Workaround for https://github.com/adamchainz/pre-commit-dprint/issues/4
- id: pretty-format-json
exclude: ".vscode/.*|dprint.json" # Exclude jsonc
exclude: ".vscode/.*" # Exclude jsonc
args: [--autofix, --no-sort-keys]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
Expand All @@ -18,7 +17,7 @@ repos:
- id: pretty-format-ini
args: [--autofix]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.0.269" # Must match requirements-dev.txt
rev: "v0.0.276" # Must match requirements-dev.txt
hooks:
- id: ruff
args: [--fix]
Expand All @@ -27,11 +26,12 @@ repos:
hooks:
- id: autopep8
- repo: https://github.com/asottile/add-trailing-comma
rev: v2.4.0 # Must match requirements-dev.txt
rev: v3.0.0 # Must match requirements-dev.txt
hooks:
- id: add-trailing-comma

ci:
autoupdate_branch: dev
skip:
# Ignore until Linux support. We don't want lf everywhere yet
# And crlf fails on CI because pre-commit runs on linux
Expand Down
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Keep in alphabetical order
{
"recommendations": [
"bungcip.better-toml",
"davidanson.vscode-markdownlint",
"eamodio.gitlens",
"emeraldwalk.runonsave",
Expand All @@ -13,11 +12,14 @@
"pkief.material-icon-theme",
"redhat.vscode-xml",
"redhat.vscode-yaml",
"tamasfe.even-better-toml",
],
"unwantedRecommendations": [
// Must disable in this workspace //
// https://github.com/microsoft/vscode/issues/40239 //
//
// even-better-toml has format on save
"bungcip.better-toml",
// VSCode has implemented an optimized version
"coenraads.bracket-pair-colorizer",
"coenraads.bracket-pair-colorizer-2",
Expand Down
39 changes: 35 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"commands": [
{
"match": "\\.pyi?",
"cmd": "add-trailing-comma ${file} --py36-plus"
"cmd": "add-trailing-comma ${file}"
},
]
},
Expand All @@ -45,9 +45,14 @@
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"build": true,
"**/.mypy_cache": true,
"**/.*_cache": true, // mypy and Ruff cache
"**/__pycache__": true,
// Only show useful PyInstaller logs
"build/*.*": true,
"build/[b-z]*": true,
"build/**/localpycs": true,
"build/**/Tree-*": true,
"build/**/*.{manifest,pkg,zip,tcl,res,pyz}": true,
},
"search.exclude": {
"**/*.code-search": true,
Expand All @@ -69,6 +74,12 @@
120, // Our hard rule
],
},
"mypy-type-checker.importStrategy": "fromEnvironment",
"mypy-type-checker.args": [
// https://github.com/microsoft/vscode-mypy/issues/37#issuecomment-1602702174
"--config-file=mypy.ini",
],
"python.terminal.activateEnvironment": true,
// Important to follow the config in pyrightconfig.json
"python.analysis.useLibraryCodeForTypes": false,
"python.analysis.diagnosticMode": "workspace",
Expand Down Expand Up @@ -109,5 +120,25 @@
"xd:pre",
// Custom
"string"
]
],
"[toml]": {
"editor.defaultFormatter": "tamasfe.even-better-toml"
},
"evenBetterToml.formatter.alignComments": false,
"evenBetterToml.formatter.alignEntries": false,
"evenBetterToml.formatter.allowedBlankLines": 1,
"evenBetterToml.formatter.arrayAutoCollapse": true,
"evenBetterToml.formatter.arrayAutoExpand": true,
"evenBetterToml.formatter.arrayTrailingComma": true,
"evenBetterToml.formatter.columnWidth": 80,
"evenBetterToml.formatter.compactArrays": true,
"evenBetterToml.formatter.compactEntries": false,
"evenBetterToml.formatter.compactInlineTables": false,
"evenBetterToml.formatter.indentEntries": false,
"evenBetterToml.formatter.indentTables": false,
"evenBetterToml.formatter.inlineTableExpand": false,
"evenBetterToml.formatter.reorderArrays": true,
"evenBetterToml.formatter.trailingNewline": true,
// We like keeping TOML keys in a certain non-alphabetical order that feels more natural
"evenBetterToml.formatter.reorderKeys": false
}
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
{
"label": "Compile resources",
"type": "shell",
"command": "scripts/compile_resources.ps1"
"command": ".venv/Scripts/Activate.ps1; scripts/compile_resources.ps1"
},
{
"label": "Build AutoSplit",
"type": "shell",
"command": "scripts/build.ps1",
"command": ".venv/Scripts/Activate.ps1; scripts/build.ps1",
"group": {
"kind": "build",
"isDefault": true
Expand Down
63 changes: 35 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,13 @@ Select the Video Capture Device that you wanna use if selecting the `Video Captu

- This value will be set as the threshold for an image if there is no custom threshold set for that image.

#### Pause Time
#### Default Delay Time

- Time in seconds that the program stops comparison after a split. Useful for if you have two of the same split images in a row and want to avoid double-splitting. Also useful for reducing CPU usage.
- Time in milliseconds that the program waits before hitting the split hotkey for that specific split if there is no custom Delay Time set for that image.

#### Default Pause Time

- This value will be set as the Pause Time for an image if there is no custom Pause Time set for that image.

#### Delay Time

- Time in milliseconds that the program waits before hitting the split hotkey for that specific split.
- Time in seconds that the program stops comparison after a split if there is no custom Pause Time set for that image. Useful for if you have two of the same split images in a row and want to avoid double-splitting. Also useful for reducing CPU usage.

#### Dummy splits when undoing / skipping

Expand All @@ -134,28 +130,38 @@ In this situation you would have only 3 splits in LiveSplit/wsplit (even though
- If you are in the 3rd, 4th or 5th image and press the skip key, it will end up on the 6th image
- If you are in the 6th image and press the undo key, it will end up on the 5th image

#### Loop Split Images
#### Loop last Split Image to first Split Image

If this option is enabled, when the last split meets the threshold and splits, AutoSplit will loop back to the first split image and continue comparisons.
If this option is disabled, when the last split meets the threshold and splits, AutoSplit will stop running comparisons.
This option does not loop single, specific images. See the Custom Split Image Settings section above for this feature.

#### Start also Resets

If this option is enabled, a "Start" command (ie: from the Start Image) will also send the "Reset" command. This is useful if you want to automatically restart your timer using the Start Image. Since AutoSplit won't be running and won't be checking for the Reset Image.

Having the reset image check be active at all time would be a better, more organic solution in the future. But that is dependent on migrating to an observer pattern (<https://github.com/Toufool/AutoSplit/issues/219>) and being able to reload all images.

#### Enable auto Reset Image

This option is mainly meant to be toggled with the `Toggle auto Reset Image` hotkey. You can enable it to temporarily disable the Reset Image if you make a mistake in your run that would cause the Reset Image to trigger. Like exiting back to the game's menu (aka Save&Quit).

### Custom Split Image Settings

- Each split image can have different thresholds, pause times, delay split times, loop amounts, and can be flagged.
- These settings are handled in the image's filename.
- Custom thresholds are place between parenthesis `()` in the filename. This value will override the default threshold.
- Custom pause times are placed between square brackets `[]` in the filename. This value will override the default pause time.
- Custom delay times are placed between hash signs `##` in the filename. Note that these are in milliseconds. For example, a 10 second split delay would be `#10000#`. You cannot skip or undo splits during split delays.
- A different comparison method can be specified with their 0-base index between carets `^^`:
- **Custom thresholds** are place between parenthesis `()` in the filename. This value will override the default threshold.
- **Custom pause times** are placed between square brackets `[]` in the filename. This value will override the default pause time.
- **Custom delay times** are placed between hash signs `##` in the filename. Note that these are in milliseconds. For example, a 10 second split delay would be `#10000#`. You cannot skip or undo splits during split delays.
- A different **comparison method** can be specified with their 0-base index between carets `^^`:
- `^0^`: L2 Norm
- `^1^`: Histogram
- `^2^`: Perceptual Hash
- Image loop amounts are placed between at symbols `@@` in the filename. For example, a specific image that you want to split 5 times in a row would be `@5@`. The current loop # is conveniently located beneath the current split image.
- Flags are placed between curly brackets `{}` in the filename. Multiple flags are placed in the same set of curly brackets. Current available flags:
- `{d}` dummy split image. When matched, it moves to the next image without hitting your split hotkey.
- `{b}` split when similarity goes below the threshold rather than above. When a split image filename has this flag, the split image similarity will go above the threshold, do nothing, and then split the next time the similarity goes below the threshold.
- `{p}` pause flag. When a split image filename has this flag, it will hit your pause hotkey rather than your split hokey.
- **Image loop** amounts are placed between at symbols `@@` in the filename. For example, a specific image that you want to split 5 times in a row would be `@5@`. The current loop # is conveniently located beneath the current split image.
- **Flags** are placed between curly brackets `{}` in the filename. Multiple flags are placed in the same set of curly brackets. Current available flags:
- `{d}` **dummy split image**. When matched, it moves to the next image without hitting your split hotkey.
- `{b}` split when **similarity goes below** the threshold rather than above. When a split image filename has this flag, the split image similarity will go above the threshold, do nothing, and then split the next time the similarity goes below the threshold.
- `{p}` **pause flag**. When a split image filename has this flag, it will hit your pause hotkey rather than your split hokey.
- Filename examples:
- `001_SplitName_(0.9)_[10].png` is a split image with a threshold of 0.9 and a pause time of 10 seconds.
- `002_SplitName_(0.9)_[10]_{d}.png` is the second split image with a threshold of 0.9, pause time of 10, and is a dummy split.
Expand All @@ -172,17 +178,18 @@ The best way to create a masked image is to set your capture region as the entir

![Mask Example](/docs/mask_example_image.png)

### Reset image
### Reset Image

You can have one (and only one) image with the keyword `reset` in its name. AutoSplit will press the reset button when it finds this image. This image will only be used for resets and it will not be tied to any split. You can set a probability and pause time for it. The pause time is the amount of seconds AutoSplit will wait before checking for the reset image once the run starts. For example: `Reset_(0.95)_[10].png`.
You can have one (and only one) image with the keyword `reset` in its name. AutoSplit will press the reset button when it finds this image. This image will only be used for resets and it will not be tied to any split. You can set a threshold and pause time for it. The pause time is the amount of seconds AutoSplit will wait before checking for the Reset Image once the run starts. For example: `Reset_(0.95)_[10].png`.

### Start image
### Start Image

The start image is similar to the reset image. You can only have one start image with the keyword `start_auto_splitter`.You can reload the image using the "`Reload Start Image`" button. The pause time is the amount of seconds AutoSplit will wait before starting comparisons of the first split image. Delay times will be used to delay starting your timer after the threshold is met.
The Start Image is similar to the Reset Image. You can only have one Start Image with the keyword `start_auto_splitter`.You can reload the image using the "`Reload Start Image`" button. The pause time is the amount of seconds AutoSplit will wait before starting comparisons of the first split image. Delay times will be used to delay starting your timer after the threshold is met.

### Profiles

- Profiles are saved under `%appdata%\AutoSplit\profiles` and use the extension `.toml`. Profiles can be saved and loaded by using File -> Save Profile As... and File -> Load Profile.
<!-- TODO: Profiles are saved under `%appdata%\AutoSplit\profiles` and -->
- Profiles use the extension `.toml`. Profiles can be saved and loaded by using `File -> Save Profile As...` and `File -> Load Profile`.
- The profile contains all of your settings, including information about the capture region.
- You can save multiple profiles, which is useful if you speedrun multiple games.
- If you change your display setup (like using a new monitor, or upgrading to Windows 11), you may need to readjust or reselect your Capture Region.
Expand Down Expand Up @@ -239,18 +246,18 @@ Not a developer? You can still help through the following methods:
- [Upvoting feature requests](../../issues?q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement) you are interested in
- Sharing AutoSplit with other speedrunners
- Upvoting the following upstream issues in libraries and tools we use:
- <https://github.com/opencv/opencv/issues/23539>
- <https://github.com/opencv/opencv/issues/14590>
- <https://github.com/opencv/opencv/pull/20370>
- <https://github.com/opencv/opencv/issues/23537>
- <https://github.com/opencv/opencv/issues/23158>
- <https://bugreports.qt.io/browse/QTBUG-114436>
- <https://github.com/astral-sh/ruff/issues?q=is%3Aopen+involves%3AAvasam>
- <https://github.com/opencv/opencv/issues?q=is%3Aopen+involves%3AAvasam>
- <https://github.com/opencv/opencv/issues/23906>
- <https://github.com/pywinrt/python-winsdk/issues/11>
- <https://github.com/adamchainz/pre-commit-dprint/issues/4>
- <https://github.com/microsoft/vscode/issues/40239>
- <https://github.com/microsoft/vscode/issues/168411>
- <https://github.com/boppreh/keyboard/issues/171>
- <https://github.com/boppreh/keyboard/issues/516>
- <https://github.com/boppreh/keyboard/issues/216>
- <https://github.com/boppreh/keyboard/issues/161>
- <https://github.com/asweigart/pyautogui/issues/663>

## Credits

Expand Down
4 changes: 4 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Please avoid using magic numbers and prefer constants and enums that have a mean
If a constant is shared throughout the app, it should live in `src/utils.py`. Unless it is very-specific to a module.
For image shape and channels, please use `utils.ImageShape` and `utils.ColorChannel`.

### Image color format and channels

To avoid image shape mismatch issues, and to keep code simpler, we standardize the image color format to BGRA. This should always be done early in the pipeline, so whatever functionality takes care of obtaining an image should also ensure its color format. You can do so with `cv2.cvtColor` (ie: `cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA)` or `cv2.cvtColor(image, cv2.COLOR_BGR2BGRA)`).

## Testing

None 😦 Please help us create test suites, we lack the time, but we really want (need!) them. <https://github.com/Toufool/AutoSplit/issues/216>
8 changes: 8 additions & 0 deletions docs/build instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@
- [Python](https://www.python.org/downloads/) 3.9+.
- [Node](https://nodejs.org) is optional, but required for complete linting.
- Alternatively you can install the [pyright python wrapper](https://pypi.org/project/pyright/) which has a bit of an overhead delay.
- [PowerShell](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell)
- [VSCode](https://code.visualstudio.com/Download) is not required, but highly recommended.
- Everything already configured in the workspace, including Run (F5) and Build (Ctrl+Shift+B) commands, default shell, and recommended extensions.
- [PyCharm](https://www.jetbrains.com/pycharm/) is also a good Python IDE, but nothing is configured. If you are a PyCharm user, feel free to open a PR with all necessary workspace configurations!

## Install and Build steps

- Create and activate a virtual environment:
- Windows / PowerShell:
- `python -m venv .venv`
- `& ./.venv/Scripts/Activate.ps1`
- Unix / Bash:
- `python3 -m venv .venv`
- `source .venv/bin/activate`
- Run `./scripts/install.ps1` to install all dependencies.
- If you're having issues with the PySide generated code, you might want to first run `pip uninstall -y shiboken6 PySide PySide-Essentials`
- Run the app directly with `./scripts/start.ps1 [--auto-controlled]`.
Expand Down
25 changes: 15 additions & 10 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
; We don't run mypy in the CI. This is just to help anyone who would like to use it manually.
; Namely, the mypy_primer tool.
[mypy]
show_column_numbers = true
mypy_path = $MYPY_CONFIG_FILE_DIR/typings
implicit_reexport = true

strict = true
; Implicit return types !
check_untyped_defs = true
disallow_untyped_calls = false
disallow_untyped_defs = false
disallow_incomplete_defs = false
disable_error_code = return

; exclude mypyc build
exclude = .*(build)/.*

; Auto-generated code, not much we can do there
[mypy-gen.*]
disable_error_code = attr-defined, arg-type

; Of course my stubs are going to be incomplete. Otherwise they'd be on typeshed!
; Mypy becomes really whack with its errors inside these stubs though
mypy_path = typings,src
; exclude doesn't work with strict=true Why?
exclude = .*(typings|gen)/.*

[mypy-gen.*,cv2.*,]
; strict=false ; Doesn't work in overrides
follow_imports = skip
implicit_reexport = true
strict_optional = false
disable_error_code = attr-defined, misc, name-defined
[mypy-cv2.*]
disable_error_code = misc, name-defined, override
Loading

0 comments on commit 30e46ae

Please sign in to comment.