Skip to content

Commit

Permalink
Fixed language problem with non-ascii symbols (farsi lang); Fixed the…
Browse files Browse the repository at this point in the history
… pumpkin color range
  • Loading branch information
devbutlazy committed Nov 3, 2024
1 parent abbdea9 commit cbac373
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
10 changes: 5 additions & 5 deletions core/clicker/blum.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def collect_pumpkin(screen: Any, rect: Tuple[int, int, int, int]) -> bool:

for x, y in product(range(0, width, 20), range(0, height, 20)):
r, g, b = screen.getpixel((x, y))
pamkin_range = (35 < b < 63) and (220 <= r < 233) and (114 <= g < 128)
pumpkin_range = (35 < b < 75) and (200 <= r < 245) and (114 <= g < 140)

play_button = screen.getpixel((int(width * 0.80), int(height * 0.63)))

if pamkin_range and not play_button == (255, 255, 255):
if pumpkin_range and not play_button == (255, 255, 255):
screen_x = rect[0] + x
screen_y = rect[1] + y
mouse.move(screen_x, screen_y, absolute=True)
Expand All @@ -134,8 +134,8 @@ def detect_reload_screen(screen: Any) -> bool:
"""
width, height = screen.size

x1, y1 = (math.ceil(width * 0.43781), math.ceil(height * 0.60252)) #grey reload button
x2, y2 = (math.ceil(width * 0.24626), math.ceil(height * 0.429775)) #white pixel on word
x1, y1 = (math.ceil(width * 0.43781), math.ceil(height * 0.60252)) # grey reload button
x2, y2 = (math.ceil(width * 0.24626), math.ceil(height * 0.429775)) # white pixel on word

reload_button = screen.getpixel((x1, y1))
white_pixel = screen.getpixel((x2, y2))
Expand Down Expand Up @@ -185,7 +185,7 @@ def detect_replay(self, screen: Any, rect: Tuple[int, int, int, int]) -> bool:
)
mouse.click(button=mouse.LEFT)

time.sleep(0.5)
time.sleep(1)

self.replays += 1
return True
Expand Down
2 changes: 1 addition & 1 deletion core/config/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"LANGUAGE": "en",
"LANGUAGE": "fa",
"REPLAYS": 50,
"REPLAY_DELAY": 3,
"TOGGLE_HOTKEY": "p",
Expand Down
22 changes: 12 additions & 10 deletions core/localization/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

from core.logger.logger import logger

from typing import Dict
from typing import Dict, Union


def load_json_file(file_path: str) -> Dict:
def load_json_file(file_path: Union[str, Path]) -> Dict:
"""
Load a JSON file and return its contents as a dictionary.
:param: file_path (str): The path to the JSON file.
:param file_path: The path to the JSON file.
:return: Dict: Parsed JSON content, or an empty dictionary if an error occurs.
:return: Parsed JSON content, or an empty dictionary if an error occurs.
"""
try:
with open(file_path, "r", encoding="utf-8") as file:
Expand Down Expand Up @@ -48,13 +48,15 @@ def get_language(key: str) -> str:
:param key: The key to look up in the language file.
:return: str: The localized string or an error message if key not found.
:return: The localized string or an error message if the key is not found.
"""
lang: str = (
get_config_value("LANGUAGE") or "en"
) # Fallback to 'en' if LANGUAGE not found
lang: str = get_config_value("LANGUAGE") or "en" # Fallback to 'en' if LANGUAGE not found
file_path: Path = Path(f"core/localization/langs/{lang}.json")

data: Dict = load_json_file(file_path) or load_json_file(f"core/localization/langs/en.json")
data: Dict = load_json_file(file_path) or load_json_file("core/localization/langs/en.json")

return data.get(key, f"Localization error: '{key}' not found.")
return ujson.dumps(
data.get(key, f"Localization error: '{key}' not found."),
ensure_ascii=False,
indent=4
) if lang == "fa" else data.get(key, f"Localization error: '{key}' not found.")

0 comments on commit cbac373

Please sign in to comment.