Skip to content

Commit eab45e1

Browse files
author
Pipeline
committed
F Added events to mobbing manager for adding and removing mobbers. File Utilities now appends properly
1 parent c01a857 commit eab45e1

File tree

4 files changed

+70
-25
lines changed

4 files changed

+70
-25
lines changed

Infrastructure/FileUtilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def create_file(self, file_path):
2424
f.close()
2525

2626
def append(self, file_path, data):
27-
f = open(file_path, "w+")
27+
f = open(file_path, "a")
2828
f.write(data)
2929
f.close()
3030

Infrastructure/MobberManager.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def __init__(self, randomize=False):
77
self.next_driver_index = 1
88
self.mobber_list = []
99
self.mobber_list_change_callbacks = []
10+
self.mobber_add_callbacks = []
11+
self.mobber_remove_callbacks = []
1012
self.randomize = randomize
1113

1214
def mobber_count(self):
@@ -16,17 +18,35 @@ def add_mobber(self, mobber_name):
1618
clean_mobber_name = str(mobber_name).strip()
1719
if clean_mobber_name != "" and not self.mobber_list.__contains__(clean_mobber_name):
1820
self.mobber_list.append(mobber_name)
21+
self.fire_mobber_add_callbacks(mobber_name)
1922
self.fire_mobber_list_change_callbacks()
2023

24+
def subscribe_to_mobber_add(self, mobber_add_callback):
25+
self.mobber_add_callbacks.append(mobber_add_callback)
26+
27+
def fire_mobber_add_callbacks(self, mobber_name):
28+
for mobber_add_callback in self.mobber_add_callbacks:
29+
if mobber_add_callback:
30+
mobber_add_callback(mobber_name)
31+
2132
def get_mobbers(self):
2233
return self.mobber_list
2334

2435
def remove_mobber(self, remove_mobber_index):
2536
if self.mobber_count() == 0:
2637
return
38+
self.fire_mobber_remove_callbacks(self.mobber_list[remove_mobber_index])
2739
del self.mobber_list[remove_mobber_index]
2840
self.fire_mobber_list_change_callbacks()
2941

42+
def subscribe_to_mobber_remove(self, mobber_remove_callback):
43+
self.mobber_remove_callbacks.append(mobber_remove_callback)
44+
45+
def fire_mobber_remove_callbacks(self, mobber_name):
46+
for mobber_remove_callback in self.mobber_remove_callbacks:
47+
if mobber_remove_callback:
48+
mobber_remove_callback(mobber_name)
49+
3050
def move_mobber_up(self, swap_index):
3151
if self.mobber_count() == 0: return
3252
destination_index = swap_index - 1
Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
Mobbers in List for Each Change
22
Action 1:
3-
Action 2:Joe (Driver) (Navigator),
4-
Action 3:Joe (Driver), Chris (Navigator),
5-
Action 4:Joe (Driver), Chris (Navigator), Sam,
6-
Action 5:Joe (Driver), Chris (Navigator), Sam, John,
7-
Action 6:Joe, Chris (Driver), Sam (Navigator), John,
8-
Action 7:Joe, Chris (Driver), Sam (Navigator), John, Bill,
9-
Action 8:Joe, Chris, Sam (Driver), John (Navigator), Bill,
10-
Action 9:Joe, Chris, Sam, John (Driver), Bill (Navigator),
11-
Action 10:Joe (Navigator), Chris, Sam, John, Bill (Driver),
12-
Action 11:Joe (Driver), Chris (Navigator), Sam, John, Bill,
3+
Action 2:Joe added
4+
Action 3:Joe (Driver) (Navigator),
5+
Action 4:Chris added
6+
Action 5:Joe (Driver), Chris (Navigator),
7+
Action 6:Sam added
8+
Action 7:Joe (Driver), Chris (Navigator), Sam,
9+
Action 8:John added
10+
Action 9:Joe (Driver), Chris (Navigator), Sam, John,
11+
Action 10:Joe, Chris (Driver), Sam (Navigator), John,
12+
Action 11:Bill added
1313
Action 12:Joe, Chris (Driver), Sam (Navigator), John, Bill,
14-
Action 13:Joe, Chris (Driver), John (Navigator), Bill,
15-
Action 14:Chris, John (Driver), Bill (Navigator),
16-
Action 15:Chris (Navigator), John, Bill (Driver),
17-
Action 16:Chris, John (Driver), Bill (Navigator),
18-
Action 17:Chris, John (Driver), Bill (Navigator), Seth,
19-
Action 18:Chris (Driver), John (Navigator), Bill, Seth,
20-
Action 19:Chris (Navigator), John, Bill, Seth (Driver),
21-
Action 20:Chris, John, Bill (Driver), Seth (Navigator),
22-
Action 21:John, Chris, Bill (Driver), Seth (Navigator),
23-
Action 22:John, Chris, Bill (Driver), Seth (Navigator), Fredrick,
24-
Action 23:John, Bill, Chris (Driver), Seth (Navigator), Fredrick,
25-
Action 24:John, Chris, Seth (Driver), Fredrick (Navigator),
26-
Action 25:Chris (Navigator), Seth, Fredrick (Driver),
27-
Action 26:Seth (Driver), Fredrick (Navigator),
14+
Action 13:Joe, Chris, Sam (Driver), John (Navigator), Bill,
15+
Action 14:Joe, Chris, Sam, John (Driver), Bill (Navigator),
16+
Action 15:Joe (Navigator), Chris, Sam, John, Bill (Driver),
17+
Action 16:Joe (Driver), Chris (Navigator), Sam, John, Bill,
18+
Action 17:Joe, Chris (Driver), Sam (Navigator), John, Bill,
19+
Action 18:Sam removed
20+
Action 19:Joe, Chris (Driver), John (Navigator), Bill,
21+
Action 20:Joe removed
22+
Action 21:Chris, John (Driver), Bill (Navigator),
23+
Action 22:Chris (Navigator), John, Bill (Driver),
24+
Action 23:Chris, John (Driver), Bill (Navigator),
25+
Action 24:Seth added
26+
Action 25:Chris, John (Driver), Bill (Navigator), Seth,
27+
Action 26:Chris (Driver), John (Navigator), Bill, Seth,
28+
Action 27:Chris (Navigator), John, Bill, Seth (Driver),
29+
Action 28:Chris, John, Bill (Driver), Seth (Navigator),
30+
Action 29:John, Chris, Bill (Driver), Seth (Navigator),
31+
Action 30:Fredrick added
32+
Action 31:John, Chris, Bill (Driver), Seth (Navigator), Fredrick,
33+
Action 32:John, Bill, Chris (Driver), Seth (Navigator), Fredrick,
34+
Action 33:Bill removed
35+
Action 34:John, Chris, Seth (Driver), Fredrick (Navigator),
36+
Action 35:John removed
37+
Action 36:Chris (Navigator), Seth, Fredrick (Driver),
38+
Action 37:Chris removed
39+
Action 38:Seth (Driver), Fredrick (Navigator),

tests/Infrastructure/MobberManager/test_MobberManager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ def time_change_callback(mobber_list, driver_index, navigator_index):
117117

118118
mobber_manager.subscribe_to_mobber_list_change(time_change_callback)
119119

120+
def on_mobber_add(mobber_name):
121+
result["increment"] += 1
122+
result["result"] += "Action " + result["increment"].__str__() + ":" + mobber_name + " added\n"
123+
124+
mobber_manager.subscribe_to_mobber_add(on_mobber_add)
125+
126+
127+
def on_mobber_remove(mobber_name):
128+
result["increment"] += 1
129+
result["result"] += "Action " + result["increment"].__str__() + ":" + mobber_name + " removed\n"
130+
131+
mobber_manager.subscribe_to_mobber_remove(on_mobber_remove)
132+
120133
mobber_manager.add_mobber("Joe")
121134
mobber_manager.add_mobber("Chris")
122135
mobber_manager.add_mobber("Sam")

0 commit comments

Comments
 (0)