fix rule default, gui input tabbing, scroll wheel, cache gamenode moves
This commit is contained in:
1 parent
485bd26b36
commit
de898569b6
9 files changed
+30
-14
No files matched your search
@@ -75,11 +75,12 @@ class Game:
|
||||
self.root.place_handicap_stones(handicap)
|
||||
else:
|
||||
board_size = katrain.config("game/size")
|
||||
rules = katrain.config("game/rules")
|
||||
self.komi = katrain.config("game/komi")
|
||||
self.root = GameNode(
|
||||
properties={
|
||||
**Game.DEFAULT_PROPERTIES,
|
||||
**{"SZ": board_size, "KM": self.komi, "DT": self.game_id},
|
||||
**{"SZ": board_size, "KM": self.komi, "DT": self.game_id, "RU": rules},
|
||||
**(game_properties or {}),
|
||||
}
|
||||
)
|
||||
|
||||
@@ -82,6 +82,10 @@ class SGFNode:
|
||||
self.parent.children.append(self)
|
||||
if parent and move:
|
||||
self.set_property(move.player, move.sgf(self.board_size))
|
||||
self._clear_cache()
|
||||
|
||||
def _clear_cache(self):
|
||||
self.moves_cache = None
|
||||
|
||||
def sgf_properties(self, **xargs) -> Dict:
|
||||
"""For hooking into in a subclass and overriding/formatting any additional properties to be output."""
|
||||
@@ -134,6 +138,7 @@ class SGFNode:
|
||||
"""Add some values to the property list."""
|
||||
# SiZe[19] ==> SZ[19] etc. for old SGF
|
||||
normalized_property = re.sub("[a-z]", "", property)
|
||||
self._clear_cache()
|
||||
self.properties[normalized_property] += values
|
||||
|
||||
def get_list_property(self, property, default=None) -> Any:
|
||||
@@ -144,6 +149,7 @@ class SGFNode:
|
||||
"""Add some values to the property. If not a list, it will be made into a single-value list."""
|
||||
if not isinstance(value, list):
|
||||
value = [value]
|
||||
self._clear_cache()
|
||||
self.properties[property] = value
|
||||
|
||||
def get_property(self, property, default=None) -> Any:
|
||||
@@ -207,11 +213,13 @@ class SGFNode:
|
||||
@property
|
||||
def moves(self) -> List[Move]:
|
||||
"""Returns all moves in the node - typically 'move' will be better."""
|
||||
return [
|
||||
Move.from_sgf(move, player=pl, board_size=self.board_size)
|
||||
for pl in Move.PLAYERS
|
||||
for move in self.get_list_property(pl, [])
|
||||
]
|
||||
if self.moves_cache is None:
|
||||
self.moves_cache = [
|
||||
Move.from_sgf(move, player=pl, board_size=self.board_size)
|
||||
for pl in Move.PLAYERS
|
||||
for move in self.get_list_property(pl, [])
|
||||
]
|
||||
return self.moves_cache
|
||||
|
||||
@property
|
||||
def placements(self) -> List[Move]:
|
||||
|
||||
@@ -254,7 +254,7 @@ class NewGamePopup(QuickConfigGui):
|
||||
def normalized_rules(self):
|
||||
rules = self.katrain.game.root.get_property("RU", "japanese").strip().lower()
|
||||
for abbr, name in self.katrain.engine.RULESETS_ABBR:
|
||||
if abbr == rules or abbr == rules:
|
||||
if abbr == rules or name == rules:
|
||||
return name
|
||||
|
||||
def update_playerinfo(self, *args):
|
||||
|
||||
@@ -76,7 +76,8 @@ class ScoreGraph(Graph):
|
||||
navigate_move = ListProperty([None, 0, 0, 0])
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
if self.collide_point(*touch.pos):
|
||||
if self.collide_point(*touch.pos) and "scroll" not in getattr(touch, "button",''):
|
||||
print(touch)
|
||||
ix, _ = min(enumerate(self.score_points[::2]), key=lambda ix_v: abs(ix_v[1] - touch.x))
|
||||
self.navigate_move = [
|
||||
self.nodes[ix],
|
||||
@@ -91,7 +92,7 @@ class ScoreGraph(Graph):
|
||||
return self.on_touch_down(touch)
|
||||
|
||||
def on_touch_up(self, touch):
|
||||
if self.collide_point(*touch.pos) and self.navigate_move[0]:
|
||||
if self.collide_point(*touch.pos) and self.navigate_move[0] and "scroll" not in getattr(touch, "button",''):
|
||||
katrain = MDApp.get_running_app().gui
|
||||
if katrain and katrain.game:
|
||||
katrain.game.set_current_node(self.navigate_move[0])
|
||||
|
||||
@@ -247,6 +247,12 @@ class MoveTree(ScrollView, BackgroundMixin):
|
||||
sy = (y - self.height / 2) / (vp.height - self.height)
|
||||
self.scroll_y = max(0, min(1, sy))
|
||||
|
||||
# disable mousewheel
|
||||
def on_scroll_start(self, touch, check_children=True):
|
||||
if "button" in touch.profile and touch.button.startswith("scroll"):
|
||||
return False
|
||||
return super().on_scroll_start(touch, check_children)
|
||||
|
||||
|
||||
Builder.load_string(
|
||||
"""
|
||||
@@ -256,7 +262,6 @@ Builder.load_string(
|
||||
<MoveTree>:
|
||||
background_color: Theme.BOX_BACKGROUND_COLOR
|
||||
move_tree_canvas: move_tree_canvas
|
||||
scroll_distance: 0 # scroll wheel is for forward/backward
|
||||
MoveTreeCanvas:
|
||||
scroll_view_widget: root
|
||||
id: move_tree_canvas
|
||||
|
||||
Binary file not shown.
@@ -752,9 +752,7 @@ msgstr "Show stats if more than ... visits"
|
||||
|
||||
#. TODO - analysis option
|
||||
msgid "cache analysis to sgf"
|
||||
msgstr ""
|
||||
"cache analysis to sgf\n"
|
||||
"(larger files, only compatible with KaTrain)"
|
||||
msgstr "Cache analysis in SGF"
|
||||
|
||||
#. TODO
|
||||
msgid "menu:save-as"
|
||||
|
||||
@@ -522,7 +522,6 @@ msgstr ""
|
||||
"possiblement pour cause de \n"
|
||||
"mémoire insuffisante : {error}"
|
||||
|
||||
#. TODO: updated
|
||||
msgid "teaching undo message"
|
||||
msgstr ""
|
||||
"Le coup {move} a été annulé car il perdait {points_lost:.1f} points.Vous "
|
||||
|
||||
@@ -389,12 +389,14 @@
|
||||
LabelledTextInput:
|
||||
text: ''
|
||||
id: black_player_name
|
||||
write_tab: False
|
||||
hint_text: i18n._("black player name hint")
|
||||
size_hint: 0.75, None
|
||||
AnchorLayout:
|
||||
LabelledTextInput:
|
||||
text: ''
|
||||
id: white_player_name
|
||||
write_tab: False
|
||||
hint_text: i18n._("white player name hint")
|
||||
size_hint: 0.75, None
|
||||
DescriptionLabel:
|
||||
@@ -404,6 +406,7 @@
|
||||
text: '19'
|
||||
id: boardsize
|
||||
input_property: 'game/size'
|
||||
write_tab: False
|
||||
size_hint: 0.5, None
|
||||
hint_text: i18n._("non square board hint")
|
||||
AnchorLayout:
|
||||
@@ -425,6 +428,7 @@
|
||||
LabelledIntInput:
|
||||
text: '0'
|
||||
input_property: 'game/handicap'
|
||||
write_tab: False
|
||||
id: handicap
|
||||
AnchorLayout:
|
||||
MDBoxLayout:
|
||||
|
||||
Reference in new issue
Block a user