Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Auto-detect and use character specific hotkeys via key file #905

Open
wants to merge 54 commits into
base: master
Choose a base branch
from

Conversation

Ezro
Copy link
Collaborator

@Ezro Ezro commented Jun 18, 2022

This implementation will read the provided 'key_file' param (which should map to the exact name in the saved_games_folder) and parse the hotkeys for the provided character. Once Botty goes into game it will then run a "discovery" to try to determine what skills are bound to the discovered hotkeys.

The PR should auto-detect sorc, pally, barb, necro, sin, and druid skill. The existing char scripts should be updated to use the proposed hotkey solution.

An important thing to note is that the implementation currently assumes that Quick Casting is disabled; if we plan on shifting to using Quick Casting then I think this solution can be tweaked to hold the keybind prior to taking the screenshot.

@Ezro Ezro changed the title Feature/auto detect hotkeys Auto-detect and use character specific hotkeys via key file Jun 18, 2022
@Ezro Ezro force-pushed the feature/auto_detect_hotkeys branch from f086892 to 59f7681 Compare June 20, 2022 17:49
aeon0
aeon0 previously requested changes Jun 21, 2022
src/utils/hotkeys.py Show resolved Hide resolved
src/utils/hotkeys.py Outdated Show resolved Hide resolved
src/utils/hotkeys.py Outdated Show resolved Hide resolved
src/ui/skills.py Show resolved Hide resolved
src/template_finder.py Outdated Show resolved Hide resolved
@@ -60,10 +60,37 @@ def stored_templates() -> dict[Template]:
)
return templates

@cache
def stored_templates_by_dir() -> dict[Template]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont like that we bascially copy the stored_templates() functionality here. I'd rather go for adding the dir normally to TEMPLATE_PATHS and to get all the specific template names loop through folder and get names of the files in a list.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we also can ditch the search_all_templates() function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stored_templates_by_dir and search_all_templates have been removed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ezro would you be willing to create a new test case for the new functionality? Just add here https://github.com/aeon0/botty/blob/master/test/template_finder_test.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgleed I added some asserts but they're very basic; please validate

@aliig
Copy link
Collaborator

aliig commented Jun 21, 2022

One thing that needs to be tested here is localization. Botty currently allows users to select characters that have names that aren't in English alphabet. Not sure if this will break things if people have a keyfile with kanji, for example.

@Ezro
Copy link
Collaborator Author

Ezro commented Jun 21, 2022

One thing that needs to be tested here is localization. Botty currently allows users to select characters that have names that aren't in English alphabet. Not sure if this will break things if people have a keyfile with kanji, for example.

image
I've confirmed that this should work for any provided language, but the Logger doesn't seem to like the encoding; I can update the debug line to "Determine hotkeys" and remove the key_name to avoid this error.

Edit: I've updated the PR to no longer print the key file name

@Ezro Ezro requested review from aeon0 and aliig June 21, 2022 19:42
@aliig
Copy link
Collaborator

aliig commented Jun 21, 2022

@Ezro left a few comments earlier

@aeon0
Copy link
Owner

aeon0 commented Jun 22, 2022

From my side it looks good. I leave it to gleed since he seems to still have some topics.

@aliig
Copy link
Collaborator

aliig commented Jun 23, 2022

Also, why'd you choose to stick with precise keyfile name rather than use regexp with character name like we discussed?

aliig
aliig previously requested changes Jun 23, 2022
Copy link
Collaborator

@aliig aliig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall very well done! See comments. Thanks for doing this.

Last wish list item for this PR would be basic validation.

There are some hotkeys that simply cannot be unset. Like force move, etc. Do you think it'd be hard to implement some basic validation for required hotkeys?

src/template_finder.py Outdated Show resolved Hide resolved
src/template_finder.py Outdated Show resolved Hide resolved
src/template_finder.py Outdated Show resolved Hide resolved
@@ -60,10 +60,37 @@ def stored_templates() -> dict[Template]:
)
return templates

@cache
def stored_templates_by_dir() -> dict[Template]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ezro would you be willing to create a new test case for the new functionality? Just add here https://github.com/aeon0/botty/blob/master/test/template_finder_test.py

src/bot.py Outdated Show resolved Hide resolved
src/inventory/belt.py Show resolved Hide resolved
src/pather.py Show resolved Hide resolved
src/utils/hotkeys.py Show resolved Hide resolved
@Ezro
Copy link
Collaborator Author

Ezro commented Jun 23, 2022

Overall very well done! See comments. Thanks for doing this.

Last wish list item for this PR would be basic validation.

There are some hotkeys that simply cannot be unset. Like force move, etc. Do you think it'd be hard to implement some basic validation for required hotkeys?

I think we can implement that very easily (at some point). Here's the current spot for parsing the key block into actual hotkeys

@Ezro
Copy link
Collaborator Author

Ezro commented Jun 23, 2022

Also, why'd you choose to stick with precise keyfile name rather than use regexp with character name like we discussed?

I haven't tested this but I think it's better to be explicit; I have a feeling that the hash is there for multi-account handling; e.g., if account A has character 'Paladin' and account B has character 'Paladin' and both were played online on the same PC then we wouldn't actually be able to determine which Paladin file to use.

This adds a bit of overhead for the users (to find and enter the explicit key file name) but I think the trade-off is that Botty wouldn't have to do decision making logic for choosing / erroring.

@aliig
Copy link
Collaborator

aliig commented Jun 23, 2022

Also, why'd you choose to stick with precise keyfile name rather than use regexp with character name like we discussed?

I haven't tested this but I think it's better to be explicit; I have a feeling that the hash is there for multi-account handling; e.g., if account A has character 'Paladin' and account B has character 'Paladin' and both were played online on the same PC then we wouldn't actually be able to determine which Paladin file to use.

This adds a bit of overhead for the users (to find and enter the explicit key file name) but I think the trade-off is that Botty wouldn't have to do decision making logic for choosing / erroring.

That's a good point and I'd bet your theory is correct.

@Ezro Ezro force-pushed the feature/auto_detect_hotkeys branch 2 times, most recently from fa84dff to eef2a92 Compare June 23, 2022 19:01
@aliig aliig self-requested a review June 23, 2022 19:15
aliig
aliig previously approved these changes Jun 23, 2022
Copy link
Collaborator

@aliig aliig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing locally. if it works well I'll merge today ™️

@Ezro Ezro force-pushed the feature/auto_detect_hotkeys branch from 813a6c1 to df2e5ac Compare June 23, 2022 20:03
@Ezro Ezro force-pushed the feature/auto_detect_hotkeys branch from d463ed2 to c1d0ddf Compare June 25, 2022 00:46
@aliig aliig dismissed their stale review June 25, 2022 01:18

not quite ready

@Ezro Ezro linked an issue Jun 25, 2022 that may be closed by this pull request
@aliig
Copy link
Collaborator

aliig commented Jun 27, 2022

Are you able to recover my test that I wrote in template_finder_test.py for this? Looks like that got overwritten with a force push.

@Ezro Ezro force-pushed the feature/auto_detect_hotkeys branch from 007c463 to 4e18c84 Compare June 27, 2022 17:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auto-detect and use character specific hotkeys via key file
3 participants