Skip to content

Commit e8e1019

Browse files
committed
import and formatting fixes
1 parent 94b38ec commit e8e1019

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

save_sphere.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import datetime
12
import json
23
import logging
34
import math
5+
import os
6+
import shutil
47

8+
from jsonmerge import merge
9+
10+
import battle.main
11+
import load_game
512
import memory
613
import pathing
714
import vars
815
import xbox
9-
import battle.main
10-
import datetime
11-
import load_game
12-
import shutil
13-
from jsonmerge import merge
1416

1517
FFXC = xbox.controller_handle()
1618

@@ -70,15 +72,15 @@ def approach_save_sphere():
7072
target_coords = memory.main.get_actor_coords(target_actor)
7173
target_details = get_save_sphere_settings(target_actor)
7274
logger.debug(f"Approaching actor: {target_actor}")
73-
75+
7476
# Time-out logic
7577
start_timer = datetime.datetime.now()
7678
if target_actor == 999:
77-
logger.debug(f"Disregard, save sphere could not be found.")
79+
logger.debug("Disregard, save sphere could not be found.")
7880
return False
7981
else:
80-
logger.debug(f"80 second time-out logic.")
81-
logger.debug(f"The run is NOT SOFT LOCKED")
82+
logger.debug("80 second time-out logic.")
83+
logger.debug("The run is NOT SOFT LOCKED")
8284
while not (
8385
memory.main.diag_progress_flag() == target_details[2]
8486
and memory.main.diag_skip_possible()
@@ -89,7 +91,7 @@ def approach_save_sphere():
8991
if total_time.total_seconds() > 80:
9092
logger.debug("Save sphere time out - could not reach save sphere.")
9193
return False
92-
94+
9395
# Touch sphere logic
9496
if memory.main.user_control():
9597
pathing.set_movement([target_coords[0], target_coords[1]])
@@ -139,6 +141,7 @@ def approach_save_sphere():
139141
FFXC.set_neutral()
140142
return True
141143

144+
142145
def disengage_save_sphere():
143146
while memory.main.save_menu_cursor() == 0 and memory.main.save_menu_cursor_2() == 0:
144147
logger.debug("Cursor")
@@ -153,7 +156,7 @@ def touch_and_go():
153156
disengage_save_sphere()
154157

155158

156-
def touch_and_save(save_num: int = 999, game_state:str="tbd", step_count:int=999):
159+
def touch_and_save(save_num: int = 999, game_state: str = "tbd", step_count: int = 999):
157160
if game_vars.nemesis():
158161
save_num += 80
159162
if save_num >= 200:
@@ -213,19 +216,19 @@ def touch_and_save(save_num: int = 999, game_state:str="tbd", step_count:int=999
213216
logger.debug(file_dest)
214217

215218
shutil.move(src=file_orig, dst=file_dest)
216-
219+
217220
# Finally, register save in json.
218-
if save_num not in [199,999]:
221+
if save_num not in [199, 999]:
219222
# 199 is used for Arena battles. Reserved.
220223
# 999 means any unused save. No special save for this.
221-
if game_state == "tbd" or step_count==999:
224+
if game_state == "tbd" or step_count == 999:
222225
return
223-
226+
224227
print("Registering save")
225-
filepath = os.path.join('json_ai_files', 'save_load_details.json')
228+
filepath = os.path.join("json_ai_files", "save_load_details.json")
226229
with open(filepath, "r") as fp:
227230
results = json.load(fp)
228-
231+
229232
# game_state already a string
230233
step_count_val = str(step_count)
231234
nem_value = str(game_vars.nemesis())
@@ -234,7 +237,7 @@ def touch_and_save(save_num: int = 999, game_state:str="tbd", step_count:int=999
234237
end_game_version_val = str(game_vars.end_game_version())
235238
nea_zone = str(game_vars.get_nea_zone())
236239
nem_ap_val = str(game_vars.nem_checkpoint_ap())
237-
240+
238241
new_val = {
239242
game_state: {
240243
step_count_val: {
@@ -244,7 +247,7 @@ def touch_and_save(save_num: int = 999, game_state:str="tbd", step_count:int=999
244247
"end_game_version_val": end_game_version_val,
245248
"nea_zone": nea_zone,
246249
"nem_ap_val": nem_ap_val,
247-
"special_movement": "none"
250+
"special_movement": "none",
248251
}
249252
}
250253
}
@@ -253,8 +256,9 @@ def touch_and_save(save_num: int = 999, game_state:str="tbd", step_count:int=999
253256
with open(filepath, "w") as fp:
254257
json.dump(results, fp, indent=4)
255258

259+
256260
def get_save_sphere_settings(actor_index: int):
257-
filepath = os.path.join('json_ai_files', 'save_sphere_details.json')
261+
filepath = os.path.join("json_ai_files", "save_sphere_details.json")
258262
with open(filepath, "r") as fp:
259263
results = json.load(fp)
260264

@@ -275,7 +279,7 @@ def get_save_sphere_settings(actor_index: int):
275279

276280

277281
def record_save_sphere(x_val: int, y_val: int, diag_prog: int, actor: int):
278-
filepath = os.path.join('json_ai_files', 'save_sphere_details.json')
282+
filepath = os.path.join("json_ai_files", "save_sphere_details.json")
279283
logger.debug(f"Recording save sphere to {filepath}")
280284
with open(filepath, "r") as fp:
281285
records = json.load(fp)

0 commit comments

Comments
 (0)