def undo_split(self, parent_markerid, child_markerid): parent = self.markerid_to_legion.get(parent_markerid) if parent is None: return child = self.markerid_to_legion.get(child_markerid) if child is None: return parent_creature_names = parent.creature_names child_creature_names = child.creature_names parent.creatures += child.creatures child.remove_observer(self) del self.markerid_to_legion[child_markerid] self.markerids_left.add(child.markerid) self.selected_markerid = None del child # One action for our player with creature names, and a # different action for other players without. action = Action.UndoSplit(self.game.name, self.name, parent_markerid, child_markerid, parent_creature_names, child_creature_names) self.notify(action, names=[self.name]) action = Action.UndoSplit(self.game.name, self.name, parent_markerid, child_markerid, len(parent_creature_names) * ["Unknown"], len(child_creature_names) * ["Unknown"]) other_playernames = self.game.playernames other_playernames.remove(self.name) self.notify(action, names=other_playernames)
def test_undo_then_do_different(): game_name = "game" playername = "player" parent_markerid = "Rd01" child_markerid = "Rd02" other_markerid = "Rd03" parent_creature_names = 4 * [None] child_creature_names = 4 * [None] history = History.History() action = Action.SplitLegion(game_name, playername, parent_markerid, child_markerid, parent_creature_names, child_creature_names) history.update(None, action, None) undo_action = Action.UndoSplit(game_name, playername, parent_markerid, child_markerid, parent_creature_names, child_creature_names) history.update(None, undo_action, None) action2 = Action.SplitLegion(game_name, playername, parent_markerid, other_markerid, parent_creature_names, child_creature_names) history.update(None, action2, None) assert history.actions == [action2] assert history.undone == [] assert history.can_undo(playername) assert not history.can_redo(playername)
def test_undo_nothing(): game_name = "game" playername = "player" parent_markerid = "Rd01" child_markerid = "Rd02" parent_creature_names = 4 * [None] child_creature_names = 4 * [None] history = History.History() undo_action = Action.UndoSplit(game_name, playername, parent_markerid, child_markerid, parent_creature_names, child_creature_names) history.update(None, undo_action, None) assert history.actions == [] assert history.undone == [] assert not history.can_undo(playername) assert not history.can_redo(playername)