4
4
5
5
class Add_A_New_Survivor (Project_Zomboid ):
6
6
def __init__ (self ):
7
- super ().__init__ ()
7
+ super ().__init__ ()
8
+
9
+ # Define the root dictionary
10
+ self .dictionary = {
11
+ "Survivor" : {},
12
+ "City" : {}
13
+ }
14
+
15
+ # Type the information about the survivor
16
+ self .Type_Survivor_Information ()
17
+
18
+ # Update the files of the survivor
19
+ self .Update_Files ()
20
+
21
+ # Execute the root class again to define the variables of the survivor
22
+ super ().__init__ ()
23
+
24
+ # Create the first survival diary file
25
+ self .Create_Survival_Diary_File ()
26
+
27
+ def Type_Survivor_Information (self ):
28
+ # Define the default local "Survivor" dictionary
29
+ survivor = {
30
+ "Name" : "" ,
31
+ "City" : "" ,
32
+ "Details" : {
33
+ "Gender" : "" ,
34
+ "Age" : 27 ,
35
+ "Date of birth" : "01/01/1966"
36
+ },
37
+ "Folders" : {
38
+ "root" : "" ,
39
+ "Survivor" : ""
40
+ },
41
+ "Diary" : {
42
+ "Numbers" : {
43
+ "Survival day" : 0 ,
44
+ "Day" : 8 ,
45
+ "Month" : 7 ,
46
+ "Year" : 1993
47
+ },
48
+ "Folders" : {}
49
+ }
50
+ }
51
+
52
+ # Ask for the name of the survivor
53
+ survivor ["Name" ] = self .Input .Type (self .language_texts ["type_the_name_of_the_survivor" ], accept_enter = False , next_line = True )
54
+
55
+ # Show the text telling the user to type the details about the survivor
56
+ print ()
57
+ print (self .separators ["5" ])
58
+ print ()
59
+ print (self .language_texts ["type_the_details_of_the_survivor" ] + ":" )
60
+
61
+ # Ask for the details of the survivor
62
+ details = {
63
+ "Gender" : {
64
+ "Lists" : {
65
+ "en" : self .Language .texts ["genders, type: list" ]["en" ],
66
+ "Language" : self .Language .language_texts ["genders, type: list" ]
67
+ }
68
+ },
69
+ "Age" : {
70
+ "Regex" : {
71
+ "Regex" : "^([2][7-9]|[3-9][0-9]|100)$" ,
72
+ "Example" : "27"
73
+ }
74
+ },
75
+ "Date of birth" : {
76
+ "Regex" : {
77
+ "Regex" : "^(0[0-9]|3[0-1])/(0[0-9]|1[0-2])/(1893|196[0-6]|19[0-5][0-9])$" ,
78
+ "Example" : "01/01/1966"
79
+ }
80
+ }
81
+ }
82
+
83
+ # Iterate through the details in the "Details" dictionary
84
+ for key , detail in details .items ():
85
+ # Define the text key of the detail
86
+ text_key = key .lower ().replace (" " , "_" )
87
+
88
+ if "_" not in text_key :
89
+ text_key += ", title()"
90
+
91
+ # Define the text of the detail
92
+ text = self .Language .language_texts [text_key ]
93
+
94
+ # If the "Lists" key is inside the "Detail" dictionary
95
+ if "Lists" in detail :
96
+ # Define the plural text key
97
+ text_key = key .lower ().replace (" " , "_" ) + "s"
98
+
99
+ if "_" not in text_key :
100
+ text_key += ", title()"
101
+
102
+ # Create the plural text
103
+ plural_text = self .Language .language_texts [text_key ]
104
+
105
+ # Define the parameters dictionary for the "Select" method of the "Input" class
106
+ dictionary = {
107
+ "options" : detail ["Lists" ]["en" ],
108
+ "language_options" : detail ["Lists" ]["Language" ],
109
+ "show_text" : text ,
110
+ "select_text" : plural_text
111
+ }
112
+
113
+ # Ask the user to select an option from the list
114
+ typed = self .Input .Select (** dictionary )["option" ]
115
+
116
+ # If the "Regex" key is inside the "Detail" dictionary
117
+ if "Regex" in detail :
118
+ # Define the regex variable for easier typing
119
+ regex = detail ["Regex" ]
120
+
121
+ # Update the detail text to add the example
122
+ new_text = text + ":" + "\n " + \
123
+ "(" + self .Language .language_texts ["leave_empty_to_use_the_default_value" ] + ': "' + regex ["Example" ] + '")'
124
+
125
+ # Ask for the detail
126
+ typed = self .Input .Type (new_text , next_line = True )
127
+
128
+ # If the typed value is an empty string
129
+ if typed == "" :
130
+ # Define the typed variable as the default detail value
131
+ typed = regex ["Example" ]
132
+
133
+ # Show the default detail
134
+ print (text + ":" )
135
+ print (typed )
136
+
137
+ # If the typed value is not an empty string
138
+ if typed != "" :
139
+ # Import the "re" module
140
+ import re
141
+
142
+ # Search for the regex in the typed value
143
+ search = re .search (regex ["Regex" ], typed )
144
+
145
+ # If the value does not match the regex
146
+ if search == None :
147
+ # Ask for the detail again
148
+ typed = self .Input .Type (new_text , accept_enter = False , next_line = True , regex = regex )
149
+
150
+ # Add the detail to the "Details" dictionary of the "Survivor" dictionary
151
+ survivor ["Details" ][key ] = typed
152
+
153
+ # Ask the user to select the city of the survivor
154
+ city = self .Select_City ()
155
+
156
+ # Add the city name to the "Survivor" dictionary
157
+ survivor ["City" ] = city ["Name" ]
158
+
159
+ # Add the city to the root dictionary
160
+ self .dictionary ["City" ] = city
161
+
162
+ # Define the root "Survivor" dictionary as the local dictionary
163
+ self .dictionary ["Survivor" ] = survivor
164
+
165
+ def Update_Files (self ):
166
+ # Define and create the survivor folder
167
+ root_folder = self .project_zomboid ["Folders" ]["Survivors" ]["root" ]
168
+
169
+ self .dictionary ["Survivor" ]["Folders" ]["root" ] = root_folder + self .dictionary ["Survivor" ]["Name" ] + "/"
170
+ self .Folder .Create (self .dictionary ["Survivor" ]["Folders" ]["root" ])
171
+
172
+ # Define and create the "Survivor.json" file
173
+ self .dictionary ["Survivor" ]["Folders" ]["Survivor" ] = self .dictionary ["Survivor" ]["Folders" ]["root" ] + "Survivor.json"
174
+ self .File .Create (self .dictionary ["Survivor" ]["Folders" ]["Survivor" ])
175
+
176
+ # Update the "Survivor.json" file
177
+ self .Update_Dictionary (self .dictionary ["Survivor" ])
178
+
179
+ def Create_Survival_Diary_File (self ):
180
+ # Update the "Survivor" dictionary inside the root dictionary
181
+ self .dictionary ["Survivor" ] = self .project_zomboid ["Survivors" ]["Dictionary" ][self .dictionary ["Survivor" ]["Name" ]]
182
+
183
+ # Import the sub-class
184
+ from Project_Zomboid .Create_Survival_Diary_File import Create_Survival_Diary_File as Create_Survival_Diary_File
185
+
186
+ # Add it to this class
187
+ self .Create_Survival_Diary_File = Create_Survival_Diary_File
188
+
189
+ # Execute the sub-class with the root dictionary
190
+ self .Create_Survival_Diary_File (self .dictionary )
0 commit comments