-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathteam_editor.py
310 lines (251 loc) · 10.1 KB
/
team_editor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
"""OBSPokemonHUD - Team Editor
This is the team editor script for OBS, so you can do it all self-contained
"""
import json
import obspython as obs
# Enabled for some extra debug output to the script log
# True or False (they need to be capitals for Python)
debug = False
# The location for the JSON file
json_file = ""
# Team information
team = {
"slot1": {
"dexnumber": 0,
"shiny": False,
},
"slot2": {
"dexnumber": 0,
"shiny": False,
},
"slot3": {
"dexnumber": 0,
"shiny": False,
},
"slot4": {
"dexnumber": 0,
"shiny": False,
},
"slot5": {
"dexnumber": 0,
"shiny": False,
},
"slot6": {
"dexnumber": 0,
"shiny": False,
},
}
def script_description():
"""Sets up the description
This is a built-in OBS function.
It outputs the value for the description part of the "Scripts" window for
this script.
"""
return "OBSPokemonHUD - Team Editor.\nAlso by Tom."
def script_properties():
"""Sets up the properties section of the "Scripts" window.
This is a built-in OBS function.
It sets up the properties part of the "Scripts" screen for this script.
Returns:
properties
"""
# Declare the properties object for us to mess with
properties = obs.obs_properties_create()
# Add in a file path property for the team.json file
obs.obs_properties_add_path(properties, "json_file", "Team JSON File", obs.OBS_PATH_FILE, "*.json", None)
# Set up the sprite style dropdown
display_type = obs.obs_properties_add_list(
properties, # The properties variable
"display_type", # Setting identifier string
"Display Type", # Localized name shown to user
obs.OBS_COMBO_TYPE_EDITABLE, # Whether it's editable or not
obs.OBS_COMBO_FORMAT_STRING, # The type of format to display
)
obs.obs_property_list_add_string(
display_type,
"Dex",
"dex"
)
# ------------------------------------------------------
obs.obs_properties_add_int(
properties, # The properties variable
"team_member_dex_1", # Setting identifier string
"Member 1 (Dex No.)", # display name
0, # Starting number
898, # Ending number
1, # Increment by
)
obs.obs_properties_add_bool(
properties, # The properties variable
"team_member_shiny_1", # Setting identifier string
"Member 1 Shiny?", # display name
)
obs.obs_properties_add_int(
properties, # The properties variable
"team_member_dex_2", # Setting identifier string
"Member 2 (Dex No.)", # display name
0, # Starting number
898, # Ending number
1, # Increment by
)
obs.obs_properties_add_bool(
properties, # The properties variable
"team_member_shiny_2", # Setting identifier string
"Member 2 Shiny?", # display name
)
obs.obs_properties_add_int(
properties, # The properties variable
"team_member_dex_3", # Setting identifier string
"Member 3 (Dex No.)", # display name
0, # Starting number
898, # Ending number
1, # Increment by
)
obs.obs_properties_add_bool(
properties, # The properties variable
"team_member_shiny_3", # Setting identifier string
"Member 3 Shiny?", # display name
)
obs.obs_properties_add_int(
properties, # The properties variable
"team_member_dex_4", # Setting identifier string
"Member 4 (Dex No.)", # display name
0, # Starting number
898, # Ending number
1, # Increment by
)
obs.obs_properties_add_bool(
properties, # The properties variable
"team_member_shiny_4", # Setting identifier string
"Member 4 Shiny?", # display name
)
obs.obs_properties_add_int(
properties, # The properties variable
"team_member_dex_5", # Setting identifier string
"Member 5 (Dex No.)", # display name
0, # Starting number
898, # Ending number
1, # Increment by
)
obs.obs_properties_add_bool(
properties, # The properties variable
"team_member_shiny_5", # Setting identifier string
"Member 5 Shiny?", # display name
)
obs.obs_properties_add_int(
properties, # The properties variable
"team_member_dex_6", # Setting identifier string
"Member 6 (Dex No.)", # display name
0, # Starting number
898, # Ending number
1, # Increment by
)
obs.obs_properties_add_bool(
properties, # The properties variable
"team_member_shiny_6", # Setting identifier string
"Member 6 Shiny?", # display name
)
obs.obs_properties_add_button(
properties, # The properties variable
"save_button", # Setting identifier string
"Save",
save_button_clicked
)
if debug:
print("Function: Properties")
# Finally, return the properties so they show up
return properties
def script_defaults(settings):
"""Sets the default values
This is a built-in OBS function.
It sets all of the default values when the user presses the "Defaults"
button on the "Scripts" screen.
"""
# Team member dex no.
obs.obs_data_set_default_int(settings, "team_member_dex_1", 0)
obs.obs_data_set_default_int(settings, "team_member_dex_2", 0)
obs.obs_data_set_default_int(settings, "team_member_dex_3", 0)
obs.obs_data_set_default_int(settings, "team_member_dex_4", 0)
obs.obs_data_set_default_int(settings, "team_member_dex_5", 0)
obs.obs_data_set_default_int(settings, "team_member_dex_6", 0)
# Team member shiny state
obs.obs_data_set_default_bool(settings, "team_member_shiny_1", False)
obs.obs_data_set_default_bool(settings, "team_member_shiny_2", False)
obs.obs_data_set_default_bool(settings, "team_member_shiny_3", False)
obs.obs_data_set_default_bool(settings, "team_member_shiny_4", False)
obs.obs_data_set_default_bool(settings, "team_member_shiny_5", False)
obs.obs_data_set_default_bool(settings, "team_member_shiny_6", False)
# If debug is enabled, print out this bit of text
if debug:
print("Function: Defaults")
def script_update(settings):
"""Updates the settings values
This is a built-in OBS function.
This runs whenever a setting is changed or updated for the script. It also
sets up and removes the timer.
"""
global json_file
global team
# If the team json file isn't given, return out so nothing happens
if not obs.obs_data_get_string(settings, "json_file"):
if debug:
print("Conditional: Returning because no JSON file is given")
return
if json_file != obs.obs_data_get_string(settings, "json_file"):
# If debug is enabled, print out this bit of text
if debug:
print("Conditional: New JSON File")
json_file = obs.obs_data_get_string(settings, "json_file")
with open(obs.obs_data_get_string(settings, "json_file"), 'r') as file:
new_team_data = json.load(file)
obs.obs_data_set_int(settings, "team_member_dex_1", new_team_data['slot1']['dexnumber'])
obs.obs_data_set_int(settings, "team_member_dex_2", new_team_data['slot2']['dexnumber'])
obs.obs_data_set_int(settings, "team_member_dex_3", new_team_data['slot3']['dexnumber'])
obs.obs_data_set_int(settings, "team_member_dex_4", new_team_data['slot4']['dexnumber'])
obs.obs_data_set_int(settings, "team_member_dex_5", new_team_data['slot5']['dexnumber'])
obs.obs_data_set_int(settings, "team_member_dex_6", new_team_data['slot6']['dexnumber'])
obs.obs_data_set_bool(settings, "team_member_shiny_1", new_team_data['slot1']['shiny'])
obs.obs_data_set_bool(settings, "team_member_shiny_2", new_team_data['slot2']['shiny'])
obs.obs_data_set_bool(settings, "team_member_shiny_3", new_team_data['slot3']['shiny'])
obs.obs_data_set_bool(settings, "team_member_shiny_4", new_team_data['slot4']['shiny'])
obs.obs_data_set_bool(settings, "team_member_shiny_5", new_team_data['slot5']['shiny'])
obs.obs_data_set_bool(settings, "team_member_shiny_6", new_team_data['slot6']['shiny'])
# Update the dex numbers
team['slot1']['dexnumber'] = obs.obs_data_get_int(settings, "team_member_dex_1")
team['slot2']['dexnumber'] = obs.obs_data_get_int(settings, "team_member_dex_2")
team['slot3']['dexnumber'] = obs.obs_data_get_int(settings, "team_member_dex_3")
team['slot4']['dexnumber'] = obs.obs_data_get_int(settings, "team_member_dex_4")
team['slot5']['dexnumber'] = obs.obs_data_get_int(settings, "team_member_dex_5")
team['slot6']['dexnumber'] = obs.obs_data_get_int(settings, "team_member_dex_6")
# Update their shiny-ness
team['slot1']['shiny'] = obs.obs_data_get_bool(settings, "team_member_shiny_1")
team['slot2']['shiny'] = obs.obs_data_get_bool(settings, "team_member_shiny_2")
team['slot3']['shiny'] = obs.obs_data_get_bool(settings, "team_member_shiny_3")
team['slot4']['shiny'] = obs.obs_data_get_bool(settings, "team_member_shiny_4")
team['slot5']['shiny'] = obs.obs_data_get_bool(settings, "team_member_shiny_5")
team['slot6']['shiny'] = obs.obs_data_get_bool(settings, "team_member_shiny_6")
# If debug is enabled, print out this bit of text
if debug:
print("Function: Script Update")
def save_button_clicked(properties, p):
"""Activates when the save button is pressed
Args:
properties (SwigPyObject): ¯\\_(ツ)_/¯
p (SwigPyObject): ¯\\_(ツ)_/¯
"""
save_team()
def save_team():
"""Saves the team information in to the team.json file that has been given
Returns:
None: Returns / exits the function if no JSON file is set
"""
global json_file
global team
if not json_file:
return
with open(json_file, 'w') as file:
json.dump(team, file, indent=4)
if debug:
print("Function: save_team")
print(f"JSON file: {json_file}")
print(f"Team data: {json.dumps(team)}")