Skip to content

Commit

Permalink
Merge branch '0.80.x' into add-pin2dmd-hd-support
Browse files Browse the repository at this point in the history
  • Loading branch information
4r3 committed Feb 6, 2025
2 parents 23d695a + ac9e468 commit 2985647
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 118 deletions.
16 changes: 1 addition & 15 deletions mpf/core/placeholder_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,7 @@ def __init__(self, machine):
"""Initialize."""
super().__init__(machine)
self._eval_methods = {
ast.Num: self._eval_num,
ast.Str: self._eval_str,
ast.NameConstant: self._eval_constant,
ast.Constant: self._eval_constant,
ast.BinOp: self._eval_bin_op,
ast.UnaryOp: self._eval_unary_op,
ast.Compare: self._eval_compare,
Expand All @@ -668,18 +666,6 @@ def _parse_template(template_str):
except SyntaxError:
raise AssertionError('Failed to parse template "{}"'.format(template_str))

@staticmethod
def _eval_num(node, variables, subscribe):
del variables
del subscribe
return node.n, []

@staticmethod
def _eval_str(node, variables, subscribe):
del variables
del subscribe
return node.s, []

@staticmethod
def _eval_constant(node, variables, subscribe):
del variables
Expand Down
303 changes: 202 additions & 101 deletions mpf/core/segment_mappings.py

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion mpf/modes/carousel/code/carousel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Carousel(Mode):

__slots__ = ["_all_items", "_items", "_select_item_events", "_next_item_events",
"_previous_item_events", "_highlighted_item_index", "_done",
"_block_events", "_release_events", "_is_blocking"]
"_block_events", "_release_events", "_is_blocking", "_wrap_items"]

def __init__(self, *args, **kwargs):
"""Initialize carousel mode."""
Expand All @@ -23,6 +23,7 @@ def __init__(self, *args, **kwargs):
self._block_events = None
self._release_events = None
self._is_blocking = None
self._wrap_items = None
self._done = None
super().__init__(*args, **kwargs)

Expand All @@ -41,6 +42,7 @@ def mode_init(self):
self._highlighted_item_index = 0
self._block_events = Util.string_to_event_list(mode_settings.get("block_events", ""))
self._release_events = Util.string_to_event_list(mode_settings.get("release_events", ""))
self._wrap_items = mode_settings.get("wrap_items", True)

if not self._all_items:
raise AssertionError("Specify at least one item to select from")
Expand Down Expand Up @@ -115,6 +117,9 @@ def _next_item(self, **kwargs):
return
self._highlighted_item_index += 1
if self._highlighted_item_index >= len(self._get_available_items()):
if not self._wrap_items:
self._highlighted_item_index -= 1
return
self._highlighted_item_index = 0
self._update_highlighted_item("forwards")

Expand All @@ -124,6 +129,9 @@ def _previous_item(self, **kwargs):
return
self._highlighted_item_index -= 1
if self._highlighted_item_index < 0:
if not self._wrap_items:
self._highlighted_item_index = 0
return
self._highlighted_item_index = len(self._get_available_items()) - 1

self._update_highlighted_item("backwards")
Expand Down
5 changes: 4 additions & 1 deletion mpf/platforms/fast/communicators/net_neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,18 @@ def _process_nn(self, msg):
model = model.strip('\x00')
model = ('-').join(model.split('-')[:3]) # Remove the revision dash if it's there

name = self.io_loop[node_id]

if not model or model == '!Node Not Found!':
self.log.error("No node board found at I/O position %s, board %s will not be available. " +
"Please check your cable connections.", node_id, name)
self.done_processing_msg_response() # TODO good candidate for retry option
return

if node_id in self.platform.io_boards:
self.done_processing_msg_response()
return

name = self.io_loop[node_id]
# Fp-I/O-3208-2 -> FP-I/O-3208
model_string_from_config = ('-').join(self.config['io_loop'][name]['model'].split('-')[:3]).upper()

Expand Down
1 change: 1 addition & 0 deletions mpf/tests/machine_files/carousel/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ modes:
- second_carousel
- conditional_carousel
- blocking_carousel
- nowrap_carousel

machine:
min_balls: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#config_version=6
mode:
start_events: start_mode_nowrap_carousel
stop_events: stop_mode_nowrap_carousel, carousel_item_selected
code: mpf.modes.carousel.code.carousel.Carousel

mode_settings:
selectable_items: item1, item2, item3
select_item_events: select, select_additional
next_item_events: next
previous_item_events: previous
wrap_items: false
48 changes: 48 additions & 0 deletions mpf/tests/test_CarouselMode.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,54 @@ def testBlockingCarousel(self):
# item2 highlighted should be called when a blocked mode restarts
self.assertEventCalledWith("item_highlighted", carousel="blocking_carousel", item="item2", direction="forwards")

def testNoWrapCarousel(self):

self.mock_event("item_highlighted")
self._start_game()
self.post_event("start_mode_nowrap_carousel")
self.advance_time_and_run()
#self.assertEqual(1, self._events["nowrap_carousel_item1_highlighted"])
self.assertEventCalledWith("item_highlighted", carousel="nowrap_carousel", item="item1", direction=None)

# Advance forward one and back
self.post_event("next")
self.advance_time_and_run()
#self.assertEqual(1, self._events["nowrap_carousel_item1_highlighted"])
#self.assertEqual(1, self._events["nowrap_carousel_item2_highlighted"])
self.assertEventCalledWith("item_highlighted", carousel="nowrap_carousel", item="item2", direction="forwards")

self.post_event("previous")
self.advance_time_and_run()

self.assertEventCalledWith("item_highlighted", carousel="nowrap_carousel", item="item1", direction="backwards")
# Try and go back but fail
self.mock_event("item_highlighted")
self.post_event("previous")
self.advance_time_and_run()
self.assertEventNotCalled("item_highlighted")
self.assertEqual(self.machine.modes["nowrap_carousel"]._highlighted_item_index, 0)
self.post_event("previous")
self.advance_time_and_run()
self.assertEventNotCalled("item_highlighted")
self.assertEqual(self.machine.modes["nowrap_carousel"]._highlighted_item_index, 0)

# Go forward to the last item
self.post_event("next")
self.advance_time_and_run()
self.assertEventCalledWith("item_highlighted", carousel="nowrap_carousel", item="item2", direction="forwards")
self.post_event("next")
self.advance_time_and_run()
self.assertEventCalledWith("item_highlighted", carousel="nowrap_carousel", item="item3", direction="forwards")
# Try and go forward but fail
self.mock_event("item_highlighted")
self.post_event("next")
self.advance_time_and_run()
self.assertEventNotCalled("item_highlighted")
self.assertEqual(self.machine.modes["nowrap_carousel"]._highlighted_item_index, 2)
self.post_event("next")
self.advance_time_and_run()
self.assertEventNotCalled("item_highlighted")
self.assertEqual(self.machine.modes["nowrap_carousel"]._highlighted_item_index, 2)

def testConditionalCarousel(self):
self.mock_event("item_highlighted")
Expand Down

0 comments on commit 2985647

Please sign in to comment.