Skip to content

Commit 172310f

Browse files
committed
Rename connector entities allow backdoor deletes
1 parent 3d20ad7 commit 172310f

File tree

3 files changed

+54
-56
lines changed

3 files changed

+54
-56
lines changed

Fruit_Jam/Fruit_Jam_Logic_Gates/entity.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ def apply_state_palette_mapping(self):
224224
for loc in self.tile_locations:
225225
self._workspace.tilegrid.pixel_shader[loc] = pal
226226

227-
class ConnectorIn(Entity):
227+
class SignalReceiver(Entity):
228228
"""
229-
Input Connector used to bring signals into an entity from an output connector
229+
Virtual Connector used to bring signals into an entity from a Signal Transmitter
230230
"""
231231

232232
def __init__(self, location, workspace, connector_number=None, add_to_workspace=True):
@@ -241,9 +241,9 @@ def __init__(self, location, workspace, connector_number=None, add_to_workspace=
241241
self._input_one = None
242242

243243
if connector_number is None:
244-
# Find the last ConnectorOut entity added to the workspace to link to
244+
# Find the last SignalTransmitter entity added to the workspace to link to
245245
for entity in self._workspace.entities:
246-
if isinstance(entity, ConnectorOut):
246+
if isinstance(entity, SignalTransmitter):
247247
self.connector_number = entity.connector_number
248248
self._input_one = entity
249249
else:
@@ -270,7 +270,7 @@ def input_one(self):
270270

271271
@input_one.setter
272272
def input_one(self, input_entity):
273-
if isinstance(input_entity, ConnectorOut):
273+
if isinstance(input_entity, SignalTransmitter):
274274
self._input_one = input_entity
275275
self.apply_state_palette_mapping()
276276

@@ -314,12 +314,12 @@ def apply_state_palette_mapping(self):
314314

315315
def handle_click(self):
316316
"""
317-
Cycle through available ConnectorOut entities on the workspace
317+
Cycle through available SignalTransmitter entities on the workspace
318318
"""
319319
connector_outs = []
320320
inuse_connector_numbers = []
321321
for entity in self._workspace.entities:
322-
if isinstance(entity, ConnectorOut):
322+
if isinstance(entity, SignalTransmitter):
323323
connector_outs.append(entity)
324324
inuse_connector_numbers.append(entity.connector_number)
325325

@@ -343,7 +343,7 @@ def handle_click(self):
343343
if entity.connector_number == self.connector_number:
344344
self.input_one = entity
345345

346-
class ConnectorOut(Entity):
346+
class SignalTransmitter(Entity):
347347
"""
348348
Output Connector used to send signals from an entity to an input connector
349349
"""
0 Bytes
Binary file not shown.

Fruit_Jam/Fruit_Jam_Logic_Gates/workspace.py

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
NeoPixelOutput,
3030
PhysicalButton,
3131
Wire,
32-
ConnectorIn,
33-
ConnectorOut,
32+
SignalReceiver,
33+
SignalTransmitter,
3434
)
3535

3636
# pylint: disable=too-many-branches, too-many-statements
@@ -63,8 +63,8 @@
6363
"XnorGate": XnorGate,
6464
"NotGate": NotGate,
6565
"Wire": Wire,
66-
"ConnectorIn": ConnectorIn,
67-
"ConnectorOut": ConnectorOut,
66+
"SignalReceiver": SignalReceiver,
67+
"SignalTransmitter": SignalTransmitter,
6868
"OutputPanel": OutputPanel,
6969
"VirtualPushButton": VirtualPushButton,
7070
"PhysicalButton": PhysicalButton,
@@ -222,8 +222,8 @@ def remove_entity(self, entity):
222222
self.tilegrid[entity.tile_locations[i]] = EMPTY
223223
self.overlay_tilegrid[entity.tile_locations[i]] = EMPTY
224224

225-
# Special case for ConnectorOut to clear its input wire tap overlay
226-
if isinstance(entity, ConnectorOut):
225+
# Special case for SignalTransmitter to clear its input wire tap overlay
226+
if isinstance(entity, SignalTransmitter):
227227
if isinstance(entity.input_entity,Wire):
228228
self.overlay_tilegrid[entity.input_entity_location] = EMPTY
229229

@@ -242,6 +242,23 @@ def _set_mouse_moving_tiles(self, entity):
242242
loc[1] - entity.location[1] + midpoint_offset,
243243
] = entity.tiles[i]
244244

245+
def _clear_cursor(self):
246+
# Special SignalTransmitter case, add connection_number back into available list
247+
if isinstance(self.moving_entity, SignalTransmitter):
248+
self.available_connectors.append(self.moving_entity.connector_number)
249+
self.available_connectors.sort()
250+
# Remove connections from SignalReceivers pointing to this SignalTransmitter
251+
for entity in self.entities:
252+
if isinstance(entity, SignalReceiver) and \
253+
entity.connector_number == self.moving_entity.connector_number:
254+
255+
entity.connector_number = None
256+
entity.input_one = None
257+
258+
self.moving_entity = None
259+
self.mouse_moving_tg.hidden = True
260+
self.update()
261+
245262
def handle_mouse_click(self, screen_x, screen_y, pressed_btns):
246263
"""
247264
Handle mouse click events sent from code.py
@@ -263,8 +280,7 @@ def handle_mouse_click(self, screen_x, screen_y, pressed_btns):
263280

264281
# if there is an entity on the mouse, remove it
265282
else:
266-
self.moving_entity = None
267-
self.mouse_moving_tg.hidden = True
283+
self._clear_cursor()
268284
return
269285

270286
# apply offset value based on scroll position
@@ -444,31 +460,13 @@ def handle_key_press(self, key_bytes, mouse_x, mouse_y):
444460
# remove action, clear out the entity moving with the mouse
445461
elif action == "remove":
446462
if self.moving_entity is not None:
447-
# Speical ConnectorOut case, add connection_number back into available list
448-
if isinstance(self.moving_entity, ConnectorOut):
449-
self.available_connectors.append(self.moving_entity.connector_number)
450-
self.available_connectors.sort()
451-
# Remove connections from all ConnectorIn entities pointing to this ConnectorOut
452-
for entity in self.entities:
453-
if isinstance(entity, ConnectorIn) and \
454-
entity.connector_number == self.moving_entity.connector_number:
455-
456-
entity.connector_number = None
457-
entity.input_one = None
458-
459-
self.moving_entity = None
460-
self.mouse_moving_tg.hidden = True
461-
self.update()
463+
self._clear_cursor()
462464

463465
# eyedropper or pipette action
464466
elif action == "eyedropper":
465467
# if there is already an entity moving with the mouse
466468
if self.moving_entity is not None:
467-
# clear out the entity moving with the mouse
468-
# This was a "back door" delete of the object, better to just ignore
469-
# otherwise we need to add the ConnectorOut special case here as well
470-
#self.moving_entity = None
471-
#self.mouse_moving_tg.hidden = True
469+
self._clear_cursor()
472470
return
473471

474472
# adjust mouse coordinates for the scroll position
@@ -482,14 +480,14 @@ def handle_key_press(self, key_bytes, mouse_x, mouse_y):
482480
# try to get the entity at the tile coordinates
483481
target_entity = self.entity_at((tile_x, tile_y))
484482

485-
# special case only limited number of ConnectorOuts
486-
if target_entity is not None and isinstance(target_entity, ConnectorOut):
487-
num_ConnectorOuts = 0
483+
# special case only limited number of SignalTransmitters
484+
if target_entity is not None and isinstance(target_entity, SignalTransmitter):
485+
num_SignalTransmitters = 0
488486
for entity in self.entities:
489-
if isinstance(entity, ConnectorOut):
490-
num_ConnectorOuts += 1
491-
if num_ConnectorOuts >= MAX_CONNECTORS:
492-
# Can't create additional ConnectorOut
487+
if isinstance(entity, SignalTransmitter):
488+
num_SignalTransmitters += 1
489+
if num_SignalTransmitters >= MAX_CONNECTORS:
490+
# Can't create additional SignalTransmitters
493491
target_entity = None
494492

495493
# if there was an entity at the coordinates
@@ -585,7 +583,7 @@ def create_entity_from_json(self, entity_json, add_to_workspace=True):
585583
location, self, entity_json["state"], add_to_workspace=add_to_workspace
586584
)
587585
# special case Connectors need the connector number
588-
elif entity_json["class"] == "ConnectorIn" or entity_json["class"] == "ConnectorOut":
586+
elif entity_json["class"] == "SignalReceiver" or entity_json["class"] == "SignalTransmitter":
589587
if entity_json.get("connector_number") is not None:
590588
new_entity = ENTITY_CLASS_CONSTRUCTOR_MAP[entity_json["class"]](
591589
location, self, entity_json["connector_number"],
@@ -611,7 +609,7 @@ def load_from_json(self, json_data):
611609
"""
612610
Load the workspace state from a JSON object.
613611
"""
614-
# reset list of available ConnectorOuts
612+
# reset list of available SignalTransmitters
615613
self.available_connectors = list(range(MAX_CONNECTORS))
616614
self.neopixels.fill(0)
617615
# clear out all sprites in the tilegrid
@@ -629,11 +627,11 @@ def load_from_json(self, json_data):
629627

630628
# Connect any connectors
631629
for entity in self.entities:
632-
if isinstance(entity,ConnectorOut):
630+
if isinstance(entity,SignalTransmitter):
633631
if entity.connector_number in self.available_connectors:
634632
self.available_connectors.remove(entity.connector_number)
635633
for entity_in in self.entities:
636-
if isinstance(entity_in,ConnectorIn) and \
634+
if isinstance(entity_in,SignalReceiver) and \
637635
entity_in.connector_number is not None and \
638636
entity.connector_number == entity_in.connector_number:
639637

@@ -751,15 +749,15 @@ class ToolBox:
751749
"size": (1, 1),
752750
},
753751
{
754-
"label": "Output Connector",
752+
"label": "Signal Transmit'r",
755753
"tiles": (31,),
756-
"constructor": ConnectorOut,
754+
"constructor": SignalTransmitter,
757755
"size": (1, 1),
758756
},
759757
{
760-
"label": "Input Connector",
758+
"label": "Signal Receiver",
761759
"tiles": (30,),
762-
"constructor": ConnectorIn,
760+
"constructor": SignalReceiver,
763761
"size": (1, 1),
764762
},
765763
{
@@ -892,13 +890,13 @@ def handle_mouse_click(self, screen_coords):
892890
(0, 0), self._workspace, clicked_item["index"], add_to_workspace=False
893891
)
894892

895-
# special case only limited number of ConnectorOuts
893+
# special case only limited number of SignalTransmitters
896894
elif clicked_item["label"] == "Output Connector":
897-
num_ConnectorOuts = 0
895+
num_SignalTransmitters = 0
898896
for entity in self._workspace.entities:
899-
if isinstance(entity, ConnectorOut):
900-
num_ConnectorOuts += 1
901-
if num_ConnectorOuts >= MAX_CONNECTORS:
897+
if isinstance(entity, SignalTransmitter):
898+
num_SignalTransmitters += 1
899+
if num_SignalTransmitters >= MAX_CONNECTORS:
902900
# close the ToolBox
903901
self.hidden = True
904902
return

0 commit comments

Comments
 (0)