Skip to content

Commit d77170d

Browse files
committed
On the "Project_Zomboid" module, I made the following changes:
I created its new sub-class "Add_A_New_Survivor". It asks the user to enter the new survivor's information. Such as name, gender, and date of birth. Using a list of genders to be selected. And checking the correct age (between 27 and 100) and date of birth (any day and month, with the year from 1893 to 1966) formats. Then the sub-class asks the user to select the survivor's city. Utilizing the new root method "Select_City", which returns the city dictionary. After that, the sub-class creates the new survivor's folder and its survivor file, writing to it. Then it updates the files of survivors and cities when executing the root class again. After that, the sub-class executes the other sub-class "Create_Survival_Diary_File". To create the new survivor's first survival diary file.
1 parent 6fbf4cc commit d77170d

File tree

8 files changed

+266
-21
lines changed

8 files changed

+266
-21
lines changed

Module Files/Food_Time/Times.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"Will be hungry": 3
1111
},
1212
"Ate": {
13-
"Object": "2024-04-22 20:45:31-03:00",
13+
"Object": "2024-04-23 20:59:33-03:00",
1414
"Time": 0,
15-
"Time text": "20:45",
15+
"Time text": "20:59",
1616
"Unit": {
1717
"en": "hours",
1818
"pt": "horas"
@@ -23,9 +23,9 @@
2323
}
2424
},
2525
"Can drink water": {
26-
"Object": "2024-04-22 21:25:31-03:00",
26+
"Object": "2024-04-23 21:39:33-03:00",
2727
"Time": 40,
28-
"Time text": "21:25",
28+
"Time text": "21:39",
2929
"Unit": {
3030
"en": "minutes",
3131
"pt": "minutos"
@@ -36,9 +36,9 @@
3636
}
3737
},
3838
"Will be hungry": {
39-
"Object": "2024-04-22 23:45:31-03:00",
39+
"Object": "2024-04-23 23:59:33-03:00",
4040
"Time": 3,
41-
"Time text": "23:45",
41+
"Time text": "23:59",
4242
"Unit": {
4343
"en": "hours",
4444
"pt": "horas"

Module Files/Project_Zomboid/Texts.json

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
"en": "Select a survivor to survive as them",
1212
"pt": "Selecione um sobrevivente para sobreviver como ele"
1313
},
14+
"type_the_name_of_the_survivor": {
15+
"en": "Type the name of the survivor",
16+
"pt": "Digite o nome do sobrevivente"
17+
},
18+
"type_the_details_of_the_survivor": {
19+
"en": "Type the details of the survivor",
20+
"pt": "Digite os detalhes do sobrevivente"
21+
},
1422
"the_class_used_a_survivor": {
1523
"en": "The class used a predefined survivor",
1624
"pt": "A classe utilizou um sobrevivente pré-definido"

Module Files/Utility/Global_Switches/Switches.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"testing": true,
2+
"testing": false,
33
"verbose": true,
44
"user_information": false,
55
"Has active switches": false

Module Files/Utility/Language/Texts.json

+20-8
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@
167167
"en": "You selected this option",
168168
"pt": "Você selecionou essa opção"
169169
},
170+
"leave_empty_to_use_the_default_value": {
171+
"en": "Leave empty to use the default value",
172+
"pt": "Deixe vazio para usar o valor padrão"
173+
},
170174
"press_enter_when_you": {
171175
"en": "Press Enter when you",
172176
"pt": "Pressione Enter quando você"
@@ -241,10 +245,6 @@
241245
"pt": "Idiomas",
242246
"en": "Languages"
243247
},
244-
"language_with_country, title()": {
245-
"pt": "Idioma Com País",
246-
"en": "Language With Country"
247-
},
248248
"full_language, title()": {
249249
"pt": "Idioma Completo",
250250
"en": "Full Language"
@@ -373,10 +373,6 @@
373373
"pt": "Idiomas",
374374
"en": "Languages"
375375
},
376-
"language_with_country, title()": {
377-
"pt": "Idioma Com País",
378-
"en": "Language With Country"
379-
},
380376
"full_language, title()": {
381377
"pt": "Idioma Completo",
382378
"en": "Full Language"
@@ -665,6 +661,10 @@
665661
"en": "Title in English"
666662
}
667663
},
664+
"country, title()": {
665+
"pt": "País",
666+
"en": "Country"
667+
},
668668
"state": {
669669
"pt": "estado",
670670
"en": "state"
@@ -1041,6 +1041,10 @@
10411041
"en": "Releases",
10421042
"pt": "Lançamentos"
10431043
},
1044+
"release_date": {
1045+
"en": "Release date",
1046+
"pt": "Data de lançamento"
1047+
},
10441048
"written_in": {
10451049
"en": "Written in",
10461050
"pt": "Escrito em"
@@ -2026,6 +2030,10 @@
20262030
"en": "Deceased",
20272031
"pt": "Falecidos"
20282032
},
2033+
"wikipedia, title()": {
2034+
"en": "Wikipedia",
2035+
"pt": "Wikipédia"
2036+
},
20292037
"it_is": {
20302038
"en": "it is",
20312039
"pt": "é"
@@ -2101,6 +2109,10 @@
21012109
"last",
21022110
"in"
21032111
],
2112+
"select_the_gender": {
2113+
"en": "Select the gender",
2114+
"pt": "Selecione o gênero"
2115+
},
21042116
"genders, type: list": {
21052117
"en": [
21062118
"Feminine",

Modules/Project_Zomboid/Add_A_New_Survivor/__init__.py

+184-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,187 @@
44

55
class Add_A_New_Survivor(Project_Zomboid):
66
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)

Modules/Project_Zomboid/Create_Survival_Diary_File/__init__.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from copy import deepcopy
66

77
class Create_Survival_Diary_File(Project_Zomboid):
8-
def __init__(self):
8+
def __init__(self, dictionary = {}):
99
super().__init__()
1010

1111
# Define the root dictionary
@@ -15,13 +15,30 @@ def __init__(self):
1515
"City": {}
1616
}
1717

18+
# If the dictionary parameter is not an empty dictionary
19+
if dictionary != {}:
20+
# Define the list of keys to update on the root dictionary
21+
keys = [
22+
"Survivor",
23+
"City"
24+
]
25+
26+
# Iterate through the list of keys
27+
for key in keys:
28+
# If the key is inside the dictionary parameter
29+
if key in dictionary:
30+
# Update the key in the root dictionary
31+
self.dictionary[key] = dictionary[key]
32+
1833
# Define the "States" dictionary
1934
self.states = {
2035
"Used pre-defined values": False
2136
}
2237

23-
# Select the survivor
24-
self.Select_A_Survivor()
38+
# If the survivor is not already defined
39+
if self.dictionary["Survivor"] == {}:
40+
# Select the survivor
41+
self.Select_A_Survivor()
2542

2643
# Define the "Date" dictionary
2744
self.Define_Date()
@@ -82,6 +99,9 @@ def Define_Date(self):
8299
# Add one to the survival day number
83100
self.diary["Numbers"]["Survival day"] += 1
84101

102+
# Define the "Date" dictionary
103+
self.dictionary = self.Define_Date_Dictionary(self.dictionary)
104+
85105
# Update the "Survivor.json" file with the root "Update_Dictionary" method
86106
self.Update_Dictionary(self.dictionary["Survivor"])
87107

0 commit comments

Comments
 (0)