Skip to content

Commit 149247a

Browse files
committed
don't let wires and transmitters get signals from above/below gates
1 parent 011dd45 commit 149247a

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Fruit_Jam/Fruit_Jam_Logic_Gates/entity.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def handle_click(self):
341341

342342
class SignalTransmitter(Entity):
343343
"""
344-
Virtual Connector used to send signals from an entity to an input connector
344+
Virtual Connector used to send signals from an entity to a Signal Receiver
345345
"""
346346

347347
def __init__(self, location, workspace, connector_number=None, add_to_workspace=True):
@@ -360,7 +360,7 @@ def __init__(self, location, workspace, connector_number=None, add_to_workspace=
360360
self.connector_number = self._workspace.available_connectors.pop(0)
361361
else:
362362
# Too many connectors, workspace shouldn't allow this to happen
363-
raise RuntimeError("Too many Output Connectors")
363+
raise RuntimeError("Too many Signal Transmitters")
364364
else:
365365
self.connector_number = connector_number
366366

@@ -371,7 +371,7 @@ def __init__(self, location, workspace, connector_number=None, add_to_workspace=
371371

372372
def _init_tile_locations(self):
373373
self.tile_locations = (self.location,)
374-
# Location of the entity connected to the input of the output connector in x,y tile coords
374+
# Location of the entity connected to the left of the Signal Transmitter in x,y tile coords
375375
self.input_entity_location = (self.location[X] - 1, self.location[Y])
376376

377377
def update(self):
@@ -391,6 +391,15 @@ def update(self):
391391
@property
392392
def input_entity(self):
393393
"""Entity at the input location"""
394+
# Only recieve input from output wire on larger gates
395+
if self._workspace.entity_at(self.input_entity_location) == \
396+
self._workspace.entity_at((self.location[X], self.location[Y] - 1)) or \
397+
self._workspace.entity_at(self.input_entity_location) == \
398+
self._workspace.entity_at((self.location[X], self.location[Y] + 1)):
399+
400+
# If entity to left is also above or below us then we're not connected to it's output
401+
return None
402+
394403
return self._workspace.entity_at(self.input_entity_location)
395404

396405
@property
@@ -621,8 +630,14 @@ def find_neighboring_wire_end(self, direction, wire_segments=None):
621630
neighbor_direction = neighbor_state[1-neighbor_state.index(opposite)]
622631
return neighbor_entity.find_neighboring_wire_end(neighbor_direction, wire_segments)
623632
elif direction == "left" and neighbor_entity.type in ("input", "gate"):
624-
# wire is properly connected to an entity that supplies a value
625-
return(neighbor_entity, wire_segments)
633+
# Only recieve input from output wire on larger gates
634+
if self._workspace.entity_at(next_location) != \
635+
self._workspace.entity_at((current_location[X], current_location[Y] - 1)) and \
636+
self._workspace.entity_at(next_location) != \
637+
self._workspace.entity_at((current_location[X], current_location[Y] + 1)):
638+
639+
# wire is properly connected to an entity that supplies a value
640+
return(neighbor_entity, wire_segments)
626641

627642
# no wire or input entity found, or not properly connected
628643
return (None, wire_segments)

0 commit comments

Comments
 (0)