GameSentenceMiner 2.7.11__py3-none-any.whl → 2.7.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
GameSentenceMiner/anki.py CHANGED
@@ -264,7 +264,7 @@ def check_for_new_cards():
264
264
  except Exception as e:
265
265
  logger.error("Error updating new card, Reason:", e)
266
266
  first_run = False
267
- previous_note_ids = current_note_ids # Update the list of known notes
267
+ previous_note_ids.update(new_card_ids) # Update the list of known notes
268
268
 
269
269
 
270
270
  def update_new_card():
@@ -284,7 +284,11 @@ def update_new_card():
284
284
  else:
285
285
  logger.info("New card(s) detected! Added to Processing Queue!")
286
286
  card_queue.append(last_card)
287
- obs.save_replay_buffer()
287
+ try:
288
+ obs.save_replay_buffer()
289
+ except Exception as e:
290
+ logger.error(f"Error saving replay buffer: {e}")
291
+ return
288
292
 
289
293
 
290
294
  def sentence_is_same_as_previous(last_card):
GameSentenceMiner/obs.py CHANGED
@@ -178,15 +178,12 @@ def stop_replay_buffer():
178
178
 
179
179
  # Save the current replay buffer
180
180
  def save_replay_buffer():
181
- try:
182
- replay_buffer_started = do_obs_call(requests.GetReplayBufferStatus())['outputActive']
183
- if replay_buffer_started:
184
- client.call(requests.SaveReplayBuffer())
185
- logger.info("Replay buffer saved. If your log stops bere, make sure your obs output path matches \"Path To Watch\" in GSM settings.")
186
- else:
187
- logger.error("Replay Buffer is not active, could not save Replay Buffer!")
188
- except Exception as e:
189
- logger.error(f"Error saving replay buffer: {e}")
181
+ replay_buffer_started = do_obs_call(requests.GetReplayBufferStatus())['outputActive']
182
+ if replay_buffer_started:
183
+ client.call(requests.SaveReplayBuffer())
184
+ logger.info("Replay buffer saved. If your log stops bere, make sure your obs output path matches \"Path To Watch\" in GSM settings.")
185
+ else:
186
+ logger.error("Replay Buffer is not active, could not save Replay Buffer!")
190
187
 
191
188
 
192
189
  def get_current_scene():
@@ -1,26 +1,67 @@
1
1
  from dataclasses import dataclass
2
+ from math import floor, ceil
3
+
2
4
  from dataclasses_json import dataclass_json
3
- from typing import List, Optional
5
+ from typing import List, Optional, Union
6
+
4
7
 
5
8
  @dataclass_json
6
9
  @dataclass
7
10
  class Monitor:
8
- left: int
9
- top: int
10
- width: int
11
- height: int
12
11
  index: int
12
+ left: Optional[int] = None
13
+ top: Optional[int] = None
14
+ width: Optional[int] = None
15
+ height: Optional[int] = None
16
+
17
+ # @dataclass_json
18
+ # @dataclass
19
+ # class Coordinates:
20
+ # coordinates: List[Union[float, int]]
21
+ # coordinate_system: str = None
13
22
 
14
23
  @dataclass_json
15
24
  @dataclass
16
25
  class Rectangle:
17
26
  monitor: Monitor
18
- coordinates: List[int]
27
+ coordinates: List[Union[float, int]]
19
28
  is_excluded: bool
20
29
 
30
+ @dataclass_json
31
+ @dataclass
32
+ class WindowGeometry:
33
+ left: int
34
+ top: int
35
+ width: int
36
+ height: int
37
+
21
38
  @dataclass_json
22
39
  @dataclass
23
40
  class OCRConfig:
24
41
  scene: str
25
42
  rectangles: List[Rectangle]
26
- window: Optional[str] = None
43
+ coordinate_system: str = None
44
+ window_geometry: Optional[WindowGeometry] = None
45
+ window: Optional[str] = None
46
+
47
+ def __post_init__(self):
48
+ if self.coordinate_system and self.coordinate_system == "percentage" and self.window:
49
+ import pygetwindow as gw
50
+ try:
51
+ window = gw.getWindowsWithTitle(self.window)[0]
52
+ self.window_geometry = WindowGeometry(
53
+ left=window.left,
54
+ top=window.top,
55
+ width=window.width,
56
+ height=window.height,
57
+ )
58
+ except IndexError:
59
+ raise ValueError(f"Window with title '{self.window}' not found.")
60
+ for rectangle in self.rectangles:
61
+ rectangle.coordinates = [
62
+ ceil(rectangle.coordinates[0] * self.window_geometry.width),
63
+ ceil(rectangle.coordinates[1] * self.window_geometry.height),
64
+ ceil(rectangle.coordinates[2] * self.window_geometry.width),
65
+ ceil(rectangle.coordinates[3] * self.window_geometry.height),
66
+ ]
67
+